フィルターのクリア

Calculate velocity from position and time

106 ビュー (過去 30 日間)
Kelly Harmison
Kelly Harmison 2018 年 2 月 28 日
編集済み: alper yeldan 2023 年 9 月 14 日
I have to write a program to calculate the velocity given position and time in two arrays.

採用された回答

KSSV
KSSV 2018 年 2 月 28 日
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
  3 件のコメント
Kelly Harmison
Kelly Harmison 2018 年 3 月 1 日
Thanks! I wrote a similar code but I was saving the loop values in v instead of v(i) This was very helpful!
alper yeldan
alper yeldan 2023 年 9 月 14 日
編集済み: alper yeldan 2023 年 9 月 14 日
There is a way to solve it withouth for loop which gives the same solution.
vel = diff(pos)./diff(t);
You can compare them
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
vel = diff(pos)./diff(t);
figure;
hold on;
plot(t(1:end-1),v,'--r+');
plot(t(1:end-1),vel,'bo');

サインインしてコメントする。

その他の回答 (1 件)

Arms Diether Reyes
Arms Diether Reyes 2021 年 9 月 6 日
The driver of a car wishes to pass a truck that is traveling at a constant speed of 20.0 m/s. Initially, the car is also traveling at 20.0m/s and its front bumper is 24.0 m behind the truck’s rear bumper. The car accelerates at a constant 0.0600 m/s^2, then pulls back into the truck’s lane when the rear of the car is 26.0 m ahead of the front of the truck. The car is 4.5 m long and the truck is 21.0 m long. (a) How much time is required for the car to pass the truck? (b) What distance does the car travel during this time? (c) What is the final speed of the car?

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by