Esempio n. 1
0
        static public double Determinant(double[,] a)
        {
            var    matrix1 = new MatrixLib.Matrix(a);
            double det1    = matrix1.Determinant;

            return(det1);
        }
Esempio n. 2
0
        public Matrix CopyMatrix()
        {
            Matrix newMatrix = new MatrixLib.Matrix(RowCount, ColumnCount);

            for (int row = 0; row < RowCount; row++)
            {
                for (int col = 0; col < ColumnCount; col++)
                {
                    newMatrix.MatrixDefinition[row, col] = MatrixDefinition[row, col];
                }
            }
            return(newMatrix);
        }
Esempio n. 3
0
        public Matrix Transpose()
        {
            Matrix transpose = new MatrixLib.Matrix(ColumnCount, RowCount);

            for (int row = 0; row < RowCount; row++)
            {
                for (int col = 0; col < ColumnCount; col++)
                {
                    transpose.MatrixDefinition[col, row] = MatrixDefinition[row, col];
                }
            }

            return(transpose);
        }
Esempio n. 4
0
        private void Button1Click(object sender, EventArgs e)
        {
            switch (_comboBoxValue)
            {
            case "Unit":
            {
                if (_operand == "Left Matrix")
                {
                    _leftMatrix = MatrixLib.Matrix <T> .CreateOnesMatrix(_numberOfRows, _numberOfColumns);
                }
                if (_operand == "Right Matrix")
                {
                    _rightMatrix = MatrixLib.Matrix <T> .CreateOnesMatrix(_numberOfRows, _numberOfColumns);
                }
                break;
            }

            case "Zero":
            {
                if (_operand == "Left Matrix")
                {
                    _leftMatrix = MatrixLib.Matrix <T> .CreateZeroMatrix(_numberOfRows, _numberOfColumns);
                }
                if (_operand == "Right Matrix")
                {
                    _rightMatrix = MatrixLib.Matrix <T> .CreateZeroMatrix(_numberOfRows, _numberOfColumns);
                }
                break;
            }

            default:
            {
                if (_operand == "Left Matrix")
                {
                    _leftMatrix = new MatrixLib.Matrix <T>(_numberOfRows, _numberOfColumns, MatrixWrite());
                }
                if (_operand == "Right Matrix")
                {
                    _rightMatrix = new MatrixLib.Matrix <T>(_numberOfRows, _numberOfColumns, MatrixWrite());
                }
                break;
            }
            }

            Close();
        }
Esempio n. 5
0
        public Matrix(int numberOfRows, int numberOfColumns, T[,] matrixValues)
        {
            InitializeComponent();
            _numberOfRows       = numberOfRows;
            _numberOfColumns    = numberOfColumns;
            _resultMatrixValues = new T[_numberOfRows, _numberOfColumns];
            for (var i = 0; i < matrixValues.GetLength(0); ++i)
            {
                for (var j = 0; j < matrixValues.GetLength(1); ++j)
                {
                    _resultMatrixValues[i, j] = matrixValues[i, j];
                }
            }
            _comboBoxValue = "Result";
            _operand       = "Result";

            _resultMatrix = new MatrixLib.Matrix <T>(_resultMatrixValues.GetLength(0),
                                                     _resultMatrixValues.GetLength(1), _resultMatrixValues);
        }
Esempio n. 6
0
        private void Matrix_Load(object sender, EventArgs e)
        {
            this.Text = _operand;

            _userMatrixValues = new T[_numberOfRows, _numberOfColumns];

            if (_resultMatrix == null || _rightMatrix == null || _numberOfRows > _rightMatrix.Get2DArray().GetLength(0) ||
                _numberOfColumns > _rightMatrix.Get2DArray().GetLength(1) ||
                _numberOfRows > _resultMatrix.Get2DArray().GetLength(0) || _numberOfColumns > _resultMatrix.Get2DArray().GetLength(1))
            {
                for (var i = 0; i < _numberOfRows; ++i)
                {
                    for (var j = 0; j < _numberOfColumns; ++j)
                    {
                        if (_leftMatrix != null && _operand == "Left Matrix")
                        {
                            _userMatrixValues[i, j] = _leftMatrix[i, j];
                        }
                        else if (_rightMatrix != null && _operand == "Right Matrix")
                        {
                            _userMatrixValues[i, j] = _rightMatrix[i, j];
                        }
                        else
                        {
                            _userMatrixValues[i, j] = (T)Convert.ChangeType(1, typeof(T));
                        }
                    }
                }
            }

            else if (_resultMatrix != null && _operand == "Left Matrix")
            {
                for (var i = 0; i < _numberOfRows; ++i)
                {
                    for (var j = 0; j < _numberOfColumns; ++j)
                    {
                        _userMatrixValues[i, j] = (T)Convert.ChangeType(_resultMatrix.Get2DArray()[i, j], typeof(T));
                    }
                }

                _leftMatrix   = new MatrixLib.Matrix <T>(_numberOfRows, _numberOfColumns, _userMatrixValues);
                _resultMatrix = new MatrixLib.Matrix <T>(_numberOfRows, _numberOfColumns, _userMatrixValues);
            }

            else if (_rightMatrix != null && _operand == "Right Matrix")
            {
                for (var i = 0; i < _numberOfRows; ++i)
                {
                    for (var j = 0; j < _numberOfColumns; ++j)
                    {
                        _userMatrixValues[i, j] = (T)Convert.ChangeType(_rightMatrix.Get2DArray()[i, j], typeof(T));
                    }
                }

                _rightMatrix = new MatrixLib.Matrix <T>(_numberOfRows, _numberOfColumns, _userMatrixValues);
            }

            switch (_comboBoxValue)
            {
            case "Custom":
                UserMatrix();
                break;

            case "Diagonal":
                DiagMatrix();
                break;

            case "Unit":
                UnitMatrix();
                break;

            case "Zero":
                ZeroMatrix();
                break;

            case "Loaded":
                LoadedMatrix();
                break;

            case "Result":
                ResultMatrix();
                break;
            }
        }