'...must return a column vector' errors when using ODE45
Ältere Kommentare anzeigen
Hi all,
Here's my function code:

and here's my solution code with the stated error:

I've not included a large amount of the code in the function as I don't believe my errors lies in there but if it'd help you help me I can add it.
I'm aiming at a solution that provides a 16x300 matrix, i.e. the value of 16 variables contained in x over 300 time steps. But Matlab is saying it must return a column vector. Is this the nature of ode45 or can I adapt my code somehow? My function is rejecting the input arguments as shown. What should they be here? The independent variable is t which defines x and Q, while all the remaining terms are constant.
Thanks in advance.
EDIT: Full code posted below
11 Kommentare
Star Strider
am 3 Dez. 2015
Bearbeitet: Star Strider
am 3 Dez. 2015
That is difficult to read.
Your ‘xdot’ needs to be a column vector, that means ‘x’ also needs to be a column vector, not a (16x300) matrix. (I have no idea what ‘B*Q’ is.)
Keelan Toal
am 4 Dez. 2015
Walter Roberson
am 4 Dez. 2015
Please post actual code. The image of the code is not clear enough for me to make out (I have vision problems.)
Keelan Toal
am 4 Dez. 2015
Walter Roberson
am 4 Dez. 2015
[T,X]=ode45(@(t,x) myode1(t,x),Tspan,IC);
Notice no string!!
Keelan Toal
am 4 Dez. 2015
Walter Roberson
am 4 Dez. 2015
xdot = xdot(:);
right you compute xdot.
Torsten
am 4 Dez. 2015
A*x is 16x1 and B*Q is 16x300. Incompatible.
Best wishes
Torsten.
Walter Roberson
am 4 Dez. 2015
Ah. We could show how to expand the A*x to be 16x300 itself, but I suspect that the poster wants a result of length 16 not a result of length 16*300 ...
Keelan Toal
am 4 Dez. 2015
Torsten
am 4 Dez. 2015
function xdot = myode1(t,x)
Here, t is 1x1 and x is 16x1.
So, you have to evaluate Q1, Q2, Q3 and Q4 at this special time t. If you do this, Q will be 4x1 and everything is fine.
Best wishes
Torsten.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Mathematics finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
