Modify this code by adding linear interpolation to the calculation in the if-condition…
- User
Modify this code by adding linear interpolation to the calculation in the if-condition
%% set initial condition to = 0; % initial time on clock (seconds) yo = 2.5; % meters (m) vyo = 5; % velocity --> meters/second (m/s) dt = 0.001; % time resolution --> seconds (s) tMax = 20; % maximum time range --> (s) epsilon = 0.7; % coefficient of restitution (unitless) %% set constants ay = -9.8; % acceleratin due to gravity m/s^2 %% solve differential equation using Euler's method tArray = to:dt:(to+tMax); % time range as an array (s) npts = length(tArray); y = zeros(1,npts); % preallocate the y array (height) (m) vy = zeros(1,npts); % preallocate the vy array (height) (m) y(1) = yo; vy(1) = vyo; % ------------------------------- calculate position as a function of time for i=1:npts-1 % ----------------------------------------------------------- detect floor t = tArray(i); vy(i+1) = vy(i) + ay*dt; y(i+1) = y(i) + vy(i)*dt; if( y(i+1) <= 0 ) % => hit the floor with dt time resolution vy(i+1) = - vy(i)*epsilon; y(i+1) = 0; end end
- Assistant
%% set initial condition to = 0; % initial time on clock (seconds) yo = 2.5; % meters (m) vyo = 5; % velocity --> meters/second (m/s) dt = 0.001; % time resolution --> seconds (s) tMax = 20; % maximum time range --> (s) epsilon = 0.7; % coefficient of restitution (unitless)
%% set constants ay = -9.8; % acceleratin due to gravity m/s^2
%% solve differential equation using Euler's method tArray = to:dt:(to+tMax); % time range as an array (s) npts = length(tArray); y = zeros(1,npts); % preallocate the y array (height) (m) vy = zeros(1,npts); % preallocate the vy array (height) (m) y(1) = yo; vy(1) = vyo;