function vend = velocity(dt, ti,  tf, vi, m, cd)
% velocity(dt, ti,  tf, vi, m, cd):
%   euler's method solution of freefalling bungee jumper using a for loop
% input: 
%   dt = delta t (sec)
%   ti = inital time (sec)
%   tf = final time (sec)
%   vi = inital value of dependent variable (m/s)
%   m = mass (kg)
%   cd = second-order drag coefficient (kg/m)
% output:
%   vend = velocity at tf (m/s)

t= ti;
v= vi;
n= (tf - ti) / dt;

vData=zeros(1,n + 1);
vData(1)= vi;

for i= 1:n
    dvdt = deriv(t, v, m, cd);
    v= v + dvdt * dt;
    vData(i+1)= v;
    t= t + dt;
end

timeArray= ti:dt:tf;
plot (timeArray, vData, 's-')
hold on

vend= v;