# Revision history [back]

How precise do you need it?

You can get within a few percent with a third order polynomial. You need to:

1) transfer all matrix values to the range -pi/2 to pi/2 by adding whole multiples of pi. (I assume matrix values are in radians, if they are in degrees multiply by pi/180).

2) calculate Sin(x)=x-(x^3)/6

3) for Cosine calculate Sin(Pi/2-x)

if you want better precision you can use higher order polynomials: sin(x) is exactly the infinite polynomial x-(x^3/3!)+(x^5/5!)-(x^7/7!) +.... (look up "Taylor series" for more info) but the accuracy increases pretty fast as you add terms.

I have not tried it, but I guarantee that this would be faster than an element by element sin function (which is probably implemented by a polynomial approximation anyway).

guy

How precise do you need it?

You can get within a few percent with a third order polynomial. You need to:

1) transfer all matrix values to the range -pi/2 to pi/2 by adding whole multiples of pi. (I assume matrix values are in radians, if they are in degrees multiply by pi/180).

2) calculate Sin(x)=x-(x^3)/6

3) for Cosine calculate Sin(Pi/2-x)Sin(pi/2-x)

if you want better precision you can use higher order polynomials: sin(x) is exactly the infinite polynomial x-(x^3/3!)+(x^5/5!)-(x^7/7!) +.... (look up "Taylor series" for more info) but the accuracy increases pretty fast as you add terms.

I have not tried it, but I guarantee that this would be faster than an element by element sin function (which is probably implemented by a polynomial approximation anyway).

guy