Home > Python > Shooting Method for Boundary Value Problem

Ch. 18.2 Example-2

Chapters Index
Program 1

Example-2

Python 3.11 Ready

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

Mathematical Problem Formulation

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

Theoretical Background & Computational Mechanics

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.

Theoretical Principles & Computational Physics Guide

Example-2: 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-2 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-2:

$$ \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-2.
  • 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-2 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).