Ordinary Differential Equations

In this lesson, we will learn about solving first-order and higher-order ordinary differential equations.

One of the most useful functions in modern problem-solving is that the solutions to ordinary differential equations (ODE) have so many varied applications in everything from pure sciences to all sorts of engineering.



To set up the ODE, we need to refer to the function we are solving and its derivatives. The Function and Eq classes in SymPy help us do this. Let’s discuss these before we move on to solving some equations ourselves.


Function is similar to Symbol but is used to define a function.

f = Function('f')

To define a function of symbol x, we use the following syntax:

x = Symbol('x')
f = Function('f')(x)

To compute the derivate of the Function, we use the diff() method:

f.diff(x) # first order derivative
f.diff(x, x) # second order derivative 


Eq is used to define equations in SymPy.

Eq(rhs, lhs)

The comma separates the right-hand side from the left-hand side.

Now let’s use these tools to solve ODEs.

Get hands-on with 1200+ tech skills courses.