'...must return a column vector' errors when using ODE45
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Torsten
2015-12-4
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.
采纳的回答
Titus Edelhofer
2015-12-4
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 个评论
Titus Edelhofer
2015-12-7
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
更多回答(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!