Python与物理学 - 计算阻力并确定物体是否达到终端速度
我正在尝试计算一个球体从建筑物上掉下来的时候受到的空气阻力。我的程序可以运行,但公式好像不对。可能是我把事情搞得太复杂了,现在卡住了。我想做的是确定球体在规定时间内移动的距离(这个部分是可以的),但我不知道怎么把空气阻力考虑进去。任何帮助都会很感激。
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
1 个回答
1
在Python 2.7中,默认是整数除法,所以
energy = 1 / 2 * mass * vellocity ** 2
等同于
energy = (1 // 2) * mass * velocity ** 2 = 0 * mass * velocity ** 2 = 0
如果你想让它默认使用浮点数除法,可以在你的脚本最上面加上这一行:
from __future__ import division
或者你也可以简单地把energy
写成:
energy = 0.5 * mass * velocity ** 2