Solve ordinary differential equations with events

版本 1.0.0 (558.3 KB) 作者: Lateef Adewale Kareem
This script solves an ordinary differential equation with events.
58.0 次下载
更新时间 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 CenterMATLAB Answers 中查找有关 Ordinary 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