Error using ode45

조회 수: 1 (최근 30일)
Mario Gonzaléz Sandoval
Mario Gonzaléz Sandoval 2016년 2월 26일
댓글: Star Strider 2016년 2월 26일
clear all; clc;
Io=0.00150;
k=0.075;
mumax=0.045;
kappa=0.075;
a=0.00018;
Leq=0.05;
ka=0.19;
Cb=100;
m=0.005;
Iav = (Io/(ka*Cb*Leq))*(1-exp(-ka*Cb*Leq));
mo= mumax * (Iav/(2*a)) * ( 1+k+(a/Iav)- sqrt(( 1-k-(a/Iav))^2 + (4*k) ));
f=@(t,Cb) Cb(mo-m);
tf=1000;
tspan=[0 tf];
Cb0=50;
[t,Cb]=ode45(f,tspan,Cb0);
plot(t,Cb);
But I get the next error:
Attempted to access Cb(0.0362687); index must be a positive integer or logical.
Error in @(t,Cb)Cb(mo-m)
Error in odearguments (line 88)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 114)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in OptFBPlacas (line 22)
[t,Cb]=ode45(f,tspan,Cb0);
What am I doing wrong? Help me, please.

채택된 답변

Star Strider
Star Strider 2016년 2월 26일
You’re doing implied multiplication (that MATLAB does not recognise), so it thinks you are addressing an array, and is throwing the error. I cannot read the reference you posted, so I also have to
See if this works:
Iav = @(Cb) (Io./(ka.*Cb.*Leq)).*(1-exp(-ka.*Cb.*Leq));
mo = @(Cb) mumax .* (Iav(Cb)./(2*a)) .* ( 1+k+(a./Iav(Cb))- sqrt(( 1-k-(a./Iav(Cb))).^2 + (4*k) ));
f=@(t,Cb) Cb.*(mo(Cb)-m);
Note that in the MathCad example, both ‘Iav’ and ‘mu’ are functions of several variables.
Your constants span a few orders of magnitude, so if ode45 gets stuck or gives strange results, see if ode15s will work.
Note — This is UNTESTED CODE so you may have to experiment with it to get it to work. My changes should at least solve some of your problems, and the revised code will not throw the error it did earlier.
  댓글 수: 2
Mario Gonzaléz Sandoval
Mario Gonzaléz Sandoval 2016년 2월 26일
Thank you! :D That was the problem.
Star Strider
Star Strider 2016년 2월 26일
My pleasure!
I aplolgise for the delay — my laptop crashed.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by