280 likes | 996 Views
How to solve ODE's in the real world: Runge-Kutta methods. Not the only way, but a good first start!. What is wrong with good old Euler? It is expensive (what do I mean by this?) And you don't know when it is right! Like a measurement without an error!. How did we fix this problem?
E N D
How to solve ODE's in the real world: Runge-Kutta methods Not the only way, but a good first start!
What is wrong with good old Euler? • It is expensive (what do I mean by this?) • And you don't know when it is right! • Like a measurement without an error!
How did we fix this problem? • we reduced the timestep Dt until the solutions "converged." (define) • should get same answer for t and t/2
But should we not have the computer do this itself? • Runge-Kutta techniques can change step size automatically • They can also take the bigger step sizes and get less error then Euler's method.
So where does error come from? • The faster d(Pop)/dt changes with time, the bigger the error. • Depends on
How do Runge-Kutta algorithms solve these problems? • First, they are more accurate, so less error for a given t • Describe vrs. Euler's • Left-hand side is Euler • Right-hand side is Midpoint or second order Runge-Kutta • Much more accurate than Euler's for a given t
Just as importantly, with Runge-Kutta we automatically see how d(Pop)/dt is changing with t • How? • If d(Pop)/dt is too much, decrease t • If too small, increase t • This is tricky to implement yourself! • Usually best to stick to canned routines.
There are more Runge-Kutta methods… • Very good for smooth solutions; advanced solvers switch between lower order and higher order solutions • Only good when increased t offsets increased number of function evaluations
Example: • Euler with 0.05 day time step • 2nd order Runge-Kutte with variable timestep • note the difference in time step • much faster to solve on computer!
Examine beginning • * are points returned, 'o' are all function evaluations. • Not quite a pure 2nd order RK. (why?) • Note search for optimal timestep
Examine decrease in timesteps? • How/when does it do it? Note peak confusion!
Conclusions: • In real life, never use Euler (almost never…) • Use R-K with adaptive time step • or equivalent • Numerical Recipies (Press et al.) is a good reference • Usually not worth writing your own. • How do you solve it with Matlab? • Monday!