-1
$\begingroup$

How can I write Mathematica code for this continued fraction with alternating terms?

How can we generate this more general form of the above-continued fraction?

$$x+\cfrac{a}{y+\cfrac{a^2}{x+\cfrac{a^3}{y+\cfrac{a^4}{x+\cfrac{a^5}{y+\cfrac{a^6}{x+\cdots}}}}}}$$

$\endgroup$
1
  • $\begingroup$ Yes thank you so much for your help. $\endgroup$
    – Shivam K
    May 16 '20 at 20:26
6
$\begingroup$

Once again, you can use ContinuedFractionK[]:

With[{n = 7}, 
     x + ContinuedFractionK[a^k, Piecewise[{{y, Mod[k, 2] == 1}}, x], {k, 1, n}]]

$$x+\cfrac{a}{y+\cfrac{a^2}{x+\cfrac{a^3}{y+\cfrac{a^4}{x+\cfrac{a^5}{y+\cfrac{a^6}{x+\cfrac{a^7}{y}}}}}}}$$

$\endgroup$
4
$\begingroup$
z = {x, y};
i = 1;
n = 6;
Style[x + Nest[a^(n - i++)/(z[[Mod[i, 2, 1]]] + #) &, …, n - 1], 32,
  ScriptSizeMultipliers -> 1]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you very much. $\endgroup$
    – Shivam K
    May 16 '20 at 20:27

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