Time for a new calculator?

Thread Starter

kdillinger

Joined Jul 26, 2009
141
I have a TI-86. It can calculate sin (2*pi) correctly but not sin(4*pi) or sin(6*pi), etc. etc.

sin(2*pi) is 0.
sin(4*pi) is -200e-15!

Ok, close enough to zero, but in electronics this can be a real calculation for capacitance, etc. I hope this does not creep into other calculations.

Maybe I need new batteries!
 

Wendy

Joined Mar 24, 2008
23,421
Welcome to the wonderful world of truncating errors. 0 is almost -200e-15, isn't it? :D

A large part of computer science is based around these kind of problems.
 

Wendy

Joined Mar 24, 2008
23,421
Don't think so, not with such a small number (it really does approach zero as a limit). If it were degrees instead of radians it would be 0.109442606 (sin (2π)) or 0.217570395 (sin(4π)). The problem is the algorithm generating the answer isn't quite precise enough. It has nothing to do with batteries, and everything do to with how the answer is calculated inside the calculator.

On the old 8 bit computers it was possible to use simple math such as 2+2=3.9999998. Not that exact problem, but simple addition. There is a whole field devoted to these kinds of problems, it is core to computer science. Binary has quirks just like all number systems.

I believe you have your calculator set in radians rather than degrees. After all, sin(2∏) = 0 rad or 0.1094°.
BTW, the sin of an angle is not in degrees (°), it is a dimensionless unit that is used to calculate length, a constant. The angle is either in degrees or radians.
 

someonesdad

Joined Jul 7, 2009
1,583
There's nothing wrong with your calculator. This is an inherent problem in the numerical calculation -- the people who design the algorithms have to decide when "enough is enough" and stop iterating to get the answer. For example, here's a calculation of 10π done on a calculator set to calculate to 50 digits of precision (set to display 4 significant figures); the result is -5.841e-52, not zero as you would expect.

This is done with a high-quality math library (mpmath) and I just looked at their code to see how they do the calculation. They use a Taylor series for calculations with less than 600 digits of precision. Most calculators probably use the same strategy because the Taylor series for exp(x) will converge quickly, especially if you reduce the argument to lie within 0 to 2π. (If you weren't aware of it, the Taylor series for sin(x) and cos(x) are closely related to the series for exp(x).)

One could argue that the designers of these things should detect when the argument of a trig function like the sine is near 0 mod 2π. This would be easy to do, but then customers would also then start to expect you to handle other well-known multiples of π correctly. But, since your calculator also likely handles degrees and grads, you've got to handle those modes too. Pretty soon you'll start using up too much ROM space with all the checks. :p

More modern calculators that will handle symbolic expressions like sin(10π) can do the calculation correctly and return 0, as you expect. But even they will fail to return 0 if you first convert 10π to its (approximate) floating point form and then calculate the sine.
 

JoeJester

Joined Apr 26, 2005
4,390
Just for S&G's I did the sin(2pi) and sin(4pi) in excel. The sin function is normally in radians so i used the pi/180 to convert to degrees. Excel computes pi accurate to 15 digits. TI-98's pi is accurate to 12 digits.

sin ( 2 pi) = 2.4503e-16 radians and 4.27657e-18 degrees

Close enough is dictated by the task at hand. If they wanted you to end up with zero, which will be difficult since pi is neverending, they would have recommended the proper equipment to get that result.
 

Wendy

Joined Mar 24, 2008
23,421
Just for S&G's I did the sin(2pi) and sin(4pi) in excel. The sin function is normally in radians so i used the pi/180 to convert to degrees. Excel computes pi accurate to 15 digits. TI-98's pi is accurate to 12 digits.

sin ( 2 pi) = 2.4503e-16 radians and 4.27657e-18 degrees

Close enough is dictated by the task at hand. If they wanted you to end up with zero, which will be difficult since pi is neverending, they would have recommended the proper equipment to get that result.
The 2π is radians. The answer is dimensionless.

I tried my calculator, Casio fx-115MS, no hickups yet.
 

maxpower097

Joined Feb 20, 2009
816
I've been using a great little calculator on my phone. Its an HD2 so its got a nice big LCD. But it has many modes for specific uses. I wrote the creator and he said he may make an electronics mode next.
 

tom66

Joined May 9, 2009
2,595
My calculator is a fx-83GT+, it has natural VPAM, so if you ask it what sin(45 degrees) is it tells you it is sqrt(2).
 

Ghar

Joined Mar 8, 2010
655
Technically you can never write Pi into a calculator in the first place since you have to end the digits somewhere so the answer should never be zero ;)
 

Wendy

Joined Mar 24, 2008
23,421
Most calculators get around this my having many more digits than they actually display. It is like Chaos theory, small changes have have large results, so it doesn't always work.
 

tom66

Joined May 9, 2009
2,595
You can demonstrate the effect with a cheap pocket calculator (not a scientific one.) Enter '2', press sqrt twice, then square it (press the multiply button twice to square.) You won't get back '2'.
 
Top