Ask Your Question
0

An infinite continued fraction of $x^n$

asked 2023-11-18 18:40:32 +0100

hbghlyj gravatar image

I coded in SageMath to compute the 50th convergent of $f(x)$ and plot for integers $x=1,\dots,50$:

def f(x, n_terms):
    result = []
    for i in range(n_terms):
        result.extend([x**i, x**i])
    return continued_fraction([0] + result).n()

list_plot(([f(x,50) for x in range(1,50)]), title='$f(x)=\\dfrac{x}{x+\\dfrac{x^2}{x^2+\\dfrac{x^3}{x^3+\\ddots}}}$')

My question is to make a continuous plot of $f(x)$. I have difficulty in that continued_fraction only support integer values of $x$.

edit retag flag offensive close merge delete

Comments

Your function f cannot be evaluated at non-integer values x since continued_fraction() expects a list with integer elements. Hence, f (as defined) is not a continuous function and cannot be plotted as such. Do you mean a continuous interpolation of f from its values at integer points or something else?

Max Alekseyev gravatar imageMax Alekseyev ( 2023-11-18 21:52:25 +0100 )edit

Yes, the built-in function continued_fraction() expects a list of integers, but I want to compute $$f(x)=\cfrac{x}{x+\cfrac{x^2}{x^2+\cfrac{x^3}{x^3+\cdots}}}$$ $f$ is a continuous function for real number $x>1$. Does SageMath have built-in function to compute continued fractions of real numbers?

hbghlyj gravatar imagehbghlyj ( 2023-11-19 00:50:53 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-11-19 05:35:14 +0100

Max Alekseyev gravatar image

Your generalized continued fraction can be reduced to the conventional one: $[0;1,1,x,x,x^2,x^2,\dots]$ Correspondingly, it can be computed for arbitrary $x$ via continuants, and then plotted as in the following code:

def g(x, n_terms):
    X = sum( ([x^i,x^i] for i in range(n_terms)), [])
    return continuant([0]+X) / continuant(X)

import functools
plot( functools.partial(g,n_terms=50), (1,50) )
edit flag offensive delete link more

Comments

The code throws error:

verbose 0 (3935: plot.py, generate_plot_points) WARNING: When plotting, failed to evaluate function at 198 points.
verbose 0 (3935: plot.py, generate_plot_points) Last error message: 'Unable to compute f(50.0)'
hbghlyj gravatar imagehbghlyj ( 2023-11-19 11:21:45 +0100 )edit

It's still plotting, isn't it? This is what I see in Sagecell: https://sagecell.sagemath.org/?q=vbtqxm The issue is in computing the function for large arguments as I understand.

Max Alekseyev gravatar imageMax Alekseyev ( 2023-11-19 12:32:40 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-11-18 18:40:32 +0100

Seen: 114 times

Last updated: Nov 19 '23