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);
MATLAB: I’ve been getting several errors, especially “index must be a positive integer or logical.”
indexindexinginteger or logicalmatricesmatrixmatrix array
Related Question
- Trying solve 7 1st order differnetial equation -Please help
- I need to plot a function that contains parameters. I do not get an error, yet the figure does not depict a graphic, it is just blank. How to produce a visible graph
- Cant get the loop to work
- Perturbing Values and determing an SFO
- Using ode45 to plot
Best Answer