First time here? Check out the FAQ!

Ask Your Question
2

Vector.normalize() function

asked 13 years ago

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.

Preview: (hide)

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 ( 13 years ago )

2 Answers

Sort by » oldest newest most voted
3

answered 11 years ago

Eviatar Bach gravatar image

updated 11 years ago

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)
Preview: (hide)
link
0

answered 13 years ago

benjaminfjones gravatar image

updated 13 years ago

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))
Preview: (hide)
link

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: 13 years ago

Seen: 12,093 times

Last updated: Jun 03 '13