Theory exercise 2

Fredrik Eikeland Fossan


Feb 17, 2019


Problem 1: Shooting method

In this problem we will look at the following ordinary differential equation (ODE): $$ \begin{align} \frac{d^2y}{dx^2} = -2\,\left(y\,\frac{dy}{dx}\right), \label{eq:ODE} \end{align} $$

with \( x \in [x_{min},x_{max}] \), and the following boundaries: $$ \begin{align} y\left(x_{\min}\right) = y\left(1\right) = 1 \qquad \text{and} \qquad y\left(x_{\max}\right) = y\left(2\right) = 0.5. \label{eq:BCs} \end{align} $$

a) With respect to problem \eqref{eq:ODE}-\eqref{eq:BCs}, state which is the order of the ODE, whether it is linear or nonlinear and whether it is an initial or a boundary value problem. Justify your statements.

Answer.

Eq. \eqref{eq:ODE} is a second order ODE since the highest order derivative is 2 (\( \frac{d^2y}{dx^2} \)). We may rewrite Eq. \eqref{eq:ODE} as \( a_2\,y'' + a_1\,y' + a_0\,y = b \), where \( a_2=1 \), \( a_2=2\,y \), \( a_0=0 \) and \( b=0 \). A linear ODE requires that \( a_2 \), \( a_1 \) and \( a_0 \) are only functions of \( x \) (or constants), consequently, since \( a_2 \) is a function of \( y \), the ODE is non-linear. Problem \eqref{eq:ODE}-\eqref{eq:BCs} is a boundary value problem since the solution is prescribed at both ends of the domain.

b) show that: $$ \begin{align} y = \frac{1}{x}, \label{eq:ODE_sol} \end{align} $$

is a solution to problem \eqref{eq:ODE}-\eqref{eq:BCs}.

Answer.

By differentiation we obtain: $$ \begin{align} \frac{dy}{dx} = -\frac{1}{x^2}, \label{_auto1}\\ \frac{d^2y}{dx^2} = 2\frac{1}{x^3}, \label{eq:ODE_der} \end{align} $$ and by substitution we see that \( y = \frac{1}{x} \) is a solution to Eq. \eqref{eq:ODE}: $$ \begin{align} 2\frac{1}{x^3} = -2\left(\frac{1}{x}\cdot-\frac{1}{x^2}\right) = 2\frac{1}{x^3}. \label{eq:ODE_subst} \end{align} $$

Furthermore, the solution also satisfies the boundary conditions given by Eq. \eqref{eq:BCs}, since \( y\left(1\right) = \frac{1}{1} = 1 \) and \( y\left(2\right) = \frac{1}{2} = 0.5 \).

c) Describe the procedure/algorithm necessary for solving problem \eqref{eq:ODE}-\eqref{eq:BCs} using the shooting method.

Answer.

We need to transform eqs. \eqref{eq:ODE} and \eqref{eq:BCs} into a system of first order ODEs: $$ \begin{align} & y_0^{\prime}(x)=y_1(x), \label{eq:ODESYS1}\\ & y_1^{\prime}(x)=-2\,\left[y_0(x) \cdot y_1(x)\right] = f, \label{eq:ODESYS2} \end{align} $$

where \( y_0(x) = y(x) \). Next we solve an initial value problem by guessing \( y^{\prime} \left( 1 \right) =s \): $$ \begin{align} y_0\left(1\right) = 1 \qquad \text{and} \qquad y_1 \left( 1 \right)=s. \label{eq:InitialValues} \end{align} $$

We want to find \( s \) such that our solution of the initial value problem is in agreement with the original boundary values, and do so by introducing a boundary value error function \( \phi \): $$ \begin{align} \phi \left(s\right) = y\left(2;s \right) - \beta = y\left(2;s \right) - 0.5, \label{eq:beta} \end{align} $$

with the property that \( \phi=0 \) for the correct value of \( y^{\prime}\left(1\right)=y_1\left(1\right) \), \( s^* \). In order to find the correct value of \( s \), we guess the two first values, \( s^0 \) and \( s^1 \), solve the two initial value problems and evaluate the corresponding boundary value error functions \( \phi_0 \) and \( \phi_1 \). Next we use the secant method iteratively to find better guesses of \( s \): $$ \begin{equation} s^{m+1}=s^m+\Delta s \label{eq:Snew} \end{equation} $$

where $$ \begin{equation*} \Delta s=s^{m+1}-s^m=-\phi (s^m)\cdot \left[ \frac{s^m- s^{m-1}}{\phi (s^m)-\phi (s^{m-1})} \right],\ m=1,2,\dots \end{equation*} $$

until our \( \phi \) function is sufficiently close to zero. In this case, where we are using a first order method a suitable stop-criteria could be \( \phi \leq h^2 \), where \( h \) is the step size. Since we have transformed the problem from a boundary value problem to initial value problems, we can use efficient ODE initial value solvers which are in general more developed than solvers for boundary value problems. In this example we will use Euler's method which is a first order explicit ODE initial value solver: $$ \begin{align} \mathbf{y}_{i+1}=\mathbf{y}_i+h\cdot \mathbf{f}(x_i,\mathbf{y}_i) \label{eq:Euler} \end{align} $$

where \( \mathbf{y}=[y_0,y_1]^T \) and \( \mathbf{f}(x,\mathbf{y})=[y_1, f]^T \).

d) Transform Eq. \eqref{eq:ODE} into a system of first order ODEs.

e) Define the boundary value error function \( \phi \).

f) Use \( s^0 = 0 \), and \( s^1 = -0.5 \) as the initial guesses to \( y'(1) \) and solve the corresponding initial value problems using Euler's method and with \( h=\Delta x = 1/3 \).

Hint.

$$ \begin{align*} &y\left(2;s^0 \right) = 1\,, \quad y^{\prime}\left(2;s^0 \right) = 0\\ &y\left(2;s^1 \right) = \frac{61}{81}\,, \quad y^{\prime}\left(2;s^1 \right) = -\frac{26}{729} \end{align*} $$

Answer.

First guess of s:

For \( s^0 = 0 \) we will solve the following initial value problem: $$ \begin{align*} & y_0^{\prime}(x)=y_1(x)\,,\\ & y_1^{\prime}(x)=-2\,\left[y_0(x) \cdot y_1(x)\right]\,,\\ & y_0\left(1\right) = 1\,, \quad y_1\left(1\right) = s^0 = 0\,. \end{align*} $$ x = 4/3: $$ \begin{align*} & y_0(4/3)=y_0(1) + \frac{1}{3}y_1(1) = 1 + \frac{1}{3}0 = 1\,,\\ & y_1(4/3)=y_1(1) + \frac{1}{3}-2 \cdot \left[y_0(1) \cdot y_1(1)\right] = 0 + \frac{1}{3} \cdot -2 \cdot 1 \cdot 0 = 0\,. \end{align*} $$

x = 5/3: $$ \begin{align*} & y_0(5/3)=y_0(4/3) + \frac{1}{3}y_1(4/3) = 1 + \frac{1}{3}0 = 1\,,\\ & y_1(5/3)=y_1(4/3) + \frac{1}{3}-2 \cdot \left[y_0(4/3) \cdot y_1(4/3)\right] = 0 + \frac{1}{3} \cdot -2 \cdot 1 \cdot 0 = 0\,. \end{align*} $$

x = 2: $$ \begin{align*} & y_0(2)=y_0(5/3) + \frac{1}{3}y_1(5/3) = 1 + \frac{1}{3}0 = 1\,,\\ & y_1(2)=y_1(5/3) + \frac{1}{3}-2 \cdot \left[y_0(5/3) \cdot y_1(5/3)\right] = 0 + \frac{1}{3} \cdot -2 \cdot 1 \cdot 0 = 0\,. \end{align*} $$

Second guess of s:

For \( s^1 = -0.5 \) we will solve the following initial value problem: $$ \begin{align*} & y_0^{\prime}(x)=y_1(x)\,,\\ & y_1^{\prime}(x)=-2\,\left[y_0(x) \cdot y_1(x)\right]\,,\\ & y_0\left(1\right) = 1\,, \quad y_1\left(1\right) = s^1 = -0.5\,. \end{align*} $$ x = 4/3: $$ \begin{align*} & y_0(4/3)=y_0(1) + \frac{1}{3}y_1(1) = 1 + \frac{1}{3} \cdot -\frac{1}{2} = \frac{5}{6}\,,\\ & y_1(4/3)=y_1(1) + \frac{1}{3}-2 \cdot \left[y_0(1) \cdot y_1(1)\right] = -\frac{1}{2} + \frac{1}{3} \cdot -2 \cdot 1 \cdot -\frac{1}{2} = -\frac{1}{6}\,. \end{align*} $$

x = 5/3: $$ \begin{align*} & y_0(5/3)=y_0(4/3) + \frac{1}{3}y_1(4/3) = \frac{5}{6} + \frac{1}{3} \cdot -\frac{1}{6} = \frac{7}{9}\,,\\ & y_1(5/3)=y_1(4/3) + \frac{1}{3}-2 \cdot \left[y_0(4/3) \cdot y_1(4/3)\right] = -\frac{1}{6} + \frac{1}{3} \cdot -2 \cdot \frac{5}{6} \cdot -\frac{1}{6} = -\frac{2}{27}\,. \end{align*} $$

x = 2: $$ \begin{align*} & y_0(2)=y_0(5/3) + \frac{1}{3}y_1(5/3) = \frac{7}{9} + \frac{1}{3} \cdot -\frac{2}{27} = \frac{61}{81}\,,\\ & y_1(2)=y_1(5/3) + \frac{1}{3}-2 \cdot \left[y_0(5/3) \cdot y_1(5/3)\right] = -\frac{2}{27} + \frac{1}{3} \cdot -2 \cdot \frac{7}{9} \cdot -\frac{2}{27} = -\frac{26}{729}\,. \end{align*} $$

g) Evaluate \( \phi \left(s^0\right) \) and \( \phi \left(s^1\right) \) and use the secant method to find a new estimate, \( s^2 \).

Hint.

$$ \begin{align*} s^{2}=-\frac{81}{80} \end{align*} $$

Answer.

evaluation of the boundary value error function: $$ \begin{align*} &\phi \left(s^0\right) = y\left(2;s^0 \right) - 0.5 = 1 - 0.5 = 0.5\,, \\ &\quad \phi \left(s^1\right) = y\left(2;s^1 \right) - 0.5 = \frac{61}{81} -\frac{1}{2} = \frac{41}{162} \end{align*} $$ The secant method is given by: $$ \begin{equation*} s^{m+1}=s^m+\Delta s\,, \quad \Delta s=s^{m+1}-s^m=-\phi (s^m)\cdot \left[ \frac{s^m- s^{m-1}}{\phi (s^m)-\phi (s^{m-1})} \right],\ \end{equation*} $$

By substitution we get: $$ \begin{equation*} \Delta s=s^{2}-s^1=-\phi (s^1)\cdot \left[ \frac{s^1- s^{0}}{\phi (s^1)-\phi (s^{0})} \right] = -\frac{41}{162}\cdot \left[ \frac{-\frac{1}{2}- 0}{\frac{41}{162}-\frac{1}{2}} \right] = -\frac{41}{80}\,, \quad \rightarrow s^{2}=-\frac{81}{80}\,, \end{equation*} $$

h) Solve the initial value problem with \( y'(1)= s_2 \) using Euler's method and with \( h=\Delta x = 1/3 \). (Optional)

i) Given \( y\left(2;s^2 \right) = \frac{1559}{3200} \), estimate \( s_3 \) and compare with the correct value of \( y'(1) \).

Answer.

evaluation of the boundary value error function: $$ \begin{align*} &\phi \left(s^2\right) = y\left(2;s^2 \right) - 0.5 = \frac{1559}{3200} - 0.5 = -\frac{41}{3200}\,, \end{align*} $$ $$ \begin{equation*} \Delta s=s^{3}-s^2=-\phi (s^1)\cdot \left[ \frac{s^2- s^{1}}{\phi (s^2)-\phi (s^{1})} \right] = \frac{41}{3200}\cdot \left[ \frac{-\frac{81}{80} + \frac{1}{2}}{-\frac{41}{3200}-\frac{41}{162}} \right] = \frac{81}{3280} \,, \quad \rightarrow s^{3}=-\frac{81}{82}\,, \end{equation*} $$

From Eq. we have that \( \frac{dy}{dx} = -\frac{1}{x^2} \) and \( \frac{dy}{dx}\rvert_{x=1}=-1 \).