static Mtr QR_Decomposition ref Mtr int si sj si getRows sj getColumns

 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
static Mtr QR_Decomposition(ref Mtr A)
{
int si, sj;
si = A.getRows();
sj = A.getColumns();
Mtr y;
Mtr U = new Mtr(si, sj);
U.makeIdentity();
for (int i = 0; i < A.getColumns() - 1; ++i)
{
y = A.getSubMatrix(i, i, A.getRows() - 1, i);
if (isNull(y))
continue;
Mtr locV = new Mtr(si - i, sj - i);
Mtr locU = new Mtr(si, sj);
locU.makeIdentity();
locV.makeIdentity();
Mtr omega = new Mtr(si - i, 1);
Mtr vecx = new Mtr(si - i, 1);
vecx.setValue(1, 0, 0);
double yNorm = Math.Sqrt((y.getTranspozed() * y).getValue(0, 0));
int sgn = mSign(y.getValue(0, 0));
omega = y + vecx * (sgn * yNorm);
double omegaNorm = Math.Sqrt((omega.getTranspozed() * omega).getValue(0, 0));
omega = omega * (1 / omegaNorm);
locV = locV - (omega ^ omega.getTranspozed()) * 2;
locU = uniteMtr(locU, locV);
A = locU * A;
U = locU * U;
}
return U;
}