ode45 - return a column vector

Below is the function i have described:
function ssir = fnsir(t,y)
b = 0.1;
q = 0.022;
m = 0.012;
l = 0.125;
r = 0.14;
ssir(1) = q - m*y(1)-b*y(1)*y(2)+ l*y(3);
ssir(2) = (b*y(1)*y(2))-((m+r)*y(2));
ssir(3) = (r*y(2)) - (y(3)*(m+r));
------------------------------
And i am calling this function using:
[t,y]=ode45('fnsir', [0 10], [200 20 2])
and i am getting the following error:
??? Error using ==> odearguments at 113 FNSIR must return a column vector.
Error in ==> ode45 at 173 [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
--------------------------
can anyone please help me sort this out
Thanks!

3 comentarios

SAFA BOUDHRAA
SAFA BOUDHRAA el 7 de En. de 2018
I'am having the same problem, but the solution mentioned doesn't help
SAFA BOUDHRAA: As the very last step of your function, turn the output into a column vector. For example if you currently have
function dy = MyOde(....)
...
dy = ....
then after that do
dy = dy(:);
as the last thing before returning. The variable you should do this to is the one returned by your function.
If that does not work, then use the debugger to check whether possibly you are returning the empty vector.
Walter Roberson
Walter Roberson el 30 de Nov. de 2019
Hoda Khesali Aghtaei comments to me:
was helpful

Iniciar sesión para comentar.

 Respuesta aceptada

Jan
Jan el 14 de Mayo de 2013
Editada: Jan el 14 de Mayo de 2013

9 votos

ODE45 expects the reply as [3 x 1] vector, but your code creates a [1 x 3] vector. Two solutions:
1. Pre-allocate ssir as a vector of the wanted shape:
ssir = zeros(3, 1);
ssir(1) = ...
2. Or append a reshaping as last line of the function fnsir:
ssir = ssir(:);
As you see, the error message is rather clear. It is worth to read Matlab's messages carefully. They are the best messages I've ever seen in a commercial software.

8 comentarios

Ojaswita
Ojaswita el 14 de Mayo de 2013
Thanks alot for the help!
Actually, people like me are new to certain parts of MATLAB and sometimes I do not know hoe to solve the problem, hence the requests for help!
Thanks alot once again, your help is much appreciated!!
Jan
Jan el 14 de Mayo de 2013
Your questions are welcome in the forum. And I know, that one can desperate on such tiny details. Therefore I spend time in this forum to answer and I'm very happy about the time, TMW has spent to create the helpful error messages - compared to the confusing stuff show by e.g. Microsoft programs...
Ojaswita
Ojaswita el 24 de Sept. de 2013
Yaa... smal small things like this sometimes take days and days... thanks to all the helpful peers around here!!!
Frank Böhnke
Frank Böhnke el 19 de Dic. de 2016
thanks very much, that answer helped on the 19 th Dec 2016 Frank, Munich
SY
SY el 30 de Oct. de 2017
Wow, I've been trying to fix this exact problem for my program and this answer from four years ago really helped me. Thanks!
Kalpit Bakal
Kalpit Bakal el 21 de Mzo. de 2019
Thank you so much for the answer. My code work perfectly after this. Best part about peer to peer learning!
Ali Amirfaridi
Ali Amirfaridi el 28 de Abr. de 2020
Editada: Ali Amirfaridi el 30 de Abr. de 2021
still helping in 2020! thank you mate
Yashee Sinha
Yashee Sinha el 27 de Abr. de 2021
thanks a lot!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 14 de Mayo de 2013

Editada:

el 30 de Abr. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by