ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 03 Jun 2013 19:31:13 +0200Vector.normalize() functionhttps://ask.sagemath.org/question/8296/vectornormalize-function/My question is something of a small complaint and need of an explination. Why is the normalize() function for vectors defined as it is, and not the "normal" way one would expect? This is somewhat confusing and frustrating especially if you need to have a normalized vector and what you get is a vector divided by the first non-zero element.Sun, 28 Aug 2011 02:29:23 +0200https://ask.sagemath.org/question/8296/vectornormalize-function/Comment by kcrisman for <p>My question is something of a small complaint and need of an explination. Why is the normalize() function for vectors defined as it is, and not the "normal" way one would expect? This is somewhat confusing and frustrating especially if you need to have a normalized vector and what you get is a vector divided by the first non-zero element.</p>
https://ask.sagemath.org/question/8296/vectornormalize-function/?comment=21298#post-id-21298This sounds like a good question. Can you post an explicit example in an edit to your question, just to make it easy to verify for others looking at it? Mon, 29 Aug 2011 09:59:12 +0200https://ask.sagemath.org/question/8296/vectornormalize-function/?comment=21298#post-id-21298Answer by Eviatar Bach for <p>My question is something of a small complaint and need of an explination. Why is the normalize() function for vectors defined as it is, and not the "normal" way one would expect? This is somewhat confusing and frustrating especially if you need to have a normalized vector and what you get is a vector divided by the first non-zero element.</p>
https://ask.sagemath.org/question/8296/vectornormalize-function/?answer=15021#post-id-15021Note that as of Sage 5.7 (see [trac #13393](http://trac.sagemath.org/sage_trac/ticket/13393)) the `normalized` method does what you'd expect, `normalize` has been deprecated, and `monic` is the old functionality.
sage: v = vector([3, 2, 1])
sage: v.normalized()
(3/14*sqrt(14), 1/7*sqrt(14), 1/14*sqrt(14))
sage: v.monic()
(1, 2/3, 1/3)Mon, 03 Jun 2013 19:31:13 +0200https://ask.sagemath.org/question/8296/vectornormalize-function/?answer=15021#post-id-15021Answer by benjaminfjones for <p>My question is something of a small complaint and need of an explination. Why is the normalize() function for vectors defined as it is, and not the "normal" way one would expect? This is somewhat confusing and frustrating especially if you need to have a normalized vector and what you get is a vector divided by the first non-zero element.</p>
https://ask.sagemath.org/question/8296/vectornormalize-function/?answer=12608#post-id-12608You can easily figure out what any given function or method does by examining its docstring as follows:
sage: v = vector([3,0,9])
sage: v.normalize?
Type: builtin_function_or_method
Base Class: <type 'builtin_function_or_method'>
String Form: <built-in method normalize of sage.modules.vector_integer_dense.Vector_integer_dense object at 0x4badd08>
Namespace: Interactive
Definition: v.normalize(self)
Docstring:
Return this vector divided through by the first nonzero entry of
this vector.
EXAMPLES:
sage: v = vector(QQ,[0,4/3,5,1,2])
sage: v.normalize()
(0, 1, 15/4, 3/4, 3/2)
So there shouldn't be any confusion about what this method does. The operation that is performed by this method is a perfectly reasonable notion of "normalization". It depends on the context, of course. This definition of normalize is probably useful when working with projective spaces or doing Guass-Jordan elimination.
To compute the unit vector in the direction of `v`, you could do:
sage: v/v.norm()
(1/10*sqrt(10), 0, 3/10*sqrt(10))
Mon, 29 Aug 2011 12:19:09 +0200https://ask.sagemath.org/question/8296/vectornormalize-function/?answer=12608#post-id-12608