Pi value estimation with series
Question
Here's my problem:
Compute the value of π using the following series:
((π^2)-8)/16=[sum from 1 to pos. infinity] 1/(((2n−1)^2)*((2n+1)^2))
• Find the smallest number of terms required to obtain an absolute value of the error on π smaller than 10e−8.
Here's my code:
x=0;
for i=1:1000
x=x+(1/((((2*i)-1)^2)*(((2*i)+1)^2)));
z=sqrt((x*16)+8);
error=abs(z-pi);
if (error < 10e-8)
i
break
end
end
The answer that I get is 81 when the loop breaks, but it is not the right answer. I have been trying to figure out what is wrong with my code that it doesn't do what I need.
I've been staring at the code for quite a while and cant see where I made a mistake.
Solution
I found the problem. The error is supposed to be less than 10^-8 not 10e-8. Somehow the numbers got changed over when copying.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow