Back in the golden age, log books, then later slide rules were required to complete trigonometrical calculations, right?
But now any entry level scientific calculator can answer a problem with a simple click of, say, the SIN button.
My question is: how can calculators do this so quickly? Are they deducing angles from first principals every time? Do they have an entire log book (only in far greater detail) within their memory? Or was some universal truth about the relationship between angles and trig functions developed right about the same time as these calculators?
Trigonometric functions can be represented by infinite series. For example the sin(x) is:
x - x[sup]3[/sup]/3! + x[sup]5[/sup]/5! - … etc. with the signs alternating plus and minus and only odd exponents and factorials.
The cos(x) is given by a similar series starting 1 - x[sup]2[/sup]/2! + … etc. and using only even exponents and factorials using alternating signs.
5 terms of either series will give its corresponding function’s value to 6 decimal places For x = 1 radian or just over 57[sup]o[/sup]. 10 terms is probably enough accuracy for any purpose for any angle and a computer will do 10 computations this simple in a very short time.
Tan(x) can be computed as sin(x)/cos(x) or the tan series used. In this case some provision has to be made to check for cos(x) = 0 or close to it, in which case x = 90[sup]o[/suo], 270[sup]o[/sup] etc.
Okay, if I type sin(400000) into my calculator, it gives me a result pretty fast. However, I know it didn’t just throw 400000 into the Taylor series for sine; it would have had to go through some massive terms before it started converging. I know that there are ways of going about it that are more efficient, but I don’t really know how my calculator does it in fact. Do you?
Yeah, well I was doing radians, but I guess the same thing applies. You think that’s what it does? Makes sense. I tried sin(4E20) and it says, “Warning: trig argument too big to reduce”.
No, but I think maybe XPav is on the right track. If I first divide all numbers greater than 360, or 2Pi as the case my be, by those number I get the increment over the number of complete rotations.
400000/2Pi = 63661.9772367581
I can throw away the whole number and just work with the fraction. 0.977 of a full rotation is 351.72[sup]o[/sup] and the sin is -.144
And, of course, there are damned few real problems that will require finding the sin of 400000 whether it’s in [sup]o[/sup] or radians.
Sorry for my too brief answer earlier (I was in the middle of cooking dinner).
There are a few different ways that calculators can work out trig functions.
The Taylor series method described by David Simmons is one. Others include:
using a lower order polynomial whose coefficients differ from the Taylor series coefficients to allow for the truncation of higher order terms.
storing a few accurate values, say at 0, 15, 30… 90 degrees, working out which one is closest, then using a shorter Taylor series to extrapolate to the required value.
again, storing a few accurate values, and using an interpolating function, say a quadratic or cubic based on some of the closest accurate values, to interpolate to the required value.
The function evaluation problem is not such a big deal these days, when storage and computational horsepower are cheap, and most of this stuff is built in to floating point hardware.
But, for the designers of early scientific calculators, it wasn’t a trivial task. You could do it faster, or more accurately, or use less storage, but not all three together.
By the way, the approximation is normally done over a single quadrant. Part of the logic of the software is to map the known quadrant, usually 0-90 degrees, on to the others. So yes, the software does a mod 360, and then also knows that sin 110 = sin 80, sin 260 = - sin 90, sin 280 = - sin 90, etc.
You have a foolhardy calculator that believes that 4E20 - 2pi is 4E20, because it has fewer than 19 data digits (basically speaking). That’s my guess, anyway.
Somehow I’m as the TA for a numerical methods course this semester… but I still don’t really know what I’m talking about.
Note that Taylor series are absolutely lousy for interpolating trig functions (and most other textbook examples). There are a horde of other interpolation methods out there that yield better accuracy using far fewer terms. My favorites are Chebyshev (spelling variants abound) polynomials.
Not even an entire quadrant. At a minimum, I’d expect a formula for each of Sine and Cosine, and you can use the one in the range 0 - 45 to get the other in 45 - 90.
Here is an article on writing an arbitrary precision math library in C, where these issues come up. This sidebar to the article describes using trigonometric identities to further reduce the range of approximation needed (to 0.0251 radians for Sine, and 0.0156 for Cosine). Whether this is the way any calculators do it, I can’t say.
In addition to the Chebyshev polynomials mentioned by ftg, other ways of efficiently approximating functions (for everyones Googleing pleasure) are economized polynomials, Pade approximations, and rational function approximations.
I just wanted to add my two cents from an engineering/electro-mechanical point of view, as far as some people’s doubts about how fast the calculator comes up with an answer.
You have to realize that these mathmatical processes have been translated (maybe that’s not the best word, maybe modeled is a better word) into electronic circuits. These circuits are dedicated, i.e. they perform one and only one function. The SIN button just does SIN. That allows it to be very very fast. It’s not encumbered by an operating system, heavy graphics, nothing, just a circuit. A number goes in, the electrons run thru the gates and pop out the other end. It can truly happen at nearly light speed.
A good analogy is the old stand-up arcade style video games. At a time when all you could play was pong and asteroids at home, the arcade games were (relatively speaking) awesome graphically and with respect to the speed and complexity of the games. Why? Because those machines were hardwired with the game and didn’t have to operate thru all the baggage that a pc or game console did at the time.
Right. The series example was just to illustrate how such things can be done. There are whole handbooks full of various computation algorithms to get a numerical answer for anything worth computing.
I guess what method is used is the programmers choice. Do you want to use memory to store look-up tables, or use up computation time in starting from scratch?
And by the way, I was a little optimistic in how many series terms would be good enough for accuracy to 6 decimal places. For the example of the sin of 0.977, it takes 13. 15 would cover all cases to that degree of accuracy.