• Quick note - the problem with Youtube videos not embedding on the forum appears to have been fixed, thanks to ZiprHead. If you do still see problems let me know.

Sin, Cos, Tan: A math question

Raskolnikov

New Blood
Joined
Dec 27, 2005
Messages
20
Okay, so sitting here doing some basic trigonometry, my questioning nature has stopped me from doing what I should be doing once again...

How does the calculator find tangens, sinus and cosinus for a given angle? I mean, once it knows one angle it will automatically know the two others, but how does it use this info to find for example tangens of 40 degrees?

Probably a stupid question, but oh well...

:confused:
 
There's two possible answers, either it uses a look-up table and interpolates, or it uses a finite polynomial approximation.

For example:
sin x= x -x^3/3! + x^5/5! -x^7/7! +x^9/9!.........

while
cos x = 1-x^2/2! +x^4/4!-x^6/6!.....

If it uses look up tables, these will have been generated by a power series expansion like the ones above.

The maths behind why these series work (i.e. actually converge to sin and cos) is quite interesting but normally left till the first year of a maths degree.
 
How does a calculator do this? My guess is that it uses expansions for sin, cos and tan

[latex] sin x = \sum_{n=1}^{ \infty } \frac {(-1)^{n-1}}{(2n -1)!} x^{2n - 1} [/latex]

etc
 
Last edited:
Thanks for the replies!

Yes, I was afraid it would be something completely out of my league. :jaw-dropp :o

I think I will simply accept that it works for the time being...
 
Using calculus you can show a lot of things, including a way to calculate sin, cos and tan. By finding what's called the Taylor Series for sin you see that it is equal to:

x - x^3/3! + x^5/5! - x^7/7! + ... on to infinity

and a similar one for cos.

You can try it on a calculator, although it might take a bit to get close to the correct answer.

This isn't what is used by computers for the most part: it doesn't converge fast enough. But it's that type of thing.
 
Note that the formula only works when x is in radians. For degrees, your calculator will first convert to radians. And if you ever get to do a calculus course you'll eventually see series expansions (provided you stick around for at least 2 semesters, as this is usually covered in calculus 2).
 
There's two possible answers, either it uses a look-up table and interpolates, or it uses a finite polynomial approximation.

I suspect that most calculators would use look-up tables since it is computationally less intensive, though I'm not discounting the possibility of HP purists frowning upon the practice.

Raskolnikov, if you wish to look into this and have access to a good library, I suggest reading Knuth, The Art of Computer Programming, volume 2.
 
I suspect that most calculators would use look-up tables since it is computationally less intensive, though I'm not discounting the possibility of HP purists frowning upon the practice.
Back in the day, there was a noticeable pause when my calculator was asked to do trig functions, suggesting that it really was calculating the series.

These days they have much faster chips and much more memory to play with, so either method would work.
 
Back in the day, there was a noticeable pause when my calculator was asked to do trig functions, suggesting that it really was calculating the series.

These days they have much faster chips and much more memory to play with, so either method would work.

Back when I had a Kingspoint SC40, it could take up to about 5 seconds to calculate an x^y function, and about a second or so to do a sin, cos, or tan.
 
Back around 1972 or 1973 my mom got a Sharp Elsi-Mini which was so cool. I can still remember that to show it off I would divide 51 by 13, and you could see the LEDs churning while it came up with the answer. I wonder where it is now.
 
Sometimes you can see the residual error left over of the infinite sums that the calculators do. You can try the following on any calculator

In degrees: tan(45)-1
In radians: tan(pi/4)-1
Both should equal zero

I did it with Calculator that comes with windows and got respectively
-7.4474808442089263531396871106442e-38 and
-8.7456166731274737622753322863144e-39.
 
I suspect that most calculators would use look-up tables since it is computationally less intensive, though I'm not discounting the possibility of HP purists frowning upon the practice.
I very much doubt that. Suppose we have 32 bit accuracy. Then we'll have 2^32 entries, each one 32 bits long. That's about 30 gigabytes of storage. Sure, optimization could reduce that somewhat, but we're still talking about way more than a calculator's memory. Heck, most computers don't have that much active memory.

I suspect that it's actually a combination. Remember, sin (x+y)=sin x cos y+cos x sin y. So let's say you have a lookup table for every tenth of a radian. Then if you want to find sin(.587), for instance, you can write that as sin(.5+.087), lookup sin(.5) and cos(.5), and then calculate sin and cos of .087. Since .087 is so small, the Taylor series will converge rather quickly. If we have, say, 1024 different angles, 32 bit accuracy, that's 8 kb. That leaves about .0015 between each angle (assuming that you have only the first quadrant), so you'll need only four terms.
 
I very much doubt that. Suppose we have 32 bit accuracy. Then we'll have 2^32 entries, each one 32 bits long. That's about 30 gigabytes of storage. Sure, optimization could reduce that somewhat, but we're still talking about way more than a calculator's memory. Heck, most computers don't have that much active memory.

I suspect that it's actually a combination. Remember, sin (x+y)=sin x cos y+cos x sin y. So let's say you have a lookup table for every tenth of a radian. Then if you want to find sin(.587), for instance, you can write that as sin(.5+.087), lookup sin(.5) and cos(.5), and then calculate sin and cos of .087. Since .087 is so small, the Taylor series will converge rather quickly. If we have, say, 1024 different angles, 32 bit accuracy, that's 8 kb. That leaves about .0015 between each angle (assuming that you have only the first quadrant), so you'll need only four terms.

That would make sense.
 
I suspect that it's actually a combination. Remember, sin (x+y)=sin x cos y+cos x sin y. So let's say you have a lookup table for every tenth of a radian. Then if you want to find sin(.587), for instance, you can write that as sin(.5+.087), lookup sin(.5) and cos(.5), and then calculate sin and cos of .087. Since .087 is so small, the Taylor series will converge rather quickly. If we have, say, 1024 different angles, 32 bit accuracy, that's 8 kb. That leaves about .0015 between each angle (assuming that you have only the first quadrant), so you'll need only four terms.
Wouldn't it be better to linearly interpolate between points than to approximate by adding a term from near zero, given the gradient fluctuations?
 
From what I remember, calculators use the series expansion for these terms.

The neat thing (in simple terms) is this. The series are usually plus this term, minus the next term, plus the next term, minus the next, etc. But the terms themselves are getting smaller. So, what's actually happening is that, if you look at it on a number line, the approximate answers bounce back and forth on either side of the true answer, gradually getting closer. By computing the size of the next term in the series, you can get a maximum amount that your current approximation can be off by. And so, it's possible (in many cases) to guarantee that the value you show on the calculator is exact, to as many places as are shown on the screen.

For instance, if the next term in the series is one billionth in size, and your calculator only shows to the millionths place (this is hypothetical; most show more), then your current approximation isn't going to get any more accurate by adding more terms, and it's time to show the answer.
 
I won't pretend to understand this, but it seems you're saying that sin, cos and tan are approximations?
 
I won't pretend to understand this, but it seems you're saying that sin, cos and tan are approximations?

Not quite. They're saying that digital calculators can only provide an approximation (which shouldn't surprise you as there are a finite number of digits available), not that we don't know the full, exact expression. For arbitrary angles, the exact function is an infinite series, so you can't get all the terms calculated in a finite amount of time.
 
Not quite. They're saying that digital calculators can only provide an approximation (which shouldn't surprise you as there are a finite number of digits available), not that we don't know the full, exact expression. For arbitrary angles, the exact function is an infinite series, so you can't get all the terms calculated in a finite amount of time.

Yes, though depending on the calculator, numerical value of expressions will not be evaluated until they are requested. In Walter Wayne's example, my TI-92 is capable of evaluating the exact value of tan(Pi/4), since it can handle some algebra, unlike Windows' calculator, which first approximates Pi, approximates the tangent of this value, and then subtracts 1 from the result. Most graphing calculators can do this in a proper fashion.
 
Not quite. They're saying that digital calculators can only provide an approximation (which shouldn't surprise you as there are a finite number of digits available), not that we don't know the full, exact expression. For arbitrary angles, the exact function is an infinite series, so you can't get all the terms calculated in a finite amount of time.

Ah, that seems obvious now that I think about it. Of course, for most calculations, how many digits do you really need to get a satisfactory result... A bit like pi then I suppose - 3,14 will do nicely.
 

Back
Top Bottom