Calculation of forces acting on bicycle using python
Writing a Python program to calculate drag force against a cyclist.
First take input values of drag coefficients, area, and different values of velocities.
Append the velocity values and plot the graph.
Formula for calculating drag force is as follows:-
Fd=0.5⋅ρ⋅A⋅V.2⋅cdFd=0.5⋅ρ⋅A⋅V.2⋅cd
Note: You have to install 'matploblib' library.
1) Program to plot Velocity vs Drag force.
import matplotlib.pyplot as plt
#inputs
c_d=0.8 #drag coefficient
A=0.1 #frontal area(m^2)
rho=1.2 #density(kg/m^3)
velocities=[2,3,4,5,6,7,8,9,10] #velocity
V_C=[]
for velocity in velocities:
V_C.append((0.5*c_d*rho*A*velocity*velocity))
print(V_C)
plt.plot(velocities,V_C)
plt.xlabel('velocity') #labelling x axis
plt.ylabel('dragforce') #labelling y axis
plt.show() #to show the plot
2) Program to plot Drag Co-efficient vs Drag force.
import matplotlib.pyplot as plt
#inputs
drag_coeffs=[0.3,0.4,0.5,0.6,0.7,0.8,0.9] #drag coefficeient values
A=0.1 #frontal area(m^2)
rho=1.2 #density(kg/m^3)
velocitiy=[5] #velocity
drag_forces_cd=[]
for drag_coeff in drag_coeffs:
drag_forces_cd.append(0.5*drag_coeff*rho*A*velocity*velocity)
print(drag_forces_cd)
plt.plot(drag_coeffs,drag_forces_cd) #graph plotting
plt.xlabel('drag coefficient') #x axis label
plt.ylabel('drag force') #y axis label
plt.show()
3) We can even combine the code in one.
import matplotlib.pyplot as plt
#inputs
c_d=0.8 #drag coefficient
drag_coeffs=[0.3,0.4,0.5,0.6,0.7,0.8,0.9]
drag_forces_cd=[]
A=0.1 #frontal area(m^2)
rho=1.2 #density(kg/m^3)
velocities=[2,3,4,5,6,7,8,9,10] #velocity
drag_forces=[]
for velocity in velocities:
drag_forces.append((0.5*c_d*rho*A*velocity*velocity))
print(drag_forces)
plt.plot(velocities,drag_forces)
plt.xlabel('velocity')
plt.ylabel('dragforce')
plt.show()
for drag_coeff in drag_coeffs:
drag_forces_cd.append(0.5*drag_coeff*rho*A*velocity*velocity)
print(drag_forces_cd)
plt.plot(drag_coeffs,drag_forces_cd)
plt.xlabel('drag coefficient')
plt.ylabel('drag force')
plt.show()