# Thread: Approximating PI using the Taylor Series - Help!

1. yes, I can clearly see that, but there is no explanation of how that formula does what std10093 says it does. are you calculating the absolute relative error of this instance only, or of floating point operations in general? all I see is a couple of strings of mathematical operations, with no reference to why they're appropriate in this case, or where they came from. I can't even google it without a little more context.

2. Oh, they're pretty standard for numerical calculations, and they make sense, too.
They are used in general to see how well your approximation compares to the real number. Obviously very important when approximating numbers to see that you actually don't get a half-baked approximation.
Approximation error - Wikipedia, the free encyclopedia

3. Elkvis these formulas come from the lesson numerical analysis of the theoretical informatics we study at DIT.As Elysia stated and you can see in the link,these formulas are in general and give the information i provided for an instance,not in general.The errors i posted were refering to the value you calculated by doing it 40 million times and for the actual value of π.However i would be very glad to see how the code that calculated this looks like.If you have problem posting it,you could send me a pm,please

4. pm sent

edit: and it was actually 40 billion times

5. Thank you very much.I appreciate it.Yes you are right about the billion

6. the taylor series is a really lousy approximation for pi though.
That specific instance is really bad.

Other forms of the "Taylor Series" work much better.

Soma

7. Originally Posted by phantomotap
That specific instance is really bad.

Other forms of the "Taylor Series" work much better.

Soma
Could you suggest one just to compare the results?

8. The one that I am familiar with is Pi/4 = 1 - 1/3 + 1/5 - 1/7 + ... with the denominators staying odd.

9. I tried what whiteflags said and got the following results :

with criterion to stop
Code:
while (current > 1.0e-10);
i had to calculate 1073741825 and π=3.14159
With the one i suggest before i calculated 100000 and got p=3,14158 (should be 3.14159..)

Then i changed the criterion to stop to
Code:
while (current > 1.0e-15);
and got the same results with whiteflags's formula as with the previous criterion(that was not expected)
and with the one i had suggested the result is
Code:
Summed 31622777 terms, pi is 3.14159
Of course i have no problem posting the code,but this post ,supposedly,is for a homework of someone(who has lost interest too soon how ever),so i would ask what are the results for you?

10. Not really sure what you're doing.
Code:
#include <iostream>
#include <sstream>
int main(int argc, char *argv[])
{
if (argc != 2)
{
std::cout << "Compute pi with the expansion of arctan 1\n";
std::cout << "usage: exe [terms]\n";
return 0;
}

std::stringstream args(argv[1]);
int terms;
args >> terms;
bool toggle = false;
double taylor = 1.0;
for (int i = 3; i < terms; i+=2)
{
if (toggle)
taylor += 1./i;
else
taylor -= 1./i;

toggle = !toggle;
}
double pi = 4 * taylor;
std::cout << pi << "\n";
}
// my output:
// 3.14139
With this I get 4 digits of precision after 10000 terms.

11. You get four digits precision you said with 100000,but you did not state if these are significant or decimal.I think you mean significant,if your output is that in line 30(with 10000 terms).
So i think that is clear that with your formula we have to calculate more terms to achieve the same precision as in 'my' formula.However your formula does less operations.But if we consider that the formula i posted has to calculate far less terms,i think that mine is better.

EDIT - > you may give me a cookie again

12. Could you suggest one just to compare the results?
I'm sorry. I actually can't.

What I know of this stuff comes from research about fast approximations, but it has been years since I read the paper.

I don't remember the exact numbers or anything, but I noticed it because it was orders of magnitude difference in calculations which obviously struck me as being very significant.

I'm sure they are only a search away in any event.

Probably something along the lines of "a faster Taylor series for pi".
[/Edit]

Soma

13. Originally Posted by phantomotap
I'm sorry. I actually can't.

What I know of this stuff comes from research about fast approximations, but it has been years since I read the paper.

I don't remember the exact numbers or anything, but I noticed it because it was orders of magnitude difference in calculations which obviously struck me as being very significant.

Soma
Oh,that's ok Whiteflags suggested a formula by the way

14. Originally Posted by std10093
EDIT - > you may give me a cookie again
I don't trust your research this time. You did not show your implementation and I don't know the significance of what I saw. After 1 million terms I definitely get something that looks like a lot like pi. You might want to experiment more to find the differences for yourself.

I don't care - would just do 4 * arctan(1.0) anyway.

15. Nobody ask for it.So no cookie this time.As for the arctan it is true.