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