如何三角函数工作? [英] How do Trigonometric functions work?

查看:160
本文介绍了如何三角函数工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此​​,在高中数学,大概大学,我们被教导如何使用三角函数,他们做什么,他们解决什么样的问题。但他们一直p​​sented把我当作一个黑盒子$ P $。如果你需要的东西正弦或余弦,你击中了正弦或余弦按钮,你的计算器,你设置。这是很好的。

So in high school math, and probably college, we are taught how to use trig functions, what they do, and what kinds of problems they solve. But they have always been presented to me as a black box. If you need the Sine or Cosine of something, you hit the sin or cos button on your calculator and you're set. Which is fine.

我不知道是如何运作三角函数的典型实现。

What I'm wondering is how trigonometric functions are typically implemented.

推荐答案

首先,你必须做某种范围减少。三角函数是周期性的,所以你需要减少参数下降到标准时间间隔。对于初学者来说,可以减少角度为0和360度之间。但是,通过使用几个身份,你意识到你可以用更少的度日。如果你计算正弦和余弦为0至45度之间的角度,你可以引导你的方式来计算所有三角函数所有角度。

First, you have to do some sort of range reduction. Trig functions are periodic, so you need to reduce arguments down to a standard interval. For starters, you could reduce angles to be between 0 and 360 degrees. But by using a few identities, you realize you could get by with less. If you calculate sines and cosines for angles between 0 and 45 degrees, you can bootstrap your way to calculating all trig functions for all angles.

一旦你降低你的论点,大多数芯片使用 CORDIC 算法计算正弦和余弦。您可能会听到有人说电子计算机使用泰勒级数。这听起来很合理,但是事实并非如此。该CORDIC算法是有效的硬件的实施更适合。 (软件的库可以使用泰勒级数,说在不支持三角函数的硬件。)可能会有一些额外的处理,使用CORDIC算法来获得相当不错的答案,但后来做别的事情,以改善准确性。

Once you've reduced your argument, most chips use a CORDIC algorithm to compute the sines and cosines. You may hear people say that computers use Taylor series. That sounds reasonable, but it's not true. The CORDIC algorithms are much better suited to efficient hardware implementation. (Software libraries may use Taylor series, say on hardware that doesn't support trig functions.) There may be some additional processing, using the CORDIC algorithm to get fairly good answers but then doing something else to improve accuracy.

有一些精炼于上述。例如,对于非常小的角度THETA(弧度),SIN(THETA)= THETA所有precision你有,所以它的效率更高,以简单地返回THETA比使用其它算法。因此,在实践中有很多特殊情况的逻辑挤压出所有的性能和精度的可能。芯片市场较小,可能不会去尽可能多的优化工作。

There are some refinements to the above. For example, for very small angles theta (in radians), sin(theta) = theta to all the precision you have, so it's more efficient to simply return theta than to use some other algorithm. So in practice there is a lot of special case logic to squeeze out all the performance and accuracy possible. Chips with smaller markets may not go to as much optimization effort.

这篇关于如何三角函数工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆