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

2 views (last 30 days)
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 Comment
Akash Singh
Akash Singh on 29 Jun 2020
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.

Sign in to comment.

Answers (0)

Tags

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!