'...must return a column vector' errors when using ODE45

1 visualización (últimos 30 días)
Keelan Toal
Keelan Toal el 3 de Dic. de 2015
Comentada: Titus Edelhofer el 7 de Dic. de 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 comentarios
Keelan Toal
Keelan Toal el 4 de Dic. de 2015
We have progress! But I get the error:
Error using odearguments (line 92)
Error using odearguments (line 92)
@(T,X)MYODE1(T,X) returns a vector of length 4800, but the length of initial conditions vector is 16. The vector returned
by @(T,X)MYODE1(T,X) and the initial conditions vector must have the same number of elements.
Error in ode45 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in Optimisation (line 2)
[T,X]=ode45(@(t,x) myode1(t,x),Tspan,IC);
If I change the length of IC to 4800 (which is wrong), the could does run but x is a 16x300 of zeros.
Torsten
Torsten el 4 de Dic. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Titus Edelhofer
Titus Edelhofer el 4 de Dic. de 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 comentarios
Keelan Toal
Keelan Toal el 4 de Dic. de 2015
That's exactly what I what I was trying to do. Thanks for pointing that out.
How would you suggest I input the constraints on Q1-4? I.e. when they are zero. Also I do not get a matrix for x, only xdot, is this correct?
Titus Edelhofer
Titus Edelhofer el 7 de Dic. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by