Rephrase this MatLab code: %% simulating a bouncing ball: my code % This script…
- User
Rephrase this MatLab code:
%% simulating a bouncing ball: my code % This script simulates a ball dropped or thrown in a vertical direction % under constant gravitational acceleration. The ball will hit the floor % and it will bounce a multiple number of times based on the coefficient % of restitution given by epsilon. We have just before/after a collision. % epsilon = |just after velocity| divided by |just before velocity| % % INPUT % yo = initial height of ball % vyo = initial velocity of ball in the y-direction % dt = time resolution % nBounces = # of bounces the ball hits the floor (at the collision) % epsilon = coefficient of restitution % % PROCESS % solve equation of motions exactly and numerically. take the points and % store them in appropriate arrays for plotting the process. % % OUTPUT % height versus time graph % velocity versus time graph clear all % never not do this %% set initial condition to = 0; % initial time on clock (seconds) yo = 2.5; % meters (m) vyo = 5; % velocity --> meters/second (m/s)
%% set user-defined parameters nBounces=25; nPtsPerBounce=100; epsilon=0.7; % coefficient of restitution (unitless)
%% set constants ay=-9.8; % acceleratin due to gravity m/s^2
%% track each bounce nptsPerBounce = 2ceil(nPtsPerBounce/2); npts = nBouncesnptsPerBounce; nptsUp = round(nptsPerBounce/2); % # of points to plot for ball going up nptsDown = nptsUp; % # of points to plot for ball going down m = npts + 2nptsPerBounce; % extra "2nptsPerBounce isn't needed tArray = zeros(1,m); % a bit bigger than needed yArray = zeros(1,m); vyArray = zeros(1,m);
t0=to; y0=yo; vy0=vyo; k=1; tArray(k)=t0; yArray(k)=y0; vyArray(k)=vy0; t=t0;
for b=1:nBounces % find time to reach max height % use formula "vyf = vyo + ay*dt" at top; vyf=0; dt = -vyo/ay dtUp = -vy0/ay; % time of flight to move up and reach the top dt = dtUp/nptsUp; % breaks up time of flight into small dt dtUp=0; % time to use in the kinematic equation
code - Assistant