Speed vs. Time Plot from position vector

조회 수: 9 (최근 30일)
Joe
Joe 2017년 11월 28일
답변: Star Strider 2017년 11월 28일
I've been given a position vector and a time interval, and I would like to plot the speed(magnitude of the velocity) over the given time interval. Here is the code to setup the problem:
% Time
t = linspace(0, 2*pi, 1000)';
% Position Vector
R_x = t.*cos(t);
R_y = t.*sin(2*t);
R_z = t;
R = [R_x, R_y, R_z];
% Velocity vector
R_x_prime = diff(R_x)./diff(t);
R_y_prime = diff(R_y)./diff(t);
R_z_prime = diff(R_z)./diff(t);
R_prime = [R_x_prime, R_y_prime, R_z_prime];
So, to find the speed, I need to use norm(R_prime); however, that only returns one value (165.5). I've tried to write a for loop that saves the values of the magnitude of R_prime as an array, but the values just aren't correct. One final note: I have to use numerical differentiation. Thanks in advance for the help.

채택된 답변

Star Strider
Star Strider 2017년 11월 28일
For the numerical derivative, I would use the gradient function, since your data are regularly-sampled. If you must use the norm function, use a loop to take the norm of every row of ‘R_prime’.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by