[問題]想請教有關matlab內建的ballode
function ballode
%BALLODE Run a demo of a bouncing ball.
tstart = 0;
tfinal = 30;
y0 = [0; 20];
refine = 4;
options = odeset('Events',@events,'OutputFcn', @odeplot,...
'OutputSel',1,'Refine',refine);
set(gca,'xlim',[0 30],'ylim',[-25 25]);
box on
hold on;
tout = tstart;
yout = y0.';
teout = [];
yeout = [];
ieout = [];
for i = 1:10
% Solve until the first terminal event.
[t,y,te,ye,ie] = ode23(@f,[tstart tfinal],y0,options);
if ~ishold
hold on
end
% Accumulate output.
nt = length(t);
tout = [tout; t(2:nt)];
yout = [yout; y(2:nt,:)];
teout = [teout; te]; % Events at tstart are never reported.
yeout = [yeout; ye];
ieout = [ieout; ie];
ud = get(gcf,'UserData');
if ud.stop
break;
end
% Set the new initial conditions, with .9 attenuation.
y0(1) = 0;
y0(2) = -.9*y(nt,2);
% A good guess of a valid first time step is the length of
% the last valid time step, so use it for faster computation.
options = odeset(options,'InitialStep',t(nt)-t(nt-refine),...
'MaxStep',t(nt)-t(1));
tstart = t(nt);
end
plot(teout,yeout(:,1),'ro')
xlabel('time');
ylabel('height');
title('Ball trajectory and the events');
hold off
odeplot([],[],'done');
% --------------------------------------------------------------
function dydt = f(t,y)
dydt = [y(2); -9.8];
% --------------------------------------------------------------
function [value,isterminal,direction] = events(t,y)
% Locate the time when height passes through zero in a
% decreasing direction and stop integration.
value = y(1); % Detect height = 0
isterminal = 1; % Stop the integration
direction = -1; % Negative direction only
----------------------------------------------------------------------
這是個物理現象 球的拋體運動
水平速度為0
垂直速度為20
是把y(t)=(-9.8*t^2)/2
拆成一組常微分方程
y_1'(t)=y_2(t)
y_2'(t)=-9.8
我知道的部分就這些
想問請程式碼的意思
像options裡面那些函數所表示的意思
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.123.61.208
※ 編輯: anikishawn 來自: 140.123.61.208 (11/06 15:48)
→
11/06 15:49, , 1F
11/06 15:49, 1F
→
11/07 08:31, , 2F
11/07 08:31, 2F
→
11/07 09:30, , 3F
11/07 09:30, 3F
→
11/07 09:30, , 4F
11/07 09:30, 4F
→
11/07 09:31, , 5F
11/07 09:31, 5F