File: %25sp_norm.sci

package info (click to toggle)
scilab 2.6-4
  • links: PTS
  • area: non-free
  • in suites: woody
  • size: 54,632 kB
  • ctags: 40,267
  • sloc: ansic: 267,851; fortran: 166,549; sh: 10,005; makefile: 4,119; tcl: 1,070; cpp: 233; csh: 143; asm: 135; perl: 130; java: 39
file content (44 lines) | stat: -rw-r--r-- 789 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function res=%sp_norm(S,flag)
// Copyright INRIA
[lhs,rhs]=argn(0)
if rhs==1 then flag=2;end //norm(S)=norm(S,2)
[m,n]=size(S)

if m==1|n==1 then //vector norm
  [ij,v]=spget(S);
  res=norm(v,flag);
  return
end

select flag
case 1 then
  res=maxi(ones(1,m)*abs(S))
case 2 then
  if m<n then
    S=S*S'
  elseif m>n then
    S=S'*S
  end
  tol=1.d-5;
  x = sum(abs(S),1)';
  res = norm(x);
  if res==0 then return,end
  x = x/res;res0 = 0;
  while abs(res-res0) > tol*res
    res0 = res;   Sx = S*x; res = norm(Sx);
    x = S'*Sx;
    x = x/norm(x);
  end
  if m<>n then res=sqrt(res),end
case %inf then
  res=maxi(abs(S)*ones(n,1))
case 'inf' then
  res=maxi(abs(S)*ones(n,1))
case 'fro' then
  [ij,v]=spget(S);
  res=sqrt(sum(abs(v.*v)))
else
  [ij,v]=spget(S);
  res=norm(v,flag);
end