Getting the data from events in ode 113

1 view (last 30 days)
Divas
Divas on 3 Oct 2014
Edited: Divas on 7 Oct 2014
I created the following events function to terminate the integration at dot product sign change
function [value,isterminal,direction] = terminator(t,yy)
jed = mjd20002jed(t);
ncent = 12;
kmflag = 0;
inc = deg2rad(23+26/60+21.448/3600);
[rr, vv] = body(jed, 3, ncent, kmflag);
rrE = equ2ecl(rr, inc);
vvE = equ2ecl(vv, inc);
A = yy(1) - rrE(1);
B = yy(2) - rrE(2);
C = yy(3) - rrE(3);
D = yy(4) - vvE(1);
E = yy(5) - vvE(2);
F = yy(6) - vvE(3);
T_1 = [A, B, C];
T_2 = [D, E, F];
d_term = dot(T_1, T_2);
value = [d_term];
isterminal = 1;
direction = 1;
end
However now I want to use the first value of yy(4:6) that enters in the event function to be used instead of the current value. Is there any way to capture that inside a variable. I tried looping but since the program executes completely the counter resets everytime. Any ideas how to proceed
  2 Comments
Bruno Pop-Stefanov
Bruno Pop-Stefanov on 6 Oct 2014
What do you mean by using the first value that enters the function? Could you describe a bit more what the counter you are mentioning is?
I am not sure what you would like to do but you can use persistent variables to capture a state between several executions of a function:
Divas
Divas on 7 Oct 2014
Edited: Divas on 7 Oct 2014
The input variable for this integration starts from variables from previous integration which I terminated at some given condition.
This value enters first in 'yy' when the events function is called from the second integration, and I want to use that to compute the difference between that value and the values that are being generated following the integration.
If I use a variable to store that data, it gets overwritten with each call of events function. Although I'll give it a try using persistent variable
********Edit********
Persistent does the job. Thanks a lot.

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!