Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica: Recursive expression

  1. Jun 13, 2013 #1

    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 [itex]a_n= n[/itex] for simplicity. My fraction is in principle infinite, but I am trying to construct a function which can find [itex]F[/itex] for a given [itex]n[/itex] recursively. I haven't had much success. So far I have

    which is the last term for a given [itex]n[/itex]. For do I propagate all the way up to [itex]a_1[/itex] then?
  2. jcsd
  3. Jun 14, 2013 #2
  4. Jun 18, 2013 #3


    User Avatar
    Gold Member

    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?
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Similar Threads for Mathematica Recursive expression
Mathematica Storing Mathematica output
Mathematica Mathematica to MATLAB
Mathematica Cannot do the integral of the Hyper-geometric function?
Mathematica Cannot Plot This Function in Mathematica
Mathematica While Loop in Mathematica