Conditionally execute a function inside a vector field while integrating with an ODE solver

2 ビュー (過去 30 日間)
Ícar
Ícar 2021 年 6 月 4 日
コメント済み: darova 2021 年 6 月 7 日
I am integrating some equations that represent an astrodynamics problem. They are defined by a vector field such as:
where x are the states (e.g. position, velocity, mass...). The dynamics that I'm integrating are fed by a control u, that is computed based on the states and time: . This control u is computed inside the vector field, which we could explicitely state as . I am integrating with an ODE solver (e.g. ode45()), and thus the solver computes the control at every time step.
Now, what I want is to avoid computing the control at every time step, but rather only at certain times, with a given frequency (e.g. let's say I want to compute the control at 0.1 Hz, every 10s). How would you recommend me to approach this?
I hope I was clear enough. Thank you for any help.

回答 (1 件)

darova
darova 2021 年 6 月 5 日
Try to pass your condition inside ode function
An example
function dy = func1(t,x)
tset = [10 20 30];
if any(abs(t-tset)>0.05)
u = x(1)*t-1;
end
% dy function ...
end
function main
[t,y] = ode45(func1,tspan,x0);
plot(t,y)
end
  2 件のコメント
Ícar
Ícar 2021 年 6 月 6 日
編集済み: Ícar 2021 年 6 月 6 日
Thanks @darova, seems a feasible option! Will keep the answer opened to see if someone else contributes to the brainstorming.
PS: shouldn't the "any()" expression have a < instead?
if any(abs(t-tset)<0.05)
...
end
will execute the control if we are close to a pre-scribed epoch with a resolution of 0.05s.
darova
darova 2021 年 6 月 7 日
  • will execute the control if we are close to a pre-scribed epoch with a resolution of 0.05s.
You are right, my bad

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

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by