Euler methods of solving ODES

Ordinary Differential Equations may well be the simplest solution methods, but are prone to errors during evaluation.

A number of steps are used to advance a parameter through time (or space, depending on the equation). For example:

d/dt(N)=-k.N

(rate of change of number proportional to the population).

The Euler method is:

time=0
loop (until fed up) {
N=N-k.N*dt
time=time+dt
}

Or in tcl

proc test {} {
set mass 1
set dt 0.001 ;# try shortening dt to see numerical inaccuracy
# use single equation Euler scheme- log decay of radioactivity, dN/dt=-n solution: N(t)=exp(-t)
set tpr 0.1
set nextpr $tpr
for {set time 0} {[expr $time<=2] } { set time [expr $time+$dt]} {
if {$time>=$nextpr} {
puts "At time $time mass is $mass"
set nextpr [expr $nextpr+$tpr]
}
set mass [expr $mass-1.0*$mass*$dt] ;# dmass/dt = -mass - mass=m0(1-exp(time/k))
}
}
test

The solution at time=1 is 0.3486784401; the theoretical value is 0.367879441171 and

Runge-Kutta with the same problem and time step gives 0.367885238126.

For Euler achieve similar accuracy to RK needs a time step of 0.001 (and the solution is only 0.36769542477, 3 digits). Thus rk uses 4 evaluations, Euler needs 1000 evaluations of the driving function. The winner is R-K!

AM Note that R-K implicitly assumes very smooth solutions to achieve the accuracy. This is not always the case. Also R-K loses usefulness when it comes to partial differential equations.