主要内容

vecnorm

矢量规范

Description

example

N = vecnorm(A)returns the 2-norm or欧几里得规范A:

  • IfAis a vector, thenvecnorm返回向量的规范。

  • IfA是矩阵,然后vecnorm返回每列的标准。

  • IfA是一个多维数组,然后vecnorm沿着大小不等于1的第一个数组维度返回标准。

example

N = vecnorm(A,p)calculates thegeneralized vector p-norm.

example

N = vecnorm(A,p,dim)operates along dimensiondim. The size of this dimension reduces to 1 while the sizes of all other dimensions remain the same.

Examples

collapse all

Calculate the 2-norm of a vector corresponding to the point (2,2,2) in 3-D space. The 2-norm is equal to the Euclidean length of the vector, 1 2 .

x = [2 2 2]; n = vecnorm(x)
n = 3.4641

Calculate the 1-norm of the vector, which is the sum of the element magnitudes.

n = vecnorm(x,1)
n = 6

计算矩阵的列的2个词。

A = [2 0 1;-1 1 0;-3 3 0]
A =3×32 0 1 -1 1 0 -3 3 0
n = vecnorm(A)
n =1×33.7417 3.1623 1.0000

As an alternative, you can use the规范function to calculate the 2-norm of the entire matrix.

Input Arguments

collapse all

Input array, specified as a vector, matrix, or multidimensional array. By convention,vecnormreturnsNaNvalues if the vector being operated on contains aNaNvalue.

Data Types:single|double
Complex Number Support:Yes

Norm type, specified as2(默认),一个正标量或inf.

Dimension to operate along, specified as a positive integer scalar. If you do not specify a value, then the default is the first array dimension whose size does not equal 1.

Dimensiondimindicates the dimension whose length reduces to 1. In other words,size(N,dim)is1, while the sizes of all other dimensions remain the same.

考虑二维输入阵列,A:

  • vecnorm(A,p,1)calculates the norm of each column.

    vecnorm(A,p,1) column-wise computation

  • vecnorm(A,p,2)计算每一行的标准。

    vecnorm(A,p,2) row-wise computation

    vecnormreturnsabs(A)whendim大于ndims(A)or whensize(A,dim)is1.

Data Types:single|double|int8|INT16|int32|int64|uint8|uint16|uint32|uint64

More About

collapse all

欧几里得规范

矢量的欧几里得规范(也称为矢量幅度,欧几里得长度或2个norm)vwithNelements is defined by

v = k = 1 N | v k | 2 .

General Vector Norm

The general definition for the p-norm of a vectorvthat hasNelements is

v p = [ k = 1 N | v k | p ] 1 / p ,

wherepis any positive real value orinf. Some interesting values ofpare:

  • Ifp = 1,然后由此产生的1个总体是向量元素的绝对值之和。

  • Ifp = 2, then the resulting 2-norm gives the vector magnitude or Euclidean length of the vector.

  • Ifp = Inf, then v = max i ( | v ( i ) | ) .

Extended Capabilities

版本历史

Introduced in R2017b

See Also

|