> > I suggest the following formula for calculating sine at (0, pi/2)
> > interval:
> > 
> > sin(x) = (0.99996736*x - 0.09779183*x^2 - 0.12839086*x^3 +
> > 0.01826627*x^4) / (1 - 0.09809942*x + 0.03936879*x^2)
> > 

> could you please attach some R code for this?
> My plan for now is to make those functions work, not spending too much time 
> optimizing precision and performance.
> After that me and others could start improving both. So you can try with your 
> formula later, hopefully also for other functions.

Well, the idea behind the formula is quite simple. The aim is to find
rational function, which match sine at predefined number of points.
Thus:

sin(x)*(a0+a1*x+a2*x^2+...) = b0+b1*x+b2*x^2+...

from x=0 it follows that b0=0 and if we create linear system from the
predefined points, we find that the matrix has less rank than the number
of rows/columns. So we can choose one more parameter and the natural
choice is a0=1.

Now let's choose the points we know the values of sine, the R command
is:

x0 <- c(pi/12, pi/6, pi/4, pi/3, 5*pi/12, pi/2)

the corresponding sine values are:

b <- c(sqrt((1 - sqrt(3)/2)/2), 1/2, sqrt(2)/2, sqrt(3)/2, sqrt((1 +
sqrt(3)/2)/2), 1)

if we are lazy, we can exploit R, and also we can do it if we want more
points:

b <- sin(x0)

Then, if we decide that the upper polynomial (b0,b1...) will be of
degree 4 and the lower one (a0,a1...) of degree 2 - let me make a short
step aside - we have 6 known values, so we can estimate 6 coefficients.
We know a0 and b0, so the sum of the polynomials degrees should be 6. I
tried all combinations, 6-0, 5-1, etc., 4-2 seems to be the best - then
the matrix can be constructed as:

A <- cbind(x0, x0^2, x0^3, x0^4, -b*x0, -b*(x0^2))

and the coefficients can be calculated as:

x1 <- solve(A, b)

first four elements of x1 are the bi coefficients, the last two are the
ai coefficients.

You can create your own function

mysin <- function(x){tst <- (x1[1]*x + x1[2]*x^2 + x1[3]*x^3 +
x1[4]*x^4)/(1 + x1[5]*x + x1[6]*x^2)
tst}

and make a test like:

mysin(pi*c(1:10)/20) - sin(pi*c(1:10)/20)

this will show match to 6 decimal places for all values.

----

So, what I want to say, that if looking for sine approximation at
interval (0, pi/2), which is of course correct idea, then for given
number of coefficients, there is always better approximation that Taylor
expansion with the same number of coefficients. Even the simple
polynomial as of the situation 6-0 (so only bx coefficients) is better
than Taylor expansion. It is even almost as good as the rational
function 4-2.

I have also made a quick research of how the sine is being numerically
calculated. It is quite difficult to find something particular, but my
impression is, that the most used method nowadays is a table of
predefined values, and the rest is somehow interpolated, probably by a
linear function.

So that's all from my side :-)

Pavel


------------------------------------------------------------------------------
HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
Find What Matters Most in Your Big Data with HPCC Systems
Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
Leverages Graph Analysis for Fast Processing & Easy Data Exploration
http://p.sf.net/sfu/hpccsystems
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to