Quantitative Finance Interviews
46

3.5 Ordinary Differential Equations

In this section, we cover four typical differential equation patterns that are commonly seen in interviews.

47

Separable differential equations

A separable differential equation has the form dydx=g(x)h(y)\frac{dy}{dx}=g(x)h(y). Since it is separable, we can express the original equation as dyh(y)=g(x)dx\frac{dy}{h(y)}=g(x)dx. Integrating both sides, we have the solution ∫dyh(y)=∫g(x)dx\int\frac{dy}{h(y)}=\int g(x)dx.

A. Solve ordinary differential equation y′+6xy=0, y(0)=1y'+6xy=0,\ y(0)=1

Solution: Let g(x)=−6xg(x)=-6x and h(y)=yh(y)=y, we have dyy=−6xdx\frac{dy}{y}=-6xdx. Integrate both sides of the equation:

∫dyy=∫−6xdx⇒ln⁡y=−3x2+c⇒y=e−3x2+c,\int\frac{dy}{y}=\int-6xdx\Rightarrow\ln y=-3x^2+c\Rightarrow y=e^{-3x^2+c},

where cc is a constant. Plugging in the initial condition y(0)=1y(0)=1, we have c=0c=0 and y=e−3x2y=e^{-3x^2}.

B. Solve ordinary differential equation y′=x−yx+yy'=\frac{x-y}{x+y}.7

Solution: Unlike the last example, this equation is not separable in its current form. But we can use a change of variable to turn it into a separable differential equation. Let z=x+yz=x+y, then the original differential equation is converted to

d(z−x)dx=x−(z−x)z⇒dzdx−1=2xz−1⇒zdz=2xdx⇒∫zdz=∫2xdx+c⇒(x+y)2=z2=2x2+c⇒y2+2xy−x2=c\begin{aligned} \frac{d(z-x)}{dx}&=\frac{x-(z-x)}{z}\Rightarrow\frac{dz}{dx}-1=\frac{2x}{z}-1\Rightarrow zdz=2xdx\Rightarrow\int zdz=\int2xdx+c\\ &\Rightarrow(x+y)^2=z^2=2x^2+c\Rightarrow y^2+2xy-x^2=c \end{aligned}

First-order linear differential equations

A first-order differential linear equation has the form dydx+P(x)y=Q(x)\frac{dy}{dx}+P(x)y=Q(x). The standard approach to solving a first-order differential equation is to identify a suitable function I(x)I(x), called an integrating factor, such that I(x)(y′+P(x)y)=I(x)y′+I(x)P(x)yI(x)(y'+P(x)y)=I(x)y'+I(x)P(x)y

48

=(I(x)y)′=(I(x)y)'; Then we have (I(x)y)′=I(x)Q(x)(I(x)y)'=I(x)Q(x) and we can integrate both sides to solve for yy:

I(x)y=∫I(x)Q(x)dx⇒y=∫I(x)Q(x)dxI(x).I(x)y=\int I(x)Q(x)dx\Rightarrow y=\frac{\int I(x)Q(x)dx}{I(x)}.

The integrating factor, I(x)I(x), must satisfy dI(x)dx=I(x)P(x)\frac{dI(x)}{dx}=I(x)P(x), which means I(x)I(x) is a separable differential equation with general solution I(x)=e∫P(x)dxI(x)=e^{\int P(x)dx}.8

Solve ordinary different equation y′+yx=1x2, y(1)=1y'+\frac{y}{x}=\frac{1}{x^2},\ y(1)=1, where x>0x>0.

Solution: This is a typical example of first-order linear equations with P(x)=1xP(x)=\frac{1}{x} and Q(x)=1x2Q(x)=\frac{1}{x^2}. So I(x)=e∫P(x)dx=e∫(1/x)dx=eln⁡x=xI(x)=e^{\int P(x)dx}=e^{\int(1/x)dx}=e^{\ln x}=x and we have I(x)Q(x)=1xI(x)Q(x)=\frac{1}{x}.

∴I(x)(y′+P(x)y)=(xy)′=I(x)Q(x)=1/x\therefore I(x)(y'+P(x)y)=(xy)'=I(x)Q(x)=1/x

Taking integration on both sides, xy=∫(1/x)dx=ln⁡x+c⇒y=ln⁡x+cxxy=\int(1/x)dx=\ln x+c\Rightarrow y=\frac{\ln x+c}{x}.

Plugging in y(1)=1y(1)=1, we get c=1c=1 and y=ln⁡x+1xy=\frac{\ln x+1}{x}.

Homogeneous linear equations

A homogenous linear equation is a second-order differential equation with the form a(x)d2ydx2+b(x)dydx+c(x)=0a(x)\frac{d^2y}{dx^2}+b(x)\frac{dy}{dx}+c(x)=0.

It is easy to show that, if y1y_1 and y2y_2 are linearly independent solutions to the homogeneous linear equation, then any y(x)=c1y1(x)+c2y2(x)y(x)=c_1y_1(x)+c_2y_2(x), where c1c_1 and c2c_2 are arbitrary constants, is a solution to the homogeneous linear equation as well.

When a,ba,b and cc (a≠0a\ne0) are constants instead of functions of xx, the homogenous linear equation has closed form solutions:

Let r1r_1 and r2r_2 be the roots of the characteristic equation ar2+br+c=0ar^2+br+c=0,9

49
  1. If r1r_1 and r2r_2 are real and r1≠r2r_1\ne r_2, then the general solution is y=c1er1x+c2er2xy=c_1e^{r_1x}+c_2e^{r_2x};
  2. If r1r_1 and r2r_2 are real and r1=r2=rr_1=r_2=r, then the general solution is y=c1erx+c2xerxy=c_1e^{rx}+c_2xe^{rx};
  3. If r1r_1 and r2r_2 are complex numbers α±iβ\alpha\pm i\beta, then the general solution is y=eαx(c1cos⁡βx+c2sin⁡βx)y=e^{\alpha x}(c_1\cos\beta x+c_2\sin\beta x).

It is easy to verify that the general solutions indeed satisfy the homogeneous linear solutions by taking the first and secondary derivatives of the general solutions.

What is the solution of ordinary differential equation y′′+y′+y=0y''+y'+y=0?

Solution: In this specific case, we have a=b=c=1a=b=c=1 and b2−4ac=−3<0b^2-4ac=-3<0, so we have complex roots r=−1/2±3/2ir=-1/2\pm\sqrt{3}/2i (α=−1/2, β=3/2\alpha=-1/2,\ \beta=\sqrt{3}/2), and the general solution to the differential equation is therefore

y=eαx(c1cos⁡βx+c2sin⁡βx)=e−1/2x(c1cos⁡(3/2x)+c2sin⁡(3/2x)).y=e^{\alpha x}(c_1\cos\beta x+c_2\sin\beta x)=e^{-1/2x}\left(c_1\cos(\sqrt{3}/2x)+c_2\sin(\sqrt{3}/2x)\right).

Nonhomogeneous linear equations

Unlike a homogenous linear equation ad2ydx2+bdydx+c=0a\frac{d^2y}{dx^2}+b\frac{dy}{dx}+c=0, a nonhomogeneous linear equation ad2ydx2+bdydx+c=d(x)a\frac{d^2y}{dx^2}+b\frac{dy}{dx}+c=d(x) has no closed-form solution. But if we can find a particular solution yp(x)y_p(x) for ad2ydx2+bdydx+c=d(x)a\frac{d^2y}{dx^2}+b\frac{dy}{dx}+c=d(x), then y=yp(x)+yg(x)y=y_p(x)+y_g(x), where yg(x)y_g(x) is the general solution of the homogeneous equation ad2ydx2+bdydx+c=0a\frac{d^2y}{dx^2}+b\frac{dy}{dx}+c=0, is a general solution of the nonhomogeneous equation ad2ydx2+bdydx+c=d(x)a\frac{d^2y}{dx^2}+b\frac{dy}{dx}+c=d(x).

50

Although it may be difficult to identify a particular solution yp(x)y_p(x) in general, in the special case when d(x)d(x) is a simple polynomial, the particular solution is often a polynomial of the same degree.

What is the solution of ODEs y′′+y′+y=1y''+y'+y=1 and y′′+y′+y=xy''+y'+y=x?

Solution: In these ODEs, we again have a=b=c=1a=b=c=1 and b2−4ac=−3<0b^2-4ac=-3<0, so we have complex solutions r=−1/2±3/2ir=-1/2\pm\sqrt{3}/2i (α=−1/2, β=3/2\alpha=-1/2,\ \beta=\sqrt{3}/2) and the general solution is y=e−1/2x(c1cos⁡(3/2x)+c2sin⁡(3/2x))y=e^{-1/2x}\left(c_1\cos(\sqrt{3}/2x)+c_2\sin(\sqrt{3}/2x)\right).

What is a particular solution for y′′+y′+y=1y''+y'+y=1? Clearly y=1y=1 is. So the solution to y′′+y′+y=1y''+y'+y=1 is

y=yp(x)+yg(x)=e−1/2x(c1cos⁡(3/2x)+c2sin⁡(3/2x))+1.y=y_p(x)+y_g(x)=e^{-1/2x}\left(c_1\cos(\sqrt{3}/2x)+c_2\sin(\sqrt{3}/2x)\right)+1.

To find a particular solution for y′′+y′+y=xy''+y'+y=x, Let yp(x)=mx+ny_p(x)=mx+n, then we have y′′+y′+y=0+m+(mx+n)=x⇒m=1,n=−1y''+y'+y=0+m+(mx+n)=x\Rightarrow m=1,n=-1. So the particular solution is x−1x-1 and the solution to y′′+y′+y=xy''+y'+y=x is

y=yp(x)+yg(x)=e−1/2x(c1cos⁡(3/2x)+c2sin⁡(3/2x))+(x−1).y=y_p(x)+y_g(x)=e^{-1/2x}\left(c_1\cos(\sqrt{3}/2x)+c_2\sin(\sqrt{3}/2x)\right)+(x-1).