Exiting an ode45 but based on a variable calculated inside the function and not based on output variable y

1 回表示 (過去 30 日間)
Hi!
I'm calculating a variable b inside myodefunc, which is further used to solve a quadprog problem.
The output of this quadrpog is what ode45 uses to integrate y.
function [u,b] = myodefunc(t,y)
Q = [1 0; 0 1];
g = zeros(2,0);
A = f1(t,y)
b = f2(t,y); % function of states and time
u = quadprog(Q,g,A,b);
end
I need to exit the ode when variable , where k is a positive constant.
Any help or suggestions would be greatly appreciated.
Thanks
  1 件のコメント
Akash Singh
Akash Singh 2020 年 6 月 29 日
Update:
So I found out it works if I calculate the b again in the event detection function and then implement condition .
function [value,isterminal,direction] = EventsFunc(t,y)
b = f1(t,y)
value = b+k;
isterminal = 1;
direction = -1;
end
I had another doubt arising out of this. Is the event detection done before next time step is processed by the ode45?
Also, can I pass other input arguments to EventsFunc, for example EventsFunc(t,y,param) ? Do I need to change the function definition in the options('Events',@EventsFunc) for that? Or any other way besides explicitly defining the parameters again inside the function.

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

回答 (0 件)

カテゴリ

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