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 2 of 4

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

General solutions and boundary conditions

Adding solutions

Lesson 6.2.1 found two basic solutions y1y_1 and y2y_2 of each equation ay′′+by′+cy=0ay'' + by' + cy = 0. For y′′+5y′+4y=0y'' + 5y' + 4y = 0 they are e−te^{-t} and e−4te^{-4t}.

Any combination of them is also a solution. Substitute y=c1y1+c2y2y = c_1y_1 + c_2y_2: each derivative splits the same way, so the left side becomes c1c_1 times what y1y_1 gives plus c2c_2 times what y2y_2 gives.

Both are 0, so the sum is 0. For example, 2e−t−3e−4t2e^{-t} - 3e^{-4t} solves y′′+5y′+4y=0y'' + 5y' + 4y = 0.

Rule: The general solution

y=c1y1+c2y2c1,c2 any numbers\begin{gathered} y = c_1y_1 + c_2y_2 \\[4pt] c_1, c_2 \text{ any numbers} \end{gathered}

Here y1y_1 and y2y_2 are the two basic solutions of lesson 6.2.1. Every solution of the equation has this form, so the two constants are all that is left to choose.

In the words of lesson 3.5.1, the solutions are the span of y1y_1 and y2y_2: a set with two dimensions, one for each constant. The pair must be independent. e−te^{-t} and 3e−t3e^{-t} are multiples of each other, and their combinations never give e−4te^{-4t}.

For each case of lesson 6.2.1, the general solution reads:

rootsgeneral solution
two real, r1r_1 and r2r_2c1er1t+c2er2tc_1e^{r_1t} + c_2e^{r_2t}
repeated, r0r_0(c1+c2t) er0t(c_1 + c_2t)\,e^{r_0t}
complex, α±iω\alpha \pm i\omegaeαt(c1cos⁡ωt+c2sin⁡ωt)e^{\alpha t}(c_1\cos\omega t + c_2\sin\omega t)

Try it

SymPy substitutes 2e−t−3e−4t2e^{-t} - 3e^{-4t} into y′′+5y′+4yy'' + 5y' + 4y, then the combination with letters c1c_1 and c2c_2. Both give 0.

⌘/Ctrl + Enter runs the cell

Initial conditions: a 2 × 2 system

An initial-value problem gives the starting value and slope, y(0)=y0y(0) = y_0 and y′(0)=v0y'(0) = v_0. Each condition is one linear equation in c1c_1 and c2c_2.

Example 1. Solve y′′+5y′+4y=0y'' + 5y' + 4y = 0 with y(0)=1y(0) = 1 and y′(0)=0y'(0) = 0. The general solution is y=c1e−t+c2e−4ty = c_1e^{-t} + c_2e^{-4t}, with slope y′=−c1e−t−4c2e−4ty' = -c_1e^{-t} - 4c_2e^{-4t}. At t=0t = 0:

c1+c2=1−c1−4c2=0\begin{aligned} c_1 + c_2 &= 1 \\ -c_1 - 4c_2 &= 0 \end{aligned}

Adding the two equations gives −3c2=1-3c_2 = 1, so c2=−13c_2 = -\frac{1}{3} and c1=43c_1 = \frac{4}{3}. The solution is y=43e−t−13e−4ty = \frac{4}{3}e^{-t} - \frac{1}{3}e^{-4t}. It starts at 1, flat, and falls towards 0:

tt00.5123
yy10.7635960.4844010.1803350.066381

Rule: Initial conditions

c1y1(0)+c2y2(0)=y0c1y1′(0)+c2y2′(0)=v0\begin{gathered} c_1y_1(0) + c_2y_2(0) = y_0 \\[4pt] c_1y_1'(0) + c_2y_2'(0) = v_0 \end{gathered}

A 2 × 2 system for c1c_1 and c2c_2. Its matrix has each basic solution's value and slope at 0 as a column. For the pairs of lesson 6.2.1 its determinant is never 0, so every y0y_0 and v0v_0 give exactly one solution.

In Example 1 the matrix is (11−1−4)\begin{pmatrix} 1 & 1 \\ -1 & -4 \end{pmatrix}, with determinant −4+1=−3-4 + 1 = -3 (lesson 3.4.1). That the solution exists and is unique is a theorem about these equations; this lesson takes it as given.

Example 2. Solve y′′+2y′+5y=0y'' + 2y' + 5y = 0 with y(0)=1y(0) = 1 and y′(0)=0y'(0) = 0. The general solution is y=e−t(c1cos⁡2t+c2sin⁡2t)y = e^{-t}(c_1\cos 2t + c_2\sin 2t), so y(0)=c1=1y(0) = c_1 = 1.

The slope needs the product rule (lesson 2.3.2): at t=0t = 0 it is y′(0)=−c1+2c2y'(0) = -c_1 + 2c_2, where −c1-c_1 comes from the factor e−te^{-t}. Setting it to 0 gives c2=12c_2 = \frac{1}{2}, so

y=e−t(cos⁡2t+12sin⁡2t)y = e^{-t}\left(\cos 2t + \tfrac{1}{2}\sin 2t\right)

This is the curve lesson 6.2.1's explorer draws for b=2b = 2 and c=5c = 5. At t=1t = 1 it is 0.014164, just above 0, and at t=2t = 2 it is −0.139672-0.139672.

Try it

np.linalg.solve (lesson 3.3.1) finds c1c_1 and c2c_2 for Example 1, and np.linalg.det gives the determinant.

The formula is then compared with solve_ivp, using v=y′v = y' as in lesson 6.2.1. The last lines solve Example 2's system.

⌘/Ctrl + Enter runs the cell

Boundary conditions: two points

A boundary-value problem gives conditions at two different points instead, such as y(0)=Ay(0) = A and y(L)=By(L) = B. They still give two linear equations in c1c_1 and c2c_2. The difference is that the system can fail.

Example 3: one solution. Solve y′′−y=0y'' - y = 0 with y(0)=0y(0) = 0 and y(1)=1y(1) = 1. The roots are ±1\pm 1, so y=c1et+c2e−ty = c_1e^{t} + c_2e^{-t}, and the conditions read

c1+c2=0c1e+c2e−1=1\begin{aligned} c_1 + c_2 &= 0 \\ c_1e + c_2e^{-1} &= 1 \end{aligned}

So c2=−c1c_2 = -c_1 and c1(e−e−1)=1c_1(e - e^{-1}) = 1. Since e−e−1=2.350402e - e^{-1} = 2.350402, c1=0.425459c_1 = 0.425459. The solution passes y(0.5)=0.443409y(0.5) = 0.443409 and starts with slope y′(0)=0.850918y'(0) = 0.850918.

Example 4: none, or infinitely many. Take y′′+y=0y'' + y = 0 with y(0)=0y(0) = 0. The general solution is c1cos⁡t+c2sin⁡tc_1\cos t + c_2\sin t, and y(0)=0y(0) = 0 forces c1=0c_1 = 0. So the candidates are c2sin⁡tc_2\sin t, and the second condition decides.

  • y(π2)=1y(\frac{\pi}{2}) = 1: c2sin⁡π2=c2=1c_2\sin\frac{\pi}{2} = c_2 = 1. One solution, y=sin⁡ty = \sin t.
  • y(π)=1y(\pi) = 1: c2sin⁡π=0c_2\sin\pi = 0 for every c2c_2, never 1. No solution.
  • y(π)=0y(\pi) = 0: every c2c_2 works. Infinitely many solutions, y=c2sin⁡ty = c_2\sin t.

The solutions of y′′+y=0y'' + y = 0 with y(0)=0y(0) = 0. On [0,π2][0, \frac{\pi}{2}] each end height is reached by exactly one curve. On [0,π][0, \pi] they all meet again at 0, so y(π)=0y(\pi) = 0 has infinitely many solutions and y(π)=1y(\pi) = 1 has none.

The 2 × 2 matrix explains it. For y(0)=Ay(0) = A and y(L)=By(L) = B it is (10cos⁡Lsin⁡L)\begin{pmatrix} 1 & 0 \\ \cos L & \sin L \end{pmatrix}, with determinant sin⁡L\sin L. When LL is a multiple of π\pi, the determinant is 0: lesson 3.3.2's rank test then gives none or infinitely many, depending on BB.

Rule: Boundary-value problems

y(0)=A,y(L)=Bone solution, none,or infinitely many\begin{gathered} y(0) = A, \quad y(L) = B \\[4pt] \text{one solution, none,} \\ \text{or infinitely many} \end{gathered}

The two conditions give a 2 × 2 system for c1c_1 and c2c_2. If its determinant is not 0 there is exactly one solution; if it is 0, lesson 3.3.2 decides between none and infinitely many.

Try it

The first lines solve Example 3's system and print c1c_1, c2c_2, y(0.5)y(0.5) and y′(0)y'(0).

Then Example 4's matrix: its determinant sin⁡L\sin L for L=π2L = \frac{\pi}{2} and π\pi, rounded so that a tiny sin⁡π\sin\pi shows as 0. The ranks of AA and of [A∣b][A \mid \mathbf{b}] (lesson 3.3.2) follow, for B=1B = 1 and B=0B = 0.

⌘/Ctrl + Enter runs the cell

With B=1B = 1 the ranks are 1 and 2, so there is no solution. With B=0B = 0 both are 1, below the two unknowns, so there are infinitely many.

A condition at infinity

On a half-line t≥0t \ge 0, the second condition can be about the far end. Solve y′′−y=0y'' - y = 0 with y(0)=1y(0) = 1 and yy bounded: it stays between two fixed numbers as t→∞t \to \infty.

The general solution is c1et+c2e−tc_1e^{t} + c_2e^{-t}. Any c1≠0c_1 \neq 0 makes yy grow without bound, so c1=0c_1 = 0, and y(0)=1y(0) = 1 gives c2=1c_2 = 1: the solution is e−te^{-t}.

The equidimensional equation

Some equations have coefficients that change, in a pattern that keeps them easy. In the equidimensional equation

ax2y′′+bxy′+cy=0for x>0\begin{gathered} ax^2y'' + bxy' + cy = 0 \\ \text{for } x > 0 \end{gathered}

each derivative is multiplied by the power of xx that matches its order.

If xx is in metres, y′′y'' is in units of yy per metre squared. So x2y′′x^2y'' is in units of yy, like xy′xy' and yy. Every term has the same units: hence the name.

The exponential trial of lesson 6.2.1 fails here, but a power works. For y=xpy = x^p, the power rule (lesson 2.3.1) gives xy′=pxpxy' = px^p and x2y′′=p(p−1)xpx^2y'' = p(p - 1)x^p. Every term carries xpx^p:

[ap(p−1)+bp+c] xp=0\big[ap(p - 1) + bp + c\big]\,x^p = 0

Rule: Equidimensional equations

ax2y′′+bxy′+cy=0has the solution y=xpwhen ap(p−1)+bp+c=0\begin{gathered} ax^2y'' + bxy' + cy = 0 \\[4pt] \text{has the solution } y = x^p \\[4pt] \text{when } ap(p - 1) + bp + c = 0 \end{gathered}

The equation for pp has p(p−1)p(p - 1) where lesson 6.2.1 had r2r^2. With two real roots p1p_1 and p2p_2, the general solution is c1xp1+c2xp2c_1x^{p_1} + c_2x^{p_2}, for x>0x > 0.

Example 5. For x2y′′+2xy′−2y=0x^2y'' + 2xy' - 2y = 0, the equation for pp is p(p−1)+2p−2=p2+p−2=0p(p - 1) + 2p - 2 = p^2 + p - 2 = 0. A table of trial powers finds its roots:

pp−3-3−2-2−1-1012
p(p−1)+2p−2p(p - 1) + 2p - 240−2-2−2-204

The algebra agrees: p2+p−2=(p−1)(p+2)p^2 + p - 2 = (p - 1)(p + 2), so p=1p = 1 or p=−2p = -2. The general solution is y=c1x+c2x−2y = c_1x + c_2x^{-2}.

Now add conditions: y(1)=3y(1) = 3, and yy bounded as x→∞x \to \infty. The term c1xc_1x grows, so c1=0c_1 = 0. Then y(1)=c2=3y(1) = c_2 = 3, and y=3x−2y = 3x^{-2}, so y(2)=0.75y(2) = 0.75.

Repeated and complex powers

Put x=esx = e^s, so that s=ln⁡xs = \ln x. By the chain rule (lesson 2.3.3), the equation becomes a constant-coefficient equation in ss, with the equation for pp as its characteristic equation. Then xp=epsx^p = e^{ps}, and lesson 6.2.1's other two cases carry over:

  • A repeated root p0p_0 gives xp0x^{p_0} and xp0ln⁡xx^{p_0}\ln x. For x2y′′−xy′+y=0x^2y'' - xy' + y = 0, p(p−1)−p+1=(p−1)2p(p - 1) - p + 1 = (p - 1)^2, so the solutions are xx and xln⁡xx\ln x.
  • Complex roots α±iω\alpha \pm i\omega give xαcos⁡(ωln⁡x)x^{\alpha}\cos(\omega\ln x) and xαsin⁡(ωln⁡x)x^{\alpha}\sin(\omega\ln x). For x2y′′+xy′+y=0x^2y'' + xy' + y = 0, p2+1=0p^2 + 1 = 0, and the solutions are cos⁡(ln⁡x)\cos(\ln x) and sin⁡(ln⁡x)\sin(\ln x).

Case study 6.4.4 uses the same change of variable on a harder equation.

Try it

The list is Example 5's table, and np.roots solves p2+p−2=0p^2 + p - 2 = 0.

SymPy then substitutes xx, x−2x^{-2} and 3x−23x^{-2} into Example 5, and xln⁡xx\ln x and cos⁡(ln⁡x)\cos(\ln x) into their equations. positive=True tells SymPy that x>0x > 0.

⌘/Ctrl + Enter runs the cell

Solving a boundary-value problem numerically

solve_ivp needs a starting value and a starting slope. A boundary-value problem gives a starting value and an end value instead. Shooting turns one into the other: guess the slope, solve forward, and see where the end lands.

For Example 3, start at y(0)=0y(0) = 0 with slope ss. A slope of 0.4 lands at y(1)=0.47y(1) = 0.47, and a slope of 1.3 at 1.53: too low, then too high. Between them, brentq (lesson 1.3.2) finds the slope that lands on 1.

Each starting slope gives a different end height. The slope 0.8509 lands on the target y(1)=1y(1) = 1, as the exact slope y′(0)=0.850918y'(0) = 0.850918 of Example 3 says.

Rule: Shooting

start at y(0)=A, y′(0)=ssolve forward to Lchoose s so that y(L)=B\begin{gathered} \text{start at } y(0) = A,\ y'(0) = s \\[4pt] \text{solve forward to } L \\[4pt] \text{choose } s \text{ so that } y(L) = B \end{gathered}

Each guess of ss costs one run of solve_ivp. Finding ss is a root-finding problem for the miss y(L)−By(L) - B.

SciPy also has a ready-made solver, solve_bvp. It takes the equation as a pair (y,v)(y, v) with v=y′v = y', the two conditions as a function, and a first guess on a grid of points.

Try it

land(s) shoots from slope s and returns y(1)y(1). brentq finds the slope whose miss is 0 between 0 and 2, and the shot from it passes y(0.5)=0.443409y(0.5) = 0.443409, as Example 3 found.

solve_bvp gets the same numbers. Its bc returns how far each end is from its condition: y(0)−0y(0) - 0 and y(1)−1y(1) - 1.

⌘/Ctrl + Enter runs the cell

Lesson 6.2.3 practises both lessons of this module. Case study 6.2.4 puts the equidimensional equation and a condition at infinity together to value a put.

Common mistakes

  1. Two conditions need both constants. y=c1e−ty = c_1e^{-t} alone cannot meet y(0)=1y(0) = 1 and y′(0)=0y'(0) = 0: it would need c1=1c_1 = 1 and c1=0c_1 = 0.
  2. Differentiate the whole combination. For e−t(c1cos⁡2t+c2sin⁡2t)e^{-t}(c_1\cos 2t + c_2\sin 2t), y′(0)=−c1+2c2y'(0) = -c_1 + 2c_2, not 2c22c_2.
  3. The pair must be independent. c1e−t+c2⋅3e−tc_1e^{-t} + c_2\cdot 3e^{-t} is only a multiple of e−te^{-t}; its matrix has determinant 0.
  4. A boundary-value problem may have no solution, or many. y′′+y=0y'' + y = 0 with y(0)=0y(0) = 0 and y(π)=1y(\pi) = 1 has none.
  5. Bounded removes the growing part. On t≥0t \ge 0 it removes ete^{t}; on x≥1x \ge 1 it removes positive powers such as xx.
  6. Use p(p−1)p(p - 1), not p2p^2. For x2y′′−6y=0x^2y'' - 6y = 0 the equation is p(p−1)−6=0p(p - 1) - 6 = 0, with roots 3 and −2-2, not p2−6=0p^2 - 6 = 0.
  7. Powers need x>0x > 0. x−2x^{-2} and xln⁡xx\ln x are solutions on x>0x > 0; at x=0x = 0 the equation's leading coefficient ax2ax^2 is 0.

General solutions and boundary conditions

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

  • If y1y_1 and y2y_2 are the two basic solutions of ay′′+by′+cy=0ay'' + by' + cy = 0, the general solution is c1y1+c2y2c_1y_1 + c_2y_2: their span.
  • Initial conditions y(0)=y0y(0) = y_0, y′(0)=v0y'(0) = v_0 give a 2 × 2 system for c1c_1 and c2c_2. Its determinant is never 0, so there is exactly one solution.
  • Boundary conditions y(0)=Ay(0) = A, y(L)=By(L) = B also give a 2 × 2 system, but it can have one solution, none or infinitely many. y′′+y=0y'' + y = 0 with y(0)=0y(0) = 0 fails at L=πL = \pi.
  • A condition "bounded as t→∞t \to \infty" removes the growing solution.
  • ax2y′′+bxy′+cy=0ax^2y'' + bxy' + cy = 0 for x>0x > 0: y=xpy = x^p works when ap(p−1)+bp+c=0ap(p - 1) + bp + c = 0. A repeated root p0p_0 adds xp0ln⁡xx^{p_0}\ln x.
  • Shooting finds the starting slope that hits the far condition, with solve_ivp and brentq; solve_bvp solves the problem directly.

Free further reading

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