Can ode45 return two column vectors or a cell array?

조회 수: 4 (최근 30일)
Stacy Genovese
Stacy Genovese 2022년 4월 7일
댓글: Bjorn Gustavsson 2022년 4월 7일
I'm passing a cell array into ode45 for my initial conditions but the resulting cell array can't be returned from the function. Is there anyway to have Matlab return a cell array? Or if I convert the result to two column vectors using cell2Mat(), is it possible for ode45 to return both of these column vectors?

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2022년 4월 7일
From the help of ode45:
For a scalar T and a vector Y, ODEFUN(T,Y) must return a column vector corresponding to f(t,y).
So what you ask for is not possible. You might have to live with a work-around where you stack your column-vectors, let's call them x and y, into a single column-vector xy. This should be "rather straightforward" when it comes to modifying your ODEFUN - you would only need to "unstack" them at the top of the function and then stack the respective derivatives (dx and dy) back together (dxy = [dx;dy]) and the ode-integration should work just fine. Then you'll have to handle having the two columns above each other instead of next-to once you get the solution, but that should be a trivial (but admittedly slightly annoying) step to take.
HTH
  댓글 수: 2
Stacy Genovese
Stacy Genovese 2022년 4월 7일
Thanks so much. I did that work around and it works.
Bjorn Gustavsson
Bjorn Gustavsson 2022년 4월 7일
My pleasure, happy that it helped.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by