You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
It seems the __abs__ method for vectors is missing the part that is
supposed to square the components before they are added.
[e.g. abs(vector([1..5])) should really be
sqrt(1+4+9+16+25)=sqrt(55) ]
The code of the current version is included below.
def __abs__(self):
"""
Return the square root of the sum of the squares of the
entries of this vector.
EXAMPLES:
sage: v = vector([1..5]); abs(v)
sqrt(15)
sage: v = vector(RDF, [1..5]); abs(v)
3.87298334621
"""
return sum(self.list()).sqrt()
The last line should be something like
return sum([x*x for x in self.list()]).sqrt()
(not sure if that is the most efficient way).
--Peter
williamstein
changed the title
sage/modules/free_module_element.pyx computing abs(vector(...))
[with patch, with 2 positive reviews] sage/modules/free_module_element.pyx computing abs(vector(...))
Jan 28, 2008
Component: commutative algebra
Issue created by migration from https://trac.sagemath.org/ticket/1954
The text was updated successfully, but these errors were encountered: