Created
June 12, 2014 06:20
-
-
Save sshine/7271208e54177daa3e0e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division | |
## Equations: | |
# x(t+h) = x(t) + 1/2 (F1 + F2) | |
# F1 = h*f(t,x) | |
# F2 = h*f(t+h, x+h*f(t,x)) | |
def rungekutta(f, a, b, x0, iterations): | |
h = (b - a) / iterations | |
x = x0 | |
result = [x] | |
for i in range(iterations): | |
s = a + h*i | |
F1 = h*f(s, x) | |
F2 = h*f(s+h, x+F1) | |
x = x + .5*(F1 + F2) | |
result.append(x) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment