Solve a BVP over an initial interval, and then iteratively extend the interval using each solution as the initial guess for the next interval.

Consider the equation

${{\mathit{y}}^{\prime}}^{\prime}=\mathit{y}$.

As a first-order system, the equation becomes a system of two equations

${{\mathit{y}}_{1}}^{\prime}={\mathit{y}}_{2}$,

${{\mathit{y}}_{2}}^{\prime}={\mathit{y}}_{1}$.

The equation is initially defined on the interval $\left[0,3\right]$ and is subject to the boundary conditions

$\mathit{y}\left(0\right)=0$,

$\mathit{y}\left(3\right)=1$.

The function that encodes the equation as a first-order system is

function dydx = bvpfun(x,y)
dydx = [y(2)
y(1)];
end

Similarly, the function that encodes the boundary conditions is

function res = bcfun(ya,yb)
res = [ya(1)
yb(1)-1];
end

You either can include the required functions as local functions at the end of a file (as done here), or you can save them as separate, named files in a directory on the MATLAB path.

Use an exponential function as the initial guess for the solution. Since the equation has two solution components, write an initial guess function of the form `y = guess(x)`

that returns a vector.

function y = guess(x)
y = [exp(x)
exp(x)];
end

A mesh of five points is sufficient to capture the behavior of the guess function.

Solve the equation in the initial interval $\left[0,3\right]$ and plot the results for ${\mathit{y}}_{1}$.

Now, use `bvpinit`

to extend the interval of integration in a loop, solving and plotting each new problem. In each iteration, form the initial guess using the previous solution `sol`

extrapolated to the new interval `[0 k]`

. In each new problem, `bvp4c`

enforces the boundary conditions at the new boundaries `[0 k]`

.

This example shows a simplified version of *continuation*, a useful technique to solve BVPs by breaking the problem down into smaller intervals or simpler problems. For more examples of this technique, see:

Listed here are the local helper functions that the BVP solver `bvp4c`

calls to calculate the solution. Alternatively, you can save these functions as their own files in a directory on the MATLAB path.