public void QRDecompositionComputeTest() { Matrix matrix = MatrixFactory.CreateSquare(12, -51, 4, 6, 167, -68, -4, 24, -41); Matrix qExpected = MatrixFactory.CreateSquare(6.0 / 7, 69.0 / 175, -58.0 / 175, 3.0 / 7, -158.0 / 175, 6.0 / 175, -2.0 / 7, -6.0 / 35, -33.0 / 35); Matrix rExpected = MatrixFactory.CreateSquare(14, 21, -14, 0, -175, 70, 0, 0, 35); QRDecomposition decomposition = new QRDecomposition(matrix); decomposition.Compute(); for (Int32 j = 0; j < matrix.NumberOfRows; j++) { for (Int32 k = 0; k < matrix.NumberOfColumns; k++) { Assert.AreEqual(qExpected[j, k], decomposition.Q[j, k], 0.001); Assert.AreEqual(rExpected[j, k], decomposition.R[j, k], 0.001); } } }
public void QRDecompositionComputeTest() { for (Int32 matrixIndex = 0; matrixIndex < this.matrices.Length; matrixIndex++) { QRDecomposition decomposition = new QRDecomposition(this.matrices[matrixIndex]); decomposition.Compute(); decomposition.Q.ShouldBe(this.expectedQ[matrixIndex], 0.001); decomposition.R.ShouldBe(this.expectedR[matrixIndex], 0.001); Matrix product = decomposition.Q * decomposition.R; product.ShouldBe(this.matrices[matrixIndex], 0.001); } }