DIFFERENTIAL EQUATIONS 09

Numerical Methods for ODEs

When an exact formula is difficult or impossible to obtain, numerical methods approximate the solution step by step.

The main idea

Consider an initial value problem

\[ \frac{dy}{dt}=f(t,y), \qquad y(t_0)=y_0. \]

The differential equation tells us the slope of the solution at each point.

A numerical method uses this slope information to estimate future values of \(y\).

\[ \boxed{ \text{current value} + \text{estimated change} = \text{next value} } \]

1. Why numerical methods are needed

Some differential equations have simple exact solutions.

For example,

\[ \frac{dy}{dt}=y \]

has the solution

\[ y(t)=Ce^t. \]

But many differential equations, especially nonlinear systems, do not have a convenient closed-form solution.

We can still approximate their solutions numerically.

2. Divide time into steps

Choose a step size

\[ h>0. \]

Starting at \(t_0\), define

\[ t_1=t_0+h, \] \[ t_2=t_0+2h, \]

and in general

\[ \boxed{ t_n=t_0+nh } \]

The numerical method estimates the solution at these discrete time points.

3. From derivative to approximate change

Recall that

\[ \frac{dy}{dt} \]

represents the instantaneous rate of change.

Over a small time interval \(h\),

\[ \Delta y \approx \frac{dy}{dt}h. \]

Since

\[ \frac{dy}{dt}=f(t,y), \]

we obtain

\[ \boxed{ \Delta y \approx f(t,y)h } \]

4. Euler's method

Euler's method uses the slope at the beginning of each step.

If the current approximation is

\[ (t_n,y_n), \]

then

\[ \boxed{ y_{n+1} = y_n + h f(t_n,y_n) } \]

and

\[ t_{n+1}=t_n+h. \]

5. Understanding the formula

The Euler update

\[ y_{n+1} = y_n + h f(t_n,y_n) \]

has three parts:

\[ y_n = \text{current value}, \] \[ f(t_n,y_n) = \text{current rate of change}, \]

and

\[ h f(t_n,y_n) = \text{approximate change during the step}. \]

Therefore,

\[ \boxed{ \text{new value} = \text{old value} + \text{rate}\times\text{time step} } \]

6. A simple example

Consider

\[ \frac{dy}{dt}=y, \qquad y(0)=1. \]

Choose

\[ h=0.1. \]

Initially,

\[ t_0=0, \qquad y_0=1. \]

The initial slope is

\[ f(t_0,y_0)=y_0=1. \]

Therefore,

\[ y_1 = 1+(0.1)(1) = 1.1. \]

So

\[ \boxed{ y(0.1)\approx1.1 } \]

7. Take another step

Now

\[ t_1=0.1, \qquad y_1=1.1. \]

The new slope is

\[ f(t_1,y_1)=1.1. \]

Therefore,

\[ y_2 = 1.1+(0.1)(1.1). \]

Hence,

\[ y_2=1.21. \]

So

\[ \boxed{ y(0.2)\approx1.21 } \]

8. Continue step by step

For this example,

\[ y_{n+1} = y_n+0.1y_n. \]

Therefore,

\[ y_{n+1}=1.1y_n. \]

The approximations begin

\[ 1, \quad 1.1, \quad 1.21, \quad 1.331, \quad \ldots \]

The numerical trajectory is built one step at a time.

9. Compare with the exact solution

The exact solution of

\[ y'=y, \qquad y(0)=1 \]

is

\[ y=e^t. \]

At

\[ t=0.2, \]

the exact value is approximately

\[ e^{0.2}\approx1.2214. \]

Euler's method gave

\[ 1.21. \]

So the approximation is close, but not exact.

10. Geometric interpretation

At the current point, Euler's method follows the tangent line for a short distance.

Euler approximation compared with a smooth solution curve A smooth curved solution is approximated by several short straight tangent-line steps. t y short numerical steps

Because the true solution curves while the tangent line is straight, an approximation error is introduced during each step.

11. The step size matters

A smaller step size usually gives a more accurate approximation.

For example,

\[ h=0.01 \]

normally follows the solution more closely than

\[ h=0.5. \]

However, a smaller step size requires more calculations.

\[ \boxed{ \text{smaller }h \Rightarrow \text{usually greater accuracy but more computation} } \]

12. Local error

During one Euler step, the method replaces the curved solution by a tangent-line approximation.

The error introduced in a single step is called the local truncation error.

For Euler's method, the local truncation error is of order

\[ O(h^2). \]

13. Global error

Errors accumulate as many steps are taken.

Over a fixed time interval, the global error of Euler's method is generally of order

\[ \boxed{ O(h) } \]

under suitable regularity conditions.

This means that reducing \(h\) tends to reduce the overall error approximately in proportion to the step size.

14. Euler's method for a system

Suppose

\[ \frac{dx}{dt}=f(x,y), \] \[ \frac{dy}{dt}=g(x,y). \]

Euler's method updates both variables:

\[ \boxed{ x_{n+1} = x_n + h f(x_n,y_n) } \] \[ \boxed{ y_{n+1} = y_n + h g(x_n,y_n) } \]

Both new values are calculated from the state at the beginning of the step.

15. Example with an epidemic model

Consider the SIR system

\[ \frac{dS}{dt} = -\beta\frac{SI}{N}, \] \[ \frac{dI}{dt} = \beta\frac{SI}{N}-\gamma I, \] \[ \frac{dR}{dt} = \gamma I. \]

Euler's method gives

\[ S_{n+1} = S_n - h\beta\frac{S_nI_n}{N}, \] \[ I_{n+1} = I_n + h\left( \beta\frac{S_nI_n}{N} - \gamma I_n \right), \]

and

\[ R_{n+1} = R_n + h\gamma I_n. \]

This produces an approximate epidemic trajectory at discrete time points.

16. Continuous model, discrete calculation

The differential equation itself describes continuous time.

Euler's method does not change the ODE into a discrete-time model. It creates a discrete numerical approximation to the continuous solution.

\[ \boxed{ \text{continuous ODE} \neq \text{numerical time grid} } \]

The grid is a computational device used to approximate the continuous trajectory.

17. Better numerical methods

Euler's method uses only the slope at the beginning of each step.

More accurate methods use additional slope information.

One important family is the Runge–Kutta methods.

The widely used fourth-order Runge–Kutta method is commonly called RK4.

18. The idea behind RK4

Instead of relying on one slope, RK4 evaluates several slopes within each time step and combines them.

For

\[ y'=f(t,y), \]

define

\[ k_1=f(t_n,y_n), \] \[ k_2= f\left( t_n+\frac h2, y_n+\frac h2k_1 \right), \] \[ k_3= f\left( t_n+\frac h2, y_n+\frac h2k_2 \right), \]

and

\[ k_4= f(t_n+h,y_n+hk_3). \]

Then

\[ \boxed{ y_{n+1} = y_n + \frac h6 \left( k_1+2k_2+2k_3+k_4 \right) } \]

19. Numerical solution versus exact solution

An exact solution gives a function such as

\[ y(t)=e^t. \]

A numerical solution usually gives approximations

\[ y_0,\; y_1,\; y_2,\; \ldots \]

at selected time points

\[ t_0,\; t_1,\; t_2,\; \ldots \]
\[ \boxed{ \text{exact solution} \rightarrow \text{formula} } \] \[ \boxed{ \text{numerical solution} \rightarrow \text{sequence of approximations} } \]

20. Numerical methods do not remove the mathematics

A computer can perform thousands of numerical steps quickly, but the mathematical model still determines the calculation.

We must still understand the differential equation, initial conditions, parameter values, step size and possible numerical error.

21. The practical Euler method

\[ \boxed{ 1.\; \text{Write }y'=f(t,y) } \] \[ \boxed{ 2.\; \text{Specify }y(t_0)=y_0 } \] \[ \boxed{ 3.\; \text{Choose a step size }h } \] \[ \boxed{ 4.\; \text{Calculate the slope }f(t_n,y_n) } \] \[ \boxed{ 5.\; y_{n+1}=y_n+h f(t_n,y_n) } \] \[ \boxed{ 6.\; t_{n+1}=t_n+h } \] \[ \boxed{ 7.\; \text{Repeat} } \]

22. The central idea

A differential equation gives an instantaneous rate of change.

A numerical method uses that local information repeatedly to construct an approximation to the full trajectory.

\[ \boxed{ \text{slope} \times \text{small time step} \approx \text{small change} } \] \[ \downarrow \] \[ \boxed{ \text{repeat many times} } \] \[ \downarrow \] \[ \boxed{ \text{approximate solution trajectory} } \]