Skip to content

Instantly share code, notes, and snippets.

@quantum9Innovation
Created January 4, 2020 20:38
Show Gist options
  • Save quantum9Innovation/e42e21bca0bb7fa97437736c10ba7a4c to your computer and use it in GitHub Desktop.
Save quantum9Innovation/e42e21bca0bb7fa97437736c10ba7a4c to your computer and use it in GitHub Desktop.
A simple differential equation solver in 8 lines of code, illustrating Euler's method (♥3b1b)
import numpy as np
def f(x, d, g):
Y = 0
if x < 0: delta = -d
else: delta = d
for t in np.arange(0, x, delta): Y+=delta*g(Y)
del t
return Y
@quantum9Innovation
Copy link
Author

Use f(x) to solve a first-order differential equation of some function g and step size d. The closer d is to zero the more accurate Euler's approximations become.

❤️ 3b1b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment