|
FreeMat
|
Section: Array Generation and Manipulations
Calculates the norm of a matrix. There are two ways to use the 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) For a vector, the regular norm calculations are performed:
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)) Here are the various norms calculated for a sample matrix
--> A = float(rand(3,4))
A =
0.8462 0.9465 0.6874 0.8668
0.1218 0.9206 0.5877 0.5837
0.7081 0.6608 0.2035 0.5083
--> norm(A,1)
ans =
2.5280
--> norm(A,2)
ans =
2.2997
--> norm(A,inf)
ans =
3.3470
--> norm(A,'fro')
ans =
2.3712
Next, we calculate some vector norms.
--> A = float(rand(4,1))
A =
0.3458
0.1427
0.3998
0.7194
--> norm(A,1)
ans =
1.6078
--> norm(A,2)
ans =
0.9041
--> norm(A,7)
ans =
0.7217
--> norm(A,inf)
ans =
0.7194
--> norm(A,-inf)
ans =
0.1427