Solving First and Second Order ODEs

10 minute read ·

Published:

First Order ODEs

First order ODE is equations that has the highest derivative of order one. It takes the form

M(x,y)+N(x,y)y=0\begin{equation}M\left(x,y\right)+N\left(x,y\right)y'=0\end{equation}

The general solution to this equation is some function y(x)y\left(x\right) that satisfies the equation.

Separable Equation

A separable equation is of the form

y=f(x)g(y)y'=f\left(x\right)g\left(y\right)

Linear Equation

A linear equation is of the form

a1(x)y+a2(x)y=a3(x)a_1\left(x\right)y'+a_2\left(x\right)y=a_3\left(x\right)

For now, we assume a1(x)0a_1\left(x\right)\ne0 for all xIx\in I, then the equation above is simplified into

y+p(x)y=q(x)y'+p\left(x\right)y=q\left(x\right)
  • If q(x)=0q\left(x\right)=0 for all xIx\in I, it is called a homogeneous equation;
  • Otherwise, it is called an inhomogeneous equation.

Homogeneous

A homogeneous linear equation is of the form

y+p(x)y=0y'+p\left(x\right)y=0

which is a separable equation. The general solution to it is

y(x;C)=Cexp(p(x)dx)y\left(x;C\right)=C\cdot\exp\left(-\int p\left(x\right)\mathrm{d}x\right)

If given an initial condition y(ξ)=ηy\left(\xi\right)=\eta, then the solution is

y(x)=ηexp(ξxp(t)dt)y\left(x\right)=\eta\cdot\exp\left(-\int_{\xi}^{x}p\left(t\right)\mathrm{d}t\right)

Inhomogeneous

An inhomogeneous linear equation is of the form

y+p(x)y=q(x)y'+p\left(x\right)y=q\left(x\right)

Let

u(x)=exp(p(x)dx)u\left(x\right)=\exp\left(\int p\left(x\right)\mathrm{d}x\right)

and multiply u(x)u\left(x\right), which is called the integrating factor, to both sides of the equation, we get (uy)=uq\left(uy\right)'=uq. Therefore the solution is

y(x;C)=1u(x)(u(x)q(x)dx+C)y\left(x;C\right)=\frac{1}{u\left(x\right)}\left(\int u\left(x\right)q\left(x\right)\mathrm{d}x+C\right)

If given initial condition y(ξ)=ηy\left(\xi\right)=\eta, then we can find a specific constant CC.

Method of substitution

In addition to separable equations and linear equations for which we have a direct solving techniques, some other first order equations can be transformed into separable equations or linear equations by method of substitution. The following are some types of those transformable equations.

Equation: y=f(ax+by+c)y'=f\left(ax+by+c\right)

Consider a equation of the form

y=f(ax+by+c)y'=f\left(ax+by+c\right)

where a,b,cRa,b,c\in \mathbb{R}, b0b\ne 0.

Let u=ax+by+cu=ax+by+c, then,

u=a+by=a+bf(u)u'=a+by'=a+bf\left(u\right)

which is a separable equation of uu.

Homogeneous Equation

A homogeneous equation has the form

y=f(yx)y'=f\left(\frac{y}{x}\right)

This type of equation has an important characteristic that its invariant under zoom, i.e., if make change xaxx\to ax, yayy\to ay, the equation does not change.

Tip:

Sometimes the equation is put into a strange form that it may not be obvious the right hand side is a function of y/xy/x. A quick judge would be to check whether the sum of power of xx and yy in the denominator and numerator of the right hand side are equal.

We solve this kind of equations by transforming them into a separable equation.

First, let z=yx\displaystyle z=\frac{y}{x}, and therefore, y=zxy=zx, and y=zx+zy'=z'x+z. Substitute that in the equation and,

zx+zf(z)=0z'x+z-f\left(z\right)=0

which is a separable equation. Here are some examples,

  • Example

    Find the general solution to the following differential equation

    y=y+xxyy'=\frac{y+x}{x-y}

    Solution:

    First, make the left hand side life a homogeneous equation,

    y=y/x+11y/xy'=\frac{y/x+1}{1-y/x}

    and let z=y/xz=y/x. Then, the equation becomes,

    xz=z2+11zxz'=\frac{z^2+1}{1-z}

    integrate both side

    1xdx=1zz2+1dz\int \frac{1}{x}\mathrm{d}x=\int\frac{1-z}{z^2+1}\mathrm{d}z

    which is

    lnx+C=arctanz12ln(z2+1)\ln x +C=\arctan z-\frac{1}{2}\ln\left(z^2+1\right)

    Change back into yy, and get

    arctan(yx)=lnx2+y2+C\arctan \left(\frac{y}{x}\right)=\ln\sqrt{x^2+y^2}+C

    Now, suppose we are in the polar coordinate, where θ=arctany/x\displaystyle \theta=\arctan y/x, and r=x2+y2r=x^2+y^2,

    θ=lnr+C\theta=\ln r+C

    or equivalently,

    r=C1eθr=C_1e^{\theta}

    which is known as the exponential spiral.

Bernoulli’s Equation

A Bernoulli’s equation has the form

y=p(x)y+q(x)yny'=p\left(x\right)y+q\left(x\right)y^n

where n0,1n\ne 0,1. We solve this kind of equations by transforming them into a linear equation.

First, multiply the equation by (1n)yn\left(1-n\right)y^{-n}, and get

(1n)yyn=(1n)p(x)yn1+(1n)q(x)\left(1-n\right)\frac{y'}{y^n}=\frac{\left(1-n\right)p\left(x\right)}{y^{n-1}}+\left(1-n\right)q\left(x\right)

Next, let v=y1n\displaystyle v=y^{1-n}, and observe that v=(1n)yyn\displaystyle v'=\left(1-n\right)\frac{y'}{y^n}, thus the equation becomes,

v=(1n)p(x)v+(1n)q(x)v'=\left(1-n\right)p\left(x\right)v+\left(1-n\right)q\left(x\right)

which is a linear equation. Here is an example.

  • Example

    Find the general solution of the following equation

    y+y1+x+(1+x)y4=0y'+\frac{y}{1+x}+\left(1+x\right)y^4=0

    Solution:

    First, divide the equation by y4y^4, which gives

    yy4+11+x1y3+(1+x)=0\frac{y'}{y^4}+\frac{1}{1+x}\cdot\frac{1}{y^3}+\left(1+x\right)=0

    Then, the substitution should be v=y3v=y^{-3}, and v=3y4yv'=-3y^{-4}y'. Thus, the equation becomes

    v31+xv3(1+x)=0v'-\frac{3}{1+x}v-3\left(1+x\right)=0

    which is a linear equation.

    Next, the integrating factor is

    u(x)=exp(31+xdx)=1(1+x)3u\left(x\right)=\exp\left(-\int\frac{3}{1+x}\mathrm{d}x\right)=\frac{1}{\left(1+x\right)^3}

    Multiply the last equation by uu gives

    v(1+x)33(1+x)4v=3(1+x)\frac{v'}{\left(1+x\right)^3}-\frac{3}{\left(1+x\right)^4}v=3\left(1+x\right)

    which is in fact,

    (1(1+x)3v)=3(1+x)\left(\frac{1}{\left(1+x\right)^3}v\right)'=3\left(1+x\right)

    Therefore,

    v=(1+x)2(C+Cx3)v=\left(1+x\right)^2\left(C+Cx-3\right)

    and substitute back to get

    y=sgn(C+Cx3)(1+x)2C+Cx33y=\frac{\mathrm{sgn}\left(C+Cx-3\right)}{\sqrt[3]{\left(1+x\right)^2\left|C+Cx-3\right|}}

Integral Curves

Even with the previous cases, there are not very much equations that we can solve. Now, we generalize the solution of a differential by not requiring it to be a explicit function. That is, we can solve (1) if we can found a function ϕ(x,y)\phi\left(x,y\right), such that (1) can be transformed into the form

ddxϕ(x,y)=0\begin{equation}\frac{\mathrm{d}}{\mathrm{d}x}\phi\left(x,y\right)=0\end{equation}

Then, we integrate it with respect to xx and get a general solution

ϕ(x,y)=c\phi\left(x,y\right)=c

for some constant cc. This kind of solution is know as the integral curve.

Now, we discuss when can we write an equation into (2). By chain rule of partial differentiation, we have

ddxϕ(x,y(x))=ϕx+ϕydydx\frac{\mathrm{d}}{\mathrm{d}x}\phi \left( x,y\left( x \right) \right) =\frac{\partial \phi}{\partial x}+\frac{\partial \phi}{\partial y}\frac{\mathrm{d}y}{\mathrm{d}x}

compare this with equation (1), we know that for such a nice function ϕ\phi to exist, we require

M(x,y)=ϕxN(x,y)=ϕy\begin{align*} M\left( x,y \right) =\frac{\partial \phi}{\partial x}&& N\left( x,y \right) =\frac{\partial \phi}{\partial y} \end{align*}

Recall from the theory of vector field, this means that ϕ\phi is indeed a potential function. This means that the condition above is equivalent to

My=Nx\begin{equation}\frac{\partial M}{\partial y}=\frac{\partial N}{\partial x}\end{equation}

Those differential equations with the above condition satisfied is said to be exact.

For some first order equations that are not exact, we can somehow turn it exact by multiplying with a function μ(x,y)\mu\left(x,y\right), which is called the integrating factor or Euler’s Multiplier.

After doing so, condition (3) then becomes

y(μ(x,y)M(x,y))=x(μ(x,y)N(x,y)) \frac{\partial}{\partial y}\left( \mu \left( x,y \right) M\left( x,y \right) \right) =\frac{\partial}{\partial x}\left( \mu \left( x,y \right) N\left( x,y \right) \right) 

or

Mμy+μMy=Nμx+μNxM\frac{\partial \mu}{\partial y}+\mu \frac{\partial M}{\partial y}=N\frac{\partial \mu}{\partial x}+\mu \frac{\partial N}{\partial x}

This turns out to be a partial differential equation for μ\mu, which is hard to solve generally. However, if we assume that μ\mu only depend on xx or yy, it then becomes an ordinary differential equation that hopefully we can solve.

For example, assume μ\mu only depend on xx, then

Ndμdx=μ(MyNx) N\frac{\mathrm{d}\mu}{\mathrm{d}x}=\mu \left( \frac{\partial M}{\partial y}-\frac{\partial N}{\partial x} \right) 

Second Order ODEs

A second-order linear ODE takes the form of

y+p(t)y+q(t)y=g(t)\begin{equation}y''+p\left(t\right)y'+q\left(t\right)y=g\left(t\right)\end{equation}

Note, we will leave the case where the coefficient of yy'' is not 1 till later. When all of p,q,rp,q,r are not dependent on tt, we say that it is an equation with constant coefficients. In addition, if g=0g=0 for all possible tt, then we say that the equation is homogeneous, otherwise inhomogeneous.

It can be proved that the general solution to a linear, second-order homogeneous ODE has the form

y=c1y1+c2y2y=c_1y_1+c_2y_2

where c1,c2Rc_1,c_2\in\mathbb{R} are constants, and y1,y2y_1,y_2 are linearly independent. See proof below.

In addition to the differential equation, we will often impose initial conditions

y(t0)=y0y(t0)=y0\begin{align*}y\left(t_0\right)=y_0&&y'\left(t_0\right)=y'_0 \end{align*}

Then the constants c1,c2c_1,c_2 are specified.

Constant Coefficient Homogeneous Equations

We begin by studying equations that have constant coefficients and are homogeneous.

y+Ay+By=0\begin{equation} y''+Ay'+By=0 \end{equation}

where A,BRA,B\in\mathbb{R}. Our goal is to find to independent solutions. This can be done basically by guessing with exponential function y=erty=e^{rt}. Substituting this back to equation (1) gives

r2ert+Arert+Bert=0r^2e^{rt}+Are^{rt}+Be^{rt}=0

Since erte^{rt} never vanishes, it can be cancelled, what is left is the following

r2+Ar+B=0\begin{equation}r^2+Ar+B=0\end{equation}

which is a simple quadratic equation, known as the characteristic equation of (1). Based on the number of solution of (2), there are the following three different cases.

Two Real Solutions, A24B>0A^2-4B>0

When there are two different real solutions r1,r2r_1,r_2 to the characteristic solution, we immediately get two independent solutions, y1=er1t,y2=er2ty_1=e^{r_1t},y_2=e^{r_2t}. Then, the general solution is

y=c1er1t+c2er2ty=c_1e^{r_1t}+c_2e^{r_2t}

Two Complex solutions, A24B<0A^2-4B<0

In this case, we get two complex conjugate solutions a±bia\pm bi for equation (2).

Now, if we plug in the formula given above, we still get y1,y2y_1,y_2 which are independent solution. However, they are complex functions. We can of course just say that we don’t care about this, but sometimes when we use this ODE in some physical models, we can’t interpret them if the solution is complex. For example, in a damped oscillation model, yy should represent a displacement from the equilibrium position, complex solution is not tolerable. Therefore, we still want to figure out a general form for the real solution of this equation.

We do this by first noticing an important property: if u+viu+vi is a complex solution, where u,vu,v are real functions of tt, then both uu and vv are a solution.

Therefore, the real part and imaginary part of the solution e(a+bi)te^{\left(a+bi\right)t} are two independent solutions, and the general solution is

y=c1eatcosbt+c2ratsinbty=c_1e^{at}\cos bt+c_2r^{at}\sin bt

Remark:

There is another way to write the general real solutions, but with real coefficients c,dc,d.

y=(c+di)e(a+bi)t+(cdi)e(abi)ty=\left(c+di\right)e^{\left(a+bi\right)t}+\left(c-di\right)e^{\left(a-bi\right)t}

One Single Solution, A24B=0A^2-4B=0

In this case, we only have one real solution rr for the characteristic equation. One obvious solution is y1=erty_1=e^{rt}, but the problem is what is the other solution?

There is a theorem related to this condition saying if y1y_1 is a solution to the equation

y+p(t)y+q(t)y=0y''+p\left(t\right)y'+q\left(t\right)y=0

then, there exist some function u(t)u\left(t\right), such that y=uy1y=uy_1 is also a solution. The proof of this theorem has something to do with Jordan Normal Form of the fundamental system, which is omitted here.

Therefore, what we need to do is to plug in y=uy1y=uy_1 and get the function uu,and then we have the second independent solution.

Let r=ar=-a, and suppose yy is a solution to y+2ay+a2y=0y''+2ay'+a^2y=0, then

a2y=a2eatu2ay=2a2eatu+2aueaty=a2eatu2aeatu+eatu\begin{align*} a^2y&=a^2e^{-at}u\\ 2ay'&=-2a^2e^{-at}u+2au'e^{-at}\\ y''&=a^2e^{-at}u-2ae^{-at}u'+e^{-at}u'' \end{align*}

Add those three equations up to get

eatu=0e^{-at}u''=0

Just one choice of uu is enough, and therefore we set u=tu=t, the second independent solution is

y2=terty_2=te^{rt}

and the general solution to this case is

y=c1ert+c2terty=c_1e^{rt}+c_2te^{rt}

Inhomogeneous Equation

Next, we want to consider a more general case, which is to find the solution to

y+p(t)y+q(t)y=g(t)\begin{equation}y''+p\left(t\right)y'+q\left(t\right)y=g\left(t\right)\end{equation}

We claim that the general solution to this equation is a superposition of a particular solution ypy_{p} and the general solution ycy_{c} to the associated homogeneous equation

y+p(t)y+q(t)y=0\begin{equation}y''+p\left(t\right)y'+q\left(t\right)y=0\end{equation}

Proof:

  1. All yp+ycy_p+y_c are solutions. This can be done by plugging those solutions into the equation.
  1. No other solutions. Suppose uu is any solution, then L(u)=g(t)L\left(u\right)=g\left(t\right). Since ypy_p is a particular solution, L(yp)=g(t)L\left(y_p\right)=g\left(t\right). Subtract those two equations and get L(uyp)=0L\left(u-y_p\right)=0. Therefore, uyp=c1y1+c2y2u-y_p=c_1y_1+c_2y_2 for some constant c1,c2c_1,c_2.

We can use the method of variation of parameters once we have found two independent solutions to the associated homogeneous equation (5). (Notice that it’s also possible to find the particular solution by inspection. First, try some simple functions before diving into the calculations!)

Let y1,y2y_1,y_2 be two solutions to equation (5) and set

y(t)=c1(t)y1(t)+c2(t)y2(t) y\left( t \right) =c_1\left( t \right) y_1\left( t \right) +c_2\left( t \right) y_2\left( t \right) 

Observe that equation (4) actually only imposes one condition on two unknown functions, which therefore gives us some freedom in the choice of c1(t)c_1\left(t\right) and c2(t)c_2\left(t\right). Therefore, we can determine those two functions by imposing another condition that can simplify our calculation.

Computing

y=(c1y1+c2y2)+(c1y1+c2y2)y'=\left(c_1y_1'+c_2y_2'\right)+\left(c_1'y_1+c_2'y_2\right)

and notice that the yy'' will contain no terms of the second order derivative of c1c_1 and c2c_2 if

c1(t)y1(t)+c2(t)y2(t)=0\begin{equation}c_1'\left(t\right)y_1\left(t\right)+c_2'\left(t\right)y_2\left(t\right)=0\end{equation}

With this condition, plugging y(t)y\left(t\right) back to (4) and get

c1(t)y1(t)+c2(t)y2(t)=g(t)\begin{equation}c_1'\left( t \right) y_1'\left( t \right) +c_2'\left( t \right) y_2'\left( t \right)=g\left(t\right) \end{equation}

Therefore, we only need to solve for c1(t)c_1'\left(t\right) and c2(t)c_2'\left(t\right) from conditions (6) and (7) and then integrate to get c1c_1 and c2c_2.

Homogeneous Equation

Now, we proceed to equations that are homogeneous without constant coefficients.

y+p(t)y+q(t)y=0\begin{equation}y''+p\left(t\right)y'+q\left(t\right)y=0\end{equation}

There is no general method for solving this kind of equation for arbitrary function pp and qq. However, we can still get its general solution if we can guess one solution.

Let y1y_1 be a solution and set

y2(t)=v(t)y1(t)y_2\left(t\right)=v\left(t\right)y_1\left(t\right)

where v(t)v\left(t\right) is some unknown function. Plugging y2y_2 into (3) and get

y1v+(2y1+py1)v=0y_1v''+\left(2y_1'+py_1\right)v'=0

from which we can solve for vv' and then vv.

Categories: Mathematics