The following algorithm is found on a web page* for
computing pi:
• step 1. Set a = 1, b = 1/sqrt(2), t = 1/4 and x = 1
• step 2. Repeat the following commands until the
difference between a and b is within some desired
accuracy (for example 1.0e-8):
y = a;
a = (a + b)/2;
b = sqrt(b*y);
t = t - x*(y - a)^2;
x = 2*x;
step 3. From the resulting values of a, b and t, an
estimate of pi is
pi_est = ((a + b)^2)/(4*t);
How many repeats are needed to estimate pi to an
accuracy of or ?
Using the tic and toc function to record the elapsed time
of this algorithm.
(tips: you can use vpa(pi,n) function to get more accurate
pi value with n digits. For example, vpa(pi,30) =
3.14159265358979323846264338328 )