SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 6.4.1 Diffusion and the heat equationConcept · 30 min
      2. 6.4.2 The fundamental solutionConcept · 30 min
      3. 6.4.3 Practice set: the heat equationPractice set · 20 min
      4. 6.4.4 Case study: from Black–Scholes to the heat equationCase study · 35 min

Level 6, Differential equations 6.4 The heat equation Lesson 2 of 4

ConceptLesson 6.4.2 in Level 6, Differential equations. About 30 minutes.

The fundamental solution

A bell curve that solves the heat equation

Put one unit of heat at the point x=0x = 0 of an endless rod at time 0, and let it spread under ut=uxxu_t = u_{xx}. The temperature it makes is a bell curve, called the fundamental solution or heat kernel.

Rule: Fundamental solution

Φ(x,t)=14πt e−x2/(4t),t>0\Phi(x, t) = \frac{1}{\sqrt{4\pi t}}\,e^{-x^2/(4t)}, \quad t > 0

It solves ut=uxxu_t = u_{xx} at every xx and every t>0t > 0. The capital Φ\Phi (phi) is this bell; the normal distribution function keeps its name NN, as in lesson 2.6.3.

Check it by computing partials (lesson 4.1.2). The chain rule gives Φx\Phi_x; the product rule then gives Φxx\Phi_{xx}; and differentiating both factors in tt gives Φt\Phi_t:

Φx=−x2t ΦΦxx=(x24t2−12t)ΦΦt=(x24t2−12t)Φ\begin{aligned} \Phi_x &= -\frac{x}{2t}\,\Phi \\ \Phi_{xx} &= \left(\frac{x^2}{4t^2} - \frac{1}{2t}\right)\Phi \\ \Phi_t &= \left(\frac{x^2}{4t^2} - \frac{1}{2t}\right)\Phi \end{aligned}

The last two agree. Both are 0 at x=±2tx = \pm\sqrt{2t}, where the bell changes from bending down to bending up (lesson 5.4.3). By lesson 6.4.1 those two points are still for a moment; between them the bell sinks, and outside them it rises.

time tt0.010.050.251
height Φ(0,t)=14πt\Phi(0, t) = \frac{1}{\sqrt{4\pi t}}2.8209481.2615660.564190.282095
width 2t\sqrt{2t}0.1414210.3162280.7071071.414214

The bell is a normal density

Lesson 5.4.3's density of N(μ,σ2)\mathcal{N}(\mu, \sigma^2) is 1σ2πe−(x−μ)2/(2σ2)\frac{1}{\sigma\sqrt{2\pi}}e^{-(x - \mu)^2/(2\sigma^2)}. With μ=0\mu = 0 and σ2=2t\sigma^2 = 2t it is exactly Φ(x,t)\Phi(x, t). So Φ(⋅,t)\Phi(\cdot, t) is the density of N(0,2t)\mathcal{N}(0, 2t), and three facts follow.

  • Its area is 1 for every tt (lesson 2.6.3): the heat is conserved, as lesson 6.4.1 said.
  • Its variance is 2t2t and its width 2t\sqrt{2t}: lesson 6.4.1's spreading, now exact.
  • As tt shrinks to 0 it narrows into a spike of area 1 at 0, which is how the heat started.

Heat reaches everywhere at once

Φ(x,t)>0\Phi(x, t) > 0 for every xx as soon as t>0t > 0. At t=0.01t = 0.01 the heat at distance 1 is Φ(1,0.01)≈3.9×10−11\Phi(1, 0.01) \approx 3.9 \times 10^{-11}: positive, but far too small to notice. So heat travels at infinite speed, in amounts that fall off like e−x2/(4t)e^{-x^2/(4t)}.

The heat from one point at three times. Each bell has area 1; as tt grows four times, the width 2t\sqrt{2t} doubles and the height halves.

Try it

SymPy prints Φt\Phi_t, Φx\Phi_x and Φxx\Phi_{xx}, each divided by Φ\Phi, then Φt−Φxx\Phi_t - \Phi_{xx}, the area and the variance.

The loop checks the equation by central differences (lesson 2.8.1) at two points. Then the table; True says that norm.pdf with standard deviation 2t\sqrt{2t} equals Φ\Phi.

⌘/Ctrl + Enter runs the cell

Building any profile from spikes

A spike of heat 1 at yy instead of 0 spreads into Φ(x−y,t)\Phi(x - y, t): the same bell, centred at yy. A spike of heat qq gives q Φ(x−y,t)q\,\Phi(x - y, t). The equation is linear (lesson 6.3.1), so several spikes spread independently and their bells add up.

Two spikes. Put heat 1 at x=−1x = -1 and heat 2 at x=1x = 1. Then u(x,t)=Φ(x+1,t)+2 Φ(x−1,t)u(x, t) = \Phi(x + 1, t) + 2\,\Phi(x - 1, t), with total heat 3 at every time.

u(x,t)u(x, t)x=−1x = -1x=0x = 0x=1x = 1x=2x = 2
t=0.05t = 0.051.26160.02552.52310.017
t=0.25t = 0.250.58490.62271.13870.4152
t=1t = 10.48960.65910.6680.4691

At t=0.05t = 0.05 the two bumps are separate, with almost nothing between them. By t=1t = 1 they have merged into one broad hump, slightly higher on the right.

A whole profile

Any starting profile u0(x)u_0(x) can be cut into thin strips of width Δy\Delta y. The strip at yy holds heat u0(y) Δyu_0(y)\,\Delta y, and spreads into a bell. Adding the bells is a Riemann sum (lesson 2.5.1), and as Δy\Delta y shrinks it becomes an integral.

Rule: Solution by the fundamental solution

u(x,t)=∫−∞∞u0(y) Φ(x−y,t) dyu(x, t) = \int_{-\infty}^{\infty} u_0(y)\,\Phi(x - y, t)\,dy

u0u_0 is the profile at t=0t = 0. For t>0t > 0, u(x,t)u(x, t) is an average of u0u_0 near xx, weighted by a bell centred at xx with width 2t\sqrt{2t}. As tt shrinks to 0 it tends to u0(x)u_0(x) wherever u0u_0 is continuous.

The next section's step profile shows the sum settling. At x=1x = 1, t=0.5t = 0.5, strips on [0,10][0, 10] give 0.843903 for Δy=0.5\Delta y = 0.5, 0.841446 for 0.1 and 0.841346 for 0.01. The integral itself is 0.841345.

Try it

The loop prints the two-spike table, with the total heat by quad in the last column.

Then the strips: each adds Δy⋅Φ(1−y,0.5)\Delta y \cdot \Phi(1 - y, 0.5), with yy at the middle of the strip.

⌘/Ctrl + Enter runs the cell

The step

Start with a rod that is cold on the left and hot on the right: u0=0u_0 = 0 for x<0x < 0 and u0=1u_0 = 1 for x>0x > 0. The integral keeps only y>0y > 0:

u(x,t)=∫0∞Φ(x−y,t) dyu(x, t) = \int_0^{\infty} \Phi(x - y, t)\,dy

Substitute z=y−x2tz = \frac{y - x}{\sqrt{2t}}, a linear inner function with dy=2t dzdy = \sqrt{2t}\,dz (lesson 2.6.1). The integrand becomes φ(z)\varphi(z), the standard normal density, and the lower limit y=0y = 0 becomes z=−x2tz = -\frac{x}{\sqrt{2t}}. The area under φ\varphi above −w-w is N(w)N(w), by symmetry (lesson 5.4.3).

Rule: The step spreads into N

u(x,t)=N ⁣(x2t)u(x, t) = N\!\left(\frac{x}{\sqrt{2t}}\right)

For the step that is 0 on the left of 0 and 1 on the right. At x=0x = 0 the value is 12\frac{1}{2} for every t>0t > 0, halfway up the jump. It tends to 1 far to the right and to 0 far to the left.

At t=0.5t = 0.5 the width 2t\sqrt{2t} is 1, so u(x,0.5)=N(x)u(x, 0.5) = N(x): 0.02275, 0.158655, 0.5, 0.841345 and 0.97725 at xx = −2-2, −1-1, 0, 1 and 2. Now follow the fixed point x=1x = 1 as the jump spreads past it. Its value falls from 1.0 (to 4 decimals) at t=0.01t = 0.01 to 0.9214 at 0.25, 0.7602 at 1 and 0.6915 at 2.

Try it

norm.cdf is NN. The first loop compares N ⁣(x2t)N\!\left(\frac{x}{\sqrt{2t}}\right) with quad of the integral at t=0.5t = 0.5.

The second loop follows the point x=1x = 1 over time.

⌘/Ctrl + Enter runs the cell

The kink

Now start from the kink u0=max⁡(x,0)u_0 = \max(x, 0): zero on the left, the line y=xy = x on the right. Then u(x,t)=∫0∞y Φ(x−y,t) dyu(x, t) = \int_0^\infty y\,\Phi(x - y, t)\,dy. Split the yy in front as x+(y−x)x + (y - x).

The xx part is xx times the step's integral, x N ⁣(x2t)x\,N\!\left(\frac{x}{\sqrt{2t}}\right). The same substitution turns the (y−x)(y - x) part into 2t\sqrt{2t} times the integral of z φ(z)z\,\varphi(z) above −x2t-\frac{x}{\sqrt{2t}}. Since −φ(z)-\varphi(z) is an antiderivative of z φ(z)z\,\varphi(z) (lesson 2.6.1), that integral is φ ⁣(x2t)\varphi\!\left(\frac{x}{\sqrt{2t}}\right).

Rule: The kink spreads

u0=max⁡(x,0)u=x N ⁣(x2t)+2t φ ⁣(x2t)\begin{gathered} u_0 = \max(x, 0) \\[4pt] u = x\,N\!\left(\tfrac{x}{\sqrt{2t}}\right) + \sqrt{2t}\,\varphi\!\left(\tfrac{x}{\sqrt{2t}}\right) \end{gathered}

The corner is rounded and lifted: at x=0x = 0 the value is 2t φ(0)=t/π\sqrt{2t}\,\varphi(0) = \sqrt{t/\pi}. Far from 0 the solution hugs the two straight pieces.

At t=0.5t = 0.5 the values at xx = −2-2, −1-1, 0, 1 and 2 are 0.008491, 0.083315, 0.398942, 1.083315 and 2.008491. Each is above max⁡(x,0)\max(x, 0), by 0.008491, 0.083315, 0.398942, 0.083315 and 0.008491. That fits lesson 6.4.1: the kink never bends down, so it can only rise.

Its slope is the step's solution: ux=N ⁣(x2t)u_x = N\!\left(\frac{x}{\sqrt{2t}}\right), since the slope of the kink is the step. Case study 6.4.4 turns a call option's payoff into a profile very like this kink.

The step and the kink, with their solutions at three times. The step's curves all pass through one half at 0. The kink's corner is rounded and lifted by t/π\sqrt{t/\pi}, while far from 0 the straight pieces barely move.

Try it

kink is the rule above. The loop compares it with quad at t=0.5t = 0.5 and prints how far it lies above max⁡(x,0)\max(x, 0).

The next lines check that its slope, by a central difference, is the step's solution. Then t/π\sqrt{t/\pi} at three times.

⌘/Ctrl + Enter runs the cell

Growing profiles: ecxe^{cx}

The integral also works for profiles that grow, if they grow slowly enough. Take u0=ecxu_0 = e^{cx} for a number cc. Completing the square in the exponent (lesson 1.2.2), as case study 2.6.5 did, moves the bell:

ecy Φ(x−y,t)=ecx+c2t Φ(x+2ct−y,t)\begin{aligned} &e^{cy}\,\Phi(x - y, t) \\ &= e^{cx + c^2 t}\,\Phi(x + 2ct - y, t) \end{aligned}

The bell is now centred at x+2ctx + 2ct and scaled by ecx+c2te^{cx + c^2 t}. Its area is 1, so the whole integral is that scale.

Rule: Exponential profiles

u0=ecx⇒u=ecx+c2tu_0 = e^{cx} \quad \Rightarrow \quad u = e^{cx + c^2 t}

Check: ut=c2uu_t = c^2 u and uxx=c2uu_{xx} = c^2 u. The profile bends up everywhere, so it rises everywhere. If u0=ecxu_0 = e^{cx} only for x>0x > 0, and 0 elsewhere, only the moved bell's area above 0 counts; by the step's rule, u=ecx+c2t N ⁣(x+2ct2t)u = e^{cx + c^2 t}\,N\!\left(\frac{x + 2ct}{\sqrt{2t}}\right).

For c=1c = 1 at x=0x = 0, t=1t = 1, the value is e≈2.718282e \approx 2.718282; for c=2c = 2 at t=0.5t = 0.5 it is e2≈7.389056e^2 \approx 7.389056. With the cut at 0, c=1c = 1 at x=0x = 0, t=0.5t = 0.5 gives e0.5N(1)≈1.387143e^{0.5}N(1) \approx 1.387143. Case study 6.4.4 needs exactly this cut version.

Where the integral fails

A profile that grows like ex2e^{x^2} is too fast. For u0=ex2u_0 = e^{x^2} at x=0x = 0 the integral is 11−4t\frac{1}{\sqrt{1 - 4t}}, which is 2.236068 at t=0.2t = 0.2; from t=14t = \frac{1}{4} on it diverges, and there is no solution. The kink, polynomials and every ecxe^{cx} are fine.

Try it

quad integrates ecy Φ(x−y,t)e^{cy}\,\Phi(x - y, t) over a window of 12 widths around the moved centre x+2ctx + 2ct, against ecx+c2te^{cx + c^2t}. Then the cut version from 0.

The last lines integrate ey2 Φ(−y,t)e^{y^2}\,\Phi(-y, t) over [−L,L][-L, L] for growing LL: it settles at t=0.2t = 0.2 and explodes at t=0.3t = 0.3.

⌘/Ctrl + Enter runs the cell

The same answer from random draws

Φ(⋅,t)\Phi(\cdot, t) is the density of a normal variable X∼N(0,2t)X \sim \mathcal{N}(0, 2t), so the rule reads u(x,t)=E[u0(x+X)]u(x, t) = \mathbb{E}[u_0(x + X)]: the starting profile, averaged over a random normal shift (module 5.4). That shift is like the end of a random walk of many small steps (lessons 5.11.1 and 5.7.3). Heat spreads the way a crowd of random walkers does.

Try it

200,000 seeded draws of XX with variance 2t=12t = 1, at x=1x = 1. The share with 1+X>01 + X > 0 estimates the step's N(1)N(1), and the average of max⁡(1+X,0)\max(1 + X, 0) the kink's value.

This run gives 0.841 and 1.0834, against 0.841345 and 1.083315. Their standard errors are about 0.0008 and 0.0019 (lesson 5.7.3).

⌘/Ctrl + Enter runs the cell

Common mistakes

  1. The variance is 2t2t, not tt. Φ(⋅,t)\Phi(\cdot, t) is the N(0,2t)\mathcal{N}(0, 2t) density, with width 2t\sqrt{2t}.
  2. Φ\Phi here is the heat kernel, a density. The normal distribution function is NN.
  3. Centre the bell where you want the answer. u(x,t)u(x, t) weights u0(y)u_0(y) by Φ(x−y,t)\Phi(x - y, t), a bell centred at xx.
  4. Only for t>0t > 0. Φ(x,0)\Phi(x, 0) divides by 0; at t=0t = 0 the answer is u0u_0 itself.
  5. The step stays at 12\frac{1}{2} at its jump, for every t>0t > 0.
  6. The kink's solution lies above the kink, by t/π\sqrt{t/\pi} at the corner.
  7. Mind the growth of u0u_0. ecxe^{cx} is fine; ex2e^{x^2} has a solution only until t=14t = \frac{1}{4}.

The fundamental solution

0 of 13 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.
  13. 13.
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

  • The fundamental solution Φ(x,t)=14πte−x2/(4t)\Phi(x, t) = \frac{1}{\sqrt{4\pi t}}e^{-x^2/(4t)} solves ut=uxxu_t = u_{xx}. It is the N(0,2t)\mathcal{N}(0, 2t) density: area 1, width 2t\sqrt{2t}, positive everywhere for t>0t > 0.
  • Any profile is a sum of spikes: u(x,t)=∫u0(y) Φ(x−y,t) dyu(x, t) = \int u_0(y)\,\Phi(x - y, t)\,dy, an average of u0u_0 near xx.
  • The step spreads into N ⁣(x2t)N\!\left(\frac{x}{\sqrt{2t}}\right); the kink into x N ⁣(x2t)+2t φ ⁣(x2t)x\,N\!\left(\frac{x}{\sqrt{2t}}\right) + \sqrt{2t}\,\varphi\!\left(\frac{x}{\sqrt{2t}}\right).
  • ecxe^{cx} becomes ecx+c2te^{cx + c^2 t}; cut at 0, it becomes ecx+c2tN ⁣(x+2ct2t)e^{cx + c^2 t}N\!\left(\frac{x + 2ct}{\sqrt{2t}}\right). Profiles like ex2e^{x^2} grow too fast.
  • u(x,t)=E[u0(x+X)]u(x, t) = \mathbb{E}[u_0(x + X)] with X∼N(0,2t)X \sim \mathcal{N}(0, 2t): heat spreads like a crowd of random walkers.

Free further reading

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