필터 지우기
필터 지우기

Attempted to access X(3); index out of bounds because numel(X)=1.

조회 수: 2 (최근 30일)
Ashley
Ashley 2011년 8월 2일
fourLumpData=[...
0, 6.593, 7.912, 4.222, 0
60, 5.149, 6.468, 5.667, 1.444
120, 3.371, 4.690, 7.444, 3.222
180, 3.149, 4.468, 7.667, 3.444
240, 2.704, 4.023, 8.111, 3.889
300, 2.037, 3.356, 8.778, 4.556
];
time=fourLumpData(2:6,1)'
tf=max(time)
tspan=(0:1:tf)'
X0(1:4,1)=fourLumpData(1,2:5)'
[t,Xcal]=ode45(@modelEquation,tspan,X0);
subfunction: function dxdt = modelEquation(X,K)
f1=K(2)*X(3)*X(4)- K(1)*X(1)*X(2);
f2= K(2)*X(3)*X(4)-K(1)*X(1)*X(2);
f3= K(1)*X(1)*X(2)-K(2)*X(3)*X(4);
f4=K(1)*X(1)*X(2)-K(2)*X(3)*X(4);
dxdt = [f1;f2;f3;f4]; ??? Attempted to access X(3); index out of bounds because numel(X)=1.
Error in ==> modelEquation at 2
f1=K(2)*X(3)*X(4)- K(1)*X(1)*X(2);
I dont't know why,and when I add the sentence disp(X(3)) after X0(1:4,1)=fourLumpData(1,2:5)',
it displays 4.222 which is the right value. Then what dose the information mean?

채택된 답변

the cyclist
the cyclist 2011년 8월 2일
I am not an expert in using ode45, but looking at the documentation for it, it is expecting the user-defined function to be f(t,y), which in your notation translates to modelEquation(t,X). So, your function seems to have two problems, I think:
  • You defined your input arguments in the incorrect order. X should be the second argument. (Notice that if you breakpoint inside of modelEquation, K is taking the values you expected for X.)
  • You are trying to use a second vector argument "K", but MATLAB is expecting a scalar argument "t" there instead (which it is going to fill in using your variable "tspan".)

추가 답변 (0개)

카테고리

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