【发布时间】:2020-05-16 07:41:19
【问题描述】:
我正在创建一个程序,该程序可以计算从一系列高度和设定的初始速度发射弹丸的最佳角度。在我需要使用的最后一个等式中,存在一个反 sec 函数,它会引起一些麻烦。
我已导入数学并尝试使用 asec(whatever),但似乎数学无法计算逆秒函数?我也知道 sec(x) = 1/cos(x) 但是当我将 1/cos(x) 代入方程并代数求解 x 时,它变成了一个非真实的结果:/。
我的代码如下:
print("This program calculates the optimum angles to launch a projectile from a given range of heights and a initial speed.")
x = input("Input file name containing list of heights (m): ")
f = open(x, "r")
for line in f:
heights = line
print("the heights you have selected are : ", heights)
f.close()
speed = float(input("Input your initial speed (m/s): "))
print("The initial speed you have selected is : ", speed)
ran0 = speed*speed/9.8
print(ran0)
f = open(x, "r")
for line in f:
heights = (line)
import math
angle = (math.asec(1+(ran0/float(heights))))/2
print(angle)
f.close()
所以我的主要问题是,有没有办法在 python 中找到任何东西的倒数,而无需安装和导入其他东西? 我意识到这可能是一个基于数学的问题,而不是一个编码问题,但是感谢任何帮助:)。
【问题讨论】: