Plotting Graphs of Flow over Bicycle using Python
Plotting Graphs of Flow over Bicycle using Python
Objective:
- create plots of Velocity Vs DragForce and DragCoeffiecient Vs DragForce using python
Description :
While riding bicycle drag is experienced by flow of air over bicycle and is given by :
where
- F_d = drag force
- rho = density of air
- A = frontal area
- V= velocity
- C_d = drag coefficient
Programming in python:
In order to plot graphs in matlab importing of matplotlib module is necessary and the flow of program as follows:
- First things first import the required modules
- Initialize the variables depends upon the usage of variables in program
- Define the code using appropriate commands in python in a logical approach
- Analyse the output wheather it is as you expected or not
- if yes, code is successful
- if No, go back to code and redefine
Program for Velocity Vs DragForce :
import matplotlib.pyplot as plt
rho,A,c_d=1.2,0.1,0.8
velocities=[5,6,7,8,9,10,11]
drag_force=[]
for v in velocities:
drag_force.append((0.5*rho*A*v**2*c_d))
plt.plot(velocities, drag_force)
plt.xlabel("Velocities")
plt.ylabel("Drag Force")
plt.show()
- To plot importing of matplotlib is necessary and is called by aliasing as plt.
- Variables are initialised where rho, A, C_d are sinle valued where as Velocities and Drag_force are arrays since multiple values are required for plotting
- Drag force formula has been incorporated in for loop to get multiple values of it .
- And by using fuctions and command from module plotting code has been defined.
commands used in programming:
similarly the code for both plots is as follows:
import matplotlib.pyplot as plt
rho,A,c_d=1.2,0.1,0.8
velocities=[5,6,7,8,9,10,11]
drag_force=[]
vel=5
coefficientOfDrag=[0.5,0.6,0.7,0.8,0.9,1.0,1.1]
drag_force1=[]
for v in velocities:
drag_force.append((0.5*rho*A*v**2*c_d))
plt.figure()
plt.plot(velocities, drag_force)
plt.xlabel("Velocities")
plt.ylabel("Drag Force")
plt.title("velocity vs Drag Force")
plt.show()
for cd in coefficientOfDrag:
drag_force1.append((0.5*rho*A*vel**2*cd))
plt.figure()
plt.plot(coefficientOfDrag, drag_force1)
plt.xlabel("coefficient Of Drag")
plt.ylabel("Drag Force")
plt.title("coefficient Of Drag vs Drag Force")
plt.show()
Results:
The following graphs are obtained as outputs :
Conclusion:
- Velocity Vs DragForce and DragCoeffiecient Vs DragForce has been plotted successfully using appropriate commands from the matplotlib.pyplot module using python.