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.

What do we do when an ODE is not exact? For example,

yd ⁣x+xd ⁣y=0-y \d{x} + x \d{y} = 0

has

P=yQ=xPy=1Qx=1\begin{align} P &= -y & Q &= x \\ \pp{}{P}{y} &= -1 & \pp{}{Q}{x} &= 1 \end{align}

so it is not exact. However, we may be able to make it exact if we multiply by an integrating factor. For example, let’s try a factor F=1/x2F = 1/x^2. Multiplying through by F:

yx2d ⁣x+1xd ⁣y=0\begin{align} -\frac{y}{x^2} \d{x} + \frac{1}{x} \d{y} = 0 \end{align}

so

P=yx2Q=1xPy=1x2Qx=1x2\begin{align} P &= -\frac{y}{x^2} & Q &= \frac{1}{x} \\ \pp{}{P}{y} &= -\frac{1}{x^2} & \pp{}{Q}{x} &= -\frac{1}{x}^2 \end{align}

Now the ODE is exact and can be solved using techniques we learned previously.

Finding the integrating factor

Let’s use these formulas to arrive at the integrating factor we used above:

R=1x(11)=2xR = \frac{1}{x}(-1 - 1) = -\frac{2}{x}

is a function of only x so

F(x)=exp(2xd ⁣x)=exp(2lnx)=(elnx)2=1x2\begin{align} F(x) &= \exp\left( \int -\frac{2}{x} \d{x} \right) \\ &= \exp\left( -2 \ln x\right) \\ &= \left( e^{\ln x} \right)^{-2} \\ &= \frac{1}{x^2} \end{align}

Note that this is not the only suitable integrating factor! Let’s try the S route for fun:

S=QPR=xy(2x)=2yS = -\frac{Q}{P} R = -\frac{x}{-y} \left( -\frac{2}{x}\right) = -\frac{2}{y}

S is a function of only y so

F=exp(2yd ⁣y)=1y2F = \exp\left( \int -\frac{2}{y} \d{y} \right) = \frac{1}{y^2}

is another suitable integrating factor.

Application to linear first-order ODEs

For linear first-order ODES,

y+p(x)y=r(x)y' + p(x)y = r(x)

Use of an integrating factor F gives the general solution:

y(x)=1F(Frd ⁣x+c)F=exp(pd ⁣x)\begin{align} y(x) &= \frac{1}{F} \left( \int F r \d{x} + c \right) \\ F &= \exp\left(\int p \d{x}\right) \end{align}

Example: Mole balance on a tank with increasing inlet/outlet flow rate

A stream with concentration cf,Ac_{{\rm f},{\rm A}} of solute A flows into a tank with initial volume V at a continuously increasing volumetric flow rate Q=q˙tQ = \dot q t, where q˙\dot q is the rate of increase in the flow rate and t is time. A well-mixed stream is withdrawn from the tank at the same rate.

Tank with inlet and outlet flows and varying concentrations

If there are initial nA,0n_{{\rm A},0} moles of the solute, derive an expression for the number of moles in the tank nAn_{\rm A} as a function of time.


Formulate overall mole balances based on entering and exit streams.

d ⁣nAd ⁣t=n˙A,inn˙A,out\dd{}{n_{\rm A}}{t} = \dot{n}_{{\rm A},\rm{in}} - \dot{n}_{{\rm A},\rm{out}}

Replace the molar flowrates with the equivalent concentrations and volumetric flow rates

n˙A,in=cf,AQ=cf,Aq˙tn˙A,out=nAVQ=nAVq˙\begin{align} \dot{n}_{{\rm A},\rm{in}} &= c_{{\rm f},{\rm A}} Q = c_{{\rm f},{\rm A}} \dot{q}t \\ \dot{n}_{{\rm A},\rm{out}} &= \frac{n_{\rm A}}{V} Q = \frac{n_{\rm A}}{V} \dot{q} \end{align}

so the initial value problem is

n˙A=cf,Aq˙tnAVq˙t,nA(0)=nA,0\dot{n}_{\rm A} = c_{{\rm f},{\rm A}}\dot{q}t - \frac{n_{\rm A}}{V} \dot{q}t, \quad n_{\rm A}(0) = n_{{\rm A},0}

Rewrite in standard form

n˙A+(q˙tV)nA=cf,Aq˙t\dot{n}_{A} + \left(\frac{\dot{q}t}{V}\right) n_{\rm A} = c_{{\rm f},{\rm A}} \dot{q}t

This is a linear first-order ODE with

p=q˙tVr=cf,Aq˙tp = \frac{\dot{q}t}{V} \qquad r = c_{{\rm f},{\rm A}} \dot{q}t

that can be solved using an integrating factor:

F=epd ⁣t=exp(q˙tVd ⁣t)=exp(12q˙t2V)F = e^{\int p \d{t}} = \exp\left(\int{\frac{\dot{q}t}{V} \d{t}}\right) = \exp\left(\frac{1}{2}\frac{\dot{q} t^2}{V}\right)

Then, evaluate the integral

Frd ⁣t=exp(12q˙t2V)cf,Aq˙td ⁣t=eucf,AVdu=cf,AVeu=cf,AVexp(12q˙t2V)\begin{align} \int F r \d{t} &= \int \exp\left(\frac{1}{2}\frac{\dot{q} t^2}{V}\right) c_{{\rm f},{\rm A}}\dot{q}t \d{t} \\ &= \int{e^{u}c_{{\rm f},{\rm A}}Vdu} \\ &= c_{{\rm f},{\rm A}}V e^u \\ &= c_{{\rm f},{\rm A}}V \exp\left(\frac{1}{2}\frac{\dot{q}t^2}{V}\right) \end{align}

using the u substitution:

u=12q˙t2Vd ⁣u=q˙tVd ⁣t\begin{align} u &= \frac{1}{2}\frac{\dot{q} t^2}{V} \\ \d{u} &= \frac{\dot{q} t}{V} \d{t} \end{align}

Last, combine the results:

nA(t)=1F(Frd ⁣t+c)=cf,AV+cexp(12q˙t2V)\begin{align} n_{\rm A}(t) &= \frac{1}{F} \left(\int F r \d{t} + c \right) \\ &= c_{{\rm f},{\rm A}} V + c \exp\left(-\frac{1}{2}\frac{\dot{q}t^2}{V}\right) \end{align}

Use the inital conditions to evaluate the integration constant:

nA(0)=cf,AV+c=nA,0c=nA,0cf,AV\begin{align} n_{\rm A}(0) &= c_{{\rm f},{\rm A}}V + c = n_{{\rm A},0} \\ c &= n_{{\rm A}, 0} - c_{{\rm f},{\rm A}} V \end{align}

The final result is:

nA(t)=cf,AV+(nA,0cf,AV)exp(12q˙t2V)n_{\rm A}(t) = c_{{\rm f},{\rm A}}V + (n_{{\rm A},0} - c_{{\rm f},{\rm A}}V) \exp\left(-\frac{1}{2}\frac{\dot{q}t^2}{V}\right)

Example: Hormone level (again)

We had

c+kc=A+Bcos(πt12),c(0)=c0c' + kc = A + B\cos\left(\frac{\pi t}{12}\right), \quad c(0) = c_0

This is a linear first-order ODE with:

p=kcr=A+Bcos(πt12)p = kc \qquad r = A + B\cos\left(\frac{\pi t}{12}\right)

that can be solved using an integrating factor:

F=ekd ⁣t=ektF = e^{\int k \d{t}} = e^{kt}

Then, evaluate the integral using the table of integrals or integration by parts to evaluate the second integral in the equation

Frd ⁣t=ekt[A+Bcos(πt12)]d ⁣t=Aektd ⁣t+Bektcos(πt12)d ⁣t=Akekt+Bektk2+(π/12)2[kcos(πt12)+π12sin(πt12)]\begin{align} \int F r \d{t} &= \int e^{kt} \left[A+B\cos\left(\frac{\pi t}{12}\right)\right]\d{t} \\ &= A\int e^{kt} \d{t} + B \int e^{kt} \cos\left(\frac{\pi t}{12}\right)\d{t} \\ &= \frac{A}{k} e^{kt} + B \frac{e^{kt}}{k^{2}+(\pi/12)^2} \Biggl[k \cos{(\frac{\pi t}{12})} + \frac{\pi}{12}\sin{\left(\frac{\pi t}{12}\right)}\Biggr] \end{align}

The general solution is:

c(t)=1F(Frd ⁣t+c)=Ak+Bk2+(π/12)2[kcos(πt12)+π12sin(πt12)]+cekt\begin{align} c(t) &= \frac{1}{F} \left(\int F r \d{t} + c^* \right) \\ &= \frac{A}{k} + \frac{B}{k^{2}+(\pi/12)^2} \Biggl[k \cos\left(\frac{\pi t}{12}\right) + \frac{\pi}{12}\sin{\left(\frac{\pi t}{12}\right)}\Biggr] + c^* e^{-kt} \end{align}

Use the inital condition to evaluate the integration constant:

c(0)=Ak+Bk2+(π/12)2k+c=c0c=c0AkBk2+(π/12)2k\begin{align} c(0) &= \frac{A}{k} + \frac{B}{k^{2}+(\pi/12)^2} k + c^* = c_0 \\ c^* &= c_0 - \frac{A}{k} - \frac{B}{k^{2}+(\pi/12)^2} k \end{align}

The final solution is:

c(t)=Ak+Bk2+(π/12)2[kcos(πt12)+π12sin(πt12)]+[c0AkBkk2+(π/12)2]ekt\begin{align} c(t) &= \frac{A}{k} + \frac{B}{k^{2}+(\pi/12)^2} \Biggl[k \cos\left(\frac{\pi t}{12}\right) + \frac{\pi}{12}\sin{\left(\frac{\pi t}{12}\right)}\Biggr] \\ &+ \Biggl[c_0 - \frac{A}{k} - \frac{Bk}{k^{2}+(\pi/12)^2} \Biggr] e^{-kt} \end{align}

Skill builder problems

Solve the following differential equations:

Solution to Exercise 1

This ODE is not in the standard form, so we need to first rearrange:

xyd ⁣y=(x4+y2)d ⁣x(x4+y2)d ⁣xxyd ⁣y=0\begin{align} xy \d{y} = (x^4+y^2) \d{x} \\ (x^4 + y^2) \d{x} - xy \d{y} = 0 \end{align}

so:

P=x4+y2Q=xy\begin{align} P &= x^4 + y^2 \\ Q &= -xy \end{align}

Check to see if the ODE is exact:

(Py)x=2y(Qx)y=y\begin{align} \td{}{P}{y}{x} &= 2y \\ \td{}{Q}{x}{y} &= -y \end{align}

The two partial derivatives are not equal, so the ODE is not exact. In order to make it exact, we need to find an integrating factor F. First, compute:

R=1Q[(Py)x(Qx)y]=1xy(2y(y))=3x\begin{align} R &= \frac{1}{Q}\left[\td{}{P}{y}{x} - \td{}{Q}{x}{y} \right] \\ &=\frac{1}{-xy}(2y-(-y)) \\ &= -\frac{3}{x} \end{align}

R is a function of only x, so use it to compute F

F=exp(3xd ⁣x)=e3ln(x)=x3F = \exp\left(\int \frac{-3}{x} \d{x}\right) = e^{-3\ln(x)} = x^{-3}

Apply the integrating factor to the original ODE:

x3(x4+y2)d ⁣xx3(xy)d ⁣y=0(x+y2x3)d ⁣xyx2d ⁣y=0\begin{align} x^{-3}(x^4+y^2) \d{x} - x^{-3}(xy) \d{y} &= 0 \\ \left(x+\frac{y^2}{x^{-3}}\right) \d{x} - \frac{y}{x^2} \d{y} &= 0 \end{align}

Integrate the Q of our exact ODE with respect to y:

f(x,y)=yx2d ⁣y=y22x2+k(x)f(x,y) = \int -\frac{y}{x^2} \d{y} = \frac{-y^2}{2x^2}+k(x)

where k is an unknown function of x. Then, differentiate f with respect to x and compare to P of the exact ODE:

(fx)y=y2x3+k(x)=P=x+y2x3k(x)=x\begin{align} \td{}{f}{x}{y} = \frac{y^2}{x^3} + k'(x) &= P = x + \frac{y^2}{x^3} \\ k'(x) &= x \\ \end{align}

This ODE for k can be integrated directly (neglecting the integration constant)

k=xd ⁣x=x22k = \int x \d{x} = \frac{x^2}{2}

Putting it all together,

f=y22x2+x22=c\begin{align} f = \frac{-y^2}{2x^2} + \frac{x^2}{2} = c \end{align}

is an implicit solution of the ODE.

Solution to Exercise 2

This ODE is not in the standard form, so we need to first rearrange:

(ex+y+yey)d ⁣x+(xey1)d ⁣y=0\begin{align} (e^{x+y} + ye^y) \d{x} + (x e^y - 1) \d{y} = 0 \end{align}

so

P=ex+y+yeyQ=xey1\begin{align} P &= e^{x+y} + ye^y \\ Q &= x e^y - 1 \end{align}

Check if the differential equation is exact:

(Py)x=ex+y+yey+ey(Qx)y=ey\begin{align} \td{}{P}{y}{x} &= e^{x+y} + y e^y + e^y \\ \td{}{Q}{x}{y} &= e^y \end{align}

These are not equal, so the equation is not exact. To make it exact, find integrating factor F. The R formula gives:

R=1Q[(Py)x(Qx)y]=1xey1(ex+y+yey+eyey)=ey(ex+y)xey1\begin{align} R &= \frac{1}{Q}\left[\td{}{P}{y}{x} - \td{}{Q}{x}{y} \right] \\ &=\frac{1}{x e^y - 1}(e^{x+y} + y e^y + e^y - e^y) \\ &= \frac{e^y(e^x + y)}{x e^y - 1} \end{align}

this is not a function of only x, so try the S formula:

S=QPR=ey(ex+y)ex+y+yey=1\begin{align} S &= -\frac{Q}{P} R \\ &= -\frac{e^y(e^x + y)}{e^{x+y} + y e^y} \\ &= -1 \end{align}

This is a function of, at most, y so:

F=exp(Sd ⁣y)=eyF = \exp\left(\int S\d{y} \right) = e^{-y}

Multiply the equation by F:

(ex+y)d ⁣x+(xey)d ⁣y=0(e^x + y) \d{x} + (x - e^{-y}) \d{y} = 0

Now the equation is exact so integrate the new P with respect to x:

f(x,y)=(ex+y)d ⁣x=ex+xy+k(y)f(x,y) = \int (e^x + y) \d{x} = e^x + xy + k(y)

where k is an unknown function of y. Then, differentiate f with respect to y and compare to Q:

(fx)y=x+k(y)=Q=xeyk=ey\begin{align} \td{}{f}{x}{y} = x + k'(y) &= Q = x - e^{-y} \\ k' &= -e^{-y} \end{align}

This ODE for k can be integrated directly (neglecting the integration constant)

k(y)=eyd ⁣y=ey\begin{align} k(y) = \int -e^{-y} \d{y} = e^{-y} \end{align}

Putting it all together,

f(x,y)=ex+ey+xy=c\begin{align} f(x, y) = e^x + e^{-y} + xy = c \end{align}

is an implicit solution for the ODE.

Solution to Exercise 3

Rewrite in linear form:

yy=12x\begin{align} y' - y = 1 - 2x \end{align}

where

p=1r=12x\begin{align} p = -1 \qquad r = 1 - 2x \end{align}

Find integrating factor:

F=epd ⁣x=e1d ⁣x=ex\begin{align} F = e^{\int p\d{x}} = e^{\int -1 \d{x}} = e^{-x} \end{align}

Then, evaluate the integral

Frd ⁣x=ex(12x)d ⁣x\int F r \d{x} = \int e^{-x} (1-2x) \d{x}

This integral can be evaluated by parts using the tabular method:

signuud ⁣v\d{v}
exe^{-x}
++12x1-2xex-e^{-x}
--2exe^{-x}
0

so

Frd ⁣x=(2x1)ex+2ex=(2x+1)ex\int F r \d{x} = (2x-1)e^{-x} + 2 e^{-x} = (2x + 1) e^{-x}

Putting it all together:

y=1F(Frd ⁣x+c)=ex[(2x+1)ex+c]=1+2x+cex\begin{align} y &= \frac{1}{F}\left(\int F r \d{x} + c \right) \\ &= e^x \left[ (2x + 1) e^{-x} + c \right] \\ &= 1 + 2x + c e^x \end{align}