python 反三角函数(特别是 arcsin)
我目前正在尝试运行涉及三角学的东西,但我遇到了涉及 math.asin 函数的问题(它也适用于 acos 和 atan,但在这些情况下,它对我想做的事情影响较小)。 我在其他地方找到的帮助线程中的两篇文章很好地总结了这个问题;
抱歉,我刚刚又试了一遍, 发现
a = sin(2)
b = asin(a)
b 不 = 2但是
a = cos(2)
b = acos(a)
b 确实= 2因为 y = sin(x) 是一个重复项 函数,有多个值 x 对于每个 y 值。 即罪(2) = 正弦(1.14) = 0.909
因此,当你执行 x = asin(y) 时, 你只会得到一个介于 -PI/2 <= x <= PI/2
我从数学上理解这是为什么,但我想知道是否有人可以帮助我找到一个范围内的所有解决方案,而不仅仅是它自动给出的解决方案。 谢谢=]
I'm currently trying to get something to run involving trigonometry but I've run across a hitch involving the math.asin function (it also applies to acos and atan but in those cases it less affects what I'm trying to do). The issue is best summarised by two posts from a help thread I found about it elsewhere;
Sorry, I have just tried it again and
found thata = sin(2)
b = asin(a)
b doesnt = 2but
a = cos(2)
b = acos(a)
b DOES= 2Because y = sin(x) is a repetitive
function, there is more than one value
of x for every value of y. ie sin(2) =
sin(1.14) = 0.909Therefore, when you do x = asin(y),
you will only ever get a value between
-PI/2 <= x <= PI/2
I understand mathematically why this is but I was wondering if anyone could give me a hand in finding all the solutions within a range rather than just the one it gives automatically. Thanks =]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
让我们考虑范围 [0, 2π)。
对于
acos
,每个值 x 也有另一个可能的值 2π - x。 (画出余弦图,您就会看到它。)对于
asin
,每个正值 x 在 π - x 处都有另一个可能的值; 每个负值在 3π - x 处都有一个可能值。请随意绘制更多图表以推广到更大的范围。 :-)
Let's consider the range [0, 2π).
For
acos
, each value x also has another possible value at 2π - x. (Picture the cosine graph and you'll see it.)For
asin
, each positive value x has another possible value at π - x; each negative value has a possible value at 3π - x.Feel free to draw further graphs to generalise to greater ranges. :-)
acrsin(a) 的所有解为:
b、pi - b、2pi + b、2pi + (pi - b) 等。
All the solutions for acrsin(a) will be:
b, pi - b, 2pi + b, 2pi + (pi - b), etc.
正如其他人已经详细解释的那样,您为 a 选择了一个值,由于三角函数的(重复)性质,导致 asin() 的结果不确定。
尽管如此,我只是想指出,由于更通用的 浮点精度问题
对于浮点,您不能不能保证这
一点
。 请小心。
As others have already explained in detail you picked a value for a that leads to indetermined results for asin() due to the (repetitive) nature of the trigonometric functions.
Nevertheless I just wanted to point out that expecting to be able to get the exact same result back on an invers operation with floating points will probably fail due to a more general Floating point accuracy problem
With floating point you can not guarantee that
or
for that matter. Just be careful.