Mathematica Mathematica: Recursive expression

AI Thread Summary
The discussion revolves around constructing a recursive function to evaluate the fraction F = a1 / (1 + a2 / (1 + a3 / (1 + a4))) where an = n for simplicity. The user is seeking an efficient method to compute F for a given n, acknowledging that the fraction is conceptually infinite. Initial attempts include defining a function f[n] that returns n and a recursive structure to propagate values upward from the last term. The conversation includes references to Mathematica code snippets intended to build the continued fraction, with a focus on whether the proposed functions effectively achieve the desired recursive evaluation of F. The main challenge lies in correctly propagating values through the recursive structure to compute F accurately.
Niles
Messages
1,834
Reaction score
0
Hi

I am trying to find a smart way to write the following fraction,

$$
F = \frac{a_1}{1+\frac{a_2}{1+\frac{a_3}{1+a_4}}}
$$

Here we can just take a_n= n for simplicity. My fraction is in principle infinite, but I am trying to construct a function which can find F for a given n recursively. I haven't had much success. So far I have

f[n_] := n;
f[n - 1]/(1 + f[n])

which is the last term for a given n. For do I propagate all the way up to a_1 then?
 
Physics news on Phys.org
Code:
f[1] = Subscript[a, 1];

f[n_] := (f[n - 1]) /.Subscript[a, n - 1] :> Subscript[a, n - 1]/(1 + Subscript[a, n])
Does that work?
 

Similar threads

Replies
4
Views
2K
Replies
1
Views
2K
Replies
3
Views
2K
Replies
2
Views
2K
Replies
5
Views
2K
Replies
3
Views
2K
Replies
2
Views
2K
Back
Top