Solved using Lagrange adjoint equation method.

ode internal name "second order ode lagrange adjoint equation method"

This method is used when hint is “adjoint”. This transformation does not use change of variables. It was discovered by Lagrange in his Miscellanea Taurensis paper.  It reduces the order of the ode by one, assuming the so called adjoint ode can be solved. This is also described in section 1.5.1 on page 14 of the “book Change and Variations A History of Differential Equations to 1900” by Jeremy Gray. This method will only work if adjoint equation turns out to be simple and can be solved. It is now only used by the program if the hint “adjoint” is detected or if all the other methods were first tried and they all fail to solve the ode. So this method works if the adjoint ode can be solved. But the adjoint ode itself is second order non constant ode. So we need to solve a second order non-constant ode in order to reduce the order by one of the original ode. Luckily the adjoint ode turns out to be possible to solve by change of variables when the original one is not, and that is why this method is tried.

Given the ode

\begin{equation} y^{\prime \prime }+p\left ( x\right ) y^{\prime }+q\left ( x\right ) y=r\left ( x\right ) \tag {1}\end{equation}

This method starts by multiplying the ode by some unknown function \(z\equiv z\left ( x\right ) \) which gives

\begin{equation} zy^{\prime \prime }+zpy^{\prime }+zqy=zr \tag {2}\end{equation}

Integrating gives

\begin{equation} \int zy^{\prime \prime }dx+\int zpy^{\prime }dx+\int zqydx=\int zrdx \tag {3}\end{equation}

Using integration by parts on \(\int zpy^{\prime }dx\) using \(\int udv=uv-\int vdu\) where \(u=zp\) and \(dv=y^{\prime }\), hence \(v=y\) and \(du=\frac {d}{dx}\left ( zp\right ) \). Therefore

\[ \int zpy^{\prime }dx=zpy-\int y\frac {d\left ( zp\right ) }{dx}dx \]

Using integration by parts on \(\int zy^{\prime \prime }dx\) using \(\int udv=uv-\int vdu\) where \(u=z\) and \(dv=y^{\prime \prime }\), hence \(v=y^{\prime }\) and \(du=z^{\prime }\). Therefore

\[ \int zy^{\prime \prime }dx=zy^{\prime }-\int y^{\prime }z^{\prime }dx \]

Eq (3) becomes

\begin{equation} \left ( zy^{\prime }-\int y^{\prime }z^{\prime }dx\right ) +\left ( zpy-\int y\frac {d\left ( zp\right ) }{dx}dx\right ) +\int zqydx=\int zrdx \tag {4}\end{equation}

Integrating by part again the term \(\int y^{\prime }z^{\prime }dx\) using \(\int udv=uv-\int vdu\) where \(u=z^{\prime }\) and \(dv=y^{\prime }\), hence \(v=y\) and \(du=z^{\prime \prime }\). Therefore

\[ \int y^{\prime }z^{\prime }dx=yz^{\prime }-\int yz^{\prime \prime }dx \]

Substituting this in (4) gives

\begin{align} \left ( zy^{\prime }-\left ( yz^{\prime }-\int yz^{\prime \prime }dx\right ) \right ) +\left ( zpy-\int y\frac {d\left ( zp\right ) }{dx}dx\right ) +\int zqydx & =\int zrdx\nonumber \\ zy^{\prime }-yz^{\prime }+\int yz^{\prime \prime }dx+zpy-\int y\frac {d\left ( zp\right ) }{dx}dx+\int zqydx & =\int zrdx\nonumber \\ zy^{\prime }-yz^{\prime }+zpy+\int \left ( yz^{\prime \prime }-y\frac {d\left ( zp\right ) }{dx}+zqy\right ) dx & =\int zrdx\nonumber \\ zy^{\prime }-yz^{\prime }+zpy+\int y\left ( z^{\prime \prime }-\frac {d\left ( zp\right ) }{dx}+zq\right ) dx & =\int zrdx\nonumber \\ zy^{\prime }+\left ( zp-z^{\prime }\right ) y+\int y\left ( z^{\prime \prime }-\frac {d\left ( zp\right ) }{dx}+zq\right ) dx & =\int zrdx \tag {5}\end{align}

The adjoint ode is the term inside the integral above given by

\begin{equation} z^{\prime \prime }-\frac {d\left ( zp\right ) }{dx}+zq=0 \tag {6}\end{equation}

If this can be solved, where the solution \(z_{sol}\left ( x\right ) \neq 0\), then (5) reduces to

\begin{align*} z_{sol}y^{\prime }+\left ( z_{sol}p-\left ( z_{sol}\right ) ^{\prime }\right ) y & =\int zrdx\\ y^{\prime }+y\left ( p-\frac {\left ( z_{sol}\right ) ^{\prime }}{z_{sol}}\right ) & =\frac {1}{z}\int zrdx \end{align*}

Which is first order ode in \(y\left ( x\right ) \) which can be easily solved for \(y\left ( x\right ) \). Equation (6) is called the Lagrange adjoint equation. This method of course works only if the adjoint ode can be solved for \(z\left ( x\right ) \) and the solution is not zero.