How do I program the approximation to π devised by François Viète, which is given by
2 * 2/Sqrt[2] * 2/Sqrt[2 + Sqrt[2]] * 2/Sqrt[2 + Sqrt[2 + Sqrt[2]]] * ...
using some of these functions: Nest
, For
, Module
, Product
, Do
?
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityHow do I program the approximation to π devised by François Viète, which is given by
2 * 2/Sqrt[2] * 2/Sqrt[2 + Sqrt[2]] * 2/Sqrt[2 + Sqrt[2 + Sqrt[2]]] * ...
using some of these functions: Nest
, For
, Module
, Product
, Do
?
You could use
VietePiApprox[n_] := (Times @@ NestList[Sqrt[2 + #] &, Sqrt[2], n])/ 2^(n + 1)
SetAttributes[VietePiApprox, Listable]
which approximates Pi as follows.
N[VietePiApprox[Range[5]] - 2/\[Pi]]
{0.0166617, 0.00410909, 0.0010238, 0.000255735, 0.0000639204}
Well, FoldList
also can finish this job:
2/Times @@ (1/2 FoldList[Sqrt[2 + #] &, ConstantArray[Sqrt[2.], 10]])
By the way, by putting the one half just before NestList
, FoldList
can save one's effort for counting the number of twos in the denominators.
Clear[VietePiApprox];
VietePiApprox[n_] := Product[FunctionExpand[Cos[Pi/2^(i + 1)]], {i, 1, n}];
Table[VietePiApprox[i], {i, 1, 10}]
% - 2.0/Pi
{0.070487, 0.0166617, 0.00410909, 0.0010238, 0.000255735, \ 0.0000639204, 0.0000159792, 3.99476*10^-6, 9.98687*10^-7, 2.49671*10^-7}