QR Method

  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
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
public int N = 4;
public double[,] _WVarray;
public double[,] _WTarray;
public double[,] _HA = new double[,] { { 1, -1, 3, 1 }, { 4, -1, 5, 4 }, { 2, -2, 4, 1 }, { 1, -4, 5, -1 } };
public double[] _B = new double[] { 5, 4, 6, 3 };
public double[,] _E = new double[,] { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } };
public double[,] _WVT;
public double[] _X;
public double[,] _H;
public double[,] _HAtemp;
public double b;
public double n;
public double sum;
public void zeroing()
{
_WVarray = new double[1, N];
_WTarray = new double[N, 1];
for (int i = 0; i < N; i++)
{
_WVarray[0, i] = 0;
_WTarray[i, 0] = 0;
}
}
public bool sign(double data)
{
return data > 0 ? (true) : (false);
}
public void transp()
{
for (int i = 0; i < N; i++)
{
_WTarray[i, 0] = _WVarray[0, i];
}
}
public void mult()
{
double[,] res = new double[N, N];
double temp = 0;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
temp = 0;
for (int k = 0; k < N; k++)
{
temp += _H[i, k] * _HA[k, j];
}
res[i,j] = temp;
}
}
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
_HA[i,j] = res[i, j];
}
}
}
public void cut()
{
double[,] res = new double[N, N];
for (int i = 0; i < N; i++)
{
_HAtemp[i, 0] = 0;
_HAtemp[0, i] = 0;
}
}
public void copy()
{
_HAtemp = new double[N,N];
for(int i = 0; i< N; i++)
{
for(int j = 0 ; j < N; j++)
{
_HAtemp[i, j] = _HA[i, j];
}
}
}
public void multMatrixVec()
{
double [] res = new double[N];
for(int i =0 ; i < N; i++)
{
double temp = 0;
for(int j = 0 ; j < N; j++)
{
temp += _H[i, j] * _B[j];
}
res[i] = temp;
}
for (int i = 0; i < N; i++)
{
_B[i] = res[i];
}
}
public void multVect()
{
_WVT = new double[N, N];
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
_WVT[i, j] = 2 * _WVarray[0, i] * _WTarray[j, 0];
}
}
}