# Mathematica: Recursive expression

1. Jun 13, 2013

### Niles

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

which is the last term for a given $n$. For do I propagate all the way up to $a_1$ then?

2. Jun 14, 2013

### Bill Simpson

3. Jun 18, 2013

### Hepth

Code (Text):

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?