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

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

问题描述

所以在高中数学,可能还有大学,我们被教导如何使用三角函数、它们做什么以及它们解决什么样的问题.但它们总是作为一个黑匣子呈现给我.如果您需要某事物的正弦或余弦,您可以点击计算器上的 sin 或 cos 按钮,然后就可以了.哪个没问题.

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.

推荐答案

首先,您必须进行某种范围缩小.Trig 函数是周期性的,因此您需要将参数减少到标准间隔.首先,您可以将角度减小到 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 到您拥有的所有精度,因此简单地返回 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天全站免登陆