C Program for Shooting Method


Shooting method is a famous method for numerical solution of second order differential equation when boundary condition is known. In this tutorial, we’re going to write a program for Shooting method in C with sample output and working procedure of the method. Shooting method converts the given boundary value problem into initial value problem and solves the problem by using Runge Kutt-4 method.

The working procedure of C program for shooting method is given below:

  1. As the user executes the program, it asks for boundary values i.e. initial value of x (x0), initial value of y (y0), final value of x (xn), final value of y (yn) and the value of increment (h).
  2. The second step of calculation is to convert this boundary value problem into initial value problem.
  3. After the conversion into initial value problem, the user has to input the initial guess value of z (M1) which is known as shooting.
  4. Using this guess value of z, the program calculates intermediate values of z & y are calculated. The final value of y obtained is assigned as B1 in the source code.
  5. Again, the user has to shoot i.e. the shooting method program asks second initial guess value of z (M2).
  6. Using M2, new values of y and z are calculated. The final value of y obtained in second guess is assigned as B2 in the program.
  7. (M1, B1), (M2, B2), and ( y0, z0 ) are assumed to be collinear in this C program and value of z0 determined using following equation,
    (B2-B1)/(M2-M1) = (z0-B2)/(y0-M2)
  1. Using this new and exact value of z, intermediate values are calculated using Runge Kuttta Method.
  2. Finally, the program prints the result upto 6 decimal places.

Source Code for Shooting Method in C:


Shooting Method in C Output
Also see,
Numerical Methods Tutorial Compilation

The aforementioned C source code for shooting method is a very useful program for solving the second order differential equation when the problem has the nature of boundary value problem. The coding is a bit long, but it is simple to understand with the use of few functions for respective purposes.


Please enter your comment!
Please enter your name here