Guriqbal Chouhan
Guriqbal Chouhan

Reputation: 49

Calculating Velocity from Position and Time lists in python

If I have two lists, one each of position values and time values. How would I calculate and plot velocity. I can do linear regression and find the slope to calculate the average velocity, however I am trying to find out and plot when the system achieves terminal velocity. PLease help, thank you.

Upvotes: 0

Views: 19193

Answers (2)

Brendan Abel
Brendan Abel

Reputation: 37509

Measure the velocity between adjoining points. Make sure to sort your points by time value. When the velocity stops changing (within a given delta), you've reached terminal velocity.

values = [[3.0,4],[6.0,9],[10.0,15]]
last_values = [0,0]
last_velocity = 0
delta = 0.1  # Will need to play with this value.
terminal_velocity = None
for pos, time in values:
    velocity = (pos - last_values[0]) / (time - last_values[1])
    if abs(velocity - last_velocity) < delta:
        terminal_velocity = velocity
        break
    last_values = [pos, time]
    last_velocity = velocity

print 'Terminal Velocity:', terminal_velocity

Upvotes: 2

Jordan
Jordan

Reputation: 912

If you have your displacement(position) and time values in let's say a tuple then you can just unpack them into a simple (and I mean very simple) velocity equation.

values = [[3.0,4],[6.0,9],[10.0,15]]
velocities = []
for pos, time in values:
    velocity = float(pos/time)
    velocities.append(velocity)

print velocities

Upvotes: 1

Related Questions