Пример #1
0
        virtual public Matrix IncludeRow(VectorRow vector, int index)
        {
            if (index > this.Rows || index < 0)
            {
                throw new IndexOutOfRangeException("Unable to include row because index is out of range.");
            }
            if (vector.Length != this.Columns)
            {
                throw new ArgumentException("Unable to include row because vector-row has invalid length.");
            }

            double[,] matrix = new double[Rows + 1, Columns];

            int _row = 0;

            for (int row = 0; row <= this.Rows; row++)
            {
                if (row == index)
                {
                    for (int col = 0; col < this.Columns; col++)
                    {
                        matrix[row, col] = vector[col];
                    }
                    continue;
                }
                for (int col = 0; col < this.Columns; col++)
                {
                    matrix[row, col] = this.matrix[_row, col];
                }
                _row++;
            }

            return(new Matrix(matrix));
        }
Пример #2
0
        public object ToVector()
        {
            if (this.Rows == 1)
            {
                VectorRow vector = new VectorRow(this.Columns);
                for (int i = 0; i < this.Columns; i++)
                {
                    vector[i] = matrix[0, i];
                }

                return(vector);
            }
            else if (this.Columns == 1)
            {
                VectorColumn vector = new VectorColumn(this.Rows);
                for (int i = 0; i < this.Rows; i++)
                {
                    vector[i] = matrix[i, 0];
                }

                return(vector);
            }
            else
            {
                throw new Exception("Unable to convert matrix to vector.");
            }
        }
Пример #3
0
        public void SetRow(VectorRow vector, int index)
        {
            if (index >= Rows || index < 0 || vector.Length != Columns)
            {
                throw new Exception("Can't set row.");
            }

            for (int i = 0; i < vector.Length; i++)
            {
                matrix[index, i] = vector[i];
            }
        }
Пример #4
0
        public VectorRow GetRow(int index)
        {
            if (index >= Rows || index < 0)
            {
                throw new Exception("Can't get row.");
            }

            var row = new VectorRow(Columns);

            for (int i = 0; i < row.Length; i++)
            {
                row[i] = matrix[index, i];
            }

            return(row);
        }
Пример #5
0
 new public SquareMatrix IncludeRow(VectorRow vector, int index) =>
 new Matrix(this.matrix).IncludeRow(vector, index).ToSquareMatrix();