Example-2
Shooting Method for Solving a Second-Order Differential Equation
Given the second-order differential equation:
\[ \frac{d^2 y}{dx^2} = -y + \cos(2x) \]
with boundary conditions:
\[ y(0) = 0 \quad \text{and} \quad y\left(\frac{\pi}{2}\right) = \frac{4}{3} \]
we want to solve for \( y(x) \) on the interval \( x \in \left[0, \frac{\pi}{2}\right] \) using the shooting method.
Exact Solution
\[ y(x) = \frac{\cos(x) - \cos(2x)}{3} + \sin(x) \]
Converting to a System of First-Order Differential Equations
Define \( y = y(x) \) and \( z = \frac{dy}{dx} \). Then rewrite the original second-order equation:
\[ \frac{d^2 y}{dx^2} = -y + \cos(2x) \]
as a system of two first-order equations:
\[ \frac{dy}{dx} = z \]
\[ \frac{dz}{dx} = -y + \cos(2x) \]
Setting Initial Conditions and Initial Guesses for \( z(0) \)
To satisfy the boundary condition \( y(0) = 0 \), we start with two initial guesses for \( z(0) \), denoted as \( z_1 = 0.1 \) and \( z_2 = 5.45 \), to find a value that will meet the boundary condition at \( x = \frac{\pi}{2} \).
Iterative Shooting Method
For each guess of \( z(0) \), solve the system of equations over the interval from \( x = 0 \) to \( x = \frac{\pi}{2} \). Let \( w_1 \) and \( w_2 \) represent the values of \( y \left( \frac{\pi}{2} \right) \) obtained with initial values \( z_1 \) and \( z_2 \), respectively.
Convergence Check and Update of \( z \) Values
Check if the error \( |y(1) - w_2| \) is within a tolerance (e.g., 0.001). If so, stop. Otherwise, update the guess for \( z \) as follows:
\[ z_{\text{new}} = z_2 + (z_2 - z_1) \cdot \frac{y_1 - w_2}{w_2 - w_1} \]
Set \( z_1 = z_2 \) and \( z_2 = z_{\text{new}} \), and repeat the process until the solution converges.