public GaussJordanSolver(int n, double[,] array) // Order of Matrix(n)
        {
            double[,] a = new double[n, n + 1];

            Debug.WriteLine("\nIn function:");
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n + 1; j++)
                {
                    a[i, j] = array[i, j];
                    // Debug.Write(a[i, j] + " ");
                }
                //Debug.WriteLine("");
            }

            int flag = 0;

            // Performing Matrix transformation
            flag = GaussJordanSolver.PerformOperation(a, n);

            if (flag == 1)
            {
                flag = GaussJordanSolver.CheckConsistency(a, n, flag);
            }

            // Printing Final Matrix
            Debug.WriteLine("Final Augumented Matrix is : ");
            GaussJordanSolver.PrintMatrix(a, n);
            Debug.WriteLine("\n");

            // Printing Solutions(if exist)
            GaussJordanSolver.PrintResult(a, n, flag); // убрать статические вызовы и сделать вместо матрицы float свою матрицу
        }
Пример #2
0
        private void solveButton_Click(object sender, EventArgs e)
        {
            double[,] array = new double[dataGridView1.RowCount, dataGridView1.ColumnCount];
            Debug.WriteLine("rows: " + dataGridView1.RowCount + " cols: " + dataGridView1.ColumnCount);
            foreach (DataGridViewRow i in dataGridView1.Rows)
            {
                if (i.IsNewRow)
                {
                    continue;
                }
                foreach (DataGridViewCell j in i.Cells)
                {
                    array[j.RowIndex, j.ColumnIndex] = Convert.ToDouble(j.Value);
                }
            }

            for (int i = 0; i < dataGridView1.RowCount; i++)
            {
                for (int j = 0; j < dataGridView1.ColumnCount; j++)
                {
                    Debug.Write(array[i, j] + " ");
                }
                Debug.WriteLine("");
            }

            try
            {
                solver = new GaussJordanSolver(M, array);
                matrix.InitResultView();
                matrix.WriteLog();
            }
            catch (IndexOutOfRangeException)
            {
                MessageBox.Show("Введенная система линейных алгебраических уравнений " +
                                "имеет бесконечное количество решений или не имеет их вовсе.",
                                "Исключение",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information
                                );
            }
        }