Why does Matlab tell me that my ODE function returns a vector of length 12, while the length of my initial conditions vector is 6?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi there!
I'm getting an error message from Matlab, telling me that my ODE model returns a vector of length 12, while the length of my initial conditions vector is 6. The state vector I've defined in my ODE function file, at the beginning of my code, is:
xG = z(1);
yG = z(2);
theta = z(3);
vGx = z(4);
vGy = z(5);
omega = z(6);
and, therefore, my first three, simple ODEs is [z(4);z(5);z(6)], and the last three ODEs are the derivatives of z(4), z(5), and z(6). So, it seems to me that I wrote a function that returns a vector of length 6, not the 12 that Matlab is suggesting.
What have I done wrong?
Thanks in advance,
댓글 수: 2
Torsten
2024년 11월 25일
편집: Torsten
2024년 11월 25일
MATLAB won't tell you that you return a vector of length 12 if you return a vector of length 6. But we must see your code to tell you what's going wrong.
You can easily determine the length of the vector returned to the ODE integrator by using
size(dydt)
at the end of your ODE function if "dydt" is the name of the output from your function.
채택된 답변
Walter Roberson
2024년 11월 25일
이동: Walter Roberson
2024년 11월 25일
It is common for this to happen if you accidentally forget to index the variable, For example,
dydt = [z(1).^2;
z(2)-z(4);
z+z(5)^3;
z(1)-5*z(6);
z(2)+sin(z(4));
z(3).*z(4).*z(5)+z(6)];
There might only be six rows in dydt, but the third one accidentally used unindexed z as part of the expression
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!