Project

flow over bicycle calculating drag force

Program to calculate the drag force

# Import module for plotting
import matplotlib.pyplot as plt

# Functions
def drag_force(c_d,A,rho,v):
    \\\"\\\"\\\"
    Calculate drag force given c_d,A,rho,v:
       
    \\\"\\\"\\\"
    return 0.5*c_d*rho*A*v**2

def plotDragForceVelocity(dragForce,v):
    \\\"\\\"\\\"
    Plots drag force v/s velocity
    \\\"\\\"\\\"
    plt.plot(v,dragForce,\\\'*-\\\')
    plt.xlabel(\\\"Velocity (m/s)\\\")
    plt.ylabel(\\\"Drag force (N)\\\")
    plt.title(\\\"Drag force v/s Velocity plot\\\")
    plt.show()

def plotDragForceCd():
    \\\"\\\"\\\"
    Plots drag force v/s drag coefficient
    \\\"\\\"\\\"
    A = 0.1
    rho = 1.2
    v = 5
    cd = {
          \\\"Flat plate\\\"   : 1.28,
          \\\"Prism\\\"        : 1.14,
          \\\"Bullet\\\"       : 0.295,
          \\\"Sphere\\\"       : 0.47,
          \\\"Airfoil\\\"      : 0.045,
          \\\"Half sphere\\\"  : 0.42,
          \\\"Cone\\\"         : 0.50,
          \\\"Cube\\\"         : 1.05,
          \\\"Angled cube\\\"  : 0.80,
          \\\"Long cylinder\\\": 0.82,
          \\\"Pac-car\\\"      : 0.075,
          \\\"Milan SL\\\"     : 0.076,
          \\\"Fiat Turbina\\\" : 0.14,
          \\\"BMW i8\\\"       : 0.26
          }
    dragForces = {}
    for i in cd.keys():
        dragForces[i] = drag_force(cd[i],A,rho,v)
    # Plot results
    for i in cd.keys():
        plt.plot(cd[i],dragForces[i],\\\'*\\\',label=i)
    plt.legend(loc=\\\'upper right\\\')
    plt.xlabel(\\\"Drag coefficient\\\")
    plt.ylabel(\\\"Drag force\\\")
    plt.title(\\\"Drag force v/s drag coefficient (5 m/s)\\\")
    plt.show()

def plotResultsForBicycle():
    \\\"\\\"\\\"
    Plot drag force v/s velocity for bicycle
    \\\"\\\"\\\"
   
    c_d = 0.8
    
    A = 0.1
   
    rho = 1.2
    
   
    v = [i/10 for i in range(10,100,1)]
    dragForce = [drag_force(c_d,A,rho,velocity) for velocity in v]
    plotDragForceVelocity(dragForce,v)

def main():
    plt.figure(\\\"Drag coefficient v/s velocity\\\")
    plotResultsForBicycle()
    plt.figure(\\\"Drag coefficient v/s drag force\\\")
    plotDragForceCd()
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.