1
$\begingroup$

I made a nested pure function

Nest[(x^2)/ ((2x+1) + #)&, x,n]

I would like that for each iteration the value of x increment of 1, to have something like

$$\frac{1^2}{\frac{3 + 2^2}{5 + ...}}$$

I'm wondering if this is possible?

$\endgroup$
4
  • 4
    $\begingroup$ What about Fold[#2^2/((2*#2+1)+#1)&,x,Range[5]//Reverse]? $\endgroup$
    – user293787
    Oct 8, 2022 at 19:44
  • 2
    $\begingroup$ Or include HoldForm, i.e., Fold[HoldForm[#2^2]/((2*#2 + 1) + #1) &, x, Range[5, 1, -1]] $\endgroup$
    – Bob Hanlon
    Oct 8, 2022 at 19:54
  • 1
    $\begingroup$ You guys are awesome, Thanks I didn't know Fold works like Nest. $\endgroup$ Oct 8, 2022 at 20:05
  • 1
    $\begingroup$ Hi. Here is a way using Nest : a = 5 + 1; Nest[(a -= 1 ; a^2/((2*a + 1) + #)) &, x, a - 1] $\endgroup$ Oct 8, 2022 at 22:27

2 Answers 2

1
$\begingroup$

You can use RecurrenceTable.

RecurrenceTable[
 {
  f[x] == (x^2)/((2 x + 1) + f[x - 1])
  , f[1] == 1/(1 + 3)
  }
 , f
 , {x, 3}]
{1/4, 16/21, 189/163}

Hope this helps.

$\endgroup$
1
$\begingroup$

I'd be tempted to implement this as a recursion:

f[x_] := f[x] = (x^2)/((2 x + 1) + f[x - 1]);
f[1] = 1/4;

Now to get the first 10 values:

f/@ Range[10]
$\endgroup$

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.