On Jul 13, 2009, at 6:18 AM, mac8090 wrote:

> Hi
>
> A recent calculation I made in Sage (version 3.4) gave me a matrix
> where each value was out by a decimal less than 10 x e-16 or e-17. I
> have two questions:
>
> 1. Is this a usual rounding error in sage or is there an error in my
> calculations? I didn't notice anything to do with rounding when I was
> working on it...

It's hard to say without knowing what your command was. It looks like  
you were doing something (implicitly or not) with floating point  
numbers, which can't be represented exactly, and 1e-16 is right  
around the epsilon for 53 bits.

>
> 2. Is there a "to the nearest integer" function in sage?

Yes, it's called round. To apply it to a matrix, do

sage: M = 10*random_matrix(RDF, 5); M

[ -5.12057996112  -1.18558673015  -8.62681125402  -4.19334191959   
-2.69635031494]
[ -1.65132436947   6.00272384105 0.0525154143363   9.99220598131  
-0.367812414154]
[-0.493904318978   2.12394741901  -6.76880905277   7.20254867925    
4.33416154842]
[  4.91500541626   4.89832445795   4.06135308986  -7.02727771047    
5.28671949449]
[  7.29758622618 -0.937496140943  -3.94546308704   1.14468826409    
8.83196271569]
sage: M.apply_map(round)

[-5.0 -1.0 -9.0 -4.0 -3.0]
[-2.0  6.0  0.0 10.0  0.0]
[ 0.0  2.0 -7.0  7.0  4.0]
[ 5.0  5.0  4.0 -7.0  5.0]
[ 7.0 -1.0 -4.0  1.0  9.0]
sage: M.apply_map(round).change_ring(ZZ)

[-5 -1 -9 -4 -3]
[-2  6  0 10  0]
[ 0  2 -7  7  4]
[ 5  5  4 -7  5]
[ 7 -1 -4  1  9]


- Robert


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to