fork download
  1. # eulers method
  2. deltax = 1
  3. def yderiv(x, y):
  4. return (x - y - 2)
  5. x = -1
  6. y = 1.5
  7. endpoint = 2
  8. print(x, y)
  9. while(x!=endpoint and -50<x<50):
  10. deriv = yderiv(x, y)
  11. y += (deriv*deltax)
  12. x += deltax
  13. print(x, y)
Success #stdin #stdout 0.11s 14104KB
stdin
Standard input is empty
stdout
-1 1.5
0 -3.0
1 -2.0
2 -1.0