clear all;
digits(30);
% 割圆法 pi = 6*2^(n+1)*S(n+1)=3*2^n*a(n), a(n)为边长
n = 10;
syms a;
for i = 1:n
a = sqrt(2-sqrt(4-a^2));
end
a = subs(a,'a','1');
pi1 = 3*2^n*vpa(a,n+5)
k = 20000;
%级数法 pi = 1-1/3+1/5+...+(-1)^(n-1)/(2n-1)+...
for n=1:k
b(n)=(-1)^(n-1)/(2*n-1);
end
pi2 = 4*sum(b)
%machin 公式 pi/4 = 4*atan(1/5)-atan(1/239)
k = 1000;
for n=1:k
c(n)=(-1)^(n-1)*(1/2)^(2*n-1)/(2*n-1) + (-1)^(n-1)*(1/3)^(2*n-1)/(2*n-1);
end
pi3 = vpa(4*sum(c))
pi1 =
3.14159251669215743884323213716
pi2 =
3.141542653589825
pi3 =
3.14159265358979222781954376842