Solve ordinary differential equations with events

This script solves an ordinary differential equation with events.
ダウンロード: 58
更新 2019/5/18

ライセンスの表示

% To simulate a ball bouncing off stair case after dropping from a height of
% 10meters onto a stair case starting from 5meters. Let the stair case be
% defined by the function y(x) = 5-floor(x). And the ball rolled off an edge
% at height of 10meters with velocity of 0.5m/s.

% The system of first order differential equation is:
odefun = @(t,y) [0.5; y(3); -9.8];

% Initial condition is:
initcon = [0, 10, 0];

% Time span of the simulation:
tspan = [0,20];

% Since we want the ball to bounce off the stair case, the effect condition is:
effectcon = @(t,y) [y(2) - (5-floor(y(1))),1,-1];

% The effect matrix is to recoil only the vertical velocity with restitution of 0.8:
effectmat = [1,0,0;0,1,0;0,0,-0.8];

% Solve the differential equation:
[t,y] = SolveOdeWithEvent(odefun, initcon, tspan, effectcon, effectmat);

% Generate the absisca for the stair case
x = linspace(y(1,1),y(end,1),10000);

% Animate the result.
figure
r = 0:0.01*pi:2*pi;
cx = 0.1*cos(r); cy = 0.1*sin(r);
plot(x,5-floor(x)); ; axis equal; hold on
c = plot(cx + y(1,1),cy + y(1,2) + 0.1);
axis([min(y(:,1)),max(y(:,1)),min(y(:,2)),max(y(:,2))]);
drawnow
for tt = 0.03:0.03:t(end)
xy = interp1(t,y,tt);
c.XData = cx + xy(1);
c.YData = cy + xy(2) + 0.1;
drawnow;
end

引用

Lateef Adewale Kareem (2024). Solve ordinary differential equations with events (https://www.mathworks.com/matlabcentral/fileexchange/71586-solve-ordinary-differential-equations-with-events), MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R2015a
R2012b 以降 R2019a 以前と互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

SolveOdeWithEvent

バージョン 公開済み リリース ノート
1.0.0