MATLAB: Calculate velocity from position and time

differentiablehomeworkloops derivatives velocity

I have to write a program to calculate the velocity given position and time in two arrays.

Best Answer

pos = rand(100,1) ;
t = 1:100 ;
v = zeros(length(t)-1,1) ;
for i = 1:length(t)-1
v(i) = (pos(i+1)-pos(i))/(t(i+1)-t(i)) ;
end