Ejemplo n.º 1
0
        public void SolveSlauTest1()
        {
            // arrange
            double[,] matrix = new double[3, 3] {
                { 4, 2, 2 },
                { 2, 4, 2 },
                { 2, 2, 4 }
            };
            double[] vector1 = new double[3] {
                4, 4, 4
            };

            Matrix m1 = _matrixFactory.CreateMatrix(matrix);
            Vector v1 = _vectorFactory.CreateVector(vector1);

            // act
            ISlauSolver solver = _slauSolverFactory.CreateSlauSolver();
            Vector      result = solver.SolveSlau(m1, v1);


            // assert
            double[] vector2 = new double[3] {
                0.5, 0.5, 0.5
            };
            Vector expected = _vectorFactory.CreateVector(vector2);

            Assert.IsTrue(expected.AreEqual(result));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a Matrix object with all elements equal to a scalar value
        /// </summary>
        public IMatrix Dense(int rows, int columns, double value)
        {
            var matrix = matrixFactory.CreateMatrix(rows, columns);

            for (int row = 0; row < rows; row++)
            {
                for (int column = 0; column < columns; column++)
                {
                    matrix[row, column] = value;
                }
            }
            return(matrix);
        }
Ejemplo n.º 3
0
        public Matrix Add(Matrix a)
        {
            if ((RowsCount != a.RowsCount) || (ColumnsCount != a.ColumnsCount))
            {
                throw new SizesDismatchException($"Error in addition two matrices: their sizes must match." +
                                                 $"Size of left matrix: [{RowsCount},{ColumnsCount}], " +
                                                 $"size of right matrix: [{a.RowsCount},{a.ColumnsCount}].");
            }


            Matrix result = _matrixFactory.CreateMatrix(RowsCount, ColumnsCount);

            for (int i = 0; i < RowsCount; i++)
            {
                for (int j = 0; j < ColumnsCount; j++)
                {
                    result[i, j] = this[i, j] + a[i, j];
                }
            }
            return(result);
        }
Ejemplo n.º 4
0
        public void ConvertToVectorTest()
        {
            // arrange
            double[,] matrix = new double[3, 3] {
                { 1, 2, 3 },
                { 4, 5, 6 },
                { 7, 8, 9 }
            };
            Matrix m1 = _matrixFactory.CreateMatrix(matrix);

            // act
            Vector result = m1.ConvertToVector();

            // assert
            double[] vector = new double[9] {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            Vector expected = _vectorFactory.CreateVector(vector);

            Assert.IsTrue(expected.AreEqual(result));
        }