Python and physics - calculating drag & determining if object has reached terminal velocity

StackOverflow https://stackoverflow.com/questions/22244295

  •  10-06-2023
  •  | 
  •  

Domanda

I'm trying to calculate the drag of a sphere if it were to be dropped off a building, the program runs but the equations wrong. It could be that I'm just making this overly complexed, but I'm stuck right now.. What I am trying to do is determine the amount of distance the sphere has traveled in the allotted time (Which works), but I am unable to figure out a way to use drag as a factor. Any help would be appreciated

import math

height = float(raw_input("Enter the height of the building: ")) #meters
weight = float(raw_input("Enter the weight of the sphere: ")) #weight of sphere in kilograms
mass = float(raw_input("Mass of the sphere: ")) #mass of the sphere
time = float(raw_input("Enter the time interval: ")) #determines how long to continue the experiment after the sphere has been dropped

# kilograms
#variables
velocity = math.sqrt(2) * height * weight #calculate the velocity
energy = 1 / 2 * mass * velocity ** 2 #kinetic energy
gravity = 9.81      #gravity
radius = 0.5       #radius of the sphere being dropped
volume = 4.3 * math.pi * radius ** 3 #calculate the volume
speed = gravity * time #determine the maximum speed in the time allotted
density = mass / volume #determine the density of the sphere
force = mass * gravity  #determine the force in newtons 
drag = gravity * density * speed ** 2 #calculate the drag
distance = .5 * gravity * time ** 2 #calculate the distance traveled

print "Force = {} Newtons".format(force)
print "The ball is", height - distance, "meters from the ground"
print "The maximum speed of the ball was:", speed
print "It would take the ball {} seconds to reach terminal velocity"#.format(None)
print "Density:", density
print "Drag: ", drag
print "Mass: ", mass
print "Volume: ", volume
print "Velocity: ", velocity
È stato utile?

Soluzione

Python 2.7 defaults to integer division, so

energy = 1 / 2 * mass * vellocity ** 2 

is equivalent to

energy = (1 // 2) * mass * velocity ** 2 = 0 * mass * velocity ** 2 = 0

To default to floating point division, place the following line at the top of your script:

from __future__ import division

or simply write energy as:

energy = 0.5 * mass * velocity ** 2
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top