static void smAlgorithm Mtr Mtr ref Mtr ref double bool secondIter fal

 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
static void smAlgorithm(Mtr A, Mtr y, ref Mtr x,ref double v, bool secondIter = false)
{
int n = A.getColumns();
double EPS = 0.000001;
double s = (y.getTranspozed() * y).getValue(0, 0);
double yNorm = Math.Sqrt(s);
Mtr lx = y * (1.0f / yNorm);
double lamdda = 0;
double lastLamda = 0;
for (int iter = 0; iter < 100000; ++iter)
{
y = A * lx;
if(secondIter)
y = y - x * ((x.getTranspozed() * y).getValue(0, 0));
s = (y.getTranspozed() * y).getValue(0, 0);
double t = (lx.getTranspozed() * y).getValue(0, 0);
yNorm = Math.Sqrt(s);
lx = y * (1.0 / yNorm);
lastLamda = lamdda;
lamdda = s / t;
if (Math.Abs(lastLamda - lamdda) < EPS)
break;
}
v = lamdda;
x = lx;
}
static void findSecondBySm(Mtr A)
{
Mtr y = new Mtr(A.getColumns(), 1);
Mtr x1 = new Mtr(A.getColumns(), 1);
double vl = 0;
for (int i = 0; i < A.getColumns(); ++i) y.setValue(1, i, 0);
smAlgorithm(A, y, ref x1, ref vl);
for (int i = 0; i < A.getColumns(); ++i) y.setValue(123, i, 0);
y = y - x1 * ((x1.getTranspozed() * y).getValue(0, 0));
smAlgorithm(A, y, ref x1, ref vl, true);
Console.WriteLine("adfasdf");
Console.WriteLine(vl);
x1.printMatrix();
}