| Mathematics |    | 
Using Continuation to Make a Good Initial Guess
To solve a boundary value problem, you need to provide an initial guess for the solution. The quality of your initial guess can be critical to the solver performance, and to being able to solve the problem at all. However, coming up with a sufficiently good guess can be the most challenging part of solving a boundary value problem. Certainly, you should apply the knowledge of the problem's physical origin. Often a problem can be solved as a sequence of relatively simpler problems, i.e., a continuation. This section provides examples that illustrate how to use continuation to:
Example: Using Continuation to Solve a Difficult BVP
This example solves the differential equation
 
for  , on the interval [-1 1], with boundary conditions
, on the interval [-1 1], with boundary conditions  and
 and  . For
. For  , the solution has a transition layer at
, the solution has a transition layer at  . Because of this rapid change in the solution for small values of
. Because of this rapid change in the solution for small values of  , the problem becomes difficult to solve numerically.
, the problem becomes difficult to solve numerically. 
The example solves the problem as a sequence of relatively simpler problems, i.e., a continuation. The solution of one problem is used as the initial guess for solving the next problem.
| Note    
The demo shockbvpcontains the complete code for this example. The demo uses subfunctions to place all required functions in a single M-file. To run this example typeshockbvpat the command line. See BVP Solver Basic Syntax and Solving BVP Problems for more information. | 
| Note This problem appears in [1] to illustrate the mesh selection capability of a well established BVP code COLSYS. | 
bvp4c can use. Because there is an additional known parameter  , the functions must be of the form
, the functions must be of the form
shockODE and shockBC. Note that shockODE is vectorized to improve solver performance. The additional parameter  is represented by
 is represented by e. 
function dydx = shockODE(x,y,e) pix = pi*x; dydx = [ y(2,:) -x/e.*y(2,:) - pi^2*cos(pix) - pix/e.*sin(pix) ]; function res = shockBC(ya,yb,e) res = [ ya(1)+2 yb(1) ];
The example passes e as an additional input argument to bvp4c. 
bvp4c then passes this argument to the functions shockODE and shockBC when it evaluates them. See Additional BVP Solver Arguments for more information.
shockJac and shockBCJac.
e, because bvp4c passes the additional argument to all the functions the user supplies. 
Tell bvp4c to use these functions to evaluate the partial derivatives by setting the options FJacobian and BCJacobian. Also set 'Vectorized' to 'on' to indicate that the differential equation function shockODE is vectorized.
bvp4c with a guess structure that contains an initial mesh and a guess for values of the solution at the mesh points. A constant guess of  and
 and  , and a mesh of five equally spaced points on [-1 1] suffice to solve the problem for
, and a mesh of five equally spaced points on [-1 1] suffice to solve the problem for  . Use
. Use bvpinit to form the guess structure.
 , the example uses continuation by solving a sequence of problems for
, the example uses continuation by solving a sequence of problems for  . The solver
. The solver bvp4c does not perform continuation automatically, but the code's user interface has been designed to make continuation easy. The code uses the output sol that bvp4c produces for one value of e as the guess in the next iteration.
Example: Using Continuation to Verify a Solution's Consistent Behavior
Falkner-Skan BVPs arise from similarity solutions of viscous, incompressible, laminar flow over a flat plate. An example is
 
 
for  on the interval
 on the interval  with boundary conditions
 with boundary conditions  ,
,  , and
, and  .
. 
The BVP cannot be solved on an infinite interval, and it would be impractical to solve it for even a very large finite interval. So, the example tries to solve a sequence of problems posed on increasingly larger intervals to verify the solution's consistent behavior as the boundary approaches  .
. 
The example imposes the infinite boundary condition at a finite point called infinity. The example then uses continuation in this end point to get convergence for increasingly larger values of infinity. It uses bvpinit to extrapolate the solution sol for one value of infinity as an initial guess for the new value of infinity. The plot of each successive solution is superimposed over those of previous solutions so they can easily be compared for consistency. 
| Note    
The demo fsbvpcontains the complete code for this example. The demo uses subfunctions to place all required functions in a single M-file. To run this example typefsbvpat the command line. See BVP Solver Basic Syntax and Solving BVP Problems for more information. | 
bvp4c can use.
function dfdeta = fsode(eta,f) beta = 0.5; dfdeta = [ f(2) f(3) -f(1)*f(3) - beta*(1 - f(2)^2) ]; function res = fsbc(f0,finf) res = [f0(1) f0(2) finf(2) - 1];
bvp4c with a guess structure that contains an initial mesh and a guess for values of the solution at the mesh points. A crude mesh of five points and a constant guess that satisfies the boundary conditions are good enough to get convergence when infinity = 3.
infinity = 3. It then prints the computed value of  for comparison with the value reported by Cebeci and Keller [2].
 for comparison with the value reported by Cebeci and Keller [2].
figure plot(eta,f(2,:),eta(end),f(2,end),'o'); axis([0 maxinfinity 0 1.4]); title('Falkner-Skan equation, positive wall shear, \beta = 0.5.') xlabel('\eta') ylabel('df/d\eta') hold on drawnow shg
infinity = 4, 5, 6.  It uses bvpinit to extrapolate the solution sol for one value of infinity as an initial guess for the next value of infinity. For each iteration, the example prints the computed value of  and superimposes a plot of the solution in the existing figure.
 and superimposes a plot of the solution in the existing figure.
Value computed using infinity = 4 is 0.92774. Value computed using infinity = 5 is 0.92770. Value computed using infinity = 6 is 0.92770.
Note that the values approach 0.92768 as reported by Cebeci and Keller. The superimposed plots confirm the consistency of the solution's behavior.
|   | Solving BVP Problems | Solving Singular BVPs |  |