3.1. Analytical Solutions to 2nd-order ODEs#

Let’s first focus on simple analytical solutions for 2nd-order ODEs. As before, let’s categorize problems based on their solution approach.

# import libraries for numerical functions and plotting
import numpy as np
import matplotlib.pyplot as plt
# these lines are only for helping improve the display
import matplotlib_inline.backend_inline
matplotlib_inline.backend_inline.set_matplotlib_formats('pdf', 'png')
plt.rcParams['figure.dpi']= 300
plt.rcParams['savefig.dpi'] = 300

3.1.1. Solution by direct integration#

If you have a 2nd-order ODE of this form:

(3.1)#d2ydx2=f(x)

then you can solve by direct integration.

For example, let’s say we are trying to solve for the deflection of a cantilever beam y(x) with a force P at the end, where E is the modulus and I is the moment of intertia, and the initial conditions are y(0)=0 and y(0)=0:

Cantilever beam with force at end

(3.2)#d2ydx2=P(Lx)EIddx(dydx)=PEI(Lx)d(dydx)=PEI(Lx)dxy=dydx=PEI(Lxx22)+C1dy=(PEI(Lxx22)+C1)dxy(x)=PEI(L2x216x3)+C1x+C2

That is our general solution; we can obtain the specific solution by applying our two initial conditions:

(3.3)#y(0)=0=C2y(0)=0=C1y(x)=PEI(x36Lx22)

3.1.2. Solution by substitution#

If we have a 2nd-order ODE of this form:

(3.4)#d2ydx2=f(x,y)

then we can solve by substitution, meaning by substituting a new variable for y. (Notice that y itself does not show up in the ODE.)

Let’s substitute u for y in the above ODE:

(3.5)#u=yu=yu=f(f,u)

Now we have a 1st-order ODE! Then, we can apply the methods previously discussed to solve this; once we find u(x), we can integrate that once more to get y(x).

3.1.2.1. Example: falling object#

For example, consider a falling mass where we are solving for the downward distance as a function of time, y(t), that is experiencing the force of gravity downward and a drag force upward. It starts at some reference point so y(0)=0, and has a zero initial downward velocity: y(0)=0. The governing equation is:

(3.6)#md2ydt2=mgc(dydt)2

where m is the mass, g is acceleration due to gravity, and c is the drag proportionality constant. We can substitute V for y, which gives us a first-order ODE:

(3.7)#letdydt=VmdVdt=mgcV2

Then, we can solve this for V(t) using our initial condition for velocity V(0)=0. Once we have that, we can integrate once more:

(3.8)#y(t)=V(t)dt

and apply our initial condition for position, y(0)=0, to obtain y(t).

Here is the full process:

(3.9)#dVdt=gcmV2dVgcmV2=dtmcdVa2V2=dt=t+c¯,wherea=mgcmc1atanh1(Va)=t+c1V=atanh(acmt+c1)V(t)=mgctanh(gcmt+c1)

Applying the initial condition for velocity, V(0)=0:

(3.10)#V(0)=0=mgctanh(0+c1)c1=0V(t)=mgctanh(gcmt)

Then, to get y(t), we just need to integrate once more:

(3.11)#dydt=V(t)=mgctanh(gcmt)dy=mgctanh(gcmt)dty(t)=mgcmgclog(cosh(gcmt))+c2y(t)=mclog(cosh(gcmt))+c2

Finally, we can apply the initial condition for position, y(0)=0, to get our solution:

(3.12)#y(0)=0=mclog(cosh(0))+c2=c2c2=0y(t)=mclog(cosh(gcmt))

3.1.2.2. Example: catenary problem#

The catenary problem describes the shape of a hanging chain or rope fixed between two points. (It was also a favorite of one of my professors, Joe Prahl, and I like to teach it as an example in his honor.) The downward displacement of the hanging string/chain/rope as a function of horizontal position, y(x), is governed by the equation

(3.13)#y=1+(y)2

Catenary problem (hanging rope/chain)

This is actually a boundary value problem, with the boundary conditions for the displacement at one side y(0)=0 and that the slope is zero in the middle: dydx(L2)=0. (Please note that I have skipped the derivation of the governing equation, and left some details out.)

We can solve this via substitution, by letting a new variable u=y; then, u=dudx=y. This gives is a first-order ODE, which we can integrate:

(3.14)#dudx=1+u2du1+u2=dxsinh1(u)=x+c1,where sinh(x)=exex2u(x)=sinh(x+c1)

Then, we can integrate once again to get y(x):

(3.15)#dydx=u(x)=sinh(x+c1)dy=sinh(x+c1)dx=(sinh(x)cosh(c1)+cosh(x)sinh(c1))dxy(x)=cosh(x)cosh(c1)+sinh(x)sinh(c1)+c2y(x)=cosh(x+c1)+c2

This is the general solution to the catenary problem, and applies to any boundary conditions.

For our specific case, we can apply the boundary conditions and find the particular solution, though it involves some algebra…:

(3.16)#y(0)=0=cosh(c1)+c2dydx(L2)=u(0)=sinh(L2+c1)c1=L20=cosh(L2)+c2c2=cosh(L2)=cosh(L2)

So, the overall solution for the catenary problem with the given boundary conditions is

(3.17)#y(x)=cosh(xL2)cosh(L2)

Let’s see what this looks like:

length = 1.0
x = np.linspace(0, 1)
y = np.cosh(x - length/2) - np.cosh(length/2)
plt.plot(x, y)
plt.grid(True)
plt.show()
../../_images/ce28fb3874085667697bf7eae613a45424c8e21df1509a1f7cc82756dd5cb5c7.png

Please note that I’ve made some simplifications in the above work, and skipped the details of how the ODE is derived. In general, the solution for the shape is

(3.18)#y(x)=Ccoshx+c1C+c2

where you would solve for the constants C, c1, and c2 using the constraints:

(3.19)#xaxb1+(y)2dx=Ly(xa)=yay(xb)=yb,

where L is the length of the rope/chain.

You can read more about the catenary problem here (for example): http://euclid.trentu.ca/aejm/V4N1/Chatterjee.V4N1.pdf

3.1.3. Homogeneous 2nd-order ODEs#

An important category of 2nd-order ODEs are those that look like

(3.20)#y+p(x)y+q(x)y=0

“Homogeneous” means that the ODE is unforced; that is, the right-hand side is zero.

Depending on what p(x) and q(x) look like, we have a few different solution approaches:

  • constant coefficients: y+ay+by=0

  • Euler-Cauchy equations: x2y+axy+by=0

  • Series solutions

First, let’s talk about the characteristics of linear, homogeneous 2nd-order ODEs:

3.1.3.1. Solutions have two parts:#

Solutions have two parts: y(x)=c1y1+c2y2, where y1 and y2 are each a basis of the solution.

3.1.3.2. Linearly independent:#

The two parts of the solution y1 and y2 are linearly independent.

One way of defining this is that a1y1+a2y2=0 only has the trivial solution a1=0 and a2=0.

Another way of thinking about this is that y1 and y2 are linearly dependent if one is a multiple of the other, like y1=x and y2=5x. This cannot be solutions to a linear, homogeneous ODE.

3.1.3.3. Both parts satisfy the ODE:#

y1 and y2 each satisfy the ODE. Meaning, you can plug each of them into the ODE for y and obtain 0.

However, we need both parts together to fully solve the ODE.

3.1.3.4. Reduction of order:#

If y1 is known, we can get y2 by reduction of order. Let y2=uy1, where u is some unknown function of x. Then, put y2 into the ODE y+p(x)y+q(x)y=0:

(3.21)#y2=uy1y2=uy1+uy1y2=2uy1+uy1+uy1u=[p(x)+(2y1y1)]uor, u=(g(x))u

Now, we have an ODE with only u, u, and some function g(x)—so we can solve by substitution! Let u=v, and then we have v=g(x)v:

(3.22)#dvdx=(p(x)+2y1y1)vdvv=(p(x)+2y1y1)dxRecall 2ddx(lny1)=2y1y1dvv=(p(x)+2ddx(lny1))dxlnv=p(x)dx2lny1v=exp(p(x)dx)y12

So, the actual solution procedure is then:

  1. Solve for v: v=exp(p(x)dx)y12

  2. Solve for u: u=vdx

  3. Get y2: y2=uy1

Here’s an example, where we know one part of the solution y1=ex:

(3.23)#y+2y+y=0Step 1:v=exp(2dx)(ex)2=e2xe2x=1Step 2:u=vdx=1dx=xStep 3:y2=xex

Then, the general solution to the ODE is y(x)=c1ex+c2xex.