public void CholeskySolver_SolveWhenFactorIsNull_ThrowsArgumentNullException()
        {
            var right = new Vector(3);

            var solver = new CholeskySolver();

            Assert.Throws <ArgumentNullException>(() => solver.Solve(null, right));
        }
Exemple #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);
        }
        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));
        }
        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));
        }
        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));
        }
        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);
        }