# 2.3.1. Integrating systems of differential equations¶

In this tutorial we look into the integration of systems of differential equations, using example models from the domain of computational physiology. We also examine the the main control parameters that can have a significant impact on the performance and accuracy of a given method.

Contents:

## 2.3.1.1. Numerical integrators¶

### 2.3.1.1.1. Euler method¶

The Euler method to integrate a system of ordinary differential equations is probably the most well known method, particularly popular given its simplicity. Due to its simplicity it is, however, usually not the most appropriate method to use when performing simulation experiments with complex models of biological systems. It is, however, a very useful example to use to demonstrate key concepts that apply to most numerical integration methods.

Given the initial value problem

we now want to approximate \(y(t)\) over some interval \(t_0 \rightarrow t_{final}\). The Euler method approximates \(y(t)\) by dividing the interval into a series of steps, of size \(h\), and stepping through the interval. One step of the Euler method from \(t_n\) to \(t_{n+1} = t_n + h\) is given by

The value of \(y_n\) is an approximation of the solution of the ODE (2.1) at time \(t_n\): \(y_n \approx y(t_n)\). The Euler method proceeds through the interval in constant steps of size \(h\) until \(t_n = t_{final}\) and the integration is complete.

#### 2.3.1.1.1.1. Task 1 - The effect of step size¶

As you’d imagine, the size of \(h\) in the Euler method is crucial to the successful application of the method. For the successful (although perhaps inaccurate) integration of a typical physiological model (see the Physiome Repository for a collection of examples), \(h\) can be so small that the computational cost of performing the simulation is very high. In some cases, mathematical models may be unsuitable for integration by Euler method, regardless of how small the step size is reduced to.

In the following task, we investigate the effect of altering the size of \(h\) on two separate simulation experiments. The first looks at a simple mathematical model where the experiment could be replicated with pen and paper, while the second looks into the application of Euler’s method to a biophysical model of cellular electrophysiology.

In this task we use the trivial model:

As you can see from (2.3), if correctly integrated \(x(t)\) and \(y(t)\) should be identical. We now use this model to demonstrate the effect of step size (\(h\)) on simulating this model using Euler integration over the interval \(0 \rightarrow 2 \pi\).

- Run MAP Client, choose

.*HOME*/projects/mapclient-workflows/DTP-Simulation-Task1
and select - This simple workflow should look similar to Fig. 2.21. The workflow is pre-configured so there is no configuration required.

- Click the Execute button and you should get a widget displayed as per Fig. 2.22.

- As described in Fig. 2.22, multiple simulations can be performed with varying values for the step size, \(h\). Shown in Fig. 2.23 you can see that as \(h\) reduces in size, the approximation of the model (2.3) by integration using the Euler method gets more accurate.

- Now have a play with combining different values for the step size and the number of points to be obtained. See if you can answer the following.
- How small should \(h\) be to accurately simulate a sine wave?
- What do you think would happen beyond a single cycle?
- Given \(h = 1\), do you obtain a more accurate solution with a large number of points or a small number of points?

### 2.3.1.1.2. CVODE¶

From the Sundials suite of tools, CVODE is a solver for stiff and nonstiff ordinary differential equation (ODE) systems (initial value problem) given in explicit form in (2.1) above. CVODE is widely regarded as one of the gold standard implementations of a robust and flexible numerical integrator. One of the advantages of CVODE over Euler’s method is that it makes use of adaptive stepping over the interval of integration - rather than taking fixed sized steps through time, for example, CVODE will determine how quickly things are changing and adjust the size of the step accordingly.

#### 2.3.1.1.2.1. Task 2 - Fixed vs Adaptive stepping¶

In this task we examine the limitations and the computational costs associated with a fixed step method (Euler) compared to an adaptive step method (CVODE). Here we continue with our sine integration demonstration model to help highlight the differences.

- Run MAP Client, choose

.*HOME*/projects/mapclient-workflows/DTP-Simulation-Task2
and select - This simple workflow should look similar to that used in task 1 above (Fig. 2.21). The workflow is pre-configured so there is no configuration required.
- Click the Execute button and you should get a widget displayed as per Fig. 2.24.

- You can now easily see the difference between the two integration methods by directly comparing them, as shown in Fig. 2.25.

- Now have a play with step sizes, number of points, and integration methods to explore the features of these two integration methods and see if you can address these questions.
- What is the largest maximum step size you can use with CVODE to accurately simulate a sine wave with number of points being set to 2?
- How small does \(h\) need to be to get the same solution with Euler?
- Are either of those a useful solution?
- What is the minimum number of points required to capture an accurate sine wave?
- Can you determine a configuration for Euler and CVODE which demonstrates a cheaper, more accurate, simulation using CVODE with this model?

#### 2.3.1.1.2.2. Task 3 - Error control¶

In addition to providing adaptive stepping, CVODE is also a very configurable solver. Beyond the maximum step size explored above, a further control parameter of that is often of interest are the tolerances used to control the accumulation of error in the numerical approximation of the mathematical model. This tolerance specifies how accurate we require the solution of the integration to be, and the value used can be very specific to the mathematical model being simulated. In task 2 above, we used a tolerance of 1.0e-7. Depending on the behaviour of your mathematical model, you may need to tighten (reduce) or loosen (increase) the tolerance values, depending on the specific application the model is being used for. Here we explore the effect of the tolerance value on the ICC model introduced above.

We use the recent biophysically based mathematical model of unitary potential activity in interstitial cells of Cajal. The interstitial cells of Cajal (ICC) are the pacemaker cells of the gastrointestinal tract and provide the electrical stimulus required to activate the contraction of smooth muscle cells nescessary for the correct behaviour of the GI tract. This particular model was developed by scientists at the Auckland Bioengineering Institute to investigate a specific hypothesis regarding the biophysical mechanism underlying the pacemaker function of ICCs.

- Run MAP Client, choose

.*HOME*/projects/mapclient-workflows/DTP-Simulation-Task3
and select - This simple workflow should look similar to that used in task 1 above (Fig. 2.21). The workflow is pre-configured so there is no configuration required.
- Click the Execute button and you should get a widget displayed as per Fig. 2.26.

- You can now investigate the effect of changing the tolerance value and maximum step size on the simulation result. Not all combinations will successfully complete. Example results are shown in Fig. 2.27.

- After exploring the effects of the integrator parameters and the simulated model behaviour, see if you can answer the following questions.
- With \(h=0.0\), how loose can the tolerance be and still get an accurate solution?
- How tight can you make the tolerance before the computational cost outweighs any improvement in solution accuracy?
- Is there any value of \(h\) that will give an accurate solution for a tolerance of 0.01?