Results 1 to 13 of 13

Thread: Finding trig ratios

  1. #1

    Thread Starter
    Addicted Member TheAlchemist's Avatar
    Join Date
    Jan 2003
    Location
    Dar-esSalaam,Tanzania
    Posts
    139

    Finding trig ratios

    hey guys,
    i've been wondering how calculators find the trig ratios, anyone know?
    One thing that sustains me through life is the conciousness of the immense inferiority of everyone else
    --Oscar Wilde

  2. #2
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810
    you mean the 6 identities at different angles?

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  3. #3
    Fanatic Member sql_lall's Avatar
    Join Date
    Jul 2002
    Location
    Up Above (i.e. AUS)
    Posts
    571

    Talking recursion stuff

    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 )
    sql_lall

  4. #4
    Fanatic Member bugzpodder's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    787
    that series converges VERY slowly for large x. i guess they make it close to 0 by taking angle mod 6.2832...
    Massey RuleZ! ^-^__Cheers!__^-^ Massey RuleZ!


    Did you know that...
    The probability that a random rational number has an even denominator is 1/3 (Salamin and Gosper 1972)? This result is independently verified by me (2002)!

  5. #5
    Fanatic Member sql_lall's Avatar
    Join Date
    Jul 2002
    Location
    Up Above (i.e. AUS)
    Posts
    571

    Talking Yeah.

    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??
    sql_lall

  6. #6
    Lively Member
    Join Date
    Aug 2002
    Location
    Jordan
    Posts
    74
    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.

  7. #7

  8. #8
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151
    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.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  9. #9

    Thread Starter
    Addicted Member TheAlchemist's Avatar
    Join Date
    Jan 2003
    Location
    Dar-esSalaam,Tanzania
    Posts
    139

    Thanks Guys!

    Thanks a lot guys!

    Guv
    what do you mean by:
    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.
    Sql_Lall
    i didn't get what you were saying about taking mods man, would you mind explaining?

    thanks guys
    One thing that sustains me through life is the conciousness of the immense inferiority of everyone else
    --Oscar Wilde

  10. #10
    Fanatic Member sql_lall's Avatar
    Join Date
    Jul 2002
    Location
    Up Above (i.e. AUS)
    Posts
    571

    Talking Sure

    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
    sql_lall

  11. #11
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    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]
    Last edited by riis; Apr 2nd, 2003 at 09:32 AM.

  12. #12
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151
    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.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  13. #13

    Thread Starter
    Addicted Member TheAlchemist's Avatar
    Join Date
    Jan 2003
    Location
    Dar-esSalaam,Tanzania
    Posts
    139
    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.
    One thing that sustains me through life is the conciousness of the immense inferiority of everyone else
    --Oscar Wilde

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width