Help with plotting in a bvp4c solver

Hello! I am having trouble plotting a function in bvp4c. I managed to plot the solution of the ODE, but I would like to multiply the solution with another piecewise defined function and then get a plot of them as well.
When I run the code I get the following error:
Operands to the || and && operators must be convertible to logical scalar values.
Error in xfgn>F (line 43)
if (xint >= 0) && (xint <= 1.25)
Error in xfgn (line 10)
Sxint2=Sxint*1000/8*F(xint);
Any suggestions on how to fix this problem with the piecewise defined function F(xint)? Thanks.
function bvp4
xlow=0;
xhigh=20;
solinit=bvpinit(linspace(xlow,xhigh,1000),[0 0]);
sol = bvp4c(@bvp4ode,@bvp4bc,solinit);
xint=linspace(xlow,xhigh);
Sxint=deval(sol,xint);
Sxint1=sqrt(Sxint);
Sxint2=Sxint*1000/8*F(xint);
plot(xint,Sxint2(1,:))
function dydx = bvp4ode(x,y)
dydx = [y(2)/(H(x)*H(x)); (G(x)+125*f(x)*y(1)-9.47646*H(x))/(35*(f(x)/8))];
function res = bvp4bc(ya,yb)
res = [ya(1); yb(1)];
function fval = f(x)
if (x >= 0) && (x <= 1.25)
fval = 0.0152;
elseif (x > 1.25) && (x <= 20)
fval = 0.0232;
end
function Gval = G(x)
if (x >= 0) && (x <= 1.25)
Gval = 0.15*1000*9.81*0.2*0.000966;
elseif (x > 1.25) && (x <= 20)
Gval = -0.25*1000*9.81*0.05*0.000966;
end
function Hval = H(x)
if (x >= 0) && (x < 1.1)
Hval = 0.2;
elseif (x >= 1.1) && (x <= 1.25)
Hval = -x+1.3;
elseif (x > 1.25) && (x <= 20)
Hval = 0.05;
end
function Fval = F(xint)
if (xint >= 0) && (xint <= 1.25)
Fval = 0.0152;
elseif (xint > 1.25) && (xint <= 20)
Fval = 0.0232;
end

 Réponse acceptée

Torsten
Torsten le 27 Avr 2016

0 votes

"xint" is a vector - thus Fval must be applied in a loop over the size of "xint".
Best wishes
Torsten.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by