![]() |
Question about trig functions approximation - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: Question about trig functions approximation (/thread-236969.html) |
Question about trig functions approximation - Namir - 01-09-2013 Hi All, In your opinion, among the sin, cos, and tan functions (as you get any two trig functions from the value of the third trig function), which one is easier to calculate using polynomial approximations or special approximation? If you are referring to a special approximation can you please state it or offer a link to that information? Thanks,
Namir
Re: Question about trig functions approximation - Eddie W. Shore - 01-09-2013 Quote: Namir, I tend to lean towards sine. However, I find the convergence for the Taylor Series for sine to be super slow. The approximations listed are stated to be good for eight-digit accuracy for the interval [0 to pi/2]. From "Scientific Analysis on the Pocket Calculator" by Jon M. Smith (published 1975):
Sine and Cosine: error < 2 x 10^-9 with 0 <= x <= pi/2The "compacted" approximations are said to give three-digit accuracy for [0, pi/2].
Sine and Cosine: Error = 2 * 10^-4 and 2 * 10^-9, respectively, for 0 <= x <= pi/2 There was also a thread of calculating trig functions with the HP 12C, that was a while ago. Hope this helps,
Eddie
Re: Question about trig functions approximation - Namir - 01-09-2013 Thanks Eddie for the nice info!!! Once I get sin(x) I can then calculate cos(x) and tan(x) as: cos(x) = sqrt(1 - sin(x)^2) And, tan(x) = sin(x)/cos(x)
Edited: 9 Jan 2013, 1:59 p.m.
Re: Question about trig functions approximation - Dieter - 01-09-2013 You can easily set up your own polynomial approximation with exactly taylored errors using standard tools like Excel and a few minutes time. I tried something similiar to the sine approximation you mentioned and came up with a result with 10-digit accuracy: sin x = x*(1 + x^2*(a2 + x^2*(a4 + x^2*(a6 + x^2*(a8 + a10*x^2)))))Max. absolute error in [0; pi/2] is approx. +/- 2 E-11 Max. relative error in [0; pi/2] is less than +5 / -2 E-11 A rational approximation should perform even better.
Dieter
Re: Question about trig functions approximation - Garth Wilson - 01-09-2013 Quote:For cos(x), why not just use the same sin function, adding 90° to the input first? Re: Question about trig functions approximation - Garth Wilson - 01-09-2013 Quote:Years ago when I was figuring out the functions to do in 16-bit scaled-integer in embedded systems where I didn't want the overhead of floating-point, I found it was better to calculate only 0-45° and get the rest of the circle from there, since when doing only a few terms of the taylor series with tweaked coeffients, the error jumped way up after 45°. Re: Question about trig functions approximation - Paul Dale - 01-09-2013 Quote: Careful with this one. As sin(x) -> 1, cos(x) -> 0 and you're going to lose precision very quickly. A fused multiply add or using sqrt( (1-sin(x))(1+sin(x))) will assist somewhat. Likewise cos(x) = sin(x+90 degrees) is also risky, although likely less so since cos(x) approaches 1 quadratically as x -> 0. The 34S uses a straight Taylor series expansion (after a high precision modulo reduction step) and calculates both sin and cos at the same time. It would converge faster if I reduced the argument into the range 0 .. pi/4 or even -pi/4 .. pi/4 but this doesn't seem necessary. See sincosTaylor() in decn.c for the implementation.
Re: Question about trig functions approximation - Valentin Albillo - 01-10-2013 Hi, Namir:
Quote:
Let's see:
Some allegedly useful references (PDF documents):
Happy New Year 2013 and
Best regards from V.
Re: Question about trig functions approximation - htom trites jr - 01-11-2013 The 0º - 45º approach I used for a >32 bit package. The hard part was strictly increasing and strictly decreasing -- and testing for that.
|