Section: Array Generation and Manipulations
norm
function. The general syntax is
y = norm(A,p)
where A
is the matrix to analyze, and p
is the
type norm to compute. The following choices of p
are supported
p = 1
returns the 1-norm, or the max column sum of A
p = 2
returns the 2-norm (largest singular value of A)
p = inf
returns the infinity norm, or the max row sum of A
p = 'fro'
returns the Frobenius-norm (vector Euclidean norm, or RMS value)
1 <= p < inf
returns sum(abs(A).^p)^(1/p)
p
unspecified returns norm(A,2)
p = inf
returns max(abs(A))
p = -inf
returns min(abs(A))
--> A = float(rand(3,4)) A = <float> - size: [3 4] Columns 1 to 4 0.113413215 0.778945625 0.951759875 0.861983240 0.206183329 0.367634743 0.910258651 0.094072342 0.233640403 0.972906291 0.578187644 0.817632318 --> norm(A,1) ans = <float> - size: [1 1] 2.440206 --> norm(A,2) ans = <float> - size: [1 1] 2.203075 --> norm(A,inf) ans = <float> - size: [1 1] 2.706102 --> norm(A,'fro') ans = <float> - size: [1 1] 2.299462
Next, we calculate some vector norms.
--> A = float(rand(4,1)) A = <float> - size: [4 1] Columns 1 to 1 0.35852790 0.61784583 0.63974983 0.79405016 --> norm(A,1) ans = <double> - size: [1 1] 2.4101736545562744 --> norm(A,2) ans = <float> - size: [1 1] 1.2450186 --> norm(A,7) ans = <double> - size: [1 1] 0.8328831813550448 --> norm(A,inf) ans = <float> - size: [1 1] 0.79405016 --> norm(A,-inf) ans = <float> - size: [1 1] 0.3585279