Home > Python > Shooting Method for Boundary Value Problem

Ch. 18.1 Example-1

Chapters Index
Program 1

Example-1

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.

Mathematical Problem Formulation

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] \]

Theoretical Background & Computational Mechanics

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.

Theoretical Principles & Computational Physics Guide

Example-1: Computational Physics Modeling & Analysis

Dr. Alorika Chatterjee & Dr. Anirban Shaw Science & Physics Learners Python 3 / NumPy / SciPy

1. Core Principles & Theoretical Framework

Core Concept: Computational formulation and simulation of Example-1 within the study of Shooting Method for Boundary Value Problem.
Algorithmic Translation: Translates theoretical governing equations into clean, discrete Python procedures and verified numerical solvers.
Numerical Verification: Evaluates numerical accuracy, parameter sensitivity, and error bounds for reliable computational results.

2. Mathematical Formulation & Algorithmic Pipeline

Governing computational formulation for Example-1:

$$ \mathcal{F}_{\text{model}}(\mathbf{x}, t; \mathbf{p}) = 0 \implies \mathbf{y}_{n+1} = \mathcal{S}(\mathbf{y}_n, \Delta t, \mathbf{p}) $$
1. Define Physical Parameters & Boundaries → 2. Execute Numerical Simulation Steps → 3. Evaluate Observables & Plot Results

3. Numerical Mechanics & Implementation Logic

  • Parameter Initialization: Set physical constants, initial states, and coordinate boundary bounds for Example-1.
  • Step Execution: Advance the computational state using optimized vector operations and scientific libraries.
  • Convergence Control: Monitor stability and ensure simulation metrics remain physically meaningful.

4. Relevant Computational Practice Exercises

Exercise 1
Implement Example-1 and observe how the output responds to variations in primary physical parameters.
Exercise 2
Refine the calculation grid or step size to observe convergence and reduction in numerical approximation error.
Exercise 3
Compare the simulated computational results against an analytical benchmark or limiting physical case.
Standard Literature & References:
  • Mark Newman, "Computational Physics", University of Michigan (2013).
  • Hans Petter Langtangen, "A Primer on Scientific Programming with Python", Springer (2016).