필터 지우기
필터 지우기

Getting the data from events in ode 113

조회 수: 1 (최근 30일)
Divas
Divas 2014년 10월 3일
편집: Divas 2014년 10월 7일
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
Bruno Pop-Stefanov
Bruno Pop-Stefanov 2014년 10월 6일
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 2014년 10월 7일
편집: Divas 2014년 10월 7일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by