Ask Your Question
1

How to import functions to program?

asked 2018-12-19 21:26:09 +0100

trrrrrr gravatar image

updated 2019-08-26 21:18:00 +0100

FrédéricC gravatar image

Hello, Sory for stupid question. Im new to sage and I would like to import a class/base that will allow me to use convergent() and numerator() functions. How could I do that?

I found class sage.rings.continued_fraction.ContinuedFraction_base Bases: sage.structure.sage_object.SageObject

However when trying something like import, it doesn't work ..

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2018-12-20 00:05:54 +0100

slelievre gravatar image

Here is an example:

sage: a = 26 / 7
sage: c = continued_fraction(a)
sage: c
[3; 1, 2, 2]

From there one can explore the convergents:

sage: c.convergent(0)
3
sage: c.convergent(1)
4
sage: c.convergent(2)
11/3
sage: c.convergent(3)
26/7

The numerator and denominator of a convergent can be called using the methods numerator and denominator or p and q.

sage: c.numerator(2)
11
sage: c.denominator(2)
3
sage: c.p(2)
11
sage: c.q(2)
3

One can also start from a list:

sage: c = continued_fraction([3, 1, 2, 2])
sage: c
[3; 1, 2, 2]

etc.

edit flag offensive delete link more

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: 2018-12-19 21:26:09 +0100

Seen: 305 times

Last updated: Dec 20 '18