How to resolve the algorithm Continued fraction step by step in the Axiom programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Continued fraction step by step in the Axiom programming language
Table of Contents
Problem Statement
The task is to write a program which generates such a number and prints a real representation of it. The code should be tested by calculating and printing the square root of 2, Napier's Constant, and Pi, using the following coefficients: For the square root of 2, use
a
0
= 1
{\displaystyle a_{0}=1}
then
a
N
= 2
{\displaystyle a_{N}=2}
.
b
N
{\displaystyle b_{N}}
is always
1
{\displaystyle 1}
. For Napier's Constant, use
a
0
= 2
{\displaystyle a_{0}=2}
, then
a
N
= N
{\displaystyle a_{N}=N}
.
b
1
= 1
{\displaystyle b_{1}=1}
then
b
N
= N − 1
{\displaystyle b_{N}=N-1}
. For Pi, use
a
0
= 3
{\displaystyle a_{0}=3}
then
a
N
= 6
{\displaystyle a_{N}=6}
.
b
N
= ( 2 N − 1
)
2
{\displaystyle b_{N}=(2N-1)^{2}}
.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Continued fraction step by step in the Axiom programming language
Source code in the axiom programming language
get(obj) == convergents(obj).1000 -- utility to extract the 1000th value
get continuedFraction(1, repeating [1], repeating [2]) :: Float
get continuedFraction(2, cons(1,[i for i in 1..]), [i for i in 1..]) :: Float
get continuedFraction(3, [i^2 for i in 1.. by 2], repeating [6]) :: Float
(1) 1.4142135623 730950488
Type: Float
(2) 2.7182818284 590452354
Type: Float
(3) 3.1415926538 39792926
Type: Float
cf(initial, a, b, n) ==
n=1 => initial
temp := 0
for i in (n-1)..1 by -1 repeat
temp := a.i/(b.i+temp)
initial+temp
cf(1, repeating [1], repeating [2], 1000) :: Float
cf(2, cons(1,[i for i in 1..]), [i for i in 1..], 1000) :: Float
cf(3, [i^2 for i in 1.. by 2], repeating [6], 1000) :: Float
You may also check:How to resolve the algorithm Averages/Median step by step in the Ada programming language
You may also check:How to resolve the algorithm Comments step by step in the Lilypond programming language
You may also check:How to resolve the algorithm Number reversal game step by step in the Java programming language
You may also check:How to resolve the algorithm Polymorphism step by step in the Factor programming language
You may also check:How to resolve the algorithm Multiple distinct objects step by step in the Haskell programming language