ode45 event trigger not responding
이전 댓글 표시
I'm trying to get the integration of ode45 to stop when the first column (which represents position) reaches a certain value. But even though I set an event trigger and the integration reaches that value, it continues to integrate until the final time and can't understand why. Is there some error in my code of the event function that I dont understand?
options = odeset('RelTol',1e-9,'AbsTol',1e-9,'Events',@event);
[tt,yy] = ode45(@ODEsystem,[0,3],[0,0,10e-3,0],options);
plot(tt,yy(:,1))
function [value,isterminal,direction] = event(~,yy)
x_max = 200e-3;
value = (yy(:,1)==x_max); %
isterminal = 1; % Halt integration
direction = -1;
end
function dydt = ODEsystem(t,y)
dydt(1) = y(2); % xa_dot = va;
dydt(2) = (1/ma)*((P4*A4) - (P5*A5) - (F_0+(k*y(1)))); % va_dot = (1/ma)*((P4*A4) - (P5*A5) - (F_0+(k*xa)));
dydt(3) = y(2)*A5; % Vt_dot = Qout;
dydt(4) = y(2)*A4; % Vacc_dot = -Qin;
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!