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 CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by