MATLAB: Help regarding use of BVP4C in solving an third order ODE.

ode

I'm trying to solve a third order ode using BVP4C and I'm getting this error. Any help ?
Attempted to access y(3); index out of bounds because numel(y)=2.
Error in rhs_bvp (line 2) rhs=[y(2); y(3); y(2)-y(1)*y(3)-1];
Error in bvparguments (line 105) testODE = ode(x1,y1,odeExtras{:});
Error in bvp4c (line 129) [n,npar,nregions,atol,rtol,Nmax,xyVectorized,printstats] = …
Error in Hiemenz (line 4) sol=bvp4c(@rhs_bvp,@bc_bvp,init);
Below is my code
function bc=bc_bvp(yl,yr) %ya(1), ya(2), yb(2)
bc=[yl(1); yl(2); yr(2)-1];
end
function rhs=rhs_bvp(x,y)
rhs=[y(2); y(3); y(2)-y(1)*y(3)-1];
end
init=bvpinit(linspace(0,4,8),[0 0])
sol=bvp4c(@rhs_bvp,@bc_bvp,init);
x=linspace(0,4,8);
BS=deval(sol,x);
plot(BS(:,1),x);

Best Answer

Hi,
this works:
init=bvpinit(linspace(0,4,8),[0 0 0]);
sol=bvp4c(@rhs_bvp,@bc_bvp,init);
plot(sol.x,sol.y(1,:),sol.x,sol.y(2,:),sol.x,sol.y(3,:))
function bc=bc_bvp(yl,yr) %ya(1), ya(2), yb(2)
bc=[yl(1); yl(2); yr(2)-1];
end
function rhs=rhs_bvp(x,y)
rhs=[y(2); y(3); y(2)-y(1)*y(3)-1];
end
Best regards
Stephan