Created
January 4, 2020 20:38
-
-
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)
This file contains 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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