Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            IMatrix A;
            Vector b;
            Vector x0;

            FileManager fileManager = new FileManager(fileName.Text);

            switch (matrixFormat.SelectedIndex)
            {
                case 0: fileManager.ReadFromFileDense(out A, out b, out x0);
                    break;
                case 1: fileManager.ReadFromFile(out A, out b, out x0);
                    break;
                case 2: fileManager.ReadFromFileProfile(out A, out b, out x0);
                    break;
                case 3: fileManager.ReadFromFileCoordinate(out A, out b, out x0);
                    break;
                default: throw new Exception("Формат не выбран");
            }
            string res_residual = "Невязка: ";

            Solver solver;

            switch(methodSolver.SelectedIndex)
            {
                case 0:
                    solver = new Jacobi(Convert.ToDouble(Relaxation.Text),
                                        Convert.ToInt16(IterationMax.Text),
                                        Convert.ToDouble(ResidualMin.Text));
                    break;
                case 1:
                    solver = new ConjugateGradient(Convert.ToInt16(IterationMax.Text),
                                                   Convert.ToDouble(ResidualMin.Text));
                    break;
                case 2:
                    solver = new GaussZeidel_New(Convert.ToDouble(Relaxation.Text),
                                        Convert.ToInt16(IterationMax.Text),
                                        Convert.ToDouble(ResidualMin.Text));
                    break;
                case 3:
                    solver = new LOS(Convert.ToInt16(IterationMax.Text),
                                        Convert.ToDouble(ResidualMin.Text));
                    res_residual = "Квадрат нормы невязки: ";
                    break;
                default:
                    throw new Exception("Метод не выбран");
            }

            Vector solution = (Vector)solver.Solve(A, b, x0);

            string result = string.Empty;
            for (int i = 0; i < solution.Size; i++)
                result += Convert.ToString(solution[i]) + "\r\n";

            File.WriteAllText("result.txt", "");

            string FinalResult = "Вектор решения: \r\n" + result + "\r\n" + "Количество итераций: " + Convert.ToString(solver.iteration) + "\r\n" + res_residual + Convert.ToString(solver.residual);

            if (solution.Size <= 20)
                MessageBox.Show(FinalResult, "РЕЗУЛЬТАТЫ РЕШЕНИЯ");
            else
            {
                MessageBox.Show("Результаты решения в файле /SLAE/slae/slae/bin/Debug/result.txt");
                File.WriteAllText("result.txt", FinalResult);
            }
            File.WriteAllText("result.txt", FinalResult);
        }
Exemple #2
0
        private void viewMatrix_Click(object sender, EventArgs e)
        {
            if (viewMatrix.BackColor == Color.Green)
            {
                IMatrix A;
                Vector b;
                Vector x0;

                FileManager fileManager = new FileManager(fileName.Text);

                switch (matrixFormat.SelectedIndex)
                {
                    case 0: fileManager.ReadFromFileDense(out A, out b, out x0);
                        break;
                    case 1: fileManager.ReadFromFile(out A, out b, out x0);
                        break;
                    case 2: fileManager.ReadFromFileProfile(out A, out b, out x0);
                        break;
                    case 3: fileManager.ReadFromFileCoordinate(out A, out b, out x0);
                        break;
                    default: throw new Exception("Формат не выбран");
                }
                if (A.Size < 100)
                {
                    DataTable table = new DataTable();
                    for (int i = 0; i < A.Size; i++)
                    {
                        DataColumn col = new DataColumn((i + 1).ToString());
                        table.Columns.Add(col);
                    }
                    for (int i = 0; i < A.Size; i++)
                    {
                        DataRow row = table.NewRow();

                        for (int j = 0; j < A.Size; j++)
                        {
                            row[j] = A[i, j];
                        }
                        table.Rows.Add(row);
                    }
                    dataGridView1.DataSource = table;
                    for (int i = 0; i < A.Size; i++)
                        dataGridView1.Rows[i].HeaderCell.Value = (i + 1).ToString();
                    dataGridView1.Visible = true;
                    this.Size = new Size(640, 640);
                    dataGridView1.Width = 620;
                    dataGridView1.Height = 280;
                    viewMatrix.BackColor = Color.White;
                }
                else
                {
                    label9.Visible = true;
                    viewMatrix.BackColor = Color.Orange;
                    viewMatrix.Enabled = false;
                }

            }
            else
            {
                dataGridView1.Visible = false;
                this.Size = new Size(640, 330);
                viewMatrix.BackColor = Color.Green;
            }
        }