Calculation of Drag force for flow over a Bicycle using Python & MATLAB
OBJECTIVE:
To write a Python & MATLAB program to calculate drag force against cyclist and to plot two graphs namely
- Velocity vs Drag force
- Drag Co-efficient vs Drag force
THEORY:
Drag is a mechanical force which is generated by a solid object moving through a fluid. This force is acts on the opposite direction of the relative velocity.
The force depends on the size, shape, density, viscosity and velocity of the fluid. The chart below will give an insight of the values of various factors and shapes.
Drag Force Equation:
where
fd = Drag force
cd = Drag coefficient
a = area in m^2
rho = density of air in kg/m^3
v = velocity in m/s
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~MATLAB~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MAIN PROGRAM:
clear all
close all
clc
%Calculation of Flow over bicycle and plotting Velocity vs Drag force
%INPUT PARAMETERS
rho = 1.225;
a = 0.2;
v = [5:50];
Cd = 0.47;
%DRAG FORCE FORMULA
fd = 0.5*rho*a*v.^2*Cd;
%where
%fd = Drag force
%rho = density of air in kg/m^3
%a = area in m^2
%v = velcoity in m/s
%Cd = Drag coefficient
%PLOT OF VELOCITY vs DRAG FORCE
plot(v,fd,'color','g','linewidth',2)
xlabel('Velocity(m/s)');
ylabel('Drag Force(N)');
grid on
Explanation:
- The standard clear all, close all, clc command has been executed for the fresh start.
- The input parameters have been assigned to the variable for the Drag force formula from line 8 to 11.
- rho is standard value 1.225, velocity(v) is assigned using range operator, Cd is kept constant(0.47 considering sphere shape), area(a) has been given 0.2.
- Drag force formula has been executed to the command in line 14
- From line 16 to 21, the formula has been explained.
- Plotting of Velocity vs Drag force has been done using plot command with line color green & linewidth 2 in line 24
- x and y axis has been labelled as velocity(m/s) & Drag force(N) respectively.
- The Grid on command is used for better viewability.
OUTPUT:
Calculated values
Drag coefficient vs Drag force using Drag force formula
PROGRAM:
clear all
close all
clc
%Calculation of Flow over bicycle plotting Drag coefficient vs Drag force
%INPUT PARAMTERS
rho = 1.225;
a = 0.8;
v = 10;
Cd = [0.04 0.47 0.50];
%DRAG FORCE FORMULA
fd = 0.5*rho*a*v.^2*Cd;
%where fd = Drag force
%rho = density of air in kg/m^3
%a = Area in m^2
%v = Velcoity in m/s
%Cd = Drag coefficient
%PLOT OF DRAG C0EFFICIENT vs DRAG FORCE
plot(Cd,fd,'color','b','linewidth',2)
xlabel('Drag Coefficient');
ylabel('Drag Force(N)');
grid on
Explanation:
- The standard clear all, close all, clc command has been executed for the fresh start.
- The input parameters have been assigned to the variable for the Drag force formula from line 8 to 11.
- rho is standard value 1.225, velocity(v) is kept standard as 10, Cd is assigned to three different values for different shapes(i.e 0.04(streamlined body) ,0.47(sphere) ,0.50(cone)), area(a) has been given 0.8.
- Drag force formula has been executed to the command in line 14
- From line 16 to 21, the formula has been explained.
- Plotting of Drag coefficient vs Drag force has been done using plot command with line color blue & linewidth 2 in line 24
- x and y axis has been labelled as Drag coefficient & Drag force(N) respectively.
- The Grid on command is used for better viewability.
OUTPUT:
Calculated values
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PYTHON~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import matplotlib.pyplot as plt
#Input Parameters
c_d = 0.8
a = 0.1
rho = 1.225
v = [4,5,6,7,8,9,10,11,12]
f_d = []
"""
where c_d = Drag coefficient
a = Frontal area (m^2)
rho = Density (kg/m^3)
v = Bicycle velocities (m/s)
f_d = Drag force (kg-m/s^2)
"""
#Drag Force formula
for velocity in v:
f_d.append(0.5*rho*a*c_d*velocity*velocity)
print(f_d)
#Plotting
plt.plot(v,f_d)
plt.xlabel('Velocity(m/s)')
plt.ylabel('Drag force')
plt.title('Velocity vs Drag Force')
plt.show()
Explanation
- The code is started with importing the plot library matlablib.pyplot as plt as such whenever plt command is used it refers to the plot for plotting various parameters.
- Input parameters for the Drag force formula such as c_d, a, rho, v & f_d is assigned.
- Here v is been given varying velocities which is predominantly used to store set of numbers.
- An empty array f_d (drag force) is computed using for loop for storing varying velocities.
- Now for loop is called by append command which is used to store each calculated drag force values.
- The f_d (drag force) values are now been printed and plotted against v (velocity) and given labels using plt command.
OUTPUT
Drag coefficient vs Drag force using drag force formula
import matplotlib.pyplot as plt
#Input Parameters
c_d = [0.04,0.47,0.50]
a = 0.1
rho = 1.225
v = 3
f_d = []
"""
where c_d = Drag coefficient
a = Frontal area (m^2)
rho = Density (kg/m^3)
v = Bicycle velocities (m/s)
f_d = Drag force (kg-m/s^2)
"""
#Drag Force formula
for drag_coeff in c_d:
f_d.append(0.5*rho*a*drag_coeff*v*v)
print(f_d)
#Plotting
plt.plot(c_d,f_d)
plt.xlabel('Drag coefficient')
plt.ylabel('Drag force')
plt.title('Drag coefficient vs Drag Force')
plt.show()
Explanation
- The code is started with importing the plot library matlablib.pyplot as plt as such whenever plt command is used it refers to the plot for plotting various parameters.
- Input parameters for the Drag force formula such as c_d, a, rho, v & f_d is assigned.
- Here c_d is been given different values based on the shapes(explained under description above) which affects the speed for the stable velocity v.
- An empty array f_d (drag force) is computed using for loop for storing varying drag force coefficients.
- Now for loop is called by append command which is used to store each calculated drag force values.
- The f_d (drag force) values are now been printed and plotted against c_d (drag coefficient) and given labels using plt command.
OUTPUT:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CONCLUSION:
Hence the program to calculate Drag force against a bicycle has been written using Python & MATLAB and was found that
- v vs f_d plot is a parabolic line which represents that for every increase of the drag force doubles for each velocity.
- c_d vs f_d plot is a linear line which increases gradually along both the axes for the varying of drag coefficient value depending on the shape.