## Demonstration of class ODESolver usage: A differential system of equations

We present a program to solve by a numerical scheme a system of first-order linear differential equations of the form

```                  A1y' + A0y = f
```
where the matrices A0 and A1 are
```        | 0  -1 |            | 1  0 |       |      0       |
A0 = |       |,      A1 = |      |, f =  |              |
| 1  -1 |            | 0  1 |       | 3(t-1)exp(t) |

```
With adapted initial conditions, the solution is given by
```        y1(t) = t*exp(-t), y2(t) = (1-t)*exp(-t)

```
• After initializing the global variables theFinalTime and theTimeStep, we declare an instance of class ODESolver, where we have chosen the BDF2 scheme (2nd order Backward Difference Formula), and set the number of equations to 2.

 ``` ODESolver ode(BDF2,theTimeStep,theFinalTime,2); ```

• Once the instance created, we declare the matrices (as dense matrices) and send them to the class. Note that since their pointers are stored, their contents can be modified thrghout the time stepping. Next we declare the necessary vectors: the solution and the right-hand side vector. We give the initial condition using the member function setInitial, the right-hand side using setRHS and, since we deal with a two-step method, an initial right-hand side. Note that this is not mandatory but improves the accuracy.

 ``` DMatrix A0(2,2), A1(2,2); ode.setMatrices(A0,A1); Vect y(2), f(2); y(1) = 0; y(2) = 1; f(1) = 0; f(2) = -3; ode.setInitial(y); ode.setRHS(f); ode.setInitialRHS(f); ```

• Since the system of equations as well as data are given, in this example, by numerical values (rather than by algebraic expressions), we explicitly use a loop over time steps, where at each time step, the matrices, as well as the right-hand side are updated. Note that this is necessary even if the matrices are constant, since they are fatorized each time step.

 ``` TimeLoop { A1 = 1; A0(1,1) = 0; A0(1,2) = -1; A0(2,1) = 1; A0(2,2) = -1; f(1) = 0; f(2) = 3*(theTime-1)*exp(-theTime); ode.runOneTimeStep(); } ```