#### Ordinary Differential Equation Solvers

An ordinary differential equation (ODE) is a differential equation containing one or more functions of a single independent variable and the derivatives of those functions.
The term "ordinary" is used to differentiate an ODE from the partial differential equation (PDE) that involves multiple independent variables. In general, an explicit
ordinary differential equation of order *n* can be written as:

*F*(*x*, *y*, *y ^{'}*,

*y*, ...,

^{''}*y*) =

^{(n+1)}*y*

^{(n)}

To solve an ODE, it is a common practice to reduce the order of the equation. The above equation can be rewritten as a system of *n* first-order ODEs by defining a new family
of unknown functions:

*y*_{i} = y^{(i-1)}

for *i*=1, 2, 3, ..., *n*. The *n*-dimensional system of first-order coupled ODEs is then:

*y* = y_{1}

*y*^{'}_{1} = y_{2}

*y*^{'}_{2} = y_{3}

.

.

.

*y*^{'}_{n-1} = y_{n}

*y*^{'}_{n} = *F*(x, y_{1}, y_{2}, y_{3}, ..., y_{n})

The first-order ODE can be solved using a few methods in iFlow.

##### The Euler method

The Euler method is the simplest numerical procedure for solving first-order ODEs with a given initial value. An initial value problem is a differential equation of the following form:

*y*^{'}(t) = *f*(*t*, *y*(*t*)), *y*(*t*_{0}) = *y*_{0}

Choose a value *h* for the size of every step and set *t*_{n} = *t*_{0} + *nh*.
Now, one step of the Euler method from *t*_{n} to *t*_{n+1} is

*y*_{n+1} = *y*_{n} + *hf*(*t*_{n}, *y*_{n})

The value of *y*_{n} is an approximation of the solution to the ODE at time *t*_{n}:
*y*_{n} ≈ *y*(*t*_{n}). We can easily implement this and compare the numerical solution with the exact solution in iFlow:

Click HERE to play with the above example

The above implementation uses a Bundled Functions block to calculate the (*x*, *y*) points that are used to draw a line plot.
Although you can implement your own Euler solver, iFlow provides a built-in ODE solver for you to use. This solver is especially useful when you have a higher-order problem.
It would be cumbersome to have to break down the equation on your own each time. As you can see, the ODE
The following screenshot shows the ODE Solver block in action:

Click HERE to play with the above example

##### The Runge-Kutta method

Notice that the above screenshot also uses the fourth-order Runge-Kutta method (RK4) and compares its result with that of the Euler method. The ODE Solver block in iFlow provides a variety of methods for you to pick and choose. The Euler and RK4 methods are two of the options. As you can see, RK4 is generally more accurate than Euler, especially when you use a larger time step.

An advantage with the built-in ODE solver is that you can directly write one or more first-order ODEs into the setup window as shown below (except that, with the current version of iFlow, you still need to follow the JSON convention to surround each ODE with double quotes, separate the ODEs with a comma, and enclose them in a pair of square brackets):

Click HERE to play with the above example

##### The Velocity-Verlet method

The Velocity-Verlet method is a numerical procedure commonly used to integrate Newton's equation of motion, which is a second-order ODE:

*x*^{''} = *f*(*x*, *t*)/m

where *x* is the coordinate, *f* is the force function that depends on time and coordinate, and *m* is the mass. This equation can be reduced to two first-order ODEs as follows:

*x*^{'} = *v*

*v*^{'} = *f*(*x*, *t*)/m

where *v* is the velocity. The following screenshot shows the iFlow diagram for solving Newton's equation of motion using the built-in ODE Solver block:

Click HERE to play with the above example

We choose the Velocity-Verlet method in the above example as it conserves the total energy more accurately than the Euler method and the Runge-Kutta method. The Velocity-Verlet method is known as a symplectic integrator that preserves the form of Newton's equation of motion.

##### Coupled ODEs

Coupled ODEs involving multiple interrelated variables can be solved using the ODE Solver block as well. The following screenshot shows two harmonic oscillators connected by a spring between them:

Click HERE to play with the above example

This is basically the way we use the ODE Solver block to solve two-body, three-body, and other complex problems.