SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 6.2.1 Constant coefficients and the characteristic equationConcept · 35 min
      2. 6.2.2 General solutions and boundary conditionsConcept · 35 min
      3. 6.2.3 Practice set: second-order equationsPractice set · 20 min
      4. 6.2.4 Case study: the perpetual American putCase study · 35 min

Level 6, Differential equations 6.2 Second-order linear ODEs Lesson 1 of 4

ConceptLesson 6.2.1 in Level 6, Differential equations. About 35 minutes.

Constant coefficients and the characteristic equation

Second-order equations

Lesson 6.1.1 called an equation for an unknown function y(t)y(t) and its derivatives a differential equation, and its order the highest derivative in it. Module 6.1 solved first-order equations such as y′=kyy' = ky, whose solutions are ekte^{kt}. This lesson solves equations with a second derivative y′′y''.

Lesson 2.3.5 met one already, written f′′=−ff'' = -f: the second derivative of sin⁡t\sin t is −sin⁡t-\sin t. The equation says the curve always bends back towards 0, by as much as it is away from 0. That makes it swing.

This lesson solves the family

ay′′+by′+cy=0ay'' + by' + cy = 0

where aa, bb and cc are numbers and a≠0a \neq 0. It is linear: yy, y′y' and y′′y'' each appear on their own, to the first power, times a constant. It has constant coefficients: aa, bb and cc do not change with tt, and the right-hand side is 0.

So y′′+5y′+4y=0y'' + 5y' + 4y = 0 belongs to the family. yy′′=1yy'' = 1 (a product), (y′)2=y(y')^2 = y (a power) and ty′′+y=0ty'' + y = 0 (a coefficient that changes) do not.

Two starting values

A first-order equation needs one starting value, y(0)y(0). A second-order equation fixes how the curve bends, so a solution also needs its starting slope y′(0)y'(0): where it starts, and which way it heads. Lesson 6.2.2 uses those two values to pick one solution.

Units. If tt is in years, y′y' is in units of yy per year and y′′y'' per year squared. With a=1a = 1, bb is then per year and cc per year squared.

Checking a solution. As in lesson 6.1.1, substitute it. For y=e−ty = e^{-t}, y′=−e−ty' = -e^{-t} and y′′=e−ty'' = e^{-t}, so y′′+5y′+4y=(1−5+4)e−t=0y'' + 5y' + 4y = (1 - 5 + 4)e^{-t} = 0. It is a solution.

Trying an exponential

The derivatives of erte^{rt} are multiples of itself: y′=rerty' = re^{rt} and y′′=r2erty'' = r^2e^{rt} (lesson 2.3.4). Put y=erty = e^{rt} into ay′′+by′+cy=0ay'' + by' + cy = 0 and every term carries the same factor:

(ar2+br+c) ert=0(ar^2 + br + c)\,e^{rt} = 0

Since erte^{rt} is never 0, the bracket must be. That quadratic in rr, ar2+br+c=0ar^2 + br + c = 0, is the characteristic equation of the differential equation, and it decides everything.

Rule: The characteristic equation

ay′′+by′+cy=0has the solution y=ertwhen ar2+br+c=0\begin{gathered} ay'' + by' + cy = 0 \\[4pt] \text{has the solution } y = e^{rt} \\[4pt] \text{when } ar^2 + br + c = 0 \end{gathered}

Read it off the equation: y′′y'' becomes r2r^2, y′y' becomes rr, and yy becomes 1. Its roots are the rates rr that work.

For y′′+5y′+4y=0y'' + 5y' + 4y = 0 the characteristic equation is r2+5r+4=0r^2 + 5r + 4 = 0. A table of trial rates finds the two that work:

rr0−1-1−2-2−3-3−4-4−5-5
r2+5r+4r^2 + 5r + 440−2-2−2-204

The quadratic formula of lesson 1.2.2 gives the same pair: r=−5±25−162=−5±32r = \frac{-5 \pm \sqrt{25 - 16}}{2} = \frac{-5 \pm 3}{2}, so r=−1r = -1 or r=−4r = -4. Both e−te^{-t} and e−4te^{-4t} solve the equation; e−2te^{-2t} does not.

Try it

The list is the table. np.roots (lesson 1.2.2) takes the coefficients [a, b, c] and returns the roots.

SymPy then substitutes each trial solution into y′′+5y′+4yy'' + 5y' + 4y and simplifies. A solution leaves 0; e−2te^{-2t} leaves −2e−2t-2e^{-2t}, the table's −2-2 times e−2te^{-2t}.

⌘/Ctrl + Enter runs the cell

Each term of the equation is a constant times yy or one of its derivatives. So a sum such as 2e−t−3e−4t2e^{-t} - 3e^{-4t} is a solution too. Lesson 6.2.2 shows that every solution is such a combination, and how to choose it.

The discriminant b2−4acb^2 - 4ac of lesson 1.2.2 sorts the equations into three cases: two real roots, one repeated root, or two complex roots.

Two real roots

When b2−4ac>0b^2 - 4ac > 0 there are two real roots r1r_1 and r2r_2, and two solutions er1te^{r_1t} and er2te^{r_2t}. The signs of the roots say what they do.

  • Both negative: both solutions die away. In y′′+5y′+4y=0y'' + 5y' + 4y = 0, e−4te^{-4t} fades fastest. At t=2t = 2, e−t=0.1353e^{-t} = 0.1353 but e−4t=0.000335e^{-4t} = 0.000335, so the root nearer 0 sets the long-run pace.
  • One positive: y′′−y=0y'' - y = 0 has r2−1=0r^2 - 1 = 0, so r=±1r = \pm 1. The solution ete^{t} grows without bound and e−te^{-t} dies away.
  • A zero root: y′′+2y′=0y'' + 2y' = 0 has r2+2r=r(r+2)=0r^2 + 2r = r(r + 2) = 0, so r=0r = 0 or −2-2. The root 0 gives e0t=1e^{0t} = 1: the constant 1 is a solution.

The rates are per unit of tt: with tt in years, e−4te^{-4t} shrinks by the factor e−4e^{-4} every year.

A repeated root

When b2−4ac=0b^2 - 4ac = 0, the two roots coincide. For y′′+4y′+4y=0y'' + 4y' + 4y = 0, r2+4r+4=(r+2)2r^2 + 4r + 4 = (r + 2)^2, so r=−2r = -2 only. That gives one solution, e−2te^{-2t}, but a second-order equation needs two.

The second is te−2tte^{-2t}. Check it with the product rule (lesson 2.3.2):

y=te−2ty′=(1−2t) e−2ty′′=(4t−4) e−2t\begin{aligned} y &= te^{-2t} \\ y' &= (1 - 2t)\,e^{-2t} \\ y'' &= (4t - 4)\,e^{-2t} \end{aligned}

Then y′′+4y′+4y=[(4t−4)+4(1−2t)+4t]e−2t=0y'' + 4y' + 4y = \big[(4t - 4) + 4(1 - 2t) + 4t\big]e^{-2t} = 0. In numbers:

ttyyy′y'y′′y''y′′+4y′+4yy'' + 4y' + 4y
001−4-40
0.50.183940−0.735759-0.7357590
10.135335−0.135335-0.13533500

Rule: A repeated root

ar2+br+c=a(r−r0)2solutions er0t and ter0t\begin{gathered} ar^2 + br + c = a(r - r_0)^2 \\[4pt] \text{solutions } e^{r_0 t} \text{ and } te^{r_0 t} \end{gathered}

The extra factor tt supplies the missing second solution. The root is r0=−b2ar_0 = -\frac{b}{2a}: in lesson 1.2.2's picture, the parabola's vertex touches the axis there.

Try it

The loop rebuilds the table from the formulas for yy, y′y' and y′′y'' above. round(…, 12) hides rounding noise in the last column.

SymPy then substitutes e−2te^{-2t} and te−2tte^{-2t} directly.

⌘/Ctrl + Enter runs the cell

Complex roots: waves

Start with y′′=−yy'' = -y, or y′′+y=0y'' + y = 0. Its characteristic equation r2+1=0r^2 + 1 = 0 has no real roots, but it has two complex ones, r=±ir = \pm i (lesson 1.7.2). By Euler's formula (lessons 1.7.3 and 2.7.2),

eit=cos⁡t+isin⁡te^{it} = \cos t + i\sin t

Its real part, cos⁡t\cos t, and its imaginary part, sin⁡t\sin t, are each solutions. Lesson 2.3.5 found this directly: differentiating sin⁡t\sin t twice gives −sin⁡t-\sin t, and cos⁡t\cos t gives −cos⁡t-\cos t. The solutions are waves of period 2π2\pi.

The same holds for y′′+4y=0y'' + 4y = 0. Now r=±2ir = \pm 2i, and e2it=cos⁡2t+isin⁡2te^{2it} = \cos 2t + i\sin 2t, so the solutions are cos⁡2t\cos 2t and sin⁡2t\sin 2t. They swing twice as fast, with period 2π2=π\frac{2\pi}{2} = \pi.

Damped waves

Now add a first-derivative term: y′′+2y′+5y=0y'' + 2y' + 5y = 0. The discriminant is 4−20=−164 - 20 = -16, and the quadratic formula gives

r=−2±−162=−1±2ir = \frac{-2 \pm \sqrt{-16}}{2} = -1 \pm 2i

Split e(−1+2i)te^{(-1 + 2i)t} by the exponent rules (lesson 1.4.1), then use Euler's formula:

e(−1+2i)t=e−t e2it=e−tcos⁡2t+i e−tsin⁡2t\begin{gathered} e^{(-1 + 2i)t} = e^{-t}\,e^{2it} \\ = e^{-t}\cos 2t + i\,e^{-t}\sin 2t \end{gathered}

Because aa, bb and cc are real, the real part and the imaginary part of a complex solution are each real solutions. So the equation has e−tcos⁡2te^{-t}\cos 2t and e−tsin⁡2te^{-t}\sin 2t. The other root, −1−2i-1 - 2i, gives the same pair again.

Rule: Complex roots

r=α±iωsolutions eαtcos⁡ωtand eαtsin⁡ωtα=−b2aω=4ac−b22a\begin{gathered} r = \alpha \pm i\omega \\[4pt] \text{solutions } e^{\alpha t}\cos\omega t \\ \text{and } e^{\alpha t}\sin\omega t \\[6pt] \alpha = -\frac{b}{2a} \\[4pt] \omega = \frac{\sqrt{4ac - b^2}}{2a} \end{gathered}

The real part α\alpha (alpha) sets the size: the waves shrink if α<0\alpha < 0, last if α=0\alpha = 0 and grow if α>0\alpha > 0. The imaginary part ω\omega (omega) sets the speed: the period is 2πω\frac{2\pi}{\omega}.

The waves of e−tcos⁡2te^{-t}\cos 2t swing between the curves e−te^{-t} and −e−t-e^{-t}, called the envelope. With tt in years, ω=2\omega = 2 is in radians per year (lesson 2.3.5), and one swing takes π≈3.14\pi \approx 3.14 years.

The two basic solutions in each case. Real roots give exponentials; a repeated root adds the factor tt; complex roots give waves inside the envelope ±eαt\pm e^{\alpha t}, here ±e−t\pm e^{-t}.

Try it

cmath (lesson 1.7.3) computes e(−1+2i)te^{(-1 + 2i)t} at t=0.5t = 0.5 and 1. Its real and imaginary parts match e−tcos⁡2te^{-t}\cos 2t and e−tsin⁡2te^{-t}\sin 2t.

SymPy then substitutes the four waves of this section into their equations.

⌘/Ctrl + Enter runs the cell

Damping

The by′by' term is called damping: with aa and cc positive, a positive bb drains the swing. Hold c=4c = 4 and change bb in y′′+by′+4y=0y'' + by' + 4y = 0:

bbb2−16b^2 - 16rootssolutions
0−16-16±2i\pm 2iwaves that last, period π\pi
0.5−15.75-15.75−0.25±1.9843i-0.25 \pm 1.9843iwaves dying down like e−0.25te^{-0.25t}
40−2-2, repeatedcritically damped: no waves
59−1-1 and −4-4overdamped: no waves, slower return
−0.5-0.5−15.75-15.750.25±1.9843i0.25 \pm 1.9843iwaves growing like e0.25te^{0.25t}

Small damping lets the waves die down slowly. At b=4b = 4 the waves just disappear.

More damping than that gives two negative real roots, and the one nearer 0 makes the return slower. A negative bb feeds the swing instead, and the waves grow.

The explorer solves y′′+by′+cy=0y'' + by' + cy = 0 from y(0)=1y(0) = 1 and y′(0)=0y'(0) = 0; its other presets are rows of the damping table. Pick the preset y′′=−yy'' = -y and raise bb from 0: the waves die down faster, and from b=2b = 2 on they no longer cross zero. Then drag bb below 0, and make cc negative.

Explore

The equation y″ + by′ + cy = 0 with y(0) = 1 and y′(0) = 0. Its behaviour is decided by the roots of r² + br + c = 0. Set b = 0 for waves that go on for ever, then raise b to damp them.

0246810−101
r² + br + c = 0
b² − 4c = −15.75: complex roots, r = −0.25 ± 1.984i
So
waves that die down like e^(−0.25t), period 3.166

With a=1a = 1, the point (b,c)(b, c) tells you the case at a glance. The roots are complex above the parabola c=b24c = \frac{b^2}{4}, where b2−4c<0b^2 - 4c < 0, and real below it. Below the bb-axis, c<0c < 0 makes b2−4c\sqrt{b^2 - 4c} larger than ∣b∣|b|, so one root is positive.

Where (b,c)(b, c) sits decides the kind of solution. The dots are this lesson's examples; the damping table walks along the line c=4c = 4, crossing the parabola at b=4b = 4.

Checking with solve_ivp

Lesson 6.1.2 solved first-order equations numerically with solve_ivp. A second-order equation becomes two first-order ones if the slope gets its own name, v=y′v = y':

y′=vv′=−bv+cya\begin{aligned} y' &= v \\ v' &= -\frac{bv + cy}{a} \end{aligned}

The second line is the equation ay′′+by′+cy=0ay'' + by' + cy = 0 solved for y′′y''. Now the unknown is the pair (y,v)(y, v), which solve_ivp handles as a list.

Try it

The cell solves y′′+2y′+5y=0y'' + 2y' + 5y = 0 from y(0)=1y(0) = 1 and y′(0)=−1y'(0) = -1, the starting value and slope of e−tcos⁡2te^{-t}\cos 2t. It prints the solution at t=0,0.5,…,5t = 0, 0.5, \ldots, 5, then the exact wave.

With rtol=1e-10 and atol=1e-12 the two agree to far more than the 6 printed decimals. With the default tolerances of lesson 6.1.2 they differ by about 2×10−42 \times 10^{-4}.

⌘/Ctrl + Enter runs the cell

Lesson 6.2.2 combines the two basic solutions to meet given starting values, or conditions at two points. Case study 6.2.4 uses the same trial-solution idea to value a put that never expires.

Common mistakes

  1. Put each coefficient in its place. y′′−9y=0y'' - 9y = 0 has no y′y' term, so its characteristic equation is r2−9=0r^2 - 9 = 0, with roots ±3\pm 3. It is not r2−9r=0r^2 - 9r = 0.
  2. Keep aa. 2y′′+3y′+y=02y'' + 3y' + y = 0 gives 2r2+3r+1=02r^2 + 3r + 1 = 0, with roots −12-\frac{1}{2} and −1-1.
  3. A repeated root gives one exponential. The second solution is ter0tte^{r_0t}, not er0te^{r_0t} again. np.roots can report a repeated root as a pair with a tiny imaginary part, such as 10−810^{-8}; decide the case from b2−4acb^2 - 4ac.
  4. Complex roots: α\alpha for size, ω\omega for speed. For −1±2i-1 \pm 2i the solutions are e−tcos⁡2te^{-t}\cos 2t and e−tsin⁡2te^{-t}\sin 2t, not e2tcos⁡te^{2t}\cos t. The waves die down only if α<0\alpha < 0.
  5. The period is 2πω\frac{2\pi}{\omega}, in radians. y′′+4y=0y'' + 4y = 0 has ω=2\omega = 2 and period π\pi.
  6. The trial erte^{rt} needs constant coefficients. In ty′′+y=0ty'' + y = 0 the factor tt stays, and no single rr works. Lesson 6.2.2 tries powers xpx^p for a different family.
  7. With a=0a = 0 there is no second derivative. The equation is first order, as in module 6.1.

Constant coefficients and the characteristic equation

0 of 12 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
  10. 10.
  11. 11.
  12. 12.
How to type answers
  • Powers with ^: x^7, 2^(1/3), a^-2.
  • Multiply with * or by writing side by side: 3x^2, 2(x+1).
  • ln(x) is the natural log, log(x, 2) is log base 2, e is Euler's number, sqrt(x) is a square root.
  • sin(x), cos(x) and tan(x) take radians; write pi for π and sin(x)^2 for sin²x.
  • Your first answer to each question is saved: it counts towards your score and brings the question back for review.
  • Exact answers like ln(20)/ln(3) are best. Decimals need about 4 significant figures.

Summary card

  • ay′′+by′+cy=0ay'' + by' + cy = 0, with constants a≠0a \neq 0, bb and cc, is a second-order linear equation. A solution needs two starting values, y(0)y(0) and y′(0)y'(0).
  • y=erty = e^{rt} is a solution exactly when ar2+br+c=0ar^2 + br + c = 0, the characteristic equation.
  • Two real roots r1r_1, r2r_2: solutions er1te^{r_1t} and er2te^{r_2t}. A repeated root r0=−b2ar_0 = -\frac{b}{2a}: er0te^{r_0t} and ter0tte^{r_0t}.
  • Complex roots α±iω\alpha \pm i\omega: eαtcos⁡ωte^{\alpha t}\cos\omega t and eαtsin⁡ωte^{\alpha t}\sin\omega t, by Euler's formula. y′′=−yy'' = -y gives cos⁡t\cos t and sin⁡t\sin t; the period is 2πω\frac{2\pi}{\omega}.
  • Damping b>0b > 0 (with a,c>0a, c > 0): waves die down while b2<4acb^2 < 4ac, vanish at b2=4acb^2 = 4ac (critically damped), and give two decaying exponentials beyond (overdamped). b<0b < 0 makes them grow.
  • For solve_ivp, write v=y′v = y': then y′=vy' = v and v′=−bv+cyav' = -\frac{bv + cy}{a}.

Free further reading

Optional. This lesson covers what you need; these add more examples and practice. All are free to read.