コード例 #1
0
        private void IndividualMatrixRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            // If individialMatrixRadioButton is checked
            if (IndividualMatrixRadioButton.Checked)
            {
                // If MatrixDataGridView isn't clear
                if (MatrixDataGridView.GetCellCount(DataGridViewElementStates.Displayed) != 0)
                {
                    ColumnsTextBox.Text = MatrixClass.COUNT_COLUMNS.ToString();
                    RowsTextBox.Text    = MatrixClass.COUNT_ROWS.ToString();
                }
                // ... is clear
                else
                {
                    ColumnsTextBox.Text = COUNT_ROW_COL_DEFAULT.ToString();
                    RowsTextBox.Text    = COUNT_ROW_COL_DEFAULT.ToString();
                }

                // Set visible group boxes
                ColRowGroupBox.Visible = true;
                ResultGroupBox.Visible = false;
            }
            else
            {
                // Set visible group boxes
                ColRowGroupBox.Visible = false;
                ResultGroupBox.Visible = true;
                individualMatrix       = null;
            }
        }
コード例 #2
0
        private void ProcessIndividualMatrix()
        {
            if (isProcessedIndividualMatrix)
            {
                return;
            }
            if (individualMatrix == null)
            {
                InitializeIndividualMatrix();
                individualMatrix = baseMatrix;
            }

            // --- Gauss method ---
            int minCells = Math.Min(individualMatrix.Columns, individualMatrix.Rows);

            for (int i = 0; i < minCells; i++)
            {
                individualMatrix.DivideRow(i, individualMatrix[i, i]);

                for (int k = i + 1; k < individualMatrix.Rows; k++)
                {
                    double pw = (-1) * individualMatrix[k, i];
                    individualMatrix.MultiplyRow(i, pw);
                    individualMatrix.AddRows(i, k);
                    individualMatrix.DivideRow(i, pw);
                }
            }
            // --- // ---

            double[][] resultArray = new double[individualMatrix.Rows][];
            for (int i = 0; i < resultArray.Length; i++)
            {
                resultArray[i] = new double[resultArray.Length - i];
            }

            for (int i = 0; i < resultArray.Length; i++)
            {
                for (int j = resultArray[i].Length - 1, k = 0; k < resultArray[i].Length; j--, k++)
                {
                    resultArray[i][j] = individualMatrix[i, j + i];
                }
            }

            MatrixDataGridView.Rows.Clear();
            MatrixDataGridView.ColumnCount = individualMatrix.Columns;
            MatrixDataGridView.RowCount    = individualMatrix.Rows;

            for (int i = 0; i < resultArray.Length; i++)
            {
                for (int j = resultArray[i].Length - 1, k = 0; k < resultArray[i].Length; j--, k++)
                {
                    MatrixDataGridView.Rows[i].Cells[j + i].Value = String.Format("{0:0}", resultArray[i][j]);
                }
            }
            isProcessedIndividualMatrix = true;
        }
コード例 #3
0
        private bool InitializeIndividualMatrix()
        {
            int cols, rows;

            try
            {
                cols = int.Parse(ColumnsTextBox.Text);
                rows = int.Parse(RowsTextBox.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Count of columns or rows is uncorrect. Correct it and try again!");
                return(false);
            }

            if (cols == 0 || rows == 0)
            {
                MessageBox.Show("Count of columns or rows is zero. Correct it and try again!");
                return(false);
            }

            individualMatrix = new MatrixClass(rows, cols);
            return(true);
        }