Distance from time and velocity vectors..HELP

3 ビュー (過去 30 日間)
EEEmatlab
EEEmatlab 2017 年 11 月 26 日
回答済み: kowshik Thopalli 2017 年 11 月 26 日
so i have 2 vectors:
time = [0,10,15,20,30,59,62,125];
velocity = [0,56.40,97.23,136.25,226.16,403.86,440.44,1265.23];
how would i get distance for each time interval? i tried using
distance = trapz(velocityChange,timeChange);
like this:
time = [0,10,15,20,30,59,62,125];
velocity = [0,56.40,97.23,136.25,226.16,403.86,440.44,1265.23];
distance = zeros(size(time)-1);
for i=1:length(time)
for ii=1:length(velocity)
for x=1:1:7
velocityChange = velocity(1,(x+1))-velocity(1,x);
timeChange = time(1,(x+1))-time(1,x);
distance(x) = trapz(velocityChange,timeChange)
%%distance = velocity*time%%
end
end
end
i want distance as a matrix but i get
distance = [ 0 0 0 0 0 00 ] basically a 0 matrix
and i get the overall distance of all the points how do i get the individual distance for each time interval?

回答 (1 件)

kowshik Thopalli
kowshik Thopalli 2017 年 11 月 26 日
trapz
cannot be used here because you are passing only one value for x and y. Moreover direct integration is not the right thing because acceleration is not constant. Instead, what you can do is fit a line (linear regression) between time and velocity.The slope of the line is the acceleration. You can then use d= 0.5*acceleration*((delta_time)^2) to get the distance traveled here for each time interval.
close all;
scatter(time,velocity);
grid on; hold on;
b1=time'\velocity';% linear regression;
%b1=acceleration
vcalc1=b1*time;
plot(time,vcalc1,'r-');grid on;
%%to get distance between each time interval
time_diff=diff(time); % diff- successive differentiation. No need of loop
d= 0.5*a.*(time_diff.^2);
%%output
d =
449.28 112.32 112.32 449.28 3778.4 40.435 17832

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by