MATLAB: Error: “The derivative function ODEFUN should return a column vector of length 3”

bvp4cerrorodefunvector of length

Hello, Writing to you with a problem… I am trying to figured out this for many hours already and still no clue where is the problem:
My code:
l=linspace(0,L,100);
sol0=bvpinit(l,@funinit);
sol=bvp4c(@ODE,@bc,sol0);
R=deval(sol,l)';
tm=R(:,1)
tg=R(:,2)
um=R(:,3)
function y=funinit(x)
global tm0 tk L tgk tg0
y=[ tm0-(tm0-tk)*x./L;
tgk-(tgk-tg0)*x./L;
3];
function dydx=ODE(~,y)
global g CD ug0 rom rop dp Wm cm Wp cwp cwm alfa
tm=y(1); tg=y(2); um=y(3);
dup=g-0.75*CD*(um-ug0)*(um-ug0).^2*rop./(dp*rom)./um;
dtp=-1.75*alfa*(um-ug0)*(tm-tg)./(dp*rom*cwm)./um;
dtg=dtp*Wm*cm./(Wp*cwp); =
dydx=[dtg;
dtp;
dup];
function y=bc(yb,yc)
global tm0 tg0 ucz
y=[yb(1)-tm0
yc(2)-tg0
yb(3)-ucz];
Matlab error: Error using bvparguments (line 108) Error in calling BVP4C(ODEFUN,BCFUN,SOLINIT): The derivative function ODEFUN should return a column vector of length 3.
Error in bvp4c (line 130) bvparguments(solver_name,ode,bc,solinit,options,varargin);
Error in Roma5a (line 43) sol=bvp4c(@ODE,@bc,sol0);

Best Answer

You are using global without having initialized some of the global variables, so some of the items you calculate come out empty, resulting in a return value that is shorter than 3.
Recommended solution: do not use global.