Shooting Method for Boundary Value Problems | Numerical Methods Lab
Numerical Methods - Shooting Method for Boundary Value Problems

Lab 6: Shooting Method for Boundary Value Problems

Lab 6: Solution of Two-Point Boundary Value Problems using Shooting Method

Experiment Information

Experiment: Solution of two-point boundary value problems using Shooting method

Course Code: Numerical Methods

Description: Complete lab report covering theory, algorithm, Python implementation and analysis of Shooting method for boundary value problems

Complete Lab Report PDF

1. Theory of Shooting Method for BVPs

1.1 Mathematical formulation of boundary value problems

1.2 Conversion to initial value problems

1.3 Secant method for root finding

2. Algorithm

2.1 Step-by-step procedure for shooting method

2.2 Implementation with Runge-Kutta method

2.3 Convergence criteria

3. Implementation

3.1 Python code with numpy and matplotlib

3.2 Handling different boundary conditions

3.3 Comparison with analytical solution

4. Observations

4.1 Data recording table

4.2 Sample calculations

4.3 Error analysis

5. Results

5.1 Solution approximation

5.2 Convergence behavior

5.3 Graphical results

6. Discussion

6.1 Advantages and limitations

6.2 Comparison with finite difference method

6.3 Applications in engineering problems

Python Implementation of Shooting Method for BVPs

shooting_method.py
import numpy as np import matplotlib.pyplot as plt def ode(x, y, dy): “””Second order ODE to solve: y” = f(x,y,y’)””” return 4*y – 4*x # Example ODE: y” = 4y – 4x def rk4_step(f, x, y, dy, h): “””Single step of RK4 for second order ODE””” # First set of weights k1 = h * dy l1 = h * f(x, y, dy) # Second set of weights k2 = h * (dy + l1/2) l2 = h * f(x + h/2, y + k1/2, dy + l1/2) # Third set of weights k3 = h * (dy + l2/2) l3 = h * f(x + h/2, y + k2/2, dy + l2/2) # Fourth set of weights k4 = h * (dy + l3) l4 = h * f(x + h, y + k3, dy + l3) # Update y and dy y_new = y + (k1 + 2*k2 + 2*k3 + k4)/6 dy_new = dy + (l1 + 2*l2 + 2*l3 + l4)/6 return y_new, dy_new def shooting_method(f, x0, y0, x_end, y_end, dy_guess1, dy_guess2, h, tol=1e-6, max_iter=100): “””Shooting method implementation””” # First shot x = np.arange(x0, x_end + h, h) y1 = np.zeros_like(x) dy1 = np.zeros_like(x) y1[0] = y0 dy1[0] = dy_guess1 for i in range(len(x)-1): y1[i+1], dy1[i+1] = rk4_step(f, x[i], y1[i], dy1[i], h) # Second shot y2 = np.zeros_like(x) dy2 = np.zeros_like(x) y2[0] = y0 dy2[0] = dy_guess2 for i in range(len(x)-1): y2[i+1], dy2[i+1] = rk4_step(f, x[i], y2[i], dy2[i], h) # Secant method iterations for _ in range(max_iter): # New guess using secant method dy_new = dy_guess2 – (y2[-1] – y_end) * (dy_guess2 – dy_guess1) / (y2[-1] – y1[-1]) # Update guesses dy_guess1, dy_guess2 = dy_guess2, dy_new # Compute new trajectory y1, y2 = y2, np.zeros_like(x) dy2 = np.zeros_like(x) y2[0] = y0 dy2[0] = dy_guess2 for i in range(len(x)-1): y2[i+1], dy2[i+1] = rk4_step(f, x[i], y2[i], dy2[i], h) # Check convergence if abs(y2[-1] – y_end) < tol: break return x, y2 # Boundary conditions x0, y0 = 0, 0 # y(0) = 0 x_end, y_end = 1, 1 # y(1) = 1 # Initial guesses for y'(0) dy_guess1 = 0 dy_guess2 = 1 # Step size h = 0.1 # Solve using shooting method x, y = shooting_method(ode, x0, y0, x_end, y_end, dy_guess1, dy_guess2, h) # Exact solution for comparison (for the example ODE) exact = lambda x: x + np.sinh(2*x)/np.sinh(2) y_exact = exact(x) # Print results print(f"{'x': < 8}{'Numerical': < 12}{'Exact': < 12}{'Error': < 12}") print("-" * 40) for xi, yi, ye in zip(x, y, y_exact): print(f"{xi: < 8.3f}{yi: < 12.6f}{ye: < 12.6f}{abs(yi-ye): < 12.6f}") # Plot results plt.figure(figsize=(10, 6)) plt.plot(x, y, 'bo-', label='Numerical Solution') plt.plot(x, y_exact, 'r--', label='Exact Solution') plt.title("Solution of Boundary Value Problem using Shooting Method") plt.xlabel("x", fontsize=12) plt.ylabel("y(x)", fontsize=12) plt.legend(fontsize=10, edgecolor="black") plt.grid(True, linestyle="--") plt.show()
×

Disclaimer

The educational materials provided on this website are intended as supplementary resources to support your learning journey. These lab reports are sample documents designed to help students understand proper formatting and content organization.

We have made every effort to ensure the accuracy of the content. However, we recommend students to perform their own experiments and prepare original reports. These samples should be used as references only.

We respect intellectual property rights. If you believe any content should be credited differently or removed, please don’t hesitate to contact us. We’re happy to make appropriate corrections or give proper attribution.

Leave a Comment

Scroll to Top