How to resolve the algorithm Golden ratio/Convergence step by step in the Raku programming language
How to resolve the algorithm Golden ratio/Convergence step by step in the Raku programming language
Table of Contents
Problem Statement
The golden ratio can be defined as the continued fraction Thus
ϕ
1 +
1
/
ϕ
{\displaystyle \phi =1+{1/\phi }}
. Multiplying both sides by
ϕ
{\displaystyle \phi }
and solving the resulting quadratic equation for its positive solution, one gets
ϕ
( 1 +
5
)
/
2 ≈ 1.61803398875
{\displaystyle \phi =(1+{\sqrt {5}})/2\approx 1.61803398875}
. The golden ratio has the slowest convergence of any continued fraction, as one might guess by noting that the denominators are made of the smallest positive integer. This task treats the problem of convergence in a somewhat backwards fashion: we are going to iterate the recursion
ϕ
n + 1
= 1 +
1
/
ϕ
n
{\displaystyle \phi _{n+1}=1+{1/\phi _{n}}}
,
ϕ
0
= 1
{\displaystyle \phi _{0}=1}
, and see how long it takes to get an answer.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Golden ratio/Convergence step by step in the Raku programming language
Source code in the raku programming language
constant phi = 1.FatRat, 1 + 1/* ... { abs($^a-$^b)≤1e-5 };
say "It took {phi.elems} iterations to reach {phi.tail}";
say "The error is {{ ($^a - $^b)/$^b }(phi.tail, (1+sqrt(5))/2)}"
You may also check:How to resolve the algorithm Snake step by step in the C programming language
You may also check:How to resolve the algorithm GUI component interaction step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Compiler/lexical analyzer step by step in the ATS programming language
You may also check:How to resolve the algorithm Arithmetic evaluation step by step in the Delphi programming language
You may also check:How to resolve the algorithm Shell one-liner step by step in the Sidef programming language