Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@d9i
Created February 22, 2012 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d9i/1883008 to your computer and use it in GitHub Desktop.
Save d9i/1883008 to your computer and use it in GitHub Desktop.
Euler method of approximating Diff. Eq.s -- MK's cut
from __future__ import division
# Euler method of approximating Diff. Eq.s
# Uses eval to reduce f(x,y) -- is this okay?
def euler(eq, x, y, h, e):
while x < e:
eqResult = eval(eq)
x = x + h
y = y + (h*eqResult)
return y
print euler("e**x+2*y**2", 0, 1, .1, .4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment