Ask Your Question
2

Vector.normalize() function

asked 2011-08-28 02:29:23 +0100

rhoslug gravatar image

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.

edit retag flag offensive close merge delete

Comments

This 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?

kcrisman gravatar imagekcrisman ( 2011-08-29 09:59:12 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
3

answered 2013-06-03 19:31:13 +0100

Eviatar Bach gravatar image

updated 2013-06-03 19:33:59 +0100

Note that as of Sage 5.7 (see trac #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)
edit flag offensive delete link more
0

answered 2011-08-29 12:19:09 +0100

benjaminfjones gravatar image

updated 2011-08-29 12:19:32 +0100

You 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))
edit flag offensive delete link more

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: 2011-08-28 02:29:23 +0100

Seen: 11,864 times

Last updated: Jun 03 '13