Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Nonhomogeneous ODEs that don’t have constant coefficients or an r(x)r(x) in our table can’t be solved using the method of undetermined coefficients. An alternative for such ODEs is the method of variation of parameters.

For example, consider the ODE

y+y=secxy'' + y = \sec x

The secant is not in our table of right-hand sides, so we will use variation of parameters to find a particular solution. The homogenous ODE is solved by y1=cosxy_1 = \cos x and y2=sinxy_2 = \sin x so

y1=cosxy2=sinxy1=sinxy2=cosx\begin{align} y_1 &= \cos x & y_2 &= \sin x \\ y_1' &= -\sin x & y_2' &= \cos x \end{align}

and

W=cos2x(sin2x)=1W = \cos^2 x - (-\sin^2 x) = 1

Hence,

yp=cosxsinxsecxd ⁣x+sinxcosxsecxd ⁣x=cosxsinxcosxd ⁣x+sinxd ⁣x=cosxlncosx+xsinx\begin{align} y_{\rm p} &= -\cos x\int\sin x\sec x\d{x} +\sin x\int\cos x\sec x\d{x} \\ &= \cos x\int \frac{-\sin x}{\cos x}\d{x} + \sin x \int \d{x} \\ &= \cos x\ln|\cos x| + x\sin x \end{align}

and

y=c1cosx+c2sinx+cosxlncosx+xsinxy = c_1 \cos x + c_2 \sin x + \cos x\ln|\cos x| + x\sin x

Example: Steady heat diffusion with internal source

We are solving the steady-state heat diffusion equation with an internal source:

αd ⁣2Td ⁣x2+qxsinx=0\alpha \dd{2}{T}{x} + qx \sin x = 0

where α\alpha is thermal diffusivity, and qxsinxqx \sin x is the heat source. The boundary conditions are:

T(1)=T(1)=1T(-1) = T(1) = 1

In standard form,

T=qxsinxT'' = -q x \sin x
  1. Find homogeneous solution:

    αTh=0αλ2=0λ=0\begin{align} \alpha T_{\rm h}'' &= 0 \\ \alpha \lambda^2 &= 0 \\ \lambda &= 0 \end{align}

    so,

    Th=c1+c2xT_{\rm h} = c_1 + c_2 x
  2. Find particular solution using variation of parameters:

    y1=1,y2=xy1=0,y2=1\begin{align} y_1 &= 1, \quad y_2 = x \\ y_1' &= 0, \quad y_2' = 1 \end{align}

    so the Wronskian is W=110x=1W = 1 \cdot 1 - 0 \cdot x = 1. The right-hand side function is

    r=qxsinxαr = -\frac{qx \sin x}{\alpha}

    so the particular solution is:

    Tp=1x(qxsinxα)d ⁣x+x(qxsinxα)d ⁣x=qαx2sinxd ⁣xqαxxsinxd ⁣x\begin{align} T_{\rm p} &= -1 \int x \left( \frac{-q x \sin x}{\alpha} \right) \, \d{x} + x \int \left( \frac{-q x \sin x}{\alpha} \right) \, \d{x} \\ &= \frac{q}{\alpha} \int x^2 \sin x \, \d{x} - \frac{q}{\alpha} x \int x \sin x \, \d{x} \end{align}

    These integrals can both be evaluated by parts. For the first integral, use the tabular method:

    signuud ⁣v\d{v}
    sinx\sin x
    ++x2x^2cosx-\cos x
    -2x2xsinx-\sin x
    ++2cosx\cos x
    0

    so

    x2sinxd ⁣x=x2cosx+2xsinx+2cosx\int x^2 \sin x \, \d{x} = -x^2 \cos x + 2x \sin x + 2 \cos x

    For the second integral, use

    u=xd ⁣v=sinxd ⁣xd ⁣u=1d ⁣xv=cosx\begin{align} u &= x & \d{v} &= \sin x \d{x} \\ \d{u} &= 1 \d{x} & v &= -\cos{x} \end{align}

    so

    xsinxd ⁣x=xcosx+cosxd ⁣x=xcosx+sinx\int x \sin x \d{x} = -x \cos x + \int \cos x \d{x} = -x \cos x + \sin x

    Substitute everything back:

    Tp=qα[x2cosx+2xsinx+2cosx]qαx[xcosx+sinx]=qα[2cosx+xsinx]\begin{align} T_{\rm p} &= \frac{q}{\alpha} \left[ -x^2 \cos x + 2x \sin x + 2 \cos x \right] - \frac{q}{\alpha} x \left[ -x \cos x + \sin x \right] \\ &= \frac{q}{\alpha} [2 \cos x + x \sin x] \end{align}
  3. Combine and apply boundary conditions.

    The general solution is

    T=c1+c2x+qα(2cosx+xsinx)T = c_1 + c_2 x + \frac{q}{\alpha}(2\cos x + x \sin x)

    The boundary conditions are:

    T(1)=c1c2+qα[2cos(1)sin(1)]=1=c1c2+qα[2cos1+sin1]T(1)=c1+c2+qα[2cos1+sin1]=1\begin{align} T(-1) &= c_1 - c_2 + \frac{q}{\alpha}[2\cos(-1) - \sin(-1)] = 1\\ &= c_1 - c_2 + \frac{q}{\alpha}[2\cos 1 + \sin 1] \\ T(1) &= c_1 + c_2 + \frac{q}{\alpha}[2\cos 1 + \sin 1] = 1 \end{align}

    This is a system of linear equations that can be solved for c1c_1 and c2c_2. Subtracting the two equations gives:

    0=2c20 = 2 c_2

    so c2=0c_2 = 0. Plugging back in and solving for c1c_1:

    1=c1+qα(2cos1+sin1)c1=1qα(2cos1+sin1)\begin{align} 1 &= c_1 + \frac{q}{\alpha}(2\cos 1 + \sin 1) \\ c_1 &= 1 - \frac{q}{\alpha}(2\cos 1 + \sin 1) \end{align}

The final result is:

T=1+qα[2(cosxcos1)+xsinxsin1]T = 1 + \frac{q}{\alpha}\left[2(\cos x - \cos 1) + x \sin x - \sin 1\right]

Skill builder problems

Solve:

Solution to Exercise 1
  1. Find homogeneous solution yhy_{\rm h}:

    yh4yh+4yh=0λ24λ+4=0(λ2)2=0\begin{align} y_{\rm h}'' - 4y_{\rm h}' + 4y_{\rm h} &= 0 \\ \lambda^2 - 4\lambda + 4 &= 0 \\ (\lambda -2)^2 &= 0 \end{align}

    so λ=2\lambda = 2 is a repeated eigenvalue and

    yh=(c1+c2x)e2xy_{\rm h} = (c_1 + c_2 x) e^{2x}
  2. Find particular solution ypy_{\rm p}:

    y1=e2xy2=xe2xy1=2e2xy2=(1+2x)e2x\begin{align} y_1 &= e^{2x} &\quad y_2&= x e^{2x} \\ y_1' &= 2 e^{2x} &\quad y_2'&= (1 + 2x) e^{2x} \end{align}

    so the Wronskian is W=(1+2x)e4x2xe4x=e4xW =(1 + 2x) \cdot e^{4x} - 2x \cdot e^{4x} = e^{4x}. The right-hand side function is

    r=x2exr = x^{2} e^{x}

    so the particular solution is:

    yp=e2xxe2x(x2ex)e4xd ⁣x+xe2xe2x(x2ex)e4xd ⁣x=e2xx3exd ⁣x+xe2xx2exd ⁣x\begin{align} y_{\rm p} &= -e^{2x} \int \frac{x e^{2x} (x^{2} e^{x})}{e^{4x}} \d{x} + x e^{2x} \int \frac{e^{2x} (x^{2} e^{x})}{e^{4x}} \d{x} \\ &= -e^{2x} \int x^{3} e^{-x} \d{x} + x e^{2x} \int x^{2} e^{-x} \d{x} \end{align}

    These integrals can both be evaluated by parts using the tabular method:

    For the first

    signuud ⁣v\d{v}
    exe^{-x}
    ++x3x^3ex-e^{-x}
    -3x23x^2exe^{-x}
    ++6x6xex-e^{-x}
    -6exe^{-x}
    0

    so

    x3exd ⁣x=x3ex3x2ex6xex6ex\int x^3 e^{-x} \d{x} = -x^3 e^{-x} - 3x^2 e^{-x} - 6x e^{-x}- 6 e^{-x}

    For the second

    signuud ⁣v\d{v}
    exe^{-x}
    ++x2x^2ex-e^{-x}
    -2x2xexe^{-x}
    ++2ex-e^{-x}
    0

    so

    x2exd ⁣x=x2ex2xex2ex\int x^2 e^{-x} \d{x} = -x^2 e^{-x} - 2x e^{-x} - 2 e^{-x}

    Substitute everything back:

    yp=e2x(x3ex3x2ex6xex6ex)+xe2x(x2ex2xex2ex)=(x2+4x+6)ex\begin{align} y_{\rm p} &= -e^{2x} \left( -x^3 e^{-x} - 3x^2 e^{-x} - 6x e^{-x} - 6 e^{-x} \right) \\ &\quad + x e^{2x} \left( -x^2 e^{-x} - 2x e^{-x} - 2 e^{-x} \right) \\ &= (x^2 + 4x + 6) e^x \end{align}
  3. Combine and apply initial conditions:

    The general solution and its first derivative are

    y=(c1+c2x)e2x+(x2+4x+6)exy=2(c1+c2x)e2x+c2e2x+(x2+4x+6)ex+(2x+4)ex\begin{align} y &= (c_1 + c_2 x) e^{2x}+(x^{2}+4x+6)e^{x} \\ y' &= 2(c_1 + c_2 x) e^{2x} + c_2e^{2x} + (x^{2}+4x+6) e^{x} + (2x+4)e^{x} \end{align}

    Plugging in intial conditions

    y(0)=c1+6=0y(0)=2c1+c2+10=0\begin{align} y(0) &= c_1 + 6 = 0 y'(0) &= 2 c_1 + c_2 + 10 = 0 \end{align}

    gives c1=6c_1 = -6 and c2=2c_2 = 2.

The final solution is:

y=(2x6)e2x+(x2+4x+6)exy = (2 x - 6) e^{2x} + (x^{2}+4x+6)e^{x}
Solution to Exercise 2
  1. Find homogeneous solution yhy_{\rm h}:

    yh+yh=0λ2+1=0\begin{align} y_{\rm h}' + y_{\rm h} &= 0 \\ \lambda^2 + 1 &= 0 \end{align}

    so λ1,2=±i\lambda_{1,2} = \pm i and:

    yh=c1cosx+c2sinxy_{\rm h} = c_1 \cos x + c_2 \sin_x
  2. Find particular solution ypy_{\rm p}:

    y1=cosx,y2=sinxy1=sinx,y2=cosx\begin{align} y_1 &= \cos x , \quad y_2 = \sin x \\ y_1' &= -\sin x, \quad y_2'= \cos x \end{align}

    so the Wronskian is W=cos2x+sin2x=1W = \cos^2 x + \sin^2 x = 1. The right-hand side function is

    r=cscxr = \csc x

    so the particular solution is:

    yp=cosxsinxcsc(x)d ⁣x+sinxcosxcsc(x)d ⁣x=cosxd ⁣x+sinxcosxsinxd ⁣x=xcosx+sinxlnx\begin{align} y_p &= -\cos x \int \sin x\csc(x) \d{x} + \sin x\int \cos x\csc(x) \d{x} \\ &= -\cos x \int \d{x} + \sin x \int \frac{\cos x}{\sin x} \d{x} \\ &= -x \cos x + \sin x \ln|x| \end{align}
  3. Combine and apply initial conditions:

    The general solution and its first derivative are

    y=c1cosx+c2sinx+sinxlnsinxxcosxy=c1sinx+c2cosx+cosx(1+lnsinx)+xsinxcosx\begin{align} y &= c_1 \cos x + c_2 \sin x \\ & \quad + \sin x \ln\left| \sin x \right| - x \cos x \\ y' &= -c_1 \sin x + c_2 \cos x \\ & \quad + \cos x (1 + \ln\left| \sin x \right|) + x \sin x - \cos x \end{align}

    Plugging in intial conditions

    y(π/2)=c2=0y(π/2)=c1+π/2=0\begin{align} y(\pi/2) &= c_2 = 0\\ y'(\pi/2) &= -c_1 + \pi/2 = 0 \end{align}

    so c1=π/2c_1 = \pi/2 and c2=0c_2 = 0.

The final solution is:

y=π2cosx+sinxlnsinxxcosxy = \frac{\pi}{2} \cos x + \sin x \ln \left| \sin x \right| - x \cos x