Given an Archimedes' scheme
$$a_{n+1}=\frac{2a_nb_n}{a_n+b_n}$$ $$b_{n+1}=\sqrt{a_{n+1}b_n}$$
with initial values $a_0=2\sqrt{3},b_0=3.$
How do I prove using Mathematica that this converges to $\pi$?
My attemp is to use RSolve
or RSolveValue
. But my when I input
RSolve[{a[n + 1] == 2 a[n] b[n]/(a[n] + b[n]),
b[n + 1] == Sqrt[a[n + 1] b[n]], a[0] == 2 Sqrt[3],
b[0] == 3}, {a[n], b[n]}, n]
It gives an output the same as input
RSolve[{a[1 + n] == (2 a[n] b[n])/(a[n] + b[n]),
b[1 + n] == Sqrt[a[1 + n] b[n]], a[0] == 2 Sqrt[3],
b[0] == 3}, {a[n], b[n]}, n]
What is wrong here?
Answer
You should use RecurrenceTable
:
N@RecurrenceTable[{a[n + 1] == 2 a[n] b[n]/(a[n] + b[n]),
b[n + 1] == Sqrt[a[n + 1] b[n]], a[0] == 2 Sqrt[3],
b[0] == 3}, {a[n], b[n]}, {n, 1, 10}]
N@Pi
with result:
{{3.21539, 3.10583}, {3.15966, 3.13263}, {3.14609, 3.13935}, {3.14271, 3.14103}, {3.14187, 3.14145}, {3.14166, 3.14156}, {3.14161, 3.14158}, {3.1416, 3.14159}, {3.14159, 3.14159}, {3.14159, 3.14159}}
3.14159
You can also change the number of digit, with N[expr,n]
(n
is the desired number of digits). See documentation.
EDIT Following @RunnyKine suggestion:
RecurrenceTable[{a[n + 1] == 2. a[n] b[n]/(a[n] + b[n]),
b[n + 1] == Sqrt[a[n + 1] b[n]], a[0] == 2. Sqrt[3.],
b[0] == 3.}, {a[n], b[n]}, {n, 1, 20}]
is much faster (on my laptop, AbsoluteTiming
gives 0.5 sec for the first version and 0.01 for the second)
Comments
Post a Comment