??? Attempted to access c(15); index out of bounds because numel(c)=14.

1 Ansicht (letzte 30 Tage)
Dennis
Dennis am 6 Dez. 2011
Beantwortet: Voss am 28 Dez. 2021
Hi i am trying to solve 14 simultaneous 1st order ODE, and i got this error"??? Attempted to access c(15); index out of bounds because numel(c)=14"
This is my m-file
1. function dcdt= HEM(t,c)
2. %c(14)=c(N), c(15)=c(O), c(16)=c(P), c(17)=c(Q), c(18)=c®, c(19)=c(S), c(20)=c(T),
3. %c(21)=c(U), c(22)=c(V), c(23)=c(W), c(24)=c(K), c(25)=c(I), c(26)=c(H), c(27)=c(L)
4. global K5 K6 K7 K8 TEMP R
5. dcdt=[-K5*c(14)*1; 0.4*K5*c(14)-0.4*K7*c(15)-0.4*K6*c(15)*1 ;0.6*K5*c(14)-0.6*K8*c(16); 1.5*K8*c(16)+2.5*K6*c(15); 0.7*K8*c(16)+0.5*K6*c(15); 0.25*K8*c(16)+0.25*K6*c(15); 0.125*K8*c(16)+0.125*K6*c(16); 0.8*K8*c(16); 0.8*K8*c(16); K7*c(15); 0.125*K6*c(15)+0.125*K8*c(16); K6*c(15); K6*c(15)+0.2*K8*c(16); 2*K6*c(15)+2*K8*c(16)];
This is my call function:
>> clear all
>> global K5 K6 K7 K8 R TEMP
>> R=8.3141;
>> TEMP =300;
>> K5=(1*10^10)*exp(-31000/(R*TEMP));
>> K5=(1*10^10)*exp(-31000/(R*TEMP));
>> K6=(3*10^9)*exp(-27000/(R*TEMP));
>> K7=(3*TEMP)*exp(-11000/(R*TEMP));
>> K8=(1*10^10)*exp(-33000/(R*TEMP));
>> tspan=[0 1];
>> c0=[1 0 0 0 0 0 0 0 0 0 0 0 0 0];
>> [t,c]=ode45('HEM',tspan,c0)
??? Attempted to access c(15); index out of bounds because numel(c)=14.
Error in ==> HEM at 5 dcdt=[-K5*c(14)*1; 0.4*K5*c(14)-0.4*K7*c(15)-0.4*K6*c(15)*1 ;0.6*K5*c(14)-0.6*K8*c(16); 1.5*K8*c(16)+2.5*K6*c(15); 0.7*K8*c(16)+0.5*K6*c(15); 0.25*K8*c(16)+0.25*K6*c(15); 0.125*K8*c(16)+0.125*K6*c(16 Error in ==> funfun\private\odearguments at 110 Please shed some light. Thanks

Antworten (1)

Voss
Voss am 28 Dez. 2021
The expression on line 5 of HEM.m references the 15th and 16th elements of c (written as "c(15)" and "c(16)", respectively). The c0 in the calling function (and passed to HEM via ode45) has 14 elements. This is the cause of the error. Perhaps the solution is as easy as appending two zeros onto the end of c0.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by