Ask Your Question
0

sqaure root type

asked 2011-12-20 16:04:47 +0100

Menny gravatar image

I guess this is a very simple question:

What changes do I need to make in order to make

sage: sqrt(2) %1

work?

Also, what chapter in the manual I need to read in order not to ask such basic questions again??

Thanks a lot, Menny

edit retag flag offensive close merge delete

Comments

What are you hoping to get? 0.414.. etc?

DSM gravatar imageDSM ( 2011-12-20 16:11:54 +0100 )edit

Yes. when you write the code above you get an error regarding the type of the objects.

Menny gravatar imageMenny ( 2011-12-21 08:07:05 +0100 )edit

4 Answers

Sort by ยป oldest newest most voted
2

answered 2011-12-21 17:02:04 +0100

parzan gravatar image

updated 2011-12-21 17:10:09 +0100

In general if x % 1 fails (for x which is real) you can try RR(x) % 1 or RR(x).frac().

Note also that %1 and .frac() are different:

sage: RR(sqrt(3)) % 1
-0.267949192431123
sage: RR(sqrt(3)).frac()
0.732050807568877

I guess you want the latter. Actually %1 is a bit weird:

sage: [RR((2*k+1)/2)%1 for k in range(10)]
[0.500000000000000, -0.500000000000000, 0.500000000000000, -0.500000000000000, 0.500000000000000, -0.500000000000000, 0.500000000000000, -0.500000000000000, 0.500000000000000, -0.500000000000000]
edit flag offensive delete link more

Comments

You can also get an numeric approximation: sqrt(2).n() % 1

Jason Grout gravatar imageJason Grout ( 2011-12-22 00:37:16 +0100 )edit

You can also get an numeric approximation:

Jason Grout gravatar imageJason Grout ( 2011-12-22 00:37:16 +0100 )edit
1

answered 2011-12-21 07:41:17 +0100

If you want a very basic stuff, then go for the sage tour.

For the documentation I guess "How do I..." manual and the tutorial section are really important to get an overview of the basics in a particular area.

Further you can start writing small codes in an area of your choice, by taking help from reference manual. (IMHO, the reference manual is quite complicated to understand for a person who is newbie to sage or python.)

Lastly, this forum plus the mailing list on google groups are quite useful places...

Hope this helps...

With best wishes,

VInay

edit flag offensive delete link more
1

answered 2011-12-20 16:17:35 +0100

Shashank gravatar image

This should do it.

sqrt(2.0) %1
edit flag offensive delete link more

Comments

It works. But I'm having similar problems when I, for example, take x to be some complex number, and y=x.real_part. Then, y%1 return a type error... where do I found how to deal with these errors?

Menny gravatar imageMenny ( 2011-12-21 08:13:06 +0100 )edit

Did you really use y=x.real_part ? You need y=x.real_part()

parzan gravatar imageparzan ( 2011-12-21 16:09:29 +0100 )edit
0

answered 2011-12-23 03:05:48 +0100

By the way there is one more place to get basics of sage: You can logon to the sagenb.org and view the published sheets.

e.g. Here is an example of one by William Stein

There are many other... Keep exploring...

-- VInay

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: 2011-12-20 16:04:47 +0100

Seen: 540 times

Last updated: Dec 23 '11