hey guys,
i've been wondering how calculators find the trig ratios, anyone know?
Printable View
hey guys,
i've been wondering how calculators find the trig ratios, anyone know?
you mean the 6 identities at different angles?
I think they use a kind of recursion.
I've heard that most programs use recursion (repeated algorithm, getting closer & closer each time) to get square roots, until a desired decimal size is required.
I am guessing they do the same for sin & cosine.
E.g, i'm sure you could write a program that gets an integer input, and figures out x/1! + x^3/3! + x^5/5! +..... until you get enough decimal places.
(is that right?? hope so :p)
that series converges VERY slowly for large x. i guess they make it close to 0 by taking angle mod 6.2832... :D
Yeah, could be (except u can't use mods for integers, but i know what you mean)
However, with things like square roots, they don't use the most obvious/well known ones. So, i am guessing with sine&cosine, that some faster algorithms are used.
It would be interesting to know though. Anyone here a calculator programmer?? :p
Well.
It is right that there are some serries to find the values of trig functions, but i don't think they are used in calculators.
It is more likely that calculators only check up the values of the trig functions in pre-defined tables.
But computer programs use those serries.
Check out this link:
http://www.math.utep.edu/Faculty/hel...c/wcordic.html
There are series which converge pretty fast if you do a little work first.
For angles in radians.
sin(x) = x - x3/3! + x5/5! - x7/7! . . .
cos(x) = 1 - x2/2! + x4/4! . . .
There are series used for exponentials and other transcendental functions.
With a little fooling around, you can get x to be less than one prior to using the series. For x less than one the above converge very fast.
A modern computer might use the above series as is, generating the coefficients as required, and testing for a term too small to be bothered with. I do not think this approach is used.
There are methods which determine adjusted coefficients, allowing for the use of an approximating polynomial. When this method is used, the coefficients are stored as constants. I think this is the modern method.
Thanks a lot guys!
Guv
what do you mean by:
Sql_LallQuote:
With a little fooling around, you can get x to be less than one prior to using the series. For x less than one the above converge very fast.
i didn't get what you were saying about taking mods man, would you mind explaining?
thanks guys
MODular arithmetic is just a number theorey dealing with remainders.
A (mod B) -where A and B are both integers- is equal to the remainder when A is divided by B
I.e. 5 (mod 3) = 2
13 (mod 5) = 3
58 (mod 5) = 3
also, 13=58 (mod 5) - but usually that should be a 'congruence' sign, not an 'equals' sign, i.e. have 3 bars not two
Anyway, what i meant was, bugz had said 'mod 2*Pi', when he meant that it was reduced by subtracting pultiples of 2*Pi until it was a number between 0 and 2*Pi
Sine and cosine are periodic functions, that's why it can be 'mod'ded. The period is 2 * pi.
[edit]
Not only they are periodic, but they are also symmetrical within a carefully chosen period. It is possible to get x always between 0 and half pi, the rest of the domain [0, 2 * pi> will be covered by mirroring the resulting graph.
[/edit]
TheAlchemist:Trigometric identities can be used to reduce find a useful value less than one when evaluating a power series. Following in degrees just because most people are mare familiar with degrees. The power series require an angle in radians.
Sin(x) = - sin(x) Can be used to simplify logic, allowing use of absolute value of x.
Sin(x) = sin(x - 360) Already mentioned in getting x less than 360.
Sin(x) = - sin(x - 180) Can be used to get an angle less than 180
Sin(x) = sin(180 - x) Might be handy for angles less than 180 and greater than 90
Sin(x) = - cos(x - 90) Can be used to get an angle less than 90
Sin(x) = cos(90 - x) Handy to further reduce angles greater than 45 and less than 90. also handy for angles less than 180 and greater than 90.
In practical problems, angles are usually not more than 90 degrees. A Select Case True Statement could be used. The test for absolute value less than 45 might be first, and test for absolute value less than 90 second.
Reduction techniques are also used for other transcendental functions. Consider the exponential function.
ex = [ ex/2 ]2
e1.3567 = e * e0.3567
e5.6479 = e5 * e0.6479
For the exponential function, I am not sure what method is best. In machine language, dividing by powers of 2 can be done by shifting, making it reasonable to reduce the exponent by using a power of two as a divisor.
Perhaps the best method might be to start by using the product of einteger and efraction. Then express the integer as a binary number. For example, the following.
e13.9876 = e8 * e4 * e * e.9876
The last term might be computed as [ e.4938 ]2
The following might be used.
e4 = [ e2 ]2
e8 = [ e4 ]2
Precalculated powers of e might be stored in a table. For large values of x, divison by a power of two might be used first followed by the above.
BTW: I did a lot of coding for basic mathematical functions, matrix algebra, differential equations, et cetera in the 1950's and early 1960's. Due to limited memory and slow processors, a lot of analysis was done to decide on the best method. More code could cut processing time at the expense of memory. Since then nobody does any analysis. You can find all sorts of published algorithms with a description of the up & down sides of each. A modern CPU is so fast and memory is so cheap that it probably does not matter how you do it for most applications.
:D Thanks again guys!
i knew of Mod Arithmetic but i have never seen it in the light that you described it Sql_Lall, i'm enlightened!!
Guv, thanks a lot, i really don't know how else to say it.
anyway i've been having a lot of fun with Taylors and Maclaurins series lately!!! Newtons method is also a very interesting way of arriving at a solution iteratively.:p