How can I convert a speed profile to displacement graph

5 views (last 30 days)
I have a speed graph that looks like the image below. The y-axis is in (m/s) and the x-axis is in (s). To generate the plot below i made use of 3 equations and applied the fplot function
max_spd = 4;
a = 2/3; %acceleration
fplot(@(x) (a)*x,[0 6],'g')
fplot(@(y) max_spd,[6 13.75],'g');
fplot(@(x) -(a)*x + (19.75)*(a),[13.75 19.75],'g')
How can I convert this velocity-time plot to a displacement-time graph?
so far I have this,
max_spd = 4;
a = 2/3; %acceleration
fplot(@(x) 0.5*(a*x)*x,[0 6],'k');
fplot(@(x) 4*x-(0.5*4*6),[6 13.75],'k');
fplot(@(x) 0.5*(-a)*x*x+(19.75)*a*x - (4*7.75) - (0.5*6*4),[13.75 19.75],'k');
which gives me this plot, is there a better function that will allow me to plot the displacement-time plot? Or is there a better method to perform this conversion?

Accepted Answer

Walter Roberson
Walter Roberson on 8 Feb 2021
Don't use 3 functions.
max_spd = 4;
a = 2/3; %acceleration
fun = @(x) (0 <= x & x < 6) .* (a) .* x + ...
(6 <= x & x < 13.75) .* max_spd.*ones(size(x)) + ...
(13.75 <= x & x < 19.75) .* a .* (19.75-x);
fplot(fun, [0 20]); ylim([0 5])
Now you can process the single function that gives the speed into displacement, by integrating . Chances are that you will want cumulative output, so use something like cumtrapz()

More Answers (0)

Community Treasure Hunt

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

Start Hunting!