Solving Boundary Value Problems

by admin in , , , on May 1, 2019

This code solves the boundary value problem BVP for a second order differential equation (or two ODEs), with one final condition. The code has three files, one for Runge Kutta code, the second for Newton Raphson, and the third contains the equations we want to solve with the sensitivity equations.You can extend the code to solve more equations.

The code changes the final condition to initial condition with unknown value, using Newton Raphson we define the value of the new initial condition, and at the same time we check the if we get the same given final value. The given system with initial new initial conditions are solved using Runge Kutta of fourth order.

Code Outputs:

  • Chart for the Differential Equations solution.
  • Chart for convergence of New-Initial-Value condition.
  • Chart of Error History.
  • Printed final value of the New-Initial-Value condition.
  • Printed final error value.

New-Initial-Condition (alpha) = 4457.4021
Final Error Value of RK4 = 1.1013e-13

Input Requirements:

  • BVP Equations you want to solve (in Linear or nonlinear form).
  • Rewriting Sensitivity Equations for your system (There are explanation how to do that).
  • (Optional) Maximum Number of iterations in RK4 .
  • (Optional) Solution accuracy (default 1e-5).

About the Method:

Shooting Method is a method for solving a boundary value problem by reducing it to the solution of an initial value problem. Roughly speaking, we ‘shoot’ out trajectories in different directions until we find a trajectory that has the desired boundary value. The following exposition may be clarified by this illustration of the shooting method.

For a boundary value problem of a second-order ordinary differential equation, the method is stated as follows. Let

be the boundary value problem. Let y(ta) denote the solution of the initial value problem

Define the function F(a) as the difference between y(t1a) and the specified boundary value y1.

If F has a root a then the solution y(ta) of the corresponding initial value problem is also a solution of the boundary value problem. Conversely, if the boundary value problem has a solution y(t), then y(t) is also the unique solution y(ta) of the initial value problem where a = y‘(t0), thus a is a root of F.

The usual methods for finding roots may be employed here, such as the bisection method or Newton’s method.


A boundary value problem is given as follows by Stoer and Burlisch (Section 7.3.1).

The initial value problem

was solved for s = −1, −2, −3, …, −100, and F(s) = w(1;s) − 1 plotted in the first figure. Inspecting the plot of F, we see that there are roots near −8 and −36. Some trajectories of w(t;s) are shown in the second figure.

Stoer and Burlisch state that there are two solutions, which can be found by algebraic methods. These correspond to the initial conditions w′(0) = −8 and w′(0) = −35.9 (approximately).

The function F(s) = w(1;s) − 1.

Trajectories w(t;s) for s = w‘(0) equal to −7, −8, −10, −36, and −40. The point (1,1) is marked with a circle.


[1] Press, WH; Teukolsky, SA; Vetterling, WT; Flannery, BP (2007). ‘Section 18.1. The Shooting Method’. Numerical Recipes: The Art of Scientific Computing (3rd ed.). New York: Cambridge University Press. ISBN 978-0-521-88068-8.

3 Sales

Share Now!

Release Information

  • Price


  • Released

    May 1, 2019

  • Last Updated

    May 28, 2019

Share Your Valuable Opinions