1
11.12 Write a user-defined MATLAB function that solves, with the shooting method, a second-order
boundary value problem of the form:
for with and
where and are constants. The function should first calculate two solutions using two assumed values
for the slope at , which are specified by the user, and use these solutions for calculating a new initial
slope using interpolation (Eq. (11.14)), which is then used for calculating the final solution of the problem.
Name the function [x,y]=BVPShootInt(fOFx,gOFx,hOFx,a,b,n,Ya,Yb,WL,WH). The input
arguments fOFx, gOFx, and hOFx are names for the functions that calculate , , and , respec-
tively. They are dummy names for the anonymous or user-defined functions that are imported into BVP-
ShootInt. a and b define the domain of the solution, n is the number of subintervals, Ya and Yb are the
boundary conditions, and WL and WH are the assumed slopes at . Once the first two solutions are cal-
culated, the program should confirm that at the given boundary condition is between the two
solutions, and then calculate the final solution with the interpolated value for the slope. If the boundary
condition at is not between the first two solutions, the program should stop and display an error
message. Use the user-defined function Sys2ODEsRK4 that was written in Example 8-8 for solving the
system of the two first-order ODEs within the user-defined function BVPShootInt.
Use BVPShootInt to solve the boundary value problem in Example 11-6. Use ,
, and .
Solution
First, the second order ODE is written as a system of two first order ODEs:
d2y
dx2
——-–fx()
dy
dx
—––gx()y++ hx()=