Iterating through a list of acceleration to calculate final velocity and then usign the answer as the initial velocity of the next

Question:

I am new to coding and am trying to gain a graph of speeds as acceleration varies. (i have coded the drag force on a car (values from CFD) and at varying speeds, this drag force changes.)

I have a 2000 term list of acceleration varying as drag varies at different speeds and I now am trying to use suvat to calculate the final velocity at each iteration takes over 0.01m.

starting from 0, I want the code to use V^2 = U^2 + 2as to find the final velocity(V) and then use this final velocity for the next acceleration term in the list and so on until the end.

Example:

acceleration = [1, 2, 3, 4, 5]
u = 0
a = acceleration


def step_final_velo(u=u, a=a, s=0.01):
    step_v = []
    count = 0
    for i in a:
        count += np.sqrt(u ** 2 + (2 * i * s))
        step_v.append(count)
    return step_v
Asked By: Tom Oliver

||

Answers:

I don’t fully get the question but here is my interpretation

import math
acc=[1,2,3,4,10,2]
output=[]
#set all the suvat
s=0.01
u=0
v=0
a=0
t=0
for i in range(len(acc)):
    #v^2=u^2+2as
    a=acc[i]
    x=u*u+(2*a*s)
    v=math.sqrt(x)
    u=v
    v=0
    output.append[u]
print(output)
    
    
    
Answered By: william

Code:-

import math
acceleration = [1, 2, 3, 4, 5]
u=0
s=0.01
final_velocity=[]
for a in acceleration:
    v=math.sqrt(u**2+2*a*s)  # v**2=u**2+2*a*s
    final_velocity.append(v)
    u=v
print(final_velocity)

Output:-

[0.1414213562373095, 0.2449489742783178, 0.34641016151377546, 0.4472135954999579, 0.5477225575051661]
Answered By: Yash Mehta
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.