How to differentiate distance in relation to time?

3 views (last 30 days)
Hello,
I am new to matllab, i want to differentiate distance (vector L ) in relation to time (vector t) to get the velocity. Then differentiate velocity in relation to time and get acceleration. And then plot acceleration over time. I know, that the values are way to small and there is a problem somewhere.
How can i tell MATLAB to differentiate in relation to time vector?
L=linspace(0,0.007,720); %distance (m)
t=linspace(0,0.0185,720); %time (s)
v=gradient(L); %velocity (m/s)
a=gradient(v); %acceleration (m/s^2)
plot(t,a); %plot acceleration over time

Accepted Answer

Jan
Jan on 26 Mar 2021
Edited: Jan on 26 Mar 2021
Your observation "the values are way to small" is the right way to find the problem. Find out the factor by which the result is too small. You find a relation between this value and the differences between the elements of t, e.g. t(2)-t(1).
L = linspace(0,0.007,720); %distance (m)
t = linspace(0,0.0185,720); %time (s)
v = gradient(L, t); %velocity (m/s)
% ^
a = gradient(v, t); %acceleration (m/s^2)
% ^
If you do not specify the time in gradient it is assume to have a stepsize of 1.
  1 Comment
Matas Mendelis
Matas Mendelis on 26 Mar 2021
Thank you!!! As always with MATLAB, it is simple when you know what and how to type in :D

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!