1
$\begingroup$

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?

$\endgroup$

2 Answers 2

1
$\begingroup$

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}]

enter image description here

$\endgroup$
1
$\begingroup$

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]
$\endgroup$
3
  • $\begingroup$ 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? $\endgroup$ Commented Oct 6, 2019 at 21:39
  • $\begingroup$ simpler: Array[a,4]. $\endgroup$ Commented Oct 7, 2019 at 1:22
  • $\begingroup$ Or a /@ Range[4]. $\endgroup$
    – murray
    Commented Oct 7, 2019 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.