This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Normalize a vector

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.




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

The result of linalg::normalize(v) is a vector that has norm 1 and the same direction as v.

The scalar product for a vector is implemented by the function linalg::scalarProduct.

The norm of a vector is computed with the function norm, which is overloaded for vectors. See the method "norm" of the domain constructor Dom::Matrix for details.

If the norm is an object that cannot be converted into an element of the component ring of v, then an error occurs (see Example 2).


Example 1

We define the following vector:

u := matrix([[1, 2]])

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


Example 2

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

v := Dom::Matrix(Dom::Rational)([[1, 2]]):
Error: Cannot normalize the given vector over its component ring. [linalg::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)



A vector, i.e., an n×1 or 1 ×n matrix of a domain of category Cat::Matrix

Return Values

Vector of the same domain type as v.

See Also

MuPAD Functions

Was this topic helpful?