Mistake in recursive algorithm

I am new to Wolfram, and I am trying to make a recursive Archimedes algorithm in Wolfram.

I read documentation and I tried to run this code

RSolve[{ a[n + 1] == 2^n Sqrt[2 (1 - Sqrt[1 - (a[n]/2^n)^2])], a[1] == 2}, a[n], n]
Table[a[n] /. First[%], {n, 10}]


But instead of a table like if the first line was RSolve[{a[n] == 2 a[n - 1], a[1] == 1}, a[n], n] I have lots of errors

ReplaceAll::reps: {a[2]==2 Sqrt[2] Sqrt[1-Sqrt[Plus[<<2>>]]],a[1]==2} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.


Can somebody help me, where is the error?

The issue is that the recurrence equation has no explicit formula. Hence you get back an unevaluated RSolve and the First of that is the original recurrence equation and not the formula.

If you change the function from RSolve to RecurrenceTable then you will directly get the list of solutions.

RecurrenceTable[{a[n + 1] == 2^n Sqrt[2 (1 - Sqrt[1 - (a[n]/2^n)^2])], a[1] == 2}, a[n], {n, 10}]


One way to solve your recursion is to define:

a[n_] := a[n] = 2^(n - 1) Sqrt[2 (1 - Sqrt[1 - (a[n - 1]/2^(n - 1))^2])];
a[1] = 2;


Then you can get the first 4 values using Table[a[i],{i,4}] or

a[#] & /@ Range[4]

• Thank you very much, yes, it is working. But still where is a mistake in my code, I thought I did everything the same way as in examples? Commented Oct 6, 2019 at 21:39
• simpler: Array[a,4]. Commented Oct 7, 2019 at 1:22
• Or a /@ Range[4]. Commented Oct 7, 2019 at 14:24