First time here? Check out the FAQ!

Ask Your Question
0

sqaure root type

asked 13 years ago

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

Preview: (hide)

Comments

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

DSM gravatar imageDSM ( 13 years ago )

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

Menny gravatar imageMenny ( 13 years ago )

4 Answers

Sort by » oldest newest most voted
2

answered 13 years ago

parzan gravatar image

updated 13 years ago

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]
Preview: (hide)
link

Comments

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

Jason Grout gravatar imageJason Grout ( 13 years ago )

You can also get an numeric approximation:

Jason Grout gravatar imageJason Grout ( 13 years ago )
1

answered 13 years ago

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

Preview: (hide)
link
1

answered 13 years ago

Shashank gravatar image

This should do it.

sqrt(2.0) %1
Preview: (hide)
link

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 ( 13 years ago )

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

parzan gravatar imageparzan ( 13 years ago )
0

answered 13 years ago

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

Preview: (hide)
link

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: 13 years ago

Seen: 576 times

Last updated: Dec 23 '11