PYTHON PROGRAM TO CALCULATE DRAG FORCE AGAINST A CYCLIST
Objective:
To write a python program for the calculation of drag force against a cyclist for following two cases.
Case 1: Keeping the drag coefficient as constant and varying the cyclist’s velocity
Case 2: Keeping the cyclist’s velocity as constant and varying the drag coefficient
Physics involved:
- A drag force is the resistance force caused by the motion of a body through a fluid,such as water or air.
- It acts opposite to the direction of the oncoming flow velocity.This is the relative velocity between the body and the fluid.
- When a cyclist is moving against the wind resistance, he would experience some amount of drag force by himself.
- This drag force is influenced by some of the factors namely the velocity of cyclist,density of the fluid,frontal area exposed to resistance and the drag coefficient.
The drag force is calculated by using the following formula,
Drag force = (1/2) * (Density of the fluid) * (Velocity of the cyclist)2 * (Frontal area) * (Drag coefficient)
Procedure:
- Library used:
The program requires a plotting function called pyplot that is imported using the library, matplotlib.The alias name used for this function is plt.
The plt function is used to plot drag forces experienced by the cyclist with respect to the variables, velocity and drag coefficient.
- Variable declaration and initialization:
The following inputs have been declared and initialized respectively.
Frontal area of the cyclist exposed to wind, A = 0.344 m2
Density of air, rho = 1.224 kg/m3
For Case 1:
Drag coefficient, Cd = 0.4
An array is used to store the values of multiple velocities.
Velocity of the cyclist (m/s), V = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
For Case 2:
Velocity, V = 4 m/s
An array is used to store the values of multiple drag coefficients.
Drag coefficient, Cd = [0.1, 0.2 ,0.3 ,0.4 ,0.5 ,0.6 ,0.7 ,0.8 ,0.9]
Empty arrays, DF_1 and DF_2 are declared for storing drag force values for both the cases accordingly.
- Calculation of drag force:
The drag force for the above two cases is calculated by using for loop and with the respective formula.
- Output:
The drag force of case 1 is stored in DF_1 and it is plotted against the velocities with velocity in x-axis and drag force in y-axis.
The drag force of case 2 is stored in DF_2 and it is plotted against the drag coefficients with drag coefficient in x-axis and drag force in y-axis
Result:
From the case 1 plot,it is observed that the drag force has a parabolic distribution with the velocity of the cyclist because the velocity variable has a power of index 2 in the drag force equation.
From the case 2 plot,it is observed that the drag force varies linearly with the drag coefficient values because there is a direct proportionality between the drag force and drag coefficient in the equation.
Program:
# To calculate drag force against a cyclist
import matplotlib.pyplot as plt
# inputs
# Frontal area (m^2)
A = 0.344
# Density of air (kg/m^3)
rho = 1.224
#Case 1: Keeping the drag coefficient as constant and varying the velocity
# Drag coefficient
Cd = 0.4
# Velocity of cyclist (m/s)
V = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
# Drag force with respect to velocity
DF_1 = []
print('Case 1: Drag force VS Velocity')
for i in V:
# Formula for calculating drag force
D = 0.5 * rho * i * i * A * Cd
print(D)
DF_1.append(D)
#plotting
plt.plot(V,DF_1)
plt.xlabel('Velocity (m/s)')
plt.ylabel('Drag force (N)')
plt.title('Drag force VS Velocity')
plt.savefig('Drag force VS Velocity.png')
plt.show()
print('\n')
#Case 2: Keeping the velocity as constant and varying the drag coefficient
# Drag coefficient
C_d = [0.1, 0.2 ,0.3 ,0.4 ,0.5 ,0.6 ,0.7 ,0.8 ,0.9]
# Velocity of cyclist (m/s)
V = 4
# Dragforce with respect to drag coefficient
DF_2 =[]
print('Case 2: Drag force VS Drag coeffcient')
for j in C_d:
# Formula for calculating drag force
D = 0.5 * rho * V * V * A * j
print(D)
DF_2.append(D)
#plotting
plt.plot(C_d, DF_2)
plt.xlabel('Drag coeffcient (Cd)')
plt.ylabel('Drag force (N)')
plt.title('Drag force VS Drag coeffcient')
plt.savefig('Drag force VS Drag coeffcient.png')
plt.show()