'...must return a column vector' errors when using ODE45
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Keelan Toal
il 3 Dic 2015
Commentato: Titus Edelhofer
il 7 Dic 2015
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 Commenti
Torsten
il 4 Dic 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.
Risposta accettata
Titus Edelhofer
il 4 Dic 2015
Keelan,
I think there is a conceptual misunderstanding of what your myfun should do: it looks as if your 300 is related to 300 time steps that you want to do? The time stepping is done by the ode solver, inside myfun you should only work with 16x1 vectors, no loop on t (t is given by the ode solver as first input argument!).
Titus
2 Commenti
Titus Edelhofer
il 7 Dic 2015
You can leave the computation of Q1-4 more or less unchanged. Simply use the t that you get as parameter (without indexing (i)). Remove the for loop and just write
if t<=2
Q1 = (h/2) * (1-cos(w*t));
else
Q1 = 0;
end
Titus
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Ordinary Differential Equations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!