Continued fractions is an alternative representation of numbers that has interesting properties for on-demand arbitrary precision while avoiding intermediary rounding errors.
Questions tagged [continued-fractions]
33 questions
1
vote
1 answer
Recursively generate LaTeX expression for continued fractions for a given python list
I am trying to generate LaTeX string expression for continued fractions in Jupyter Notebook.
for example, a given Python list x=[1,2,3,4,5] can be written as continued fraction:
Structure expression to generate this LaTeX fraction is…

Rajesh Swarnkar
- 601
- 1
- 6
- 18
1
vote
2 answers
The sum of a sequence
I'm trying to make a function for calculating this formula
#include
#include
double Sequence(std::vector < double > & a) {
double result = 0;
for (int i = a.size() - 1; i > 0; i--) {
if (a[i] == 0) throw…

Rocket Procd
- 103
- 10
1
vote
1 answer
Continued fraction natural logarithm(number of iterations needed to calculate right logarithm)
I have problem with my continued fraction algorithm for natural logarithm. I need to calculate natural logarithm for example ln(0.31) with accuracy on 1e-6 in 6 iterations, my algorithm will do it in 8.
This is my…

Marklar
- 21
- 1
- 8
1
vote
1 answer
matlab code for golden ratio continued fraction
I'm trying to write a Matlab function that computes how many terms, m, it takes the golden fraction to get to n digits of accuracy. Here is what I have so far, but I keep getting an output of 0.
phi = (1+sqrt(5))/2;
p=1;
p=[1+1/p];
LoopCounter =…

kettlebar
- 13
- 3
1
vote
2 answers
Continued Fraction to Fraction Malfunction
I've been working on Project euler Problem 57 (Love the site!). For this problem a conversion is required between a finite continued fraction and a normal fraction. I devised an algorithm that basically takes the inverse of the last number in a…

Sebastian Garrido
- 311
- 3
- 12
0
votes
1 answer
I'm getting a segmentation fault error in my program, but it is unclear how
From my understanding of segmentation faults, they occur when you try to access memory outside of the "space" of the program. My IDE says the exception occurs within in the first for loop where I perform the following operation: pi = w + i * i; I…

LoopGod
- 67
- 5
0
votes
1 answer
scheme, continued-fraction, tail-recursion
As a scheme-newbie I'm trying to solve some basic problems.
One of them are continued fractions, which I like to realize both ways, recursively and via tailrecursion.
My recursive soloution (d and n are functions and k is the…

Peer
- 1
- 1
0
votes
1 answer
Approximating pi using Recursion in Matlab
I am supposed to approximate pi by using the continued fraction below in the link using recursion in Matlab. I am new to recursion and am unsure how to keep getting the fraction to repeat…

Sarah Tate
- 13
- 2
0
votes
0 answers
Rcpp: continued fractions and precision
I am struggling about floating points in Rcpp and how to get the numeric output from continued fractions in a numeric vector.
Here is my demo code:
library(Rcpp)
cppFunction('NumericVector signC() {
NumericVector out1(3);
…

Joanna
- 663
- 7
- 21
0
votes
1 answer
I am trying to calculate this continued fraction but i cant seem to work, the program however can be compiled properly but crashes while it works
Im trying to get this program working as it requires to calculate continued fraction inputed in a linked list. the programme doesn't show any error however it always crashes in the middle. Can someone help me?
The task is simply to store the…

navesaurus
- 9
- 2
0
votes
2 answers
working with large numbers in the fraction module in Python
EDIT: solved but since the solution was in the comments and I cant accept my own solution reffering to the comment till tomorrow it is still open. Once again a big thank you to this great community and its people
optional context: I am computing…

Ilovescience
- 133
- 2
- 8
0
votes
1 answer
solution of Pell equation with continued fraction
we know that Pell equation is expressed as
which in case of D is not perfect square, can be approximated by continued fraction expansion of D, for instance let us consider such kind of equation
square root of 61 can be approximated by …
user466534
0
votes
1 answer
Cannot understand how we can give a procedures as actual parameter when formal parameters are used as values in scheme?
In SICP exercise 1.37
Section 1.3.3 in SICP Scroll Down to the end of section (just before 1.3.4) to find the exercise [3rd exercise in the section].
According to the problem, I defined cont-frac as
(define (cont-frac n d k)
(if (= k 0)
…

Tarun Maganti
- 3,076
- 2
- 35
- 64
0
votes
0 answers
Project Euler 57, Run-time error
I'm currently working in Probelm 57 in Project Euler:
https://projecteuler.net/problem=57
My problem is that whilst I believe the correct answers are being given the counting of the digits appears to be incorrect. I am unsure on what the error could…

Tujamo
- 93
- 8
0
votes
1 answer
Continued Fractions Solving
Here's what I thought of so far which works for 2 elements in the array.
the elements in the array are the variables to be plugged in to the continued fraction.
double continuedFraction(int a[], int size)
{
double fraction = a[0];
for(int…

What
- 73
- 1
- 6