python中arcsec,在Python中使用sec逆函数

I am creating a program that calculates the optimum angles to fire a projectile from a range of heights and a set initial velocity. Within the final equation I need to utilise, there is an inverse sec function present that is causing some troubles.

I have imported math and attempted to use asec(whatever) however it seems math can not calculate inverse sec functions? I also understand that sec(x) = 1/cos(x) but when I sub 1/cos(x) into the equation instead and algebraically solve for x it becomes a non real result :/.

The code I have is as follows:

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()

So my main question is, is there any way to find the inverse sec of anything in python without installing and importing something else?

I realise this may be more of a math based problem than a coding problem however any help is appreciated :).

解决方案

Let's say we're looking for real number x whose arcsecant is angle θ. Then we have:

θ = arcsec(x)

sec(θ) = x

1 / cos(θ) = x

cos(θ) = 1 / x

θ = arccos(1/x)

So with this reasoning, you can write your arcsecant function as:

from math import acos

def asec(x):

return acos(1/x)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值