Python和物理 - 计算拖动和放大确定物体是否达到最终速度

时间:2014-03-07 07:41:20

标签: python python-2.7 physics

我正在尝试计算一个球体的拖拽,如果它要从建筑物上掉下来,程序会运行,但方程式错误。可能是因为我只是让这个过于复杂,但我现在被困住了......我想要做的是确定球体在规定的时间内行进的距离(哪个有效),但我是无法找出使用拖拽作为一个因素的方法。任何帮助将不胜感激

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 个答案:

答案 0 :(得分: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