Ejemplo n.º 1
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.");
            }
        }
Ejemplo n.º 2
0
        public void GenerateTridiagonalSystem()
        {
            if (MATRIX_SIZE == -1)
            {
                throw new InvalidOperationException("System is yet implemented.");
            }

            if (MATRIX_SIZE != 4)
            {
                throw new Exception("Only for 4-dimensions system");
            }
            var matrix = new double[4, 4] {
                { (N + k), -k, 0, 0 },
                { -(N / 2.0), 2 * N, k, 0 },
                { 0, -(N / 5.0), N, -(k / 2.0) },
                { 0, 0, -(N / 3.0), N }
            };

            var vector = new double[4]      {
                N, (N / 2.0), N - k, 2 * N
            };

            Matrix      = new SquareMatrix(matrix);
            FreeElems   = new VectorColumn(vector);
            MATRIX_SIZE = -1;
        }
Ejemplo n.º 3
0
        virtual public Matrix IncludeColumn(VectorColumn vector, int index)
        {
            if (index > this.Columns || index < 0)
            {
                throw new IndexOutOfRangeException("Unable to include row because index is out of range.");
            }
            if (vector.Length != this.Rows)
            {
                throw new ArgumentException("Unable to include column because vector-column has invalid length.");
            }

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

            int _col = 0;

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

            return(new Matrix(matrix));
        }
Ejemplo n.º 4
0
 public LSystem(int student_number, int group_number, int matrix_size)
 {
     N           = student_number;
     k           = group_number;
     MATRIX_SIZE = matrix_size;
     Matrix      = new SquareMatrix(matrix_size);
     FreeElems   = new VectorColumn(matrix_size);
 }
Ejemplo n.º 5
0
        public void SetColumn(VectorColumn vector, int index)
        {
            if (index >= Columns || index < 0 || vector.Length != Rows)
            {
                throw new Exception("Can't set column.");
            }

            for (int i = 0; i < vector.Length; i++)
            {
                matrix[i, index] = vector[i];
            }
        }
Ejemplo n.º 6
0
        public VectorColumn GetColumn(int index)
        {
            if (index >= Columns || index < 0)
            {
                throw new Exception("Can't get column.");
            }

            var column = new VectorColumn(Rows);

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

            return(column);
        }
Ejemplo n.º 7
0
        public void GenerateRegularSystem()
        {
            if (MATRIX_SIZE == -1)
            {
                throw new InvalidOperationException("System is yet implemented.");
            }

            var matrix    = new SquareMatrix(MATRIX_SIZE);
            var freeElems = new VectorColumn(MATRIX_SIZE);

            for (int i = 0; i < MATRIX_SIZE; i++)
            {
                for (int j = 0; j < MATRIX_SIZE; j++)
                {
                    if (i < j)
                    {
                        matrix[i, j] = (i + 1) + (j + 1) - N / 3.0 - k;
                    }
                    if (i == j)
                    {
                        matrix[i, j] = (i + 1) + (j + 1) + N / 4.0 + k;
                    }
                    if (i > j)
                    {
                        matrix[i, j] = (i + 1) + (j + 1) - N / 5.0 - k;
                    }
                }
            }

            for (int i = 0; i < MATRIX_SIZE; i++)
            {
                freeElems[i] = 3 * (i + 1) + N / 2.0 + k;
            }

            Matrix      = matrix;
            FreeElems   = freeElems;
            MATRIX_SIZE = -1;
        }
Ejemplo n.º 8
0
 new public SquareMatrix IncludeColumn(VectorColumn vector, int index) =>
 new Matrix(this.matrix).IncludeColumn(vector, index).ToSquareMatrix();
Ejemplo n.º 9
0
 public LSystem(SquareMatrix matrix, VectorColumn freeElems)
 {
     this.Matrix      = matrix;
     this.FreeElems   = freeElems;
     this.MATRIX_SIZE = -1;
 }
Ejemplo n.º 10
0
 public VectorColumn CalcResiduals(VectorColumn solutions) =>
 new VectorColumn((Matrix * solutions - FreeElems).ToDoubleArray());