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

조회 수: 1 (최근 30일)
Dennis
Dennis 2011년 12월 6일
답변: Voss 2021년 12월 28일
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

답변 (1개)

Voss
Voss 2021년 12월 28일
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.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by