---
author: Nathan Carter (ncarter@bentley.edu)
---

This answer assumes you have imported SymPy as follows.


```python
from sympy import *                   # load all math functions
init_printing( use_latex='mathjax' )  # use pretty math output
```

The following code tells SymPy that $x$ is a variable and that
$y$ is a function of $x$.  It then expresses $\frac{dy}{dx}$ as the
derivative of $y$ with respect to $x$.


```python
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.
```




$\displaystyle \frac{d}{d x} y{\left(x \right)}$



Let's now write a very simple differential equation, $\frac{dy}{dx}=y$.

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
$\frac{dy}{dx}-y=0$, and we will use just the left-hand side to express our ODE.


```python
ode = dydx - y
ode
```




$\displaystyle - y{\left(x \right)} + \frac{d}{d x} y{\left(x \right)}$



309d94af3e3206f5ab7dcf4a346dd6b8e1cbd114
ipynb
Jupyter Notebook
database/tasks/How to write an ordinary differential equation/Python, using SymPy.ipynb
nathancarter/how2data
7d4f2838661f7ce98deb1b8081470cec5671b03a
MIT
database/tasks/How to write an ordinary differential equation/Python, using SymPy.ipynb
nathancarter/how2data
7d4f2838661f7ce98deb1b8081470cec5671b03a
MIT
database/tasks/How to write an ordinary differential equation/Python, using SymPy.ipynb
nathancarter/how2data
7d4f2838661f7ce98deb1b8081470cec5671b03a
MIT
2021-07-18T19:01:29.000Z
2022-03-29T06:47:11.000Z
Qwen/Qwen-72B
1. YES
2. YES