1
$\begingroup$

In Mathematica, is it possible to form the continued fraction of the following formula? $$ f = a_1+\cfrac{b_1}{a_1+a_2+\cfrac{b_2}{a_2+a_3+\cfrac{b_3}{a_3+a_4+\cfrac{b_4}{a_4+...}}}} $$

$\endgroup$
5
  • 1
    $\begingroup$ You are looking for Fold? $\endgroup$
    – xzczd
    Jan 6, 2016 at 7:43
  • $\begingroup$ @halirutan I read this post before, it's not what I need though. $\endgroup$
    – Tony Dong
    Jan 6, 2016 at 7:57
  • $\begingroup$ Tony, please explain how your situation is different. It looks similar on the surface. $\endgroup$
    – Mr.Wizard
    Jan 6, 2016 at 7:58
  • $\begingroup$ Related: (39476) $\endgroup$
    – Mr.Wizard
    Jan 6, 2016 at 8:03
  • $\begingroup$ thanks @Mr.Wizard, let me check first, it does look similar~ $\endgroup$
    – Tony Dong
    Jan 6, 2016 at 8:11

1 Answer 1

5
$\begingroup$

Well, it is really simple with Fold

Fold[a[#2] + b[#2]/(a[#2] + #1) &, 0, Reverse[Range[6]]]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ For the updated question, I think you only have to modify this as Fold[a[#2] + b[#2]/(a[#2] + #1) &, (Range[10]~Join~{0}) // Reverse], I put the 0 in there so it doesn't have a constant in the terminal fraction. $\endgroup$
    – Jason B.
    Jan 6, 2016 at 8:20
  • $\begingroup$ @JasonB That's what I want. Thanks :) $\endgroup$
    – Tony Dong
    Jan 6, 2016 at 8:25

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