8
$\begingroup$

$$\varphi+\cfrac{1}{\varphi^{-1}+\cfrac{1}{\varphi+\cfrac{1}{\varphi^{-1}+\cfrac{1}{\varphi+\cdots}}}}$$

I saw this continued fraction on Facebook. I need the Mathematica code for this using continued fraction or Nest or Fold. Normal continued fraction code is not working for me, as I am new to Mathematica. Looking for help in this, Thanks in advance.

$\endgroup$
0

5 Answers 5

15
$\begingroup$

You can use ContinuedFractionK[] for this:

φ + ContinuedFractionK[1, φ^(1 - 2 Boole[Mod[k, 2] == 1]), {k, n}] 

Greg Martin suggests the simpler expression

φ + ContinuedFractionK[1, φ^((-1)^k), {k, n}] 

An exercise for the motivated reader is to prove that this is equivalent to the simpler

(Fibonacci[n + 2] φ)/Fibonacci[n + 1] 
$\endgroup$
2
  • 2
    $\begingroup$ φ^(1 - 2 Boole[Mod[k, 2] == 1]) is unnecessarily complicated; φ^(1 - 2 Mod[k, 2]) works just as well, as does φ^((-1)^k). $\endgroup$ Commented May 17, 2020 at 19:40
  • $\begingroup$ Indeed, thank you @Greg. I thought about φ^((-1)^k) only quite a while after writing this answer. $\endgroup$ Commented May 18, 2020 at 1:52
9
$\begingroup$
z = Defer /@ {-1, ""}; φ + Nest[1/(φ^Last[z = RotateLeft[z]] + #) &, …, 5] 

enter image description here

z = Defer /@ {Style[-1, 14], ""}; Style[φ + Nest[1/(φ^Last[z = RotateLeft@z] + #) &, …, 5], 32, ScriptSizeMultipliers -> 1] 

enter image description here

Alternatively,

z = φ^(Defer /@ {Style[-1, 14], ""}); i = 1; Style[φ + Nest[1/(z[[Mod[i++, 2, 1]]] + #) &, …, 5], 32, ScriptSizeMultipliers -> 1] 

enter image description here

$\endgroup$
0
6
$\begingroup$

You can use Fold[] for this (an example from Documentation Center):

ϕ + Fold[1/(#2 + #1) &, ϕ, Reverse[Table[ϕ^(1 - 2 Boole[Mod[k, 2] == 1]), {k, 1, 7}]]] 
$\endgroup$
0
2
$\begingroup$

You can use Solve to find the value of this continued fraction by noticing that it satisfies a recursion relation:

$$ x = \varphi + \frac{1}{\varphi^{-1}+\frac{1}{x}} $$

Solve[x == φ + 1/(φ^-1 + 1/x), x] // FullSimplify (* {{x -> -1/2 (-1 + Sqrt[5]) φ}, {x -> 1/2 (1 + Sqrt[5]) φ}} *) % /. φ -> GoldenRatio // FullSimplify (* {{x -> -1}, {x -> 1/2 (3 + Sqrt[5])}} *) 

The first of these solutions is an unstable fixed point and the second is a stable fixed point. So in reality only the second of these solutions represents the limit of an infinite continued fraction.

Stability analysis: by setting

$$ x_{n+1} = \varphi + \frac{1}{\varphi^{-1}+\frac{1}{x_n}} $$

we see that

$$ \frac{dx_{n+1}}{dx_n} = \frac{\varphi^2}{(\varphi+x_n)^2} $$

which for the first solution gives

D[φ + 1/(φ^-1 + 1/x), x] /. x -> -1/2 (-1 + Sqrt[5]) φ // FullSimplify (* 1/2 (7 + 3 Sqrt[5]) *) 

(magnitude is larger than 1, so unstable) and for the second solution gives

D[φ + 1/(φ^-1 + 1/x), x] /. x -> 1/2 (1 + Sqrt[5]) φ // FullSimplify (* 4/(3 + Sqrt[5])^2 *) 

(magnitude is smaller than 1, so stable).

$\endgroup$
1
  • $\begingroup$ The result of GoldenRatio^2 is consistent with the closed form in my answer, if φ is taken as GoldenRatio, and $n \to \infty$. $\endgroup$ Commented May 17, 2020 at 8:42
0
$\begingroup$

Since no one else has put it out here and I'm not 100% clear from The Question that FromContinuedFraction is disallowed or just not working as the OP expects.

FromContinuedFraction[{{GoldenRatio, GoldenRatio^-1}}] 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.