Artificial Intelligence 🤖
Differential equations
Ordinary differential equations
Exact & Inexact ODEs

Exact & Inexact ODEs

This section is concerned with a class of differential equations known as exact for which we can also identify a method of solution. We demonstrate the meaning of exactness through an example before going in to the details of the solution method.

Consider the following ODE,

4xy+1+(2x2+cosy)dydx=04 x y+1+\left(2 x^{2}+\cos y\right) \frac{d y}{d x}=0

We observe that Eq. (12.49) is neither separable nor linear and so neither of the methods discussed so far can be used. Note that here, the term which dictates that ODE (12.49) is nonlinear is cosy\cos y. Now, consider a function of two variables, f(x,y)f(x, y) given as,

f(x,y)=2x2y+x+sinyf(x, y)=2 x^{2} y+x+\sin y

where y=y(x)y=y(x). Next, we determine the total derivative of f(x,y)f(x, y) through implicit differentiation

ddx[f(x,y)]=4xy+2x2dydx+1+cosydydx\frac{d}{d x}[f(x, y)]=4 x y+2 x^{2} \frac{d y}{d x}+1+\cos y \frac{d y}{d x}

note that the first two terms on the RHS in Eq. (12.51) are the result of the product rule when 2x2y2 x^{2} y is differentiated wrt xx. Rearranging (12.51) yields,

ddx[f(x,y)]=4xy+1+(2x2+cosy)dydx\frac{d}{d x}[f(x, y)]=4 x y+1+\left(2 x^{2}+\cos y\right) \frac{d y}{d x}

which is equivalent to the LHS of Eq. (12.49). It follows that Eq. (12.49) may be expressed as

ddx[f(x,y)]=0\frac{d}{d x}[f(x, y)]=0

where f(x,y)f(x, y) is given by Eq. (12.50). Equation (12.53) states that the total derivative of f(x,y)f(x, y) is zero. Upon integrating both sides wrt xx yields

f(x,y)=c,f(x, y)=c,

which is equal to

2x2y+x+siny=c2 x^{2} y+x+\sin y=c

where cc is a constant. Equation (12.55) is the implicit form of the general solution to ODE (12.49). As usual, the particular solution is obtained by solving for the constant cc through application of an IC.

Using this 'special' function f(x,y)f(x, y) we are able to reduce an ODE which looks pretty difficult to solve at first and determine the general solution. This approach is applied to all first order exact ODEs but there are two main concerns:

  1. How can we tell if an ODE is exact?
  2. How can we determine the function f(x,y)f(x, y) for every exact ODE we encounter?

Condition for exactness

At this point let us recall the definition of the total derivative of a multivariable function. This is relevant when the variables that make up the function (like xx and yy in f(x,y)f(x, y) above) are not truly independent. To define the total rate of change of ff wrt xx, the partial derivative f/x\partial f / \partial x does not suffice because it does not give any information on how varying xx, changes yy. In such cases, to find the true slope of ff along the xx-direction, we need to define the total derivative of the function f(x,y)f(x, y) which in turn is expressed through the partial derivatives via the chain rule:

ddx[f(x,y)]=fxdxdx+fydydx\frac{d}{d x}[f(x, y)]=\frac{\partial f}{\partial x} \frac{d x}{d x}+\frac{\partial f}{\partial y} \frac{d y}{d x}

which simplifies to,

ddx[f(x,y)]=fx+fydydx\frac{d}{d x}[f(x, y)]=\frac{\partial f}{\partial x}+\frac{\partial f}{\partial y} \frac{d y}{d x}

We revisit ODE (12.49) using the assumption that a special function f(x,y)f(x, y) exists and it is given by Eq. (12.50). Next, let us obtain the partial derivatives of f(x,y)f(x, y) wrt xx and yy [as always, recall that y=y(x)]y=y(x)] :

fx=x[2x2y+x+siny]=4xy+1fy=y[2x2y+x+siny]=2x2+cosy\begin{aligned} \frac{\partial f}{\partial x} & =\frac{\partial}{\partial x}\left[2 x^{2} y+x+\sin y\right] \\ & =4 x y+1 \\ \frac{\partial f}{\partial y} & =\frac{\partial}{\partial y}\left[2 x^{2} y+x+\sin y\right] \\ & =2 x^{2}+\cos y \end{aligned}

Observe that Eq. (12.57) gives the first two terms on LHS of Eq. (12.49) and Eq. (12.58) is the coefficient of dy/dxd y / d x in Eq. (12.49). This implies that ODE (12.49) may be expressed as,

fx+fydydx=0\frac{\partial f}{\partial x}+\frac{\partial f}{\partial y} \frac{d y}{d x}=0

Definition 12.3 Any first order ODE that is exact may be put in the following form,

fx+fydydx=0\frac{\partial f}{\partial x}+\frac{\partial f}{\partial y} \frac{d y}{d x}=0

It follows that we can rewrite (12.59) as,

ddx[f(x,y)]=0\frac{d}{d x}[f(x, y)]=0

So far we have discussed exact ODEs using the example ODE (12.49). Now, let us consider a generalised form of ODE (12.49), given by

P(x,y)+Q(x,y)dydx=0P(x, y)+Q(x, y) \frac{d y}{d x}=0

where P(x,y)P(x, y) and Q(x,y)Q(x, y) are continuous functions. Note that Eq. (12.61) is often expressed in terms of the differential terms dx,dyd x, d y, as indicated in Eq. (12.40). However, now we look at the more general case where P(x,y),Q(x,y)P(x, y), Q(x, y) do not necessarily need to be homogeneous functions of the same degree. According to Definition 12.3, if there exists a function f(x,y)f(x, y) such that

P(x,y)=fx and Q(x,y)=fy,P(x, y)=\frac{\partial f}{\partial x} \quad \text { and } \quad Q(x, y)=\frac{\partial f}{\partial y},

then Eq. (12.62) is known to be exact.

Next, we discuss the condition for exactness. We start by partially differentiating PP wrt yy, yielding

Py=y(fx)=2fyx\frac{\partial P}{\partial y}=\frac{\partial}{\partial y}\left(\frac{\partial f}{\partial x}\right)=\frac{\partial^{2} f}{\partial y \partial x}

Similarly, the partial derivative of QQ wrt xx is

Qx=x(fy)=2fxy\frac{\partial Q}{\partial x}=\frac{\partial}{\partial x}\left(\frac{\partial f}{\partial y}\right)=\frac{\partial^{2} f}{\partial x \partial y}

If PP and QQ as well as all their partial derivatives exist and are continuous over some region R\mathcal{R} then, the order in which we take the first and second derivatives is irrelevant. Therefore, if the continuity of the above-mentioned quantities is guaranteed, then

2fxy=2fyx\frac{\partial^{2} f}{\partial x \partial y}=\frac{\partial^{2} f}{\partial y \partial x}

Equation (12.65) is equivalent to

Py=Qx\frac{\partial P}{\partial y}=\frac{\partial Q}{\partial x}

Definition 12.4 Any ODE which can be put in the form

P(x,y)+Q(x,y)dydx=0P(x, y)+Q(x, y) \frac{d y}{d x}=0

is exact if and only if (iff)

Py=Qx\frac{\partial P}{\partial y}=\frac{\partial Q}{\partial x}

The above equation gives a condition that needs to be satisfied for an ODE to be exact.

Example 12.6 Show that the following ODE

4xy+1+(2x2+cosy)dydx=04 x y+1+\left(2 x^{2}+\cos y\right) \frac{d y}{d x}=0

is exact.

Solution Note that the ODE in this example is the equation given by Eq. (12.49) considered above. Comparing the ODE to Eq. (12.61), it is easy to see that

P(x,y)=4xy+1 and Q(x,y)=2x2+cosyP(x, y)=4 x y+1 \quad \text { and } \quad Q(x, y)=2 x^{2}+\cos y

To show that the ODE is exact, we need the condition given by (12.66) to hold true. Differentiating PP wrt yy while keeping xx constant yields

Py=4x\frac{\partial P}{\partial y}=4 x

while the partial derivative of QQ wrt xx gives

Qx=4x\frac{\partial Q}{\partial x}=4 x

Since Py=QxP_{y}=Q_{x}, the ODE is exact.

Solving exact ODEs

We now know how to check whether a first order ODE is exact. Here, we develop a method to solve exact differential equations. To reiterate from the previous section, to solve an exact ODE we need to find the function f(x,y)f(x, y) which allows us to express the exact ODE as in Eq. (12.53) and subsequently write the solution as in Eq. (12.54).

Once we know the ODE we are trying to solve is exact, then we also know that there exists a function f(x,y)f(x, y) which satisfies

fx=P(x,y),fy=Q(x,y).\begin{aligned} & \frac{\partial f}{\partial x}=P(x, y), \\ & \frac{\partial f}{\partial y}=Q(x, y) . \end{aligned}

Note that integrating either Eq. (12.67) wrt xx or Eq. (12.68) wrt yy, gives us f(x,y)f(x, y). Let us start with Eq. (12.67); integrating wrt xx yields,

f(x,y)=P(x,y)dx+k1(y)f(x, y)=\int P(x, y) d x+k_{1}(y)

Recall that when integrating a multivariable function only wrt one variable, we do not obtain a constant of integration but rather an arbitrary function of the variable that was kept constant in integration. Here, we obtain k1=k1(y)k_{1}=k_{1}(y) as P(x,y)P(x, y) was integrated solely wrt xx. Similarly, integrating (12.68) wrt yy,

f(x,y)=Q(x,y)dy+k2(x)f(x, y)=\int Q(x, y) d y+k_{2}(x)

Equations (12.69) and (12.70) contain the same information [i.e. they both describe f(x,y)]f(x, y)]. Comparing the two equations for ff allows us to determine the arbitrary functions obtained as a result of integration, k1(y)k_{1}(y) and k2(x)k_{2}(x). With knowledge of k1(y)k_{1}(y) and k2(x)k_{2}(x), we have f(x,y)f(x, y) from either (12.69) or (12.70). The most important results for exact ODEs are summarised in the box below.

A differential equation of the form

P(x,y)+Q(x,y)dydx=0P(x, y)+Q(x, y) \frac{d y}{d x}=0

is exact if there exists a function f(x,y)f(x, y) such that fx=P(x,y)f_{x}=P(x, y) and fy=Q(x,y)f_{y}=Q(x, y).

The ODE is then expressed as

ddx[f(x,y)]=0\frac{d}{d x}[f(x, y)]=0

and the general solution to the exact differential equation is given by

f(x,y)=c.f(x, y)=c .

The general solution represents a 1-parameter family of solutions. Here, the parameter refers to the constant cc above and it is determined using an IC. Example 12.7 Solve the following ODE

4xy+1+(2x2+cosy)dydx=0.4 x y+1+\left(2 x^{2}+\cos y\right) \frac{d y}{d x}=0 .

Solution We have shown in Example 12.6 that the ODE above with P(x,y)=4xy+1P(x, y)=4 x y+1 and Q(x,y)=2x2+cosyQ(x, y)=2 x^{2}+\cos y, is exact. Using Eqs. (12.67) and (12.68), we have

fx=4xy+1\frac{\partial f}{\partial x}=4 x y+1

and

fy=2x2+cosy.\frac{\partial f}{\partial y}=2 x^{2}+\cos y .

Integrating (12.71) wrt xx and (12.72) wrt yy gives,

f(x,y)=2x2y+x+k1(y),f(x,y)=2x2y+siny+k2(x).\begin{array}{r} f(x, y)=2 x^{2} y+x+k_{1}(y), \\ f(x, y)=2 x^{2} y+\sin y+k_{2}(x) . \end{array}

Since (12.73) and (12.74) both define f(x,y)f(x, y), comparing the two equations gives

k1(y)=siny and k2(x)=x.k_{1}(y)=\sin y \quad \text { and } \quad k_{2}(x)=x .

Finally, we can write down f(x,y)f(x, y) as

f(x,y)=2x2y+x+siny,f(x, y)=2 x^{2} y+x+\sin y,

which is the 'special' function we defined in Eq. (12.50). With knowledge of f(x,y)f(x, y), the original ODE is expressed as

ddx[2x2y+x+siny]=0,\frac{d}{d x}\left[2 x^{2} y+x+\sin y\right]=0,

which is integrated wrt xx to give the implicit solution to the ODE as follows,

2x2y+x+siny=c.2 x^{2} y+x+\sin y=c .

Integrating factors for inexact ODEs

Consider again a differential equation given in the form of (12.61). We can imagine that there are far more cases for which the exactness condition given by (12.66) is violated, i.e.

PyQx.\frac{\partial P}{\partial y} \neq \frac{\partial Q}{\partial x} .

It follows that the LHS of (12.61) cannot be expressed as the derivative of this 'special' function f(x,y)f(x, y) which is obtained using the methodology outlined in Subsec. 12.4.2. At this point let us revisit the topic of linear ODEs from Subsec. 12.2.1. We reproduce the first order LODE given by (12.19) here for convenience,

dydx+p(x)y=f(x)\frac{d y}{d x}+p(x) y=f(x)

To solve the above equation, in Subsec. 12.2.1, we transformed the LHS into the derivative of some function by making use of an I.F. In solving the exact ODE (12.61), we transform the LHS to the total derivative of f(x,y)f(x, y). It is possible, in some cases, to find an I.F. for an inexact ODE which transforms it into an exact one. An inexact ODE is a differential equation of the form (12.61) for which the exactness condition (12.66) does not hold true.

Suppose we have an inexact ODE, i.e.

P(x,y)+Q(x,y)dydx=0,PyQx.P(x, y)+Q(x, y) \frac{d y}{d x}=0, \quad P_{y} \neq Q_{x} .

We are looking for an I.F., μ(x,y)\mu(x, y) which turns the ODE exact. To see this, we want a function μ(x,y)\mu(x, y) which when multiplied by the ODE, i.e.

μ(x,y)P(x,y)+μ(x,y)Q(x,y)dydx=0,\mu(x, y) P(x, y)+\mu(x, y) Q(x, y) \frac{d y}{d x}=0,

satisfies the exactness condition,

y(μP)=x(μQ)\frac{\partial}{\partial y}(\mu P)=\frac{\partial}{\partial x}(\mu Q)

In the case of first order LODEs, we can derive the form of the I.F. which have shown to be μ=μ(x)\mu=\mu(x). In the more general case of first order ODEs (i.e. where nonlinearity is a possibility), we can no longer easily show whether the I.F. is just a univariate function or, if it takes the more general form as we denoted it in Eq. (12.77) of μ(x,y)\mu(x, y). An I.F. is, however, guaranteed to exist as long as the differential equation has a solution.

Since P,Q,PyP, Q, P_{y}, and QxQ_{x} can be functions of both the dependent and independent variables, from Eq. (12.78), we have

μPy+Pμy=μQx+Qμx\mu \frac{\partial P}{\partial y}+P \frac{\partial \mu}{\partial y}=\mu \frac{\partial Q}{\partial x}+Q \frac{\partial \mu}{\partial x}

When rearranged, Eq. (12.79) yields

PμyQμx=μ(QxPy).P \frac{\partial \mu}{\partial y}-Q \frac{\partial \mu}{\partial x}=\mu\left(\frac{\partial Q}{\partial x}-\frac{\partial P}{\partial y}\right) .

Given an ODE, the functions P,Q,PyP, Q, P_{y}, and QxQ_{x} are known and therefore the only unknown in Eq. (12.80) is μ\mu. However, solving for μ\mu from (12.80) requires solving a partial differential equation. To find an I.F. for inexact ODEs therefore, we consider two special cases for which the I.F. reduces to a single-variable function.

Special case 1: μ\mu is only a function of xx

Suppose that the I.F. is only a function of xx. Then,

μ=μ(x),μy=0μx=dμdx.\mu=\mu(x), \quad \frac{\partial \mu}{\partial y}=0 \Rightarrow \frac{\partial \mu}{\partial x}=\frac{d \mu}{d x} .

Upon making the above substitutions in Eq. (12.80), we obtain the following simplifying expression

1μdμdx=1Q(PyQx).\frac{1}{\mu} \frac{d \mu}{d x}=\frac{1}{Q}\left(\frac{\partial P}{\partial y}-\frac{\partial Q}{\partial x}\right) .

Note that the LHS of Eq. (12.81) is only a function of xx. If the quantity on the RHS is also only a function of xx then (12.81) is a (12.81) \overline{\text { is a }} first order, separable ODE for μ(x)\mu(x),

1μdμ=1Q(PyQx)dx\int \frac{1}{\mu} d \mu=\int \frac{1}{Q}\left(\frac{\partial P}{\partial y}-\frac{\partial Q}{\partial x}\right) d x

Integrating Eq. (12.82) yields the I.F.,

μ(x)=exp(1Q(PyQx)dx).\mu(x)=\exp \left(\int \frac{1}{Q}\left(\frac{\partial P}{\partial y}-\frac{\partial Q}{\partial x}\right) d x\right) .

If the quantity on the RHS of (12.81) is not a function of xx only, then μμ(x)\mu \neq \mu(x) and we proceed to check whether μ=μ(y)\mu=\mu(y) (special case 2 ).

Special case 2: μ\mu is only a function of yy

Here, we assume that the I.F. is only a function of yy, such that

μ=μ(y),μx=0μy=dμdy.\mu=\mu(y), \quad \frac{\partial \mu}{\partial x}=0 \Rightarrow \frac{\partial \mu}{\partial y}=\frac{d \mu}{d y} .

Similarly to special case 1, upon making the above substitutions in Eq. (12.80), we obtain the following simplifying expression,

1μdμdy=1P(QxPy).\frac{1}{\mu} \frac{d \mu}{d y}=\frac{1}{P}\left(\frac{\partial Q}{\partial x}-\frac{\partial P}{\partial y}\right) .

Assuming μ=μ(y)\mu=\mu(y), the LHS is only a function of yy; if the RHS is also only a function of yy then the I.F. is given by,

μ(y)=exp(1P(QxPy)dy)\mu(y)=\exp \left(\int \frac{1}{P}\left(\frac{\partial Q}{\partial x}-\frac{\partial P}{\partial y}\right) d y\right)

Method for solving inexact ODEs

We develop a simple algorithmic process as a method of solution for inexact ODEs. Given an inexact ODE, our aim is to find an I.F.. For the purposes of this course, we only consider the aforementioned two special cases.

Step 1:

Check if

1Q(PyQx)=g(x), i.e. only a function of x.\frac{1}{Q}\left(\frac{\partial P}{\partial y}-\frac{\partial Q}{\partial x}\right)=g(x), \text { i.e. only a function of } x .

If yes, the I.F. is μ=μ(x)\mu=\mu(x) and defined by (12.83). If no, proceed to Step 2.

Step 2:

Check if

1P(QxPy)=h(y), i.e. only a function of y.\frac{1}{P}\left(\frac{\partial Q}{\partial x}-\frac{\partial P}{\partial y}\right)=h(y), \quad \text { i.e. only a function of } y .

If yes, the I.F. is μ=μ(y)\mu=\mu(y) and defined by (12.85). If no, then the I.F. takes a more complex form and finding it falls beyond the scope of this course. Example 12.8 Find a particular solution to the following IVP

x+(x2y+4y)dydx=0,y(4)=1.x+\left(x^{2} y+4 y\right) \frac{d y}{d x}=0, \quad y(4)=1 .

Solution The ODE is nonlinear but separable. For the purposes of this example however we choose to solve it using integrating factors. With P=xP=x and Q=x2y+4yQ=x^{2} y+4 y, we check for exactness

Py=0,Qx=2xy\frac{\partial P}{\partial y}=0, \quad \frac{\partial Q}{\partial x}=2 x y

since PyQxP_{y} \neq Q_{x}, the ODE is inexact. The next step is to look for a simple I.F. (as in special cases 1 or 2 above) if it exists to render the ODE exact. We check whether μ=μ(x)\mu=\mu(x) using Eq. (12.86)

1Q(PyQx)=2xyy(x2+4)=g(x)\frac{1}{Q}\left(\frac{\partial P}{\partial y}-\frac{\partial Q}{\partial x}\right)=-\frac{2 x y}{y\left(x^{2}+4\right)}=g(x) \checkmark

Using (12.83), the I.F. is

μ(x)=exp(2xx2+4dx)=1x2+4\begin{aligned} \mu(x) & =\exp \left(\int-\frac{2 x}{x^{2}+4} d x\right) \\ & =\frac{1}{x^{2}+4} \end{aligned}

Multiplying the original ODE by the I.F. yields the equivalent exact ODE (after simplification) as

xx2+4f/x+yf/ydydx=0.\underbrace{\frac{x}{x^{2}+4}}_{\partial f / \partial x}+\underbrace{y}_{\partial f / \partial y} \frac{d y}{d x}=0 .

We proceed to solve ODE (12.88) using the method developed for exact ODEs in Subsec. 12.4.2. The two equations for f(x,y)f(x, y) are

xx2+4dx=12ln(x2+4)+k1(y) and ydy=y22+k2(x)\int \frac{x}{x^{2}+4} d x=\frac{1}{2} \ln \left(x^{2}+4\right)+k_{1}(y) \quad \text { and } \quad \int y d y=\frac{y^{2}}{2}+k_{2}(x)

Comparing the two equations, k1(y)=y2/2k_{1}(y)=y^{2} / 2 and k2(x)=ln(x2+4)/2k_{2}(x)=\ln \left(x^{2}+4\right) / 2 we obtain the general solution f(x,y)=cf(x, y)=c as

12[ln(x2+4)+y2]=c.\frac{1}{2}\left[\ln \left(x^{2}+4\right)+y^{2}\right]=c .

Finally, applying the IC y(4)=1y(4)=1, we arrive at the particular solution

y(x)=1+ln(20x2+4).y(x)=\sqrt{1+\ln \left(\frac{20}{x^{2}+4}\right)} .

Note that the IC is only satisfied with the positive square root.

Exercises

  1. Consider the following first order, nonlinear ODE:
(x2xy+ey)+(yx2+xey)dydx=0\left(x-2 x y+e^{y}\right)+\left(y-x^{2}+x e^{y}\right) \frac{d y}{d x}=0

Show that the ODE is exact and find a particular solution satisfying y(1)=0y(1)=0.

  1. Find the value of aa for which the following differential equation is exact,
ye2xy+x+axe2xydydx=0.y e^{2 x y}+x+a x e^{2 x y} \frac{d y}{d x}=0 .

Solve the ODE using that value of aa.