comparison scripts/linear-algebra/norm.m @ 3801:bc61e418f200

[project @ 2001-02-23 02:13:10 by jwe]
author jwe
date Fri, 23 Feb 2001 02:13:11 +0000
parents e031284eea27
children c5cf860b756d
comparison
equal deleted inserted replaced
3800:115cbfcd067e 3801:bc61e418f200
73 if (rows (x) == 1 || columns (x) == 1) 73 if (rows (x) == 1 || columns (x) == 1)
74 74
75 if (nargin == 2) 75 if (nargin == 2)
76 if (isstr (p)) 76 if (isstr (p))
77 if (strcmp (p, "fro")) 77 if (strcmp (p, "fro"))
78 retval = sqrt (sum (diag (x' * x))); 78 retval = sqrt (sum (abs (x) .^ 2));
79 elseif (strcmp (p, "inf")) 79 elseif (strcmp (p, "inf"))
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
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 = sqrt (sum (abs (x) .^ 2));
95 endif 95 endif
96 96
97 else 97 else
98 98
99 if (nargin == 2) 99 if (nargin == 2)
100 if (isstr (p)) 100 if (isstr (p))
101 if (strcmp (p, "fro")) 101 if (strcmp (p, "fro"))
102 retval = sqrt (sum (diag (x' * x))); 102 retval = sqrt (sum (sum (abs (x) .^ 2)));
103 elseif (strcmp (p, "inf")) 103 elseif (strcmp (p, "inf"))
104 retval = max (sum (abs (x'))); 104 retval = max (sum (abs (x')));
105 else 105 else
106 error ("norm: unrecognized norm"); 106 error ("norm: unrecognized norm");
107 endif 107 endif