Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm an Android programmer and am working on a graphing calculator. I have been looking for a formula for sine and cosine to put in there. I have a decent understanding of mathematics but can not seem to find this formula. Any help would be great, thanks.

share|cite|improve this question
3  
en.wikipedia.org/wiki/CORDIC – Qiaochu Yuan Feb 23 '12 at 1:45
1  
for information : every processor with a FPU implements those – user1952009 Feb 13 at 20:43
1  
I would just use some free library to do this. It's likely going to be much faster than anything you could write by hand. Unless you're just doing it for fun, in which case, knock yourself out! – Jair Taylor Feb 13 at 21:02
up vote 1 down vote accepted

The best-known formulas are the Taylor series:

Taylor series for sin and cos

share|cite|improve this answer
    
Thanks so much. – jersam515 Feb 23 '12 at 1:44
1  
These work well when $x$ is small. One must suspect for larger $x$ there are refinements that are more computationally efficient. – Michael Hardy Feb 23 '12 at 1:51
3  
You may want to reduce the argument to an angle within 0 and $2\pi$. Then you'd only need a few terms to get a good approximation (you can even reduce it to an angle between $-\pi/2$ and $\pi/2$ and adjust appropriately, using the symmetry of the functions, afterwards). – David Mitra Feb 23 '12 at 1:51
1  
@David That's why I suggested Bhaskhara's formula. – Pedro Tamaroff Mar 9 '12 at 23:20

Are you sure you don't have access to java.lang.Math?

share|cite|improve this answer
    
Yes, thanks for pointing out that method. Knowing the formula doesn't hurt anyways though. – jersam515 Feb 23 '12 at 1:47

You might want to consider finite expressions too. Particularily

$$ \cos \frac{\pi x}{2} \approx 4\frac{1-x^2}{4+x^4} \text{ ; for} -1 <x<1$$ and

$$\sin x \approx \frac{{16x\left( {\pi - x} \right)}}{{5{\pi ^2} - 4x\left( {\pi - x} \right)}} \text{ ; for } 0 <x<\pi $$

They give a great approximation: see here.

share|cite|improve this answer
    
The equals signs look bad here. And the first one isn't really great: the difference in graphs can be seen with naked eyes. – Ruslan Feb 13 at 18:24
    
@Rusland Agreed. – Pedro Tamaroff Feb 13 at 20:37

You can express them using MacLaurin series or Taylor series expansions. You can find this on Wikipedia.

$$\sin(x) = \sum_{n=0}^{\infty}\frac{(-1)^n}{(2n+1)!}x^{2n+1}= x-\frac{x^3}{3!}+\frac{x^5}{5!}-\frac{x^7}{7!}+\ldots$$

$$\cos(x) =\sum_{n=0}^{\infty}\frac{(-1)^n}{(2n)!}x^{2n}=1-\frac{x^2}{2!}+\frac{x^4}{4!}-\frac{x^6}{6!}+\ldots$$

share|cite|improve this answer
1  
This is too little information to be of use for a compute program. How many terms should be calculated? What pre-processing (range reduction) can be done on the parameter? How should the polynomial be calculated? And son. Can you add any of these details? Worst of all, another answer, previous to yours, already gives this information. What can you add to that other answer? – Rory Daulton Feb 13 at 21:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.