% [reserve space for function call ] % *** set constants and initialize variables *** g = -9.8 % accel. of gravity, units m/s/s dt = 0.1; % time step in seconds t(1) = 0; % array ('vector') of times, first time in s y(1) = 14.1; % array of heights, initial height in m v(1) = 0.0; % array of velocities, initial velocity at start of drop m = 0.1; % mass of ball, in kg Ftot = m*g; % total force on ball w/o drag, in N % *** might need to put other things here to set up for drag *** % *** now set up for loop *** for i=2:1000 % note were starting on the second step accel = Ftot/m; % this appears to be a constant, why put it here? v(i) = v(i-1) + accel*dt; % next velocity, our equation A vavg = 0.5 * (v(i)+v(i-1)); % average v over step dt y(i) = y(i-1) + vavg*dt; % next position, our eqn B t(i) = t(i-1) + dt; % bookeeping, makes time vector if (y(i)<=0), break, end % run without at first end %plot(t,y) close all plot(t,y,'k+') grid on xlabel('time (s)') ylabel('height (m)') figure(2) plot(t,v,'k+') grid on xlabel('time (s)') ylabel('velocity (m/s)')
g = -9.8000