# Calculus/Ordinary differential equations

 ← Differential Equations Calculus Partial differential equations → Ordinary differential equations

Ordinary differential equations involve equations containing:

• variables
• functions
• their derivatives

and their solutions.

In studying integration, you already have considered solutions to very simple differential equations. For example, when you look to solving

${\displaystyle \int f(x)\,dx=g(x)}$

for g(x), you are really solving the differential equation

${\displaystyle g'(x)=f(x)\,}$

## Notations and terminology

The notations we use for solving differential equations will be crucial in the ease of solubility for these equations.

This document will be using three notations primarily:

• f' to denote the derivative of f
• D f to denote the derivative of f
• ${\displaystyle {df \over dx}}$ to denote the derivative of f (for separable equations).

### Terminology

Consider the differential equation

${\displaystyle 3f^{\prime \prime }(x)+5xf(x)=11}$

Since the equation's highest derivative is 2, we say that the differential equation is of order 2.

## Some simple differential equations

A key idea in solving differential equations will be that of integration.

Let us consider the second order differential equation (remember that a function acts on a value).

${\displaystyle f''(x)=2\,}$

How would we go about solving this? It tells us that on differentiating twice, we obtain the constant 2 so, if we integrate twice, we should obtain our result.

Integrating once first of all:

${\displaystyle \int f''(x)\,dx=\int 2\,dx}$
${\displaystyle f'(x)=2x+C_{1}\,}$

We have transformed the apparently difficult second order differential equation into a rather simpler one, viz.

${\displaystyle f'(x)=2x+C_{1}\,}$

This equation tells us that if we differentiate a function once, we get ${\displaystyle 2x+C_{1}}$. If we integrate once more, we should find the solution.

${\displaystyle \int f'(x)\,dx=\int 2x+C_{1}\,dx}$
${\displaystyle f(x)=x^{2}+C_{1}x+C_{2}\,}$

This is the solution to the differential equation. We will get ${\displaystyle f''=2\,}$ for all values of ${\displaystyle C_{1}}$ and ${\displaystyle C_{2}}$.

The values ${\displaystyle C_{1}}$ and ${\displaystyle C_{2}}$ are related to quantities known as initial conditions.

Why are initial conditions useful? ODEs (ordinary differential equations) are useful in modeling physical conditions. We may wish to model a certain physical system which is initially at rest (so one initial condition may be zero), or wound up to some point (so an initial condition may be nonzero, say 5 for instance) and we may wish to see how the system reacts under such an initial condition.

When we solve a system with given initial conditions, we substitute them after our process of integration.

### Example

When we solved ${\displaystyle f''(x)=2\,}$ say we had the initial conditions ${\displaystyle f'(0)=3\,}$ and ${\displaystyle f(0)=2\,}$. (Note, initial conditions need not occur at f(0)).

After we integrate we make substitutions:

${\displaystyle f'(0)=2(0)+C_{1}\,}$
${\displaystyle 3=C_{1}\,}$
${\displaystyle \int f'(x)\,dx=\int 2x+3\,dx}$
${\displaystyle f(x)=x^{2}+3x+C_{2}\,}$
${\displaystyle f(0)=0^{2}+3(0)+C_{2}\,}$
${\displaystyle 2=C_{2}\,}$
${\displaystyle f(x)=x^{2}+3x+2\,}$

Without initial conditions, the answer we obtain is known as the general solution or the solution to the family of equations. With them, our solution is known as a specific solution.

## Basic first order DEs

In this section we will consider four main types of differential equations:

• separable
• homogeneous
• linear
• exact

There are many other forms of differential equation, however, and these will be dealt with in the next section

### Separable equations

A separable equation is in the form (using dy/dx notation which will serve us greatly here)

${\displaystyle {dy \over dx}=f(x)/g(y)}$

Previously we have only dealt with simple differential equations with g(y)=1. How do we solve such a separable equation as above?

We group x and dx terms together, and y and dy terms together as well.

${\displaystyle g(y)\ dy=f(x)\ dx}$

Integrating both sides with respect to y on the left hand side and x on the right hand side:

${\displaystyle \int g(y)\,dy=\int f(x)\,dx+C}$

we will obtain the solution.

#### Worked example

Here is a worked example illustrating the process.

${\displaystyle {dy \over dx}=3x^{2}y}$

Separating

${\displaystyle {dy \over y}=(3x^{2})\,dx}$

Integrating

${\displaystyle \int {dy \over y}=\int 3x^{2}\,dx}$
${\displaystyle \ln {y}=x^{3}+C\,\!}$
${\displaystyle y=e^{x^{3}+C}}$

Letting ${\displaystyle k=e^{C}}$ where k is a constant we obtain

${\displaystyle y=ke^{x^{3}}}$

which is the general solution.

#### Verification

This step does not need to be part of your work, but if you want to check your solution, you can verify your answer by differentiation.

We obtained

${\displaystyle y=ke^{x^{3}}}$

as the solution to

${\displaystyle {dy \over dx}=3x^{2}y}$

Differentiating our solution with respect to x,

${\displaystyle {dy \over dx}=3kx^{2}e^{x^{3}}}$

And since ${\displaystyle y=ke^{x^{3}}}$, we can write

${\displaystyle {dy \over dx}=3x^{2}y}$

We see that we obtain our original differential equation, thus our work must be correct.

### Homogeneous equations

A homogeneous equation is in the form

${\displaystyle {dy \over dx}=f(y/x)}$

This looks difficult as it stands, however we can utilize the substitution

${\displaystyle v={y \over x}}$

so that we are now dealing with F(v) rather than F(y/x).

Now we can express y in terms of v, as y=xv and use the product rule.

The equation above then becomes, using the product rule

${\displaystyle {dy \over dx}=v+x{dv \over dx}}$

Then

${\displaystyle v+x{dv \over dx}=f(v)}$
${\displaystyle x{dv \over dx}=f(v)-v}$
${\displaystyle {dv \over dx}={f(v)-v \over x}}$

which is a separable equation and can be solved as above.

However let's look at a worked equation to see how homogeneous equations are solved.

#### Worked example

We have the equation

${\displaystyle {dy \over dx}={y^{2}+x^{2} \over yx}}$

This does not appear to be immediately separable, but let us expand to get

${\displaystyle {dy \over dx}={y^{2} \over yx}+{x^{2} \over yx}}$
${\displaystyle {dy \over dx}={x \over y}+{y \over x}}$

Substituting y=xv which is the same as substituting v=y/x:

${\displaystyle {dy \over dx}=1/v+v}$

Now

${\displaystyle v+x{dv \over dx}=1/v+v}$

Canceling v from both sides

${\displaystyle x{dv \over dx}=1/v}$

Separating

${\displaystyle v\,dv=dx/x}$

Integrating both sides

${\displaystyle {1 \over 2}v^{2}+C=\ln(x)\,}$
${\displaystyle {1 \over 2}\left({y \over x}\right)^{2}=\ln(x)-C}$
${\displaystyle y^{2}=2x^{2}\ln(x)-2Cx^{2}\,}$
${\displaystyle y=x{\sqrt {2\ln(x)-2C}}}$

which is our desired solution.

### Linear equations

A linear first order differential equation is a differential equation in the form

${\displaystyle a(x){dy \over dx}+b(x)y=c(x)}$

Multiplying or dividing this equation by any non-zero function of x makes no difference to its solutions so we could always divide by a(x) to make the coefficient of the differential 1, but writing the equation in this more general form may offer insights.

At first glance, it is not possible to integrate the left hand side, but there is one special case. If b happens to be the differential of a then we can write

${\displaystyle a(x){dy \over dx}+b(x)y=a(x){dy \over dx}+y{da \over dx}={d \over dx}a(x)y}$

and integration is now straightforward.

Since we can freely multiply by any function, lets see if we can use this freedom to write the left hand side in this special form.

We multiply the entire equation by an arbitrary, I(x), getting

${\displaystyle aI{dy \over dx}+bIy=cI}$

then impose the condition

${\displaystyle {\frac {d}{dx}}aI=bI}$

If this is satisfied the new left hand side will have the special form. Note that multiplying I by any constant will leave this condition still satisfied.

Rearranging this condition gives

${\displaystyle {\frac {1}{I}}{\frac {dI}{dx}}={\frac {b-{\frac {da}{dx}}}{a}}}$

We can integrate this to get

${\displaystyle \ln I(x)=\int {\frac {b(z)}{a(z)}}dz-\ln a(x)+c\quad I(x)={\frac {k}{a(x)}}e^{\int {\frac {b(z)}{a(z)}}dz}}$

We can set the constant k to be 1, since this makes no difference.

Next we use I on the original differential equation, getting

${\displaystyle e^{\int {\frac {b(z)}{a(z)}}dz}{dy \over dx}+e^{\int {\frac {b(z)}{a(z)}}dz}{\frac {b(x)}{a(x)}}y=e^{\int {\frac {b(z)}{a(z)}}dz}{\frac {c(x)}{a(x)}}}$

Because we've chosen I to put the left hand side in the special form we can rewrite this as

${\displaystyle {d \over dx}(ye^{\int {\frac {b(z)}{a(z)}}dz})=e^{\int {\frac {b(z)}{a(z)}}dz}{\frac {c(x)}{a(x)}}}$

Integrating both sides and dividing by ${\displaystyle e^{I}}$ we obtain the final result

${\displaystyle y=e^{-\int {\frac {b(z)}{a(z)}}dz}\left(\int e^{\int {\frac {b(z)}{a(z)}}dz}{\frac {c(x)}{a(x)}}dx+C\right)}$

We call I an integrating factor. Similar techniques can be used on some other calculus problems.

#### Example

Consider

${\displaystyle {\frac {dy}{dx}}+y\tan x=1\quad y(0)=0}$

First we calculate the integrating factor.

${\displaystyle I=e^{\int \tan xdx}=e^{\ln \sec x}=\sec x}$

Multiplying the equation by this gives

${\displaystyle \sec x{\frac {dy}{dx}}+y\sec x\tan x=\sec x}$

or

${\displaystyle {\frac {d}{dx}}y\sec x=\sec x}$

We can now integrate

${\displaystyle y=\cos x\int _{0}^{x}\sec z\,dz=\cos x\ln(\sec x+\tan x)}$

### Exact equations

An exact equation is in the form

f(x, y) dx + g(x, y) dy = 0

and, has the property that

Dx f = Dy g

(If the differential equation does not have this property then we can't proceed any further).

As a result of this, if we have an exact equation then there exists a function h(x, y) such that

Dy h = f and Dx h = g

So then the solutions are in the form

h(x, y) = c

by using the fact of the total differential. We can find then h(x, y) by integration

## Basic second and higher order ODE's

The generic solution of a nth order ODE will contain n constants of integration. To calculate them we need n more equations. Most often, we have either

boundary conditions, the values of y and its derivatives take for two different values of x

or

initial conditions, the values of y and its first n-1 derivatives take for one particular value of x.

### Reducible ODE's

1. If the independent variable, x, does not occur in the differential equation then its order can be lowered by one. This will reduce a second order ODE to first order.

Consider the equation:

${\displaystyle F\left(y,{\frac {dy}{dx}},{\frac {d^{2}y}{dx^{2}}}\right)=0}$

Define

${\displaystyle u={\frac {dy}{dx}}}$

Then

${\displaystyle {\frac {d^{2}y}{dx^{2}}}={\frac {du}{dx}}={\frac {du}{dy}}\cdot {\frac {dy}{dx}}={\frac {du}{dy}}\cdot u}$

Substitute these two expression into the equation and we get

${\displaystyle F\left(y,u,{\frac {du}{dy}}\cdot u\right)}$=0

which is a first order ODE

#### Example

Solve

${\displaystyle 1+2y^{2}\operatorname {D} ^{2}y=0}$

if at x=0,  y=Dy=1

First, we make the substitution, getting

${\displaystyle 1+2y^{2}u{\frac {du}{dy}}=0}$

This is a first order ODE. By rearranging terms we can separate the variables

${\displaystyle udu=-{\frac {dy}{2y^{2}}}}$

Integrating this gives

${\displaystyle u^{2}/2=c+1/2y}$

We know the values of y and u when x=0 so we can find c

${\displaystyle c=u^{2}/2-1/2y=1^{2}/2-1/(2\cdot 1)=1/2-1/2=0}$

Next, we reverse the substitution

${\displaystyle {\frac {dy}{dx}}^{2}=u^{2}={\frac {1}{y}}}$

and take the square root

${\displaystyle {\frac {dy}{dx}}=\pm {\frac {1}{\sqrt {y}}}}$

To find out which sign of the square root to keep, we use the initial condition, Dy=1 at x=0, again, and rule out the negative square root. We now have another separable first order ODE,

${\displaystyle {\frac {dy}{dx}}={\frac {1}{\sqrt {y}}}}$

Its solution is

${\displaystyle {\frac {2}{3}}y^{\frac {3}{2}}=x+d}$

Since y=1 when x=0, d=2/3, and

${\displaystyle y=\left(1+{\frac {3x}{2}}\right)^{\frac {2}{3}}}$

2. If the dependent variable, y, does not occur in the differential equation then it may also be reduced to a first order equation.

Consider the equation:

${\displaystyle F\left(x,{\frac {dy}{dx}},{\frac {d^{2}y}{dx^{2}}}\right)=0}$

Define

${\displaystyle u={\frac {dy}{dx}}}$

Then

${\displaystyle {\frac {d^{2}y}{dx^{2}}}={\frac {du}{dx}}}$

Substitute these two expressions into the first equation and we get

${\displaystyle F\left(x,u,{\frac {du}{dx}}\right)}$=0

which is a first order ODE

### Linear ODEs

An ODE of the form

${\displaystyle {\frac {d^{n}y}{dx^{n}}}+a_{1}(x){\frac {d^{n-1}y}{dx^{n-1}}}+...+a_{n}y=F(x)}$

is called linear. Such equations are much simpler to solve than typical non-linear ODEs. Though only a few special cases can be solved exactly in terms of elementary functions, there is much that can be said about the solution of a generic linear ODE. A full account would be beyond the scope of this book

If F(x)=0 for all x the ODE is called homogeneous

Two useful properties of generic linear equations are

1. Any linear combination of solutions of an homogeneous linear equation is also a solution.
2. If we have a solution of a nonhomogeneous linear equation and we add any solution of the corresponding homogenous linear equation we get another solution of the nonhomogeneous linear equation

#### Variation of constants

Suppose we have a linear ODE,

${\displaystyle {\frac {d^{n}y}{dx^{n}}}+a_{1}(x){\frac {d^{n-1}y}{dx^{n-1}}}+...+a_{n}y=0}$

and we know one solution, y=w(x)

The other solutions can always be written as y=wz. This substitution in the ODE will give us terms involving every differential of z upto the nth, no higher, so we'll end up with an nth order linear ODE for z.

We know that z is constant is one solution, so the ODE for z must not contain a z term, which means it will effectively be an n-1th order linear ODE. We will have reduced the order by one.

Lets see how this works in practice.

##### Example

Consider

${\displaystyle {\frac {d^{2}y}{dx^{2}}}+{\frac {2}{x}}{\frac {dy}{dx}}-{\frac {6}{x^{2}}}y=0}$

One solution of this is y=x2, so substitute y=zx2 into this equation.

${\displaystyle \left(x^{2}{\frac {d^{2}z}{dx^{2}}}+4x{\frac {dz}{dx}}+2z\right)+{\frac {2}{x}}\left(x^{2}{\frac {dz}{dx}}+2xz\right)-{\frac {6}{x^{2}}}x^{2}z=0}$

Rearrange and simplify.

${\displaystyle x^{2}D^{2}z+6xDz=0}$

This is first order for Dz. We can solve it to get

${\displaystyle z=Ax^{-5}\quad y=Ax^{-3}}$

Since the equation is linear we can add this to any multiple of the other solution to get the general solution,

${\displaystyle y=Ax^{-3}+Bx^{2}}$

#### Linear homogeneous ODE's with constant coefficients

Suppose we have a ODE

${\displaystyle (D^{n}+a_{1}D^{n-1}+...+a_{n-1}D+a_{0})y=0}$

we can take an inspired guess at a solution (motivate this)

${\displaystyle y=e^{px}}$

For this function Dny=pny so the ODE becomes

${\displaystyle (p^{n}+a_{1}p^{n-1}+...+a_{n-1}p+a_{0})y=0}$

y=0 is a trivial solution of the ODE so we can discard it. We are then left with the equation

${\displaystyle p^{n}+a_{1}p^{n-1}+...+a_{n-1}p+a_{0})=0}$

This is called the characteristic equation of the ODE.

It can have up to n roots, p1, p2 … pn, each root giving us a different solution of the ODE.

Because the ODE is linear, we can add all those solution together in any linear combination to get a general solution

${\displaystyle y=A_{1}e^{p_{1}x}+A_{2}e^{p_{2}x}+...+A_{n}e^{p_{n}x}}$

To see how this works in practice we will look at the second order case. Solving equations like this of higher order uses exactly the same principles; only the algebra is more complex.

##### Second order

If the ODE is second order,

${\displaystyle D^{2}y+bDy+cy=0}$

then the characteristic equation is a quadratic,

${\displaystyle p^{2}+bp+c=0}$

with roots

${\displaystyle p_{\pm }={\frac {-b\pm {\sqrt {b^{2}-4c}}}{2}}}$

What these roots are like depends on the sign of b2-4c, so we have three cases to consider.

1) b2 > 4c

In this case we have two different real roots, so we can write down the solution straight away.

${\displaystyle y=A_{+}e^{p_{+}}+A_{-}e^{p_{-}}}$

2) b2 < 4c

In this case, both roots are imaginary. We could just put them directly in the formula, but if we are interested in real solutions it is more useful to write them another way.

Defining k2=4c-b2, then the solution is

${\displaystyle y=A_{+}e^{ikx-{\frac {bx}{2}}}+A_{-}e^{-ikx-{\frac {bx}{2}}}}$

For this to be real, the A's must be complex conjugates

${\displaystyle A_{\pm }=Ae^{\pm ia}}$

Make this substitution and we can write,

${\displaystyle y=Ae^{-bx/2}\cos(kx+a)}$

If b is positive, this is a damped oscillation.

3) b2 = 4c

In this case the characteristic equation only gives us one root, p=-b/2. We must use another method to find the other solution.

We'll use the method of variation of constants. The ODE we need to solve is,

${\displaystyle D^{2}y-2pDy+p^{2}y=0}$

rewriting b and c in terms of the root. From the characteristic equation we know one solution is ${\displaystyle y=e^{px}}$ so we make the substitution ${\displaystyle y=ze^{px}}$, giving

${\displaystyle (e^{px}D^{2}z+2pe^{px}Dz+p^{2}e^{px}z)-2p(e^{px}Dz+pe^{px}z)+p^{2}e^{px}z=0}$

This simplifies to D2z=0, which is easily solved. We get

${\displaystyle z=Ax+B\quad y=(Ax+B)e^{px}}$

so the second solution is the first multiplied by x.

Higher order linear constant coefficient ODE's behave similarly: an exponential for every real root of the characteristic and a exponent multiplied by a trig factor for every complex conjugate pair, both being multiplied by a polynomial if the root is repeated.

E.g., if the characteristic equation factors to

${\displaystyle (p-1)^{4}(p-3)(p^{2}+1)^{2}=0}$

the general solution of the ODE will be

${\displaystyle y=(A+Bx+Cx^{2}+Dx^{3})e^{x}+Ee^{3x}+F\cos(x+a)+Gx\cos(x+b)}$

The most difficult part is finding the roots of the characteristic equation.

#### Linear nonhomogeneous ODEs with constant coefficients

First, let's consider the ODE

${\displaystyle Dy-y=x}$

a nonhomogeneous first order ODE which we know how to solve.

Using the integrating factor e-x we find

${\displaystyle y=ce^{-x}+1-x}$

This is the sum of a solution of the corresponding homogeneous equation, and a polynomial.

Nonhomogeneous ODE's of higher order behave similarly.

If we have a single solution, yp of the nonhomogeneous ODE, called a particular solution,

${\displaystyle (D^{n}+a_{1}D^{n-1}+\cdots +a_{n})y=F(x)}$

then the general solution is y=yp+yh, where yh is the general solution of the homogeneous ODE.

Find yp for an arbitrary F(x) requires methods beyond the scope of this chapter, but there are some special cases where finding yp is straightforward.

Remember that in the first order problem yp for a polynomial F(x) was itself a polynomial of the same order. We can extend this to higher orders.

Example:

${\displaystyle D^{2}y+y=x^{3}-x+1}$

Consider a particular solution

${\displaystyle y_{p}=b_{0}+b_{1}x+b_{2}x^{2}+x^{3}}$

Substitute for y and collect coefficients

${\displaystyle x^{3}+b_{2}x^{2}+(6+b_{1})x+(2b_{2}+b_{0})=x^{3}-x+1}$

So b2=0, b1=-7, b0=1, and the general solution is

${\displaystyle y=a\sin x+b\cos x+1-7x+x^{3}}$

This works because all the derivatives of a polynomial are themselves polynomials.

Two other special cases are

${\displaystyle F(x)=P_{n}e^{kx}\quad y_{p}(x)=Q_{n}e^{kx}}$
${\displaystyle F(x)=A_{n}\sin kx+B_{n}\cos kx\quad y_{p}(x)=P_{n}\sin kx+Q_{n}\cos kx}$

where Pn,Qn,An, and Bn are all polynomials of degree n.

Making these substitutions will give a set of simultaneous linear equations for the coefficients of the polynomials.