Previous Page Next Page Contents

linalg::normalize -- normalize a vector

Introduction

linalg::normalize(v) normalizes the vector v with respect to the 2-norm (|v|=sqrt( v*v )).

Call(s)

linalg::normalize(v)

Parameters

v - a vector, i.e., an n x 1 or 1 x n matrix of a domain of category Cat::Matrix

Returns

a vector of the same domain type as v.

Related Functions

norm, linalg::scalarProduct

Details

Example 1

We define the following vector:

>> u := matrix([[1, 2]])
                                 +-    -+
                                 | 1, 2 |
                                 +-    -+

Then the vector of norm 1 with the same direction as u is given by:

>> linalg::normalize(u)
                            +-              -+
                            |   1/2     1/2  |
                            |  5     2 5     |
                            |  ----, ------  |
                            |   5      5     |
                            +-              -+

Example 2

The following computation fails because the vector [1,2] cannot be normalized over the rationals:

>> v := Dom::Matrix(Dom::Rational)([[1, 2]]):
   linalg::normalize(v)
      Error: can't normalize given vector over its component ring [l\
      inalg::normalize]

If we define v over the real numbers, then we get the normalized vector of v as follows:

>> w := Dom::Matrix(Dom::Real)(v): linalg::normalize(w)
                            +-              -+
                            |   1/2     1/2  |
                            |  5     2 5     |
                            |  ----, ------  |
                            |   5      5     |
                            +-              -+




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000