public QRArgs QR_Householder2() { QRArgs result = new QRArgs(); result.Hs = new Matrix[Columns]; result.Qs = new Matrix[Columns]; result.Rs = new Matrix[Columns]; Matrix Q = I(Rows); Matrix R = this; for (int k = 0; k < Columns; k++) { Vector x = R.GetColumn(k); for (int i = 0; i < k; i++) { x.Data[i] = 0; } double[] w_array = new double[x.Data.Length]; w_array[k] = 1; Vector e = new Vector(x.Rows, x.Columns, w_array); double norm = x.Length; double sign = System.Math.Sign(x.Data[k]); Vector u = x + (sign == 0 ? 1 : sign) * norm * e; Vector v = u / R.Data[k * Columns + k]; //Vector v = u / u.Length; Vector vt = v.Transposed(); Matrix H = I(x.Data.Length) - 2 * ((v * vt) / (vt * v)); result.Hs[k] = H; R = H * R; result.Rs[k] = R; Q = Q * H; result.Qs[k] = H; } result.Q = Q; result.R = R; return(result); }
public QRArgs QR_Householder() { QRArgs result = new QRArgs(); result.Hs = new Matrix[Columns]; result.Qs = new Matrix[Columns]; result.Rs = new Matrix[Columns]; Matrix Q = Matrix.I(Rows); Matrix R = this; for (int k = 0; k < Columns; k++) { Vector x = R.GetColumn(k); for (int i = 0; i < k; i++) { x.Data[i] = 0; } double[] w_array = new double[x.Data.Length]; w_array[k] = x.Length; Vector w = new Vector(x.Rows, x.Columns, w_array); Vector v = w - x; Matrix I = Matrix.I(v.Data.Length); Vector vt = v.Transposed(); Matrix H = I - (2 * (v * vt)) * (1 / (vt * v)); result.Hs[k] = H; R = H * R; result.Rs[k] = R; Q = Q * H; result.Qs[k] = H; } result.Q = Q; result.R = R; return(result); }
public QRArgs QR_Householder3() { QRArgs result = new QRArgs(); result.Hs = new Matrix[Columns]; result.Qs = new Matrix[Columns]; result.Rs = new Matrix[Columns]; Matrix Q = I(Rows); Matrix R = this; Matrix A = this; for (int k = 0; k < Columns; k++) { if (k != 0) { A = A.Minor(0, 0); } Vector x = A.GetColumn(0); Matrix B = Householder2(x); Matrix H = I(Rows).Replace(k, k, B); result.Hs[k] = H; R = H * R; result.Rs[k] = R; Q = Q * H; result.Qs[k] = H; } result.Q = Q; result.R = R; return(result); }