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:
yi = y(i-1)
for i=1, 2, 3, ..., n. The n-dimensional system of first-order coupled ODEs is then:
y = y1
y'1 = y2
y'2 = y3
y'n-1 = yn
y'n = F(x, y1, y2, y3, ..., yn)
The first-order ODE can be solved using a few methods in iFlow.
The Euler method
y'(t) = f(t, y(t)), y(t0) = y0
Choose a value h for the size of every step and set tn = t0 + nh. Now, one step of the Euler method from tn to tn+1 is
yn+1 = yn + hf(tn, yn)
The value of yn is an approximation of the solution to the ODE at time tn: yn ≈ y(tn). We can easily implement this and compare the numerical solution with the exact solution in iFlow:
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:
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):
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:
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 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:
This is basically the way we use the ODE Solver block to solve two-body, three-body, and other complex problems.