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?
34 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Torsten
el 25 de Nov. de 2024 a las 22:06
Editada: Torsten
el 25 de Nov. de 2024 a las 22:07
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.
Respuestas (1)
Walter Roberson
el 25 de Nov. de 2024 a las 22:30
Movida: Walter Roberson
el 25 de Nov. de 2024 a las 22:30
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
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!