Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
0

An infinite continued fraction of xn

asked 1 year ago

hbghlyj gravatar image

I coded in SageMath to compute the 50th convergent of f(x) and plot for integers x=1,,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.

Preview: (hide)

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 ( 1 year ago )

Yes, the built-in function continued_fraction() expects a list of integers, but I want to compute f(x)=xx+x2x2+x3x3+ 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 ( 1 year ago )

1 Answer

Sort by » oldest newest most voted
0

answered 1 year ago

Max Alekseyev gravatar image

Your generalized continued fraction can be reduced to the conventional one: [0;1,1,x,x,x2,x2,] 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) )
Preview: (hide)
link

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 ( 1 year ago )

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 ( 1 year ago )

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: 1 year ago

Seen: 161 times

Last updated: Nov 19 '23