I've been getting several errors, especially "index must be a positive integer or logical."

1 view (last 30 days)
Hello, I've been trying to run this code and it keeps getting the following errors:
Attempted to access k2(0); index must be a positive integer or logical.
Error in toluene (line 14)
r(3)= -k1*P(1)*(P(2)^0.5)+(2*k2(P(3)^2-(P(5)*P(2)/Kp)));
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in Untitled2 (line 12)
[V,F]= ode45('toluene', Vspan, F0);
I don't really know what's wrong?
-------------------------------------------------------------------------------------
This is the code:
function dFdV = toluene(~, F)
global k1 k2 Kp Pt0
Ft = F(1)+F(2)+F(3)+F(4)+F(5);
P(1)= Pt0*(F(1)/Ft);
P(2)= Pt0*(F(2)/Ft);
P(3)= Pt0*(F(3)/Ft);
P(4)= Pt0*(F(4)/Ft);
P(5)= Pt0*(F(5)/Ft);
r(1)= -k1*P(1)*(P(2)^0.5);
r(2)= -k1*P(1)*(P(2)^0.5)+(k2*(P(3)^2-(P(5)*P(2)/Kp)));
r(3)= -k1*P(1)*(P(2)^0.5)+(2*k2(P(3)^2-(P(5)*P(2)/Kp)));
r(4)= k1*P(1)*(P(2)^0.5);
r(5)= k2*((P(3)^2)-((P(5)*P(2))/Kp));
dFdV= [r(1); r(2); r(3); r(4); r(5)];
end
clear;
global k1 k2 Kp Pt0;
k1= 2.22*10^-8;
k2= 3.60*10^-10;
Kp= 0.2338;
Pt0= 600;
Vspan= [0 608];
F0= [0.121 2.42 0 0 0];
[V,F]= ode45('toluene', Vspan, F0);

Accepted Answer

James Tursa
James Tursa on 5 May 2015
In one line you have this:
...+(k2*(...
and in the next line you have this:
...+(2*k2(...
I assume the 2nd line is a typo and is missing a multiply operator:
...+(2*k2*(...

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!