Archived

This topic is now archived and is closed to further replies.

cplusasterisk

cosine without pi

Recommended Posts

PI is like, the most important constant... EVER! Why do you want to get rid of it? While you are correct that there is a way involving cosine to evaluate PI, I remember there being lots of nasty exponents and coefficients... very slow!

PI is your friend. Don''t hate him for what he is.

Share this post


Link to post
Share on other sites
Using this formula for arctan:

∞ x2n-1(-1)n-1
Σ -----------
n=1 2n-1


We can plug in 1 for x, and get one-fourth the value of PI (arctan(1) = π/4). You might have to evaluate to a bunch of terms though. I know it doesn't use cosine, but that's the best a quick google search could do for finding PI...

EDIT: Grrr, growing hostility towards formatting...

[edited by - Zipster on October 1, 2002 1:25:57 AM]

Share this post


Link to post
Share on other sites
I''ve already got my own formula to find pi,

lim (n*cos(90-180/n))
x->infinity

I just wanted a way to evaluate the cos part without having to convert 90 to 1/2pi and 180 to pi. I tried looking for the definition of cosine, but I got scared away. Coding a definition for cosine is a whole different project.

c+*

Share this post


Link to post
Share on other sites
Hmmm...

lim(n->inf) n cos(pi/2 - pi/n)
= lim(n->inf) [cos(pi/2 - pi/n)] / [1/n]
= lim(n->inf) [-pi/n² sin(pi/2 - pi/n)] / [-1/n²]
= lim(n->inf) pi sin(pi/2 - pi/n)
= lim(n->inf) pi sin(pi/2 - 0)
= lim(n->inf) pi
= pi

...yeah, it works. I''m not too sure whether it''ll be useful, though.

Share this post


Link to post
Share on other sites
quote:
Original post by cplusasterisk
I''ve already got my own formula to find pi,

lim (n*cos(90-180/n))
x->infinity

I just wanted a way to evaluate the cos part without having to convert 90 to 1/2pi and 180 to pi. I tried looking for the definition of cosine, but I got scared away. Coding a definition for cosine is a whole different project.



Do you mean n->infinity? If so that limit just evaluates to ∞

Share this post


Link to post
Share on other sites
It tends to pi. Did you try to substitute n = ∞? Take a closer look: if n = ∞, the cosine ends up as cos(90°), which is zero. And then you have zero times infinity, which doesn't really tell you anything.

[edited by - Beer Hunter on October 1, 2002 2:28:09 AM]

Share this post


Link to post
Share on other sites
Just use the Maclaurin Series for cos(x)


∞ x2n x2 x4
cos(x) = Σ (-1)n ---- = 1 - -- + -- - + ...
n=0 (2n)! 2! 4!


Timkin

[edited by - Timkin on October 1, 2002 2:34:30 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Beer Hunter
It tends to pi. Did you try to substitute n = ‡? Take a closer look: if n = ‡, the cosine ends up as cos(90‹ ), which is zero. And then you have zero times infinity, which doesn''t really tell you anything.



Oops, I read that as n*cos( (90-180)/n)


Share this post


Link to post
Share on other sites
quote:
Original post by Zipster
EDIT: Grrr, growing hostility towards formatting...

Next time, try the [ code ] tags; not < code > (I think that''s why the formatting is not preserved.

You can also use the Maclaurin serie for arctan.

pi = 4 * arctan(1)

Cédric

Share this post


Link to post
Share on other sites
Cosine is naturally defined using radians. Your notation is fooling you. When you say cos(90-180/n), you actually mean cos((90-180/n)*Pi/180). What your limit is doing is extracting Pi from the definition of a degree, which is Pi/180.

By the way, cos(Pi/2-x)=sin(x).

Share this post


Link to post
Share on other sites
[start-r]-"calc"-[newline]-[p]-[ctrl-c]-[alt-f4]-[ctrl-v]
result:
3.1415926535897932384626433832795
is that pi good enough for you?
why do you want to calculate pi? its a natural constant, just.. use it that way (hint, there is a keyword called const...)

"take a look around" - limp bizkit
www.google.com

Share this post


Link to post
Share on other sites

cos(1.57079632679489661923132169156 - 0.054831135561607547882413838885408/n)


There, use that, and now you don''t need PI .

Or you can write a simple function like this:


inline double MyCos(float Degree)
{
return cos(Degree*0.017453292519943295769236907684883);
}


or a macro...


#define MyCos(Degree) cos(Degree*0.017453292519943295769236907684883)

That works too... and it doesn''t use Pi directly... it uses Pi/180 instead, and you simply pass it a Degree instead of a radian.

Billy - BillyB@mrsnj.com

Share this post


Link to post
Share on other sites
quote:
Original post by alvaro
Cosine is naturally defined using radians. Your notation is fooling you. When you say cos(90-180/n), you actually mean cos((90-180/n)*Pi/180). What your limit is doing is extracting Pi from the definition of a degree, which is Pi/180.

By the way, cos(Pi/2-x)=sin(x).




That''s what I was afraid of. I thought there might be a way to change the definition of cos to make it take degrees, but I see now that that would put pi into the definition of cos.

Thanks for your help.

c+*

Share this post


Link to post
Share on other sites
the cosine function ONLY works with radians. people get it to wirk with degrees by multiplying by 180/pi

if you want pi, there are 2 incredibly easy ways to get it:

1) computers store numbers to at most about 20 significant figures so 3.1415926535897932384626433832795 (from windows calculator) is as accurate as you're ever going to need

2) the processor stores it internally:
double pi;
__asm {
fldpi
fstp qword ptr pi
}

********


A Problem Worthy of Attack
Proves It's Worth by Fighting Back

[edited by - walkingcarcass on October 2, 2002 5:51:07 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by walkingcarcass

if you want pi, there are 2 incredibly easy ways to get it:





I don''t care what pi specificaly is, and I know how to use the windows calculator. I just thought it would be cool to have an equation that could potentialy calculate pi exactly, even though it would take an infinite amount of time.

c+*

Share this post


Link to post
Share on other sites
quote:
Original post by cplusasterisk
[quote]Original post by KalvinB
Precalculate the values to an array size 360.

Ben




Precalculate them based on what, pi? I don''t want to use pi.


c+*

I think KalvinB meant to precalculate from 0 to 359 degrees. The clue was that the array size is 360, the same as the number of whole-number degrees in a circle. No pi anywhere in there. Just take your angle in degrees, cast to an integer, and use that as your array index. May be accurate enough.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post


Link to post
Share on other sites