How to write an ordinary differential equation
Description
Differential equations are equations that contain differentials like
Using SymPy, in Python
This answer assumes you have imported SymPy as follows.
1
2
from sympy import * # load all math functions
init_printing( use_latex='mathjax' ) # use pretty math output
The following code tells SymPy that
1
2
3
4
var( 'x' ) # Let x be a variable.
y = Function('y')(x) # Literally, y is a function, named y, based on x.
dydx = Derivative( y, x ) # How to write dy/dx.
dydx # Let's see how SymPy displays dy/dx.
Let’s now write a very simple differential equation,
As with how to do implicit differentiation, SymPy expects us to move everything
to the left hand side of the equation. In this case, that makes the equation
1
2
ode = dydx - y
ode
Content last modified on 24 July 2023.
See a problem? Tell us or edit the source.
Topics that include this task
Opportunities
This website does not yet contain a solution for this task in any of the following software packages.
- R
- Excel
- Julia
If you can contribute a solution using any of these pieces of software, see our Contributing page for how to help extend this website.