Responsive Navbar with Google Search
Shooting Method for Boundary Value Problem: Example-1
Python runs in your browser. Heavy or infinite loops may freeze your browser tab. Use "Stop" if needed; for heavy jobs, run locally.
Program 1

Example-1

Given the second-order differential equation:

\[ y'' = -y + 2 \frac{\left(y'\right)^2}{y} \]

Boundary Conditions

The equation has the following boundary conditions:

\[ y(-1) = \frac{1}{e} + \frac{1}{e}, \quad y(1) = \frac{1}{e} + \frac{1}{e} \]

Exact Solution

We want to find an approximate numerical solution for \( y(x) \) using the shooting method and compare it with the exact solution:

\[ y(x) = \frac {1}{e^x + e^{-x}} \]

The solution will be evaluated over the interval:

\[ x \in [-1, 1] \]

Output 1

Convert to a System of First-Order Differential Equations

Let \( y = y(x) \) and \( z = y'(x) \). Then the second-order equation:

\[ y'' = -y + \frac{2(y')^2}{y} \]

can be expressed as two first-order equations:

\[ y' = z \]

\[ z' = -y + \frac{2z^2}{y} \]

This system can be represented as a function \( f(u, x) \), where \( u = [y, z] \).

Initial Guess for the Derivative at the Start Point

Start with two initial guesses for \( z(-1) \), denoted \( z_1 \) and \( z_2 \). For example:

\[ z_1 = 0.1, \quad z_2 = 0.25 \]

Iterative Shooting Method

For each guess \( z_i \), solve the system of equations from \( x = -1 \) to \( x = 1 \).

Let \( w_1 \) and \( w_2 \) represent the values of \( y(1) \) 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.