norm

Compute matrix and vector norms.

Syntax

R = norm(x)

R = norm(x,p)

R = norm(x,type)

R = norm(...,opt)

Inputs

x
The vector or matrix whose norm is computed.
Dimension: vector | matrix
p
A parameter that specifies the vector p-norm (default: 2).
  • For a matrix x, p must be an integer.
  • For a vector x, p can be a real value.
Dimension: scalar
type
Specifies an infinity norm or the Frobenius norm.
  • '-inf': valid for vector input.
  • 'inf': valid for vector or matrix input.
  • 'fro': valid for vector or matrix input.
Type: string
opt
'rows' or 'cols'.
When x is a matrix, specify the direction on which to compute vector norms.
Type: string

Outputs

R
The norm output.
Type: double | vector

Examples

Vector example:
R = norm([3,6,4,2,5,8])
R = 12.4096736
Matrix example:
R = norm([3,6,4;2,5,8;6,1,7],'fro')
R = 15.4919334

Comments

For a vector input with p=2, the norm is the geometric vector length.

For a vector input with p=0, the Hamming norm is the number of non-zero elements.