Hi, this is my first post. Hope I'm not breaking any rules. Anyway, I was messing arround programming the other day, and I accedently came up with an algorithm that will approximate the cosine of a number with a great deal of precisision. Here's the code:(adsbygoogle = window.adsbygoogle || []).push({});

double cosine(double n){

double a=1;

double da=0;

double p=1000;//Bigger numbers will give you a better value for cos(n)

for(double i=0;i<=n;i+=pow(p,-1)){

da+=-a/pow(p,2);

a+=da;}

return a;}

It's kinda hard to put this into words, and I imagine a lot of people here know a little bit of c++, so, for now, I won't try to explain what it does. I can try though, if you want. So, yeah, if anyone could tell me why this works, that would rock.

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Why does this work?

**Physics Forums | Science Articles, Homework Help, Discussion**