-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNorm1.cpp
executable file
·89 lines (75 loc) · 1.92 KB
/
Norm1.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/////////////////////////////////////////////////////////////////////////
// Program : norm1.cpp
// Coded by : Prof. Gang-Gyoo Jin, Korea Maritime University
// Coded on : 12/12/2003
#include <math.h>
#include "cmatrix.h"
/////////////////////////////////////////////////////////////////////////
// 1-norm of a REAL vector x, |x[0]|+..+|x[n-1]|
REAL ms_Norm1(REAL x[], int n)
{
REAL norm= 0;
for(int i=0; i<n; i++)
norm+= ABS(x[i]);
return norm;
}
/////////////////////////////////////////////////////////////////////////
// 1-norm of a REAL vector x, |x[0]|+..+|x[n-1]|
REAL ms_Norm1(const RVECTOR &x)
{
REAL norm= 0;
for(int i=0; i<x.num; i++)
norm+= ABS(x(i));
return norm;
}
/////////////////////////////////////////////////////////////////////////
// 1-norm of a COMPLEX vector x, |x[0]|+..+|x[n-1]|
REAL ms_Norm1(const CVECTOR &x)
{
REAL norm= 0;
for(int i=0; i<x.num; i++)
norm+= abs(x(i));
return norm;
}
/////////////////////////////////////////////////////////////////////////
// 1-norm of a REAL matrix, the largest column sum
REAL ms_Norm1(REAL** a, int n, int m)
{
REAL norm= 0, sum;
for(int j=0; j<m; j++)
{
sum= 0;
for(int i=0; i<n; i++)
sum+= ABS(a[i][j]);
norm= MAX(norm, sum);
}
return norm;
}
/////////////////////////////////////////////////////////////////////////
// 1-norm of a REAL matrix, the largest column sum
REAL ms_Norm1(const RMATRIX &a)
{
REAL norm= 0, sum;
for(int j=0; j<a.m; j++)
{
sum= 0;
for(int i=0; i<a.n; i++)
sum+= ABS(a(i,j));
norm= MAX(norm, sum);
}
return norm;
}
/////////////////////////////////////////////////////////////////////////
// 1-norm of a REAL matrix, the largest column sum
REAL ms_Norm1(const CMATRIX &a)
{
REAL norm= 0, sum;
for(int j=0; j<a.m; j++)
{
sum= 0;
for(int i=0; i<a.n; i++)
sum+= abs(a(i,j));
norm= MAX(norm, sum);
}
return norm;
}