Mercurial > hg > octave-lojdl
comparison scripts/linear-algebra/norm.m @ 3426:f8dde1807dee
[project @ 2000-01-13 08:40:00 by jwe]
author | jwe |
---|---|
date | Thu, 13 Jan 2000 08:40:53 +0000 |
parents | ae7adbb591e8 |
children | 434790acb067 |
comparison
equal
deleted
inserted
replaced
3425:8625164a0a39 | 3426:f8dde1807dee |
---|---|
19 | 19 |
20 ## -*- texinfo -*- | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} norm (@var{a}, @var{p}) | 21 ## @deftypefn {Function File} {} norm (@var{a}, @var{p}) |
22 ## Compute the p-norm of the matrix @var{a}. If the second argument is | 22 ## Compute the p-norm of the matrix @var{a}. If the second argument is |
23 ## missing, @code{p = 2} is assumed. | 23 ## missing, @code{p = 2} is assumed. |
24 ## | 24 ## |
25 ## If @var{a} is a matrix: | 25 ## If @var{a} is a matrix: |
26 ## | 26 ## |
27 ## @table @asis | 27 ## @table @asis |
28 ## @item @var{p} = @code{1} | 28 ## @item @var{p} = @code{1} |
29 ## 1-norm, the largest column sum of @var{a}. | 29 ## 1-norm, the largest column sum of @var{a}. |
30 ## | 30 ## |
31 ## @item @var{p} = @code{2} | 31 ## @item @var{p} = @code{2} |
32 ## Largest singular value of @var{a}. | 32 ## Largest singular value of @var{a}. |
33 ## | 33 ## |
34 ## @item @var{p} = @code{Inf} | 34 ## @item @var{p} = @code{Inf} |
35 ## @cindex infinity norm | 35 ## @cindex infinity norm |
36 ## Infinity norm, the largest row sum of @var{a}. | 36 ## Infinity norm, the largest row sum of @var{a}. |
37 ## | 37 ## |
38 ## @item @var{p} = @code{"fro"} | 38 ## @item @var{p} = @code{"fro"} |
39 ## @cindex Frobenius norm | 39 ## @cindex Frobenius norm |
40 ## Frobenius norm of @var{a}, @code{sqrt (sum (diag (@var{a}' * @var{a})))}. | 40 ## Frobenius norm of @var{a}, @code{sqrt (sum (diag (@var{a}' * @var{a})))}. |
41 ## @end table | 41 ## @end table |
42 ## | 42 ## |
43 ## If @var{a} is a vector or a scalar: | 43 ## If @var{a} is a vector or a scalar: |
44 ## | 44 ## |
45 ## @table @asis | 45 ## @table @asis |
46 ## @item @var{p} = @code{Inf} | 46 ## @item @var{p} = @code{Inf} |
47 ## @code{max (abs (@var{a}))}. | 47 ## @code{max (abs (@var{a}))}. |
48 ## | 48 ## |
49 ## @item @var{p} = @code{-Inf} | 49 ## @item @var{p} = @code{-Inf} |
50 ## @code{min (abs (@var{a}))}. | 50 ## @code{min (abs (@var{a}))}. |
51 ## | 51 ## |
52 ## @item other | 52 ## @item other |
53 ## p-norm of @var{a}, @code{(sum (abs (@var{a}) .^ @var{p})) ^ (1/@var{p})}. | 53 ## p-norm of @var{a}, @code{(sum (abs (@var{a}) .^ @var{p})) ^ (1/@var{p})}. |
54 ## @end table | 54 ## @end table |
55 ## @end deftypefn | 55 ## @end deftypefn |
56 ## @seealso{cond and svd} | 56 ## @seealso{cond and svd} |
80 retval = max (abs (x)); | 80 retval = max (abs (x)); |
81 else | 81 else |
82 error ("norm: unrecognized norm"); | 82 error ("norm: unrecognized norm"); |
83 endif | 83 endif |
84 else | 84 else |
85 if (p == Inf) | 85 if (p == Inf) |
86 retval = max (abs (x)); | 86 retval = max (abs (x)); |
87 elseif (p == -Inf) | 87 elseif (p == -Inf) |
88 retval = min (abs (x)); | 88 retval = min (abs (x)); |
89 else | 89 else |
90 retval = sum (abs (x) .^ p) ^ (1/p); | 90 retval = sum (abs (x) .^ p) ^ (1/p); |
91 endif | 91 endif |
92 endif | 92 endif |
93 elseif (nargin == 1) | 93 elseif (nargin == 1) |
94 retval = sum (abs (x) .^ 2) ^ 0.5; | 94 retval = sum (abs (x) .^ 2) ^ 0.5; |
95 endif | 95 endif |
96 | 96 |