/// <summary> /// Computes the QR decomposition. /// </summary> /// <param name="matrix">The matrix.</param> /// <param name="q">The Q matrix.</param> /// <param name="r">The R matrix.</param> private static void Compute(Matrix matrix, out Matrix q, out Matrix r) { // source: Rosetta Code, http://rosettacode.org/wiki/QR_decomposition q = MatrixFactory.CreateIdentity(matrix.NumberOfRows); r = new Matrix(matrix); for (Int32 i = 0; i < matrix.NumberOfRows - 1 && i < matrix.NumberOfColumns; i++) { Vector v = new Vector(matrix.NumberOfRows - i); for (Int32 j = i; j < matrix.NumberOfRows; j++) { v[j - i] = r[j, i]; } Matrix h = HouseholderTransformation.Transform(v); Matrix hFull = MatrixFactory.CreateIdentity(matrix.NumberOfRows); for (Int32 j = i; j < matrix.NumberOfRows; j++) { for (Int32 k = i; k < matrix.NumberOfColumns; k++) { hFull[j, k] = h[j - i, k - i]; } } q = q * hFull; r = hFull * r; } }
/// <summary> /// Transforms the specified vector. /// </summary> /// <param name="vector">The vector.</param> /// <returns>The Householder matrix of the <paramref name="vector" />.</returns> /// <exception cref="System.ArgumentNullException">The vector is null.</exception> public static Matrix Transform(Double[] vector) { HouseholderTransformation transformation = new HouseholderTransformation(vector); transformation.Compute(); return(transformation.H); }