[問題]想請教有關matlab內建的ballode

看板MATLAB作者 (哲平)時間11年前 (2012/11/06 15:34), 編輯推噓0(005)
留言5則, 2人參與, 最新討論串1/1
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
help odeset 他有對每個設定做解釋
11/07 08:31, 2F

11/07 09:30, , 3F
謝謝哦 我昨天使用過help去找了 看了很久的時間 應該是
11/07 09:30, 3F

11/07 09:30, , 4F
這個code在做什麼 表達什麼了
11/07 09:30, 4F

11/07 09:31, , 5F
^知道
11/07 09:31, 5F
文章代碼(AID): #1GcBrlcW (MATLAB)