bvp4c
Solves boundary value problems for ordinary differential equations.
Category: Mathematics > Numerical Integration and Differential Equations
Syntax
sol = bvp4c(odefun, bcfun, solinit)
Solves y' = odefun(x, y) subject to the boundary conditions bcfun(y(a), y(b)) = 0, starting from the guess solinit.
sol = bvp4c(odefun, bcfun, solinit, options)
Also applies options created with bvpset.
Description
Write the equation as a first-order system, then give the boundary conditions as a function of the values at both ends. The solver adapts the mesh until the residual is below the tolerance, so sol.x is generally finer than solinit.x.
Use deval(sol, x) to evaluate the solution at any point, since the mesh points are not chosen by you. Boundary value problems can have several solutions or none, and the initial guess decides which one is found.
Input arguments
odefun- Function handle
dydx = odefun(x, y)returning a column vector. bcfun- Function handle
res = bcfun(ya, yb)returning the residuals of the boundary conditions. solinit- Initial mesh and guess, built with
bvpinit. options- Structure from
bvpset(tolerances, maximum mesh size, and so on).
Output arguments
sol- Structure with the mesh
sol.x, the solutionsol.y(one row per component), the derivativesol.ypandsol.stats.
Example
y'' + y = 0 with y(0) = 0, y(1) = 1
odefun = @(x, y) [y(2); -y(1)];
bcfun = @(ya, yb) [ya(1); yb(1) - 1];
solinit = bvpinit(linspace(0, 1, 5), [0; 1]);
sol = bvp4c(odefun, bcfun, solinit);
y = deval(sol, 0.5);
fprintf('%.4f %.4f\n', y(1), sin(0.5)/sin(1))
Output
0.5697 0.5697