BVP 4 C
BVP 4 C
BVP 4 C
Contents
bvp4c
Solve boundary value problems for ordinary differential equations
Syntax
sol = bvp4c(odefun,bcfun,solinit)
sol = bvp4c(odefun,bcfun,solinit,options)
solinit = bvpinit(x, yinit, params)
Arguments
dydx = odefun(x,y)
dydx = odefun(x,y,parameters)
res = bcfun(ya,yb)
res = bcfun(ya,yb,parameters)
solinit
file:///C:/Program%20Files/MATLAB/R2013a/help/matlab/ref/bvp4c.html 29/05/2019
bvp4c Page 2 of 11
The structure can have any name, but the fields must be named x,
y, and parameters. You can form solinit with the helper
function bvpinit. See bvpinit for details.
Description
sol = bvp4c(odefun,bcfun,solinit) integrates a system of
ordinary differential equations of the form
y′ = f(x,y)
file:///C:/Program%20Files/MATLAB/R2013a/help/matlab/ref/bvp4c.html 29/05/2019
bvp4c Page 3 of 11
bvp4c can also solve multipoint boundary value problems. See Multipoint
Boundary Value Problems. You can use the function bvpinit to specify the
boundary points, which are stored in the input argument solinit. See the
reference page for bvpinit for more information.
The bvp4c solver can also find unknown parameters p for problems of the form
y′ = f(x,y, p)
0 = bc(y(a),y(b),p)
bvp4c produces a solution that is continuous on [a,b] and has a continuous first
derivative there. Use the function deval and the output sol of bvp4c to
evaluate the solution at specific points xint in the interval [a,b].
sxint = deval(sol,xint)
sol.solver 'bvp4c'
file:///C:/Program%20Files/MATLAB/R2013a/help/matlab/ref/bvp4c.html 29/05/2019
bvp4c Page 4 of 11
The structure sol can have any name, and bvp4c creates the fields x, y, yp,
parameters, and solver.
y′ = S · y/x + F(x,y,p)
0 = bc(y(0),y(b),p)
The interval is required to be [0, b] with b > 0. Often such problems arise when
computing a smooth solution of ODEs that result from partial differential equations
(PDEs) due to cylindrical or spherical symmetry. For singular problems, you specify
the (constant) matrix S as the value of the 'SingularTerm' option of
bvpset, and odefun evaluates only f(x,y,p). The boundary conditions must be
consistent with the necessary condition S · y(0) = 0 and the initial guess should
satisfy this condition.
yp = odefun(x,y,k)
file:///C:/Program%20Files/MATLAB/R2013a/help/matlab/ref/bvp4c.html 29/05/2019
bvp4c Page 5 of 11
bcfun(yleft,yright)
yleft(:,1) = y(a)
and
yright(:,end) = y(b)
solinit = bvpinit(xinit,yinit),
use double entries in xinit for each interface point. See the reference page for
bvpinit for more information.
Note: The bvp5c function is used exactly like bvp4c, with the exception of
the meaning of error tolerances between the two solvers. If S(x) approximates
the solution y(x), bvp4c controls the residual |S′(x) – f(x,S(x))|. This controls
indirectly the true error |y(x) – S(x)|. bvp5c controls the true error directly.
bvp5c is more efficient than bvp4c for small error tolerances.
Examples
Example 1
Boundary value problems can have multiple solutions and one purpose of the initial
guess is to indicate which solution you want. The second-order differential equation
file:///C:/Program%20Files/MATLAB/R2013a/help/matlab/ref/bvp4c.html 29/05/2019
bvp4c Page 6 of 11
y′′ + |y| = 0
has exactly two solutions that satisfy the boundary conditions y(0) = 0, y(4) = −2.
Prior to solving this problem with bvp4c, you must write the differential equation as
a system of two first-order ODEs
y1′ = y2
y2′ = −|y1|.
y′ = f(x,y)
bc(y(a),y(b)) = 0
The function f and the boundary conditions bc are coded in MATLAB software as
functions twoode and twobc.
Form a guess structure consisting of an initial mesh of five equally spaced points in
[0,4] and a guess of constant values
y1(x) ≡ 0
and
y2(x) ≡ 0
file:///C:/Program%20Files/MATLAB/R2013a/help/matlab/ref/bvp4c.html 29/05/2019
bvp4c Page 7 of 11
sol = bvp4c(@twoode,@twobc,solinit);
Evaluate the numerical solution at 100 equally spaced points and plot y(x) with
x = linspace(0,4);
y = deval(sol,x);
plot(x,y(1,:));
You can obtain the other solution of this problem with the initial guess
file:///C:/Program%20Files/MATLAB/R2013a/help/matlab/ref/bvp4c.html 29/05/2019
bvp4c Page 8 of 11
Example 2
This boundary value problem involves an unknown parameter. The task is to
compute the fourth (q = 5) eigenvalue λ of Mathieu's equation
y" + (λ – 2q cos2x)y = 0.
y′(0) = 0
y′(π) = 0
y(0) = 1
It is convenient to use local functions to place all the functions required by bvp4c in
a single file.
function mat4bvp
lambda = 15;
solinit = bvpinit(linspace
(0,pi,10),@mat4init,lambda);
sol = bvp4c(@mat4ode,@mat4bc,solinit);
file:///C:/Program%20Files/MATLAB/R2013a/help/matlab/ref/bvp4c.html 29/05/2019
bvp4c Page 9 of 11
xint = linspace(0,pi);
Sxint = deval(sol,xint);
plot(xint,Sxint(1,:))
axis([0 pi -1 1.1])
title('Eigenfunction of Mathieu''s equation.')
xlabel('x')
ylabel('solution y')
% -----------------------------------------------
-------------
function dydx = mat4ode(x,y,lambda)
q = 5;
dydx = [ y(2)
-(lambda - 2*q*cos(2*x))*y(1) ];
% -----------------------------------------------
-------------
function res = mat4bc(ya,yb,lambda)
res = [ ya(2)
yb(2)
ya(1)-1 ];
% -----------------------------------------------
-------------
function yinit = mat4init(x)
yinit = [ cos(4*x)
-4*sin(4*x) ];
The guess structure solinit is formed with bvpinit. An initial guess for the
solution is supplied in the form of a function mat4init. We chose y = cos 4x
file:///C:/Program%20Files/MATLAB/R2013a/help/matlab/ref/bvp4c.html 29/05/2019
bvp4c Page 10 of 11
because it satisfies the boundary conditions and has the correct qualitative behavior
(the correct number of sign changes). In the call to bvpinit, the third argument
(lambda = 15) provides an initial guess for the unknown parameter λ.
After the problem is solved with bvp4c, the field sol.parameters returns the
value λ = 17.097, and the plot shows the eigenfunction associated with this
eigenvalue.
More About
Algorithms
bvp4c is a finite difference code that implements the three-stage Lobatto IIIa
formula. This is a collocation formula and the collocation polynomial provides a
C1-continuous solution that is fourth-order accurate uniformly in [a,b]. Mesh
selection and error control are based on the residual of the continuous solution.
References
[1] Shampine, L.F., M.W. Reichelt, and J. Kierzenka, "Solving Boundary Value
Problems for Ordinary Differential Equations in MATLAB with bvp4c," available at
http://www.mathworks.com/bvp_tutorial
file:///C:/Program%20Files/MATLAB/R2013a/help/matlab/ref/bvp4c.html 29/05/2019
bvp4c Page 11 of 11
See Also
@ | bvp5c | bvpget | bvpinit | bvpset | bvpxtend | deval
file:///C:/Program%20Files/MATLAB/R2013a/help/matlab/ref/bvp4c.html 29/05/2019