Respuesta :
The question is incomplete! The complete question along with Matlab code and explanation is provided below!
Question:
The value of pi can be estimated by: √6*∑1/n² from n=1 to n=∞
Write a program (using a loop) that determines the expression. Run the program with n= 1:10, n=1:1,000, n= 1:100,000. Compare the results with pi function. (use Format long)
Explanation:
We implemented a summation series that approximates the value of pi. The value of pi approaches to the real value of pi as n gets larger. we calculated the value of pi using a for loop with n= 10, n=1,000, and n= 100,000 then compared this value with the value of built-in function of Maltab pi. The results are discussed below.
Matlab Code:
format long
n = 100000;
sum = 0;
for k=1:n
sum = sum + 1/k^2;
end
value = sqrt(6*sum)
pi
diff = pi - value
Output:
For n = 10:
pi = 3.141592653589793
value = 3.049361635982070
diff = 0.092231017607723
For n = 100:
pi = 3.141592653589793
value = 3.140638056205995
diff = 0.000954597383798
For n = 100,000:
pi = 3.141592653589793
value = 3.141583104326456
diff = 0.000009549263336
As you can see the difference between real and calculated value of pi is quite large for n = 10 but the difference is very small for n = 100,000. The calculated value is correct up to 4 decimal digits for n = 100,000.