BVP solver with an array of initial conditions

Hello,
I have a question regarding an BVP solvers with numerous initial condition guesses. My BVP5c function is shown below. The code works well. I have checked it for a simple IC guess of [1 5] and it works.
y1=linspace(0,1,10) %initial condition array 1
y2=linspace(1,-1,10) %IC array 2
xlow = 0; xhigh =1;
solinit = bvpinit(linspace(xlow,xhigh,10),[y1' y2']);
sol = bvp5c(@bvp5ode, @bvp5bc,solinit);
xint=linspace(xlow,xhigh);
Sxint=deval(sol,xint);
plot(xint,Sxint(1,:)); hold all
function dydx = bvp5ode(x,y)
dydx = [y(2) -x(1)*y(1)];
%dydx = [y(2) -x(1)*y(1)];
end
function res = bvp5bc(ya,yb)
res = [ya(1)-1 yb(2)];
end
However, when I try an array of ICs, it gives me the error:
The guess for the solution must return a vector.
The IC array of [y1' y2'] is:
0 1.0000
0.1111 0.7778
0.2222 0.5556
0.3333 0.3333
0.4444 0.1111
0.5556 -0.1111
0.6667 -0.3333
0.7778 -0.5556
0.8889 -0.7778
1.0000 -1.0000
As shown in the code, x varies from 0 to 1 with 10 intervals. I am hoping to run each row of the IC for each x interval. Thus, for x(i), the IC guess will be the ith row of y1' and y2'.

Answers (1)

solinit = bvpinit(linspace(xlow,xhigh,10),@init);
function yinit = init(x)
yinit = [ x
1-2*x ];
Best wishes
Torsten.

Answered:

on 7 May 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!