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 dxdy=g(x)h(y). Since it is separable, we can express the original equation as h(y)dy=g(x)dx. Integrating both sides, we have the solution ∫h(y)dy=∫g(x)dx.
A. Solve ordinary differential equation y′+6xy=0,y(0)=1
Solution: Let g(x)=−6x and h(y)=y, we have ydy=−6xdx. Integrate both sides of the equation:
∫ydy=∫−6xdx⇒lny=−3x2+c⇒y=e−3x2+c,
where c is a constant. Plugging in the initial condition y(0)=1, we have c=0 and y=e−3x2.
B. Solve ordinary differential equation y′=x+yx−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+y, then the original differential equation is converted to
A first-order differential linear equation has the form dxdy+P(x)y=Q(x). The standard approach to solving a first-order differential equation is to identify a suitable function I(x), called an integrating factor, such that I(x)(y′+P(x)y)=I(x)y′+I(x)P(x)y
48
=(I(x)y)′; Then we have (I(x)y)′=I(x)Q(x) and we can integrate both sides to solve for y:
I(x)y=∫I(x)Q(x)dx⇒y=I(x)∫I(x)Q(x)dx.
The integrating factor, I(x), must satisfy dxdI(x)=I(x)P(x), which means I(x) is a separable differential equation with general solution I(x)=e∫P(x)dx.8
Solve ordinary different equation y′+xy=x21,y(1)=1, where x>0.
Solution: This is a typical example of first-order linear equations with P(x)=x1 and Q(x)=x21. So I(x)=e∫P(x)dx=e∫(1/x)dx=elnx=x and we have I(x)Q(x)=x1.
∴I(x)(y′+P(x)y)=(xy)′=I(x)Q(x)=1/x
Taking integration on both sides, xy=∫(1/x)dx=lnx+c⇒y=xlnx+c.
Plugging in y(1)=1, we get c=1 and y=xlnx+1.
Homogeneous linear equations
A homogenous linear equation is a second-order differential equation with the form a(x)dx2d2y+b(x)dxdy+c(x)=0.
It is easy to show that, if y1 and y2 are linearly independent solutions to the homogeneous linear equation, then any y(x)=c1y1(x)+c2y2(x), where c1 and c2 are arbitrary constants, is a solution to the homogeneous linear equation as well.
When a,b and c (a=0) are constants instead of functions of x, the homogenous linear equation has closed form solutions:
Let r1 and r2 be the roots of the characteristic equation ar2+br+c=0,9
49
If r1 and r2 are real and r1=r2, then the general solution is y=c1er1x+c2er2x;
If r1 and r2 are real and r1=r2=r, then the general solution is y=c1erx+c2xerx;
If r1 and r2 are complex numbers α±iβ, then the general solution is y=eαx(c1cosβx+c2sinβ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=0?
Solution: In this specific case, we have a=b=c=1 and b2−4ac=−3<0, so we have complex roots r=−1/2±3/2i (α=−1/2,β=3/2), and the general solution to the differential equation is therefore
Unlike a homogenous linear equation adx2d2y+bdxdy+c=0, a nonhomogeneous linear equation adx2d2y+bdxdy+c=d(x) has no closed-form solution. But if we can find a particular solution yp(x) for adx2d2y+bdxdy+c=d(x), then y=yp(x)+yg(x), where yg(x) is the general solution of the homogeneous equation adx2d2y+bdxdy+c=0, is a general solution of the nonhomogeneous equation adx2d2y+bdxdy+c=d(x).
50
Although it may be difficult to identify a particular solution yp(x) in general, in the special case when 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=1 and y′′+y′+y=x?
Solution: In these ODEs, we again have a=b=c=1 and b2−4ac=−3<0, so we have complex solutions r=−1/2±3/2i (α=−1/2,β=3/2) and the general solution is y=e−1/2x(c1cos(3/2x)+c2sin(3/2x)).
What is a particular solution for y′′+y′+y=1? Clearly y=1 is. So the solution to y′′+y′+y=1 is
To find a particular solution for y′′+y′+y=x, Let yp(x)=mx+n, then we have y′′+y′+y=0+m+(mx+n)=x⇒m=1,n=−1. So the particular solution is x−1 and the solution to y′′+y′+y=x is