ODE, how to retrive variables computed in the previous step

1 回表示 (過去 30 日間)
Adriano Filippo Inno
Adriano Filippo Inno 2018 年 11 月 6 日
編集済み: Torsten 2018 年 11 月 6 日
I need to solve a nonlinear system inside the ODE at each time step in order to construct the current state derivatives. Since the system is quite involved I wish I can use, as initial condition to solve it, the solution of the system computed at the previous step. How can I do that? I also want to know if there is a faster procedure to get all the solutions of the system after all, instead of re-evaluating the ode function (not with global or persistent variables because I want just the accepted steps).
  2 件のコメント
Jan
Jan 2018 年 11 月 6 日
What exactly is "the previous step"? Which ODE integrator are you using? Even the one-step solvers evaluate the function to be integrated several times for each step. Afterwards the step size controller can reject a step. In consequence "previous step" is not clear.
"faster procedure to get all the solutions" - faster than what and what do you mean by "all the solutions"? The integrator replies one solution only.
Torsten
Torsten 2018 年 11 月 6 日
編集済み: Torsten 2018 年 11 月 6 日
ode15i is a solver for systems that are implicit in the state derivatives. So no nonlinear systems have to be solved by the user during the solution process.
Maybe it's worth changing the solver.
Best wishes
Torsten.

サインインしてコメントする。

採用された回答

Stephen23
Stephen23 2018 年 11 月 6 日
編集済み: Stephen23 2018 年 11 月 6 日
The simplest solution is: use nested functions.
Write the input odefun (usually the first input) as a nested function. In its parent workspace you can initialize whatever variables you want, e.g.:
function dydt = main()
prev = [];
dydt = ode45(@myode,...)
%
function dydt = myode(t,y)
... = prev % whatever using previous value
...
prev = dydt;
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by