Decimal form of a unit converted answer

30 views
Skip to first unread message

Justin

unread,
May 20, 2012, 3:15:18 AM5/20/12
to sage-s...@googlegroups.com
I was wondering what a good way might be to get a decimal answer when using units. For example, say I try

For example, say I do

#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

Awesome! However, suppose I'd rather see this represented as a decimal than a fraction. 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.

Does anyone know why this is doing this or how I might better ask Sage to give me a decimal answer of converted units?


Thank you in advance,


Justin

Justin

unread,
May 21, 2012, 12:28:20 AM5/21/12
to sage-s...@googlegroups.com
It turns out the solution is quite simple. (I feel stupid for not figuring this one out on my own) In order to get an answer in decimal form, all i have to do is...

   #define units
   ft =  units.length.foot
   m = units.length.meter
   
   #add some lengths and convert to ft
   (3.0*ft + 4.0*m).convert(units.length.foot)

This gives

   16.1233595800525*foot

Haha. Silly me.

Also, say pi was a part of my length. I'd just do something like

   (4.0*(pi.n())*ft + 5.0*m).convert(units.length.foot)


Justin
Reply all
Reply to author
Forward
0 new messages