Linear second order not exact but solved by finding mu(x) integrating factor.
ode internal name "linear_second_order_ode_solved_by_mu_integrating_factor"
(not implemented yet).
As mentioned above, an exact ode is one which has a corresponding adjoint ODE. In the
case when the ode was exact, we did not use an integrating factor (this is the same as saying
the integrating factor was \(1\)), i.e. \(\mu \left ( x\right ) =1\).
But if the ode is not exact, then we look for integrating factor \(\mu \left ( x\right ) \) that when multiplied
by the ode makes it exact and hence will have an adjoint ODE. Given
\begin{equation} py^{\prime \prime }+q\left ( x\right ) y^{\prime }+r\left ( x\right ) y=f\left ( x\right ) \tag {1}\end{equation}
Which
is assumed not to be exact. Multiplying both sides by \(\mu \left ( x\right ) \) gives \(\mu \left ( py^{\prime \prime }+q\left ( x\right ) y^{\prime }+r\left ( x\right ) y\right ) =\mu f\left ( x\right ) \). Let
\begin{equation} \mu \left ( py^{\prime \prime }+q\left ( x\right ) y^{\prime }+r\left ( x\right ) y\right ) =\left ( \mu py^{\prime }+By\right ) ^{\prime } \tag {2}\end{equation}
Expanding
gives
\begin{align*} \mu \left ( py^{\prime \prime }+q\left ( x\right ) y^{\prime }+r\left ( x\right ) y\right ) & =\mu ^{\prime }py^{\prime }+\mu p^{\prime }y^{\prime }+\mu py^{\prime \prime }+B^{\prime }y+By^{\prime }\\ \mu py^{\prime \prime }+\mu qy^{\prime }+\mu ry & =\mu py^{\prime \prime }+y^{\prime }\left ( \mu ^{\prime }p+\mu p^{\prime }+B\right ) +yB^{\prime }\end{align*}
Comparing coefficients gives the following 2 equations
\begin{align} \mu q & =\mu ^{\prime }p+\mu p^{\prime }+B\tag {2A}\\ \mu r & =B^{\prime } \tag {2B}\end{align}
Taking derivative of (2A) gives
\[ \mu ^{\prime }q+\mu q^{\prime }=\mu ^{\prime \prime }p+\mu ^{\prime }p^{\prime }+\mu ^{\prime }p^{\prime }+\mu p^{\prime \prime }+B^{\prime }\]
Substituting for \(B^{\prime }\) from (2B) into the above gives
\begin{equation} \mu ^{\prime }q+\mu q^{\prime }=\mu ^{\prime \prime }p+\mu ^{\prime }p^{\prime }+\mu ^{\prime }p^{\prime }+\mu p^{\prime \prime }+\mu r \tag {3}\end{equation}
Arranging
\begin{equation} \mu ^{\prime \prime }p+\mu ^{\prime }\left ( 2p^{\prime }-q\right ) +\mu \left ( p^{\prime \prime }-q^{\prime }+r\right ) =0 \tag {4}\end{equation}
The integrating factor \(\mu \) is the solution to the above ODE (called the adjoint ode
also). Note that in (4), the term \(p^{\prime \prime }-q^{\prime }+r\) will not be zero, as this is the condition for
exactness, and this ode is not exact (else we will not need an integrating factor to start
with).
We can obtain (4) directly from \(py^{\prime \prime }+qy^{\prime }+ry=0\). Since the relation between an ode and its adjoint ode is the
following: given
\[ py^{\prime \prime }+qy^{\prime }+ry=0 \]
Its adjoint ode is
\begin{align*} \left ( \left ( p\mu \right ) ^{\prime }-q\mu \right ) ^{\prime }+r\mu & =0\\ \left ( p\mu \right ) ^{\prime \prime }-\left ( q\mu \right ) ^{\prime }+r\mu & =0\\ \left ( p^{\prime }\mu +p\mu ^{\prime }\right ) ^{\prime }-\left ( q^{\prime }\mu +q\mu ^{\prime }\right ) +r\mu & =0\\ p^{\prime \prime }\mu +p^{\prime }\mu ^{\prime }+p^{\prime }\mu ^{\prime }+p\mu ^{\prime \prime }-q^{\prime }\mu -q\mu ^{\prime }+r\mu & =0\\ p\mu ^{\prime \prime }+\mu ^{\prime }\left ( 2p^{\prime }-q\right ) +\mu \left ( p^{\prime \prime }-q^{\prime }+r\right ) & =0 \end{align*}
We see this is the same as (4). In summary, an ode \(py^{\prime \prime }+qy^{\prime }+ry=0\) has adjoint ode \(\left ( p\mu \right ) ^{\prime \prime }-\left ( q\mu \right ) ^{\prime }+r\mu =0\) where the solution to
the adjoint ode makes the first ode exact. Once the integrating factor \(\mu \) is found then the first
integral is given by
\[ py^{\prime \prime }+qy^{\prime }+ry=\left ( \mu py^{\prime }+By\right ) ^{\prime }\]
Where
\begin{align*} B & =\mu q-\mu ^{\prime }p-\mu p^{\prime }\\ & =\mu \left ( q-p^{\prime }\right ) -\mu ^{\prime }p \end{align*}
Hence
\begin{equation} py^{\prime \prime }+qy^{\prime }+ry=\left ( \mu py^{\prime }+\left ( \mu \left ( q-p^{\prime }\right ) -\mu ^{\prime }p\right ) y\right ) ^{\prime } \tag {5}\end{equation}
There is a known relation between an ode and its adjoint ode given by
\[ \mu \left ( py^{\prime \prime }+qy^{\prime }+ry\right ) -y\overline {\left ( py^{\prime \prime }+qy^{\prime }+ry\right ) }=\frac {d}{dx}\left ( P\left ( y,u\right ) \right ) \]
Where the bar
above the ode means its complex conjugate. The function \(P\left ( y,u\right ) \) is called the bilinear concomitant
(see Murphy book, page 93). And is given by
\[ P\left ( y,u\right ) =p\left ( y^{\prime }\mu -y\mu ^{\prime }\right ) +\left ( q-p^{\prime }\right ) y\mu \]
Unfortunately, all this does not help us in
solving the adjoint ode (4) in order to find the integrating factor \(\mu \). Since it will
also be a second order ode which can be as hard to solve as the original ode. So
this method is not practical as far as I can see unless the adjoint ODE comes
out very simple to solve, but in all the examples I looked at, this was not the
case.
Example 1
\[ y^{\prime \prime }-4xy^{\prime }+\left ( 4x^{2}-2\right ) y=0 \]
\(p=1,q=-4x,r=\left ( 4x^{2}-2\right ) \,.\) Let us first check if the ode is exact or not as is. The condition for exactness is
\[ p^{\prime \prime }-q^{\prime }+r=0 \]
Therefore the above becomes
\[ 0+4+\left ( 4x^{2}-2\right ) =0 \]
The LHS is not zero. This means the ode is not exact.
Therefore we need to try to find an integration factor \(\mu \left ( x\right ) \) to make the ode exact. (4)
becomes
\begin{align*} \mu ^{\prime \prime }p+\mu ^{\prime }\left ( 2p^{\prime }-q\right ) +\mu \left ( p^{\prime \prime }-q^{\prime }+r\right ) & =0\\ \mu ^{\prime \prime }+\mu ^{\prime }\left ( 4x\right ) +\mu \left ( 4+\left ( 4x^{2}-2\right ) \right ) & =0\\ \mu ^{\prime \prime }+4x\mu ^{\prime }+\mu \left ( 2+4x^{2}\right ) & =0 \end{align*}
We see in practice that finding the integrating factor leads to yet another second order ode
which is as hard to solve as the original ode. The solution to this ode can be found to be
\(e^{-x^{2}},xe^{-x^{2}}\). We only need one integrating factor. Hence let
\[ \mu \left ( x\right ) =e^{-x^{2}}\]
Multiplying this by the given
ode now makes it exact
\[ e^{-x^{2}}y^{\prime \prime }-4xe^{-x^{2}}y^{\prime }+\left ( 4x^{2}-2\right ) e^{-x^{2}}y=0 \]
To see this let us check the condition again now. Here \(p=e^{-x^{2}},q=-4xe^{-x^{2}},r=\left ( 4x^{2}-2\right ) e^{-x^{2}}\).
Hence
\begin{align*} p^{\prime \prime }-q^{\prime }+r & =0\\ \left ( 4e^{-x^{2}}x^{2}-2e^{-x^{2}}\right ) -\left ( 8e^{-x^{2}}x^{2}-4e^{-x^{2}}\right ) +\left ( 4x^{2}-2\right ) e^{-x^{2}} & =0\\ 0 & =0 \end{align*}
We see that it is now exact. Hence it has adjoint ODE of the form (5)
\[ \left ( \mu py^{\prime }+\left ( \mu \left ( q-p^{\prime }\right ) -\mu ^{\prime }p\right ) y\right ) ^{\prime }=0 \]
Hence the first
integral is
\[ \mu py^{\prime }+\left ( \mu \left ( q-p^{\prime }\right ) -\mu ^{\prime }p\right ) y=c \]
Using \(\mu =e^{-x^{2}},p=1,q=-4x\) the above becomes
\begin{align*} e^{-x^{2}}y^{\prime }+\left ( -4xe^{-x^{2}}-\left ( -2xe^{-x^{2}}\right ) \right ) y & =c\\ e^{-x^{2}}y^{\prime }-2xe^{-x^{2}}y & =c\\ y^{\prime }-2xy & =ce^{x^{2}}\end{align*}
This is linear first ode whose solution is
\[ y=e^{x^{2}}\left ( cx+c_{2}\right ) \]
Example 2
\[ y^{\prime \prime }+\frac {1}{x}y^{\prime }+\frac {1}{x}y=0 \]
Here \(p=1,q=\frac {1}{x},r=\frac {1}{x},f\left ( x\right ) =0\). The condition of exactness is
\begin{align*} p^{\prime \prime }-q^{\prime }+r & =0\\ 0-\left ( -\frac {1}{x^{2}}\right ) +\frac {1}{x} & =0 \end{align*}
Is not satisfied. Hence the ode is not exact. The adjoint ode (4) to find the integrating factor
becomes
\begin{align*} \mu ^{\prime \prime }p+\mu ^{\prime }\left ( p^{\prime }-q\right ) +\mu \left ( p^{\prime \prime }-q^{\prime }+r\right ) & =0\\ \mu ^{\prime \prime }+\mu ^{\prime }\left ( -\frac {1}{x}\right ) +\mu \left ( -\frac {1}{x^{2}}+\frac {1}{x}\right ) & =0\\ \mu ^{\prime \prime }-\frac {1}{x}\mu ^{\prime }-\mu \left ( \frac {1-x}{x^{2}}\right ) & =0\\ x^{2}\mu ^{\prime \prime }-x\mu ^{\prime }-\left ( 1-x\right ) \mu & =0 \end{align*}
Which has solutions \(\mu \) as bessel functions. We see that trying to find an integrating factor
using this method is not practical, as it leads to an ode just as hard to solve as the original
one. We could just have solved \(y^{\prime \prime }+\frac {1}{x}y^{\prime }+\frac {1}{x}y=0\) directly, since this is Bessel ode. Unless there is a short cut
to solving the ODE to find the integrating factor, this method is not practical. See section
below for simpler method
The main difficulty when second order is not exact, is in finding the integrating factor \(\mu \left ( x\right ) \) which
itself requires solving another second order ode. The whole point of an ODE being exact is
that it is a complete differential which means the order is reduced by one to make it easier to
solve. This means solving a second order ode becomes solving a first order ode when the ode
is exact.