Solve ordinary differential equations with events

This script solves an ordinary differential equation with events.
58 descargas
Actualizado 18 may 2019

Ver licencia

% 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

Citar como

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. Recuperado .

Compatibilidad con la versión de MATLAB
Se creó con R2015a
Compatible con cualquier versión desde R2012b hasta R2019a
Compatibilidad con las plataformas
Windows macOS Linux
Categorías
Más información sobre Ordinary Differential Equations en Help Center y MATLAB Answers.

Community Treasure Hunt

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

Start Hunting!

SolveOdeWithEvent

Versión Publicado Notas de la versión
1.0.0