19
19
// IBM Journal of Research and Development 1983; 27(6):577-581.
21
21
function y=norm(A,flag)
22
//compute various matrix norms
23
if argn(2)==1 then flag=2,end
22
//compute various matrix norms
23
if argn(2)==1 then flag=2,end
26
if A==[] then y=0,return,end
27
if or(size(A)==1) then // vector norm
28
if type(flag)==10 then //'inf' or 'fro'
29
select convstr(part(flag,1))
35
// Scaling for better floating point accuracy.
46
error("invalid value for flag")
48
elseif type(flag)==1 then //p_norm
51
error('flag must be real')
65
// Scaling for better floating point accuracy.
69
y=sum(abs(A).^p)^(1/p);
72
y = s * sum(abs(sA).^p)^(1/p);
26
if A==[] then y=0,return,end
27
if or(size(A)==1) then // vector norm
28
if type(flag)==10 then //'inf' or 'fro'
29
select convstr(part(flag,1))
35
// Scaling for better floating point accuracy.
44
y = s * sqrt(abs(sA'*sA));
47
error("invalid value for flag")
49
elseif type(flag)==1 then //p_norm
52
error('flag must be real')
66
// Scaling for better floating point accuracy.
70
y=sum(abs(A).^p)^(1/p);
73
y = s * sum(abs(sA).^p)^(1/p);
77
error("invalid value for flag")
80
if type(flag)==10 then //'inf' or 'fro'
81
select convstr(part(flag,1))
86
// Scaling for better floating point accuracy.
90
if size(A,1)>size(A,2) then
91
y=sqrt(sum(diag(A'*A)))
93
y=sqrt(sum(diag(A*A')))
97
if size(A,1)>size(A,2) then
99
y = s * sqrt(sum(abs(diag(sA'*sA))))
101
y = s * sqrt(sum(abs(diag(sA*sA'))))
105
error("invalid value for flag")
107
elseif type(flag)==1 then //p_norm
117
error('flag must be 1 2 or inf')
120
error("invalid value for flag")
76
error("invalid value for flag")
124
if type(A)==16|type(A)==17 then
125
n=getfield(1,A);n=n(1)
128
n=stripblanks(n(find(t==type(A))))
131
if exists(fun)==1 then
132
execstr('y='+fun+'(A,flag)')
134
error('norm not defined for type ""'+n+'"" .'+..
135
'Check argument or define function '+fun)
79
if type(flag)==10 then //'inf' or 'fro'
80
select convstr(part(flag,1))
85
// Scaling for better floating point accuracy.
89
if size(A,1)>size(A,2) then
90
y=sqrt(sum(diag(A'*A)))
92
y=sqrt(sum(diag(A*A')))
96
if size(A,1)>size(A,2) then
97
y = s * sqrt(sum(diag(sA'*sA)))
99
y = s * sqrt(sum(diag(sA*sA')))
103
error("invalid value for flag")
105
elseif type(flag)==1 then //p_norm
115
error('flag must be 1 2 or inf')
118
error("invalid value for flag")
122
if type(A)==16|type(A)==17 then
123
n=getfield(1,A);n=n(1)
126
n=stripblanks(n(find(t==type(A))))
129
if exists(fun)==1 then
130
execstr('y='+fun+'(A,flag)')
132
error('norm not defined for type ""'+n+'"" .'+..
133
'Check argument or define function '+fun)