I am given this data in an excel spreadsheet. So after importing it would I just do velocity = cumtrapz(t,y)
and then position = cumtrapz(velocity)
?

- 718
- 2
- 15
- 38
-
1Sounds reasonable. Have you tried it? You would probably want `position=cumtrapz(t,velocity)` though wouldn't you? – David Apr 25 '14 at 03:19
-
I have tried it. This was a project assigned by my professor, just thought it seemed much too simple of a solution so I'd check here to make sure it was right. – Josh Apr 25 '14 at 03:22
1 Answers
It is correct if the car starts from zero at distance zero. Otherwise you need to have the initial velocity there as well. Just notice that what you really do here is solving the the equation a = f(t) = dv/dt
and further a = d^2s/dt^2
by identifying v
as ds/dt
. You does it by solving a system of ordinary differential equations:
a = dv/dt
v = ds/dt
This can be done in a few ways. Eg with Euler forward.
v'(t) = (v(t+h)-v(t))/h
<=> v(t+h) = hv'(t)+v(t)
where the derivate is given, which means that a = a(t)
. The iteration is initialized with the initial condition v(0)
, which must be given.
When you know v
then you go to s. Use again Euler forward as,
s'(t) = (s(t+h)-s(t))/h
<=> s(t+h) = hs'(t)+s(t)
where you must know the initial condition s(0)
. If v(0) = s(0) = 0
. Euler forward is an O(h) algorithm, but knowing the trick of solving the differential equations step by step doing the transformation s'(t) = v(t)
it is also possible to do better. Now any runge-kutta method is available for you. And the method which you use, cumtrapz, is actually a O(h^2) method. This is a little more theory than what is custom in stackoverflow, but hopefully it will be helpful. There is also a matrix solution to second order boundary value problems, called Finite differance method, but that one is slighly more advanced. For further reading, start with
http://en.wikipedia.org/wiki/Numerical_methods_for_ordinary_differential_equations

- 4,506
- 6
- 24
- 48