[What are ordinary differential equations? Read my detailed notes here on Evernote:Math:ODE]
Solving an ordinary differential equation is computationally expensive. One of the most common approximation methods used to solve this is euler. Understanding this for non math buffs means a lot of effort.(Lets say "Ordinary.Differential.Equations_Tenenbaum_Pollard" has too many pages). So I wrote a python program that implements both euler and its more accurate form the predictor corrector method and thought I will share it.
What are we trying to achieve?
When we plot from 0 to 3 with step size 0.01
-- Pure awesomeness :)
Solving an ordinary differential equation is computationally expensive. One of the most common approximation methods used to solve this is euler. Understanding this for non math buffs means a lot of effort.(Lets say "Ordinary.Differential.Equations_Tenenbaum_Pollard" has too many pages). So I wrote a python program that implements both euler and its more accurate form the predictor corrector method and thought I will share it.
What are we trying to achieve?
- Implement euler and corrector predictor method
- Plot them on a graph to understand their nature
- Compare the graph plots to visually understand the accuracy differences
What equation are we trying to solve?
dy/dx = x + 2y
What python libraries do we need?
import math
from pylab import *
Show me the code?
What are the results?
We can visually see from the following plots that
When we plot from 0 to 3 with step size 0.2
We can visually see from the following plots that
- Reducing step size increases accuracy
- The predictor corrector (shown with '+' ) is more closer to original equation (shown with '.' ) than the traditional euler method (shown with '*')
-- Pure awesomeness :)
Cool, A nice writeup :)!
ReplyDeleteThough some suggestions on hosting code, probably github is a better place to host your public code (its easy to embed them anywhere with a short script they give!), that would also allow collaborating and improving the code :).