• OK, it's on.
  • Please note that many, many Email Addresses used for spam, are not accepted at registration. Select a respectable Free email.
  • Done now. Domine miserere nobis.

Sine, Cosine and Tangent Formula

speiss

Active Member
Local time
Today 5:35 PM
Joined
Jun 15, 2010
Messages
309
---
Location
Where puppies and rainbows abound!
I don't know which thread this goes in, but how does the calculator figure out what the cosine of .4 and such -- like, what's the formula? Not the law of cosines, a squared equals b squared plus c squared and so on..

:3
 

Latro

Well-Known Member
Local time
Today 5:35 PM
Joined
Apr 18, 2009
Messages
755
---
The formula that it uses is based on an idea from calculus called Taylor's theorem. The idea is essentially to use properties of something called the derivative to approximate a function by polynomials of different degrees; the theorem then has some statements about how good these approximations are. In the case of cosine and sine, it turns out that this holds:
cos(x) = 1 - x^2/2 + x^4/4! - x^6/6! + ...
sin(x) = x - x^3/3! + x^5/5! - ...
where n! is n factorial = n*(n-1)*...*2*1. Note that these are only in radians; it is possible to do the computation in degrees, but the scale factors just get in the way, so it's easier to convert to radians and do the computations there.

The calculator takes this infinite series out until the next term is less than the decimal precision of the calculator and then stops. In the process (due to a theorem having to do with properties of convergent alternating series) the error from truncating the series is automatically less than the decimal precision of the calculator. (There is a little more error from doing arithmetic in finite precision as well, but that's unavoidable.)

The calculator might also take numbers outside the range [-pi,pi] and put them into that range by removing multiples of 2*pi first.

So to compute, say, sin(0.01):
sin(0.01)=0.01
-0.01^3/6 (~10^-7)
+0.01^5/120 (~10^-12)
-0.01^7/5040 (~10^-17)
and so we're actually done with the term before (the decimal precision of the calculator is typically at most 10^-16). So:
sin(0.01) = 0.01-0.01^3/6+0.01^5/120 - y
where 0 < y < 0.01^7/5040

The "good" formulae for tan(x) turn out to be more complicated than this, but a relatively efficient way to do it would just be to compute sin(x) and cos(x) and divide. This is probably not what calculators actually do, however.
 

speiss

Active Member
Local time
Today 5:35 PM
Joined
Jun 15, 2010
Messages
309
---
Location
Where puppies and rainbows abound!
Oh wow, thank you! I've always wondered this, thank you for explaining :D
 

Latro

Well-Known Member
Local time
Today 5:35 PM
Joined
Apr 18, 2009
Messages
755
---
Oh wow, thank you! I've always wondered this, thank you for explaining :D
Well...I handwaved a fair bit, not explaining what Taylor's theorem actually says, or even what a derivative is, but you're welcome. With questions like this you should enjoy calculus.
 
Top Bottom