필터 지우기
필터 지우기

ode45 - return a column vector

조회 수: 15 (최근 30일)
Ojaswita
Ojaswita 2013년 5월 14일
편집: Ali Amirfaridi 2021년 4월 30일
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
Walter Roberson
Walter Roberson 2018년 1월 7일
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 2019년 11월 30일
Hoda Khesali Aghtaei comments to me:
was helpful

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2013년 5월 14일
편집: Jan 2013년 5월 14일
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
Ali Amirfaridi
Ali Amirfaridi 2020년 4월 28일
편집: Ali Amirfaridi 2021년 4월 30일
still helping in 2020! thank you mate
Yashee Sinha
Yashee Sinha 2021년 4월 27일
thanks a lot!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by