Skip to content

Instantly share code, notes, and snippets.

@renegarcia
Created February 5, 2018 17:49
Show Gist options
  • Save renegarcia/2bf2dcb20e77f2df76b369f6bb419b86 to your computer and use it in GitHub Desktop.
Save renegarcia/2bf2dcb20e77f2df76b369f6bb419b86 to your computer and use it in GitHub Desktop.
How to test the solution to an ordinary differential equation found with sympy.
'''
How to test a ODE in sympy properly.
See [http://docs.sympy.org/latest/modules/solvers/ode.html#checkodesol] for more
'''
import sympy as sp
x, h = sp.symbols('x h')
eq = sp.diff(h(x), x) - h(x)
sols = sp.dsolve(eq)
sol = sols.rhs
print(sp.checkodesol(eq, sol))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment