How to find a velocity when you have time and position values in an array?

조회 수: 5 (최근 30일)
Kelly Harmison
Kelly Harmison 2018년 2월 21일
편집: Kelly Harmison 2018년 2월 21일
I am required to differentiate by calling values from an array. I am also required to use either a for or a while loop.
  댓글 수: 2
James Tursa
James Tursa 2018년 2월 21일
What have you done so far? What specific problems are you having with your code? What is the relationship between velocity and position?
Kelly Harmison
Kelly Harmison 2018년 2월 21일
편집: Kelly Harmison 2018년 2월 21일
The main idea is to know how to differentiate on Matlab. I have two vectors: time and position. I am supposed to use a loop to call specific values from the position vector and find their slope (velocity).

댓글을 달려면 로그인하십시오.

답변 (1개)

Roger Stafford
Roger Stafford 2018년 2월 21일
편집: Roger Stafford 2018년 2월 21일
Let x and y be row vectors of the same length where x gives successive values of the independent variable and y the corresponding dependent variable values - in this case x values are times and y values distances. It is not necessary that x values be equally-spaced. To get a second order approximation of the derivative at each point, do this:
x1 = x([3,1:end-1]); x2 = x([2:end,end-2]);
y1 = y([3,1:end-1]); y2 = y([2:end,end-2]);
dydx = ((y2-y).*(x-x1).^2+(y-y1).*(x2-x).^2)./((x2-x).*(x-x1).*(x2-x1));
The row vector dydx will give approximate values of the derivative of y with respect to x. This is a vectorized solution - no for loops or while loops are necessary.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by