在ODE45中触发Matlab事件?

时间:2013-06-14 22:53:25

标签: matlab matlab-guide

我一直试图在Matlab中模拟弹跳球,但是无法成功触发事件(可能是因为我没有使用事件功能吗?)。我知道value是您想要跟踪的值,一旦它越过0,事件将会消失。 isTerminal指定是否要ode45停止集成,direction是参数在触发事件时的方向。

以下是我的事件功能:

function [value,isterminal,direction] = ground_contact(t,y)

% Return event vectors VALUE, ISTERMINAL, and DIRECTION.
value = y(2);
isterminal = 1; %terminate the integration
direction = -1; %only trigger when moving downward

这是我实际上称之为ode45的地方:

tspan = [0 50]; % seconds
ic = [100 100 0 0]; % rad rad/s rad rad/s
m = 5; 
g = 9.81;

%% solving the ode 
options = odeset('Events',@ground_contact,'MaxStep',0.001,'RelTol',1E-10,'AbsTol',1E-10);
[t,u,TE,YE,IE] = ode45(@(t,x)pointmass_eom(t,x,m,g),tspan,ic,options);

有人能告诉我我做错了吗?

0 个答案:

没有答案