'...must return a column vector' errors when using ODE45
이전 댓글 표시
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
Star Strider
2015년 12월 3일
편집: Star Strider
2015년 12월 3일
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
2015년 12월 4일
Walter Roberson
2015년 12월 4일
Please post actual code. The image of the code is not clear enough for me to make out (I have vision problems.)
Keelan Toal
2015년 12월 4일
Walter Roberson
2015년 12월 4일
[T,X]=ode45(@(t,x) myode1(t,x),Tspan,IC);
Notice no string!!
Keelan Toal
2015년 12월 4일
Walter Roberson
2015년 12월 4일
xdot = xdot(:);
right you compute xdot.
Torsten
2015년 12월 4일
A*x is 16x1 and B*Q is 16x300. Incompatible.
Best wishes
Torsten.
Walter Roberson
2015년 12월 4일
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
2015년 12월 4일
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.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
