Ask Your Question
0

decimal form of a unit converted answer

asked 12 years ago

anonymous user

Anonymous

updated 12 years ago

Shashank gravatar image

I was wondering what a good way might be to get a decimal answer when using units. For example, say I try

#define units
ft =  units.length.foot
m = units.length.meter
#add some lengths and output in ft
(3*ft + 4*m).convert(units.length.ft)

I get back

6143/381*foot

Now, suppose I'd rather see this represented as a decimal than a fraction (for homework, perhaps?). If I try

(3*ft + 4*m).convert(units.length.foot).n()

I get an error. This is occuring on Sage 4.8 for sure, and I'm pretty sure in Sage 5.0 as well.

Can anyone think of a good solution to this?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 12 years ago

Shashank gravatar image

It is better to write the units to convert in decimal form

#define units
ft =  units.length.foot
m = units.length.meter
#add some lengths and output in ft
(3.0*ft+4.0*m).convert(units.length.foot)
Preview: (hide)
link

Comments

wow, do i feel dumb. i can't believe it didn't occur to me to try that. thank you.

Arrgh_Jay gravatar imageArrgh_Jay ( 12 years ago )

Not dumb at all, especially if you haven't used that much yet. I would say that this still smells like a bug.

kcrisman gravatar imagekcrisman ( 12 years ago )
1

answered 12 years ago

Eviatar Bach gravatar image

updated 12 years ago

There is actually a way to do this; see here.

#define units
ft =  units.length.foot
m = units.length.meter
#add some lengths and output in ft
(3*ft + 4*m).convert(units.length.foot).polynomial(RR)

This returns

16.1233595800525*foot
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

Stats

Asked: 12 years ago

Seen: 1,070 times

Last updated: May 28 '12