예제 #1
0
        public void CholeskySolver_SolveWhenFactorIsNull_ThrowsArgumentNullException()
        {
            var right = new Vector(3);

            var solver = new CholeskySolver();

            Assert.Throws <ArgumentNullException>(() => solver.Solve(null, right));
        }
예제 #2
0
        public void TestCholeskySolver()
        {
            IVector x = new SparseVector(new double[] { 2, 4, 1 });
            IVector b = A.Multiply(x);

            IVector x_pi = CholeskySolver.Solve(A, b);

            Assert.Equal(x, x_pi);
        }
예제 #3
0
        public void CholeskySolver_SolveWhenRightIsNull_ThrowsArgumentNullException()
        {
            var matrix = new Matrix(3, 3, new double[, ] {
                { 81, -45, 45 }, { -45, 50, 5 }, { 45, -15, 38 }
            });

            var solver = new CholeskySolver();

            Assert.Throws <ArgumentNullException>(() => solver.Solve(matrix, null));
        }
예제 #4
0
        public void CholeskySolver_SolveWhenFactorAndRightHaveDifferentSize_ThrowsArgumentNullException()
        {
            var matrix = new Matrix(3, 3, new double[, ] {
                { 81, -45, 45 }, { -45, 50, 5 }, { 45, -15, 38 }
            });
            var right = new Vector(2);

            var solver = new CholeskySolver();

            Assert.Throws <ArgumentException>(() => solver.Solve(matrix, right));
        }
예제 #5
0
        public void CholeskySolver_SolveWhenFactorIsNotSquare_ThrowsNonSymmetricMatrixException()
        {
            var matrix = new Matrix(3, 3, new double[, ] {
                { 81, -45, 45 }, { -45, 50, 5 }, { 45, -15, 38 }
            });
            var right = new Vector(3, new double[] { 531, -460, 193 });

            var solver = new CholeskySolver();

            Assert.Throws <NonSymmetricMatrixException>(() => solver.Solve(matrix, right));
        }
예제 #6
0
        public void CholeskySolver_Solve_ReturnsResultAsExpected()
        {
            var matrix = new Matrix(3, 3, new double[, ] {
                { 81, -45, 45 }, { -45, 50, -15 }, { 45, -15, 38 }
            });
            var right = new Vector(3, new double[] { 531, -460, 193 });

            var expected = Vector.From(new double[] { 6, -5, -4 });

            var solver = new CholeskySolver();

            var x = solver.Solve(matrix, right);

            Assert.AreEqual(expected, x);
        }