Derivatives of graph from points

5 ビュー (過去 30 日間)
Hans Vertongen
Hans Vertongen 2020 年 3 月 6 日
回答済み: Star Strider 2020 年 3 月 6 日
Hello,
I'm a highschool teacher. And one of my student is currently working on the position, velocity and acceleration of the road surface of a bridge.
He has the following point from his bridge:
Position = [0 0.5 1 2 3 4 5 6 7 8 9 9.5 10]; % in cm
Time = [0 0.25 0.5 0.75 1 1.25 1.5 1.75 2 2.25 2.5 2.75 3]; % in seconds
Is it posible to create a position-time graph from this points and then create the first derivative (velocity-time graph) and after this the second derivative (acceleration-time graph)?
I ask this question, because we're having some problems with finding the mathmatical function of the first graph.
If there is an other way of solving this problem, we are open for suggestions!
With Regards
Hans Vertongen and the student of GO! Campus De Brug, Belgium

回答 (2 件)

darova
darova 2020 年 3 月 6 日
If you timestep (0.25) doesn't change use gradient
velocity = gradient(Position,Time);
Use diff if timestep is different
velocity = diff(Position)./diff(Time);
t1 = Time(2:end) - diff(Time)/2; % new time for velocity

Star Strider
Star Strider 2020 年 3 月 6 日
To calculate derivatives of a vector or matrix, use the gradient function:
Position = [0 0.5 1 2 3 4 5 6 7 8 9 9.5 10]; % in cm
Time = [0 0.25 0.5 0.75 1 1.25 1.5 1.75 2 2.25 2.5 2.75 3]; % in seconds
h = mean(diff(Time)); % Constant Sampling Interval
dPdt = gradient(Position,h); % Veolcity
d2Pdt2 = gradient(dPdt,h); % Acceleration
figure
plot(Time, Position)
hold on
plot(Time, dPdt)
plot(Time, d2Pdt2)
hold off
grid
legend({'Position', 'Velocity', 'Acceleration'}, 'Location','NW')
Here, the sampling interval is constant. If the sampling interval is varying, calculate the derivatives as:
dxdt = gradient(x) ./ gradient(t);
where ‘x’ is the dependent variable and ‘t’ is the independent variable. Alternatively, use the resample funciton to resample the vector to a constant sampling interval.

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by