'...must return a column vector' errors when using ODE45
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Keelan Toal
le 3 Déc 2015
Commenté : Titus Edelhofer
le 7 Déc 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 commentaires
Torsten
le 4 Déc 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.
Réponse acceptée
Titus Edelhofer
le 4 Déc 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 commentaires
Titus Edelhofer
le 7 Déc 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!