Example #1
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            int[][] MatrixA = new int[][] {
                new int[] { Convert.ToInt32(dataGridView1[0, 1].Value), Convert.ToInt32(dataGridView1[1, 1].Value), Convert.ToInt32(dataGridView1[2, 1].Value), Convert.ToInt32(dataGridView1[3, 1].Value) },
                new int[] { Convert.ToInt32(dataGridView1[0, 2].Value), Convert.ToInt32(dataGridView1[1, 2].Value), Convert.ToInt32(dataGridView1[2, 2].Value), Convert.ToInt32(dataGridView1[3, 2].Value) },
                new int[] { Convert.ToInt32(dataGridView1[0, 3].Value), Convert.ToInt32(dataGridView1[1, 3].Value), Convert.ToInt32(dataGridView1[2, 3].Value), Convert.ToInt32(dataGridView1[3, 3].Value) },
            };
            int[] MatrixB = new int[] { Convert.ToInt32(dataGridView5[0, 0].Value), Convert.ToInt32(dataGridView5[0, 1].Value), Convert.ToInt32(dataGridView5[0, 2].Value) };
            int[] MatrixC = new int[] { Convert.ToInt32(dataGridView2[0, 0].Value), Convert.ToInt32(dataGridView2[1, 0].Value), Convert.ToInt32(dataGridView2[2, 0].Value), Convert.ToInt32(dataGridView2[3, 0].Value), Convert.ToInt32(dataGridView2[4, 0].Value) };



            mefunc f = new mefunc();

            int []  y = new int[5];
            int []  x = new int[4];
            int[][] F = new int[10][];
            for (int o = 0; o < F.Length; o++)
            {
                F[o] = new int[2000];
                for (int p = 0; p < 2000; p++)
                {
                    F[o][p] = 0;
                }
            }

            /* x[3] = MatrixA[0][3];
             * x[2] = MatrixA[0][2];
             * x[1] = MatrixA[0][1];
             * x[0] = MatrixA[0][0];*/
            //int[] x = new int[MatrixA.Length];
            try
            {
                x[0] = f.algo1(MatrixA, MatrixB, MatrixC, y, F);
                x[1] = f.algo2(MatrixA, MatrixB, MatrixC, y, F);
                x[2] = f.algo3(MatrixA, MatrixB, MatrixC, y, F);
                x[3] = f.algo4(MatrixA, MatrixB, MatrixC, y, F);
                int[] d = f.d_exp(MatrixA, MatrixB);
                if ((F[6][0] >= 1000000000) || (F[6][1] >= 1000000000) || (F[6][2] >= 1000000000) || (F[6][3] >= 1000000000))
                {
                    MessageBox.Show("Слишком большой шаг", "Ошибка");
                }
                else
                {
                    richTextBox1.Text =
                        "x1 = " + x[0].ToString() + "  y1 =  " + y[1].ToString() + "  d1 =  " + d[0].ToString() + "  F1 =  " + F[6][0].ToString() + ";\n" +
                        "x2 = " + x[1].ToString() + "  y2 =  " + y[2].ToString() + "  d2 =  " + d[1].ToString() + "  F2 =  " + F[6][1].ToString() + ";\n" +
                        "x3 = " + x[2].ToString() + "  y3 =  " + y[3].ToString() + "  d3 =  " + d[2].ToString() + "  F3 =  " + F[6][2].ToString() + ";\n" +
                        "x4 = " + x[3].ToString() + "  y4 =  " + y[4].ToString() + "  d4 =  " + d[3].ToString() + "  F4 =  " + F[6][3].ToString() + ";\n";
                    textBox4.Text = F[6][3].ToString();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Слишком большой шаг", "Ошибка");
            }
        }
Example #2
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            double ver;
            string pr = comboBox1.Text;

            switch (pr)
            {
            //  case "0.95": ver = 0.65788; break;
            case "0.9": ver = 0.63188; break;

            case "0.85": ver = 0.60468; break;

            case "0.8": ver = 0.57628; break;

            case "0.75": ver = 0.54674; break;

            case "0.7": ver = 0.51607; break;

            case "0.65": ver = 0.4843; break;

            case "0.6": ver = 0.4515; break;

            default: ver = 0.45149; break;
            }

            //double[][][] matr_a = new double[3][][];

            //matr_a[0] = new double[this.dataGridView1.ColumnCount / 2][];
            //matr_a[1] = new double[this.dataGridView3.ColumnCount / 2][];
            //matr_a[2] = new double[this.dataGridView4.ColumnCount / 2][];

            //for (int i = 0; i < matr_a.Length; i++)
            //{
            //    for (int j = 0; j < matr_a[i].Length; i++)
            //    {
            //        matr_a[i][j] = new double[this.dataGridView1.RowCount - 1];
            //    }
            //}

            //for (int i = 0; i < matr_a[0].Length; i++)
            //{
            //    for (int j = 0; j < matr_a[0][i].Length; i++)
            //    {
            //        matr_a[0][i][j] = Double.Parse(this.dataGridView1[i * 2, j + 1].Value.ToString());
            //    }
            //}

            //for (int i = 0; i < matr_a[1].Length; i++)
            //{
            //    for (int j = 0; j < matr_a[1][i].Length; i++)
            //    {
            //        matr_a[1][i][j] = Double.Parse(this.dataGridView2[i * 2, j + 1].Value.ToString());
            //    }
            //}

            //for (int i = 0; i < matr_a[2].Length; i++)
            //{
            //    for (int j = 0; j < matr_a[2][i].Length; i++)
            //    {
            //        matr_a[2][i][j] = Double.Parse(this.dataGridView3[i * 2, j + 1].Value.ToString());
            //    }
            //}

            //double[][][] matr_d = new double[3][][];

            //matr_d[0] = new double[this.dataGridView1.ColumnCount / 2][];
            //matr_d[1] = new double[this.dataGridView3.ColumnCount / 2][];
            //matr_d[2] = new double[this.dataGridView4.ColumnCount / 2][];

            //for (int i = 0; i < matr_d.Length; i++)
            //{
            //    for (int j = 0; j < matr_d[i].Length; i++)
            //    {
            //        matr_d[i][j] = new double[this.dataGridView1.RowCount - 1];
            //    }
            //}

            //for (int i = 0; i < matr_d[0].Length; i++)
            //{
            //    for (int j = 0; j < matr_d[0][i].Length; i++)
            //    {
            //        matr_d[0][i][j] = Double.Parse(this.dataGridView1[i * 2 + 1, j + 1].Value.ToString());
            //    }
            //}

            //for (int i = 0; i < matr_d[1].Length; i++)
            //{
            //    for (int j = 0; j < matr_d[1][i].Length; i++)
            //    {
            //        matr_d[1][i][j] = Double.Parse(this.dataGridView2[i * 2 + 1, j + 1].Value.ToString());
            //    }
            //}

            //for (int i = 0; i < matr_d[2].Length; i++)
            //{
            //    for (int j = 0; j < matr_d[2][i].Length; i++)
            //    {
            //        matr_d[2][i][j] = Double.Parse(this.dataGridView3[i * 2 + 1, j + 1].Value.ToString());
            //    }
            //}

            //int n = 0;
            //int m = this.dataGridView1.RowCount - 1;
            //for (int i = 0; i < matr_a.Length; i++)
            //{
            //    n += matr_a[i].Length;
            //}

            //double[][] MatrixA = new double[n][];
            //double[][] MatrixD = new double[n][];
            //double[] MatrixB = new double[m];
            //double[] MatrixC = new double[m];

            //for (int i = 0; i < n; i++)
            //{
            //    MatrixA[i] = new double[m];
            //    MatrixD[i] = new double[m];
            //}

            //for (int i = 0; i < m; i++)
            //{
            //    MatrixC[i] = Double.Parse(dataGridView2[i, 0].Value.ToString());
            //    MatrixC[i] = Double.Parse(dataGridView5[0, i].Value.ToString());
            //}

            //for (int i = 0; i < matr_a.Length; i++)
            //{
            //    int k = 0;
            //    for (int j = 0; j < i; j++)
            //    {
            //        k += matr_a[j].Length;
            //    }
            //    for (int j = 0; j < matr_a[i].Length; j++)
            //    {
            //        for (int q = 0; q < matr_a[i][j].Length; q++)
            //        {
            //            MatrixA[k + j][q] = matr_a[i][j][q];
            //            MatrixD[k + j][q] = matr_d[i][j][q];
            //        }
            //    }
            //}

            int n = 7;
            int m = 3;

            double[][] MatrixA = new double[][] { new double[] { 0.4, 0.8, 0.6 }, new double[] { 0.5, 0, 0.9 },
                                                  new double[] { 0.6, 0.4, 0.9 }, new double[] { 0.5, 0.6, 0.8 }, new double[] { 1, 0.4, 0.5 },
                                                  new double[] { 0.8, 0.2, 0 }, new double[] { 0, 1, 1.5 } };
            double[][] MatrixD = new double[][] { new double[] { 0.2, 0.5, 0.3 }, new double[] { 0.2, 0, 0.45 },
                                                  new double[] { 0.3, 0.4, 0.3 }, new double[] { 0.2, 0.1, 0.5 }, new double[] { 0.5, 0.2, 0.3 },
                                                  new double[] { 0.3, 2, 0 }, new double[] { 0, 0.5, 0.8 } };
            double[] MatrixB = new double[] { 400, 300, 500 };
            double[] MatrixC = new double[] { 30, 40, 20 };

            double r = 1.5;       // Convert.ToDouble(textBox1.Text);
            int    b = 2;         //  Convert.ToInt16(textBox2.Text);
            int    p = 2;         //  Convert.ToInt16(textBox3.Text);

            mefunc f = new mefunc();

            double[] x = new double[MatrixA.Length];
            try
            {
                if (radioButton1.Checked)
                {
                    x = f.func1(MatrixC, MatrixA, MatrixB, MatrixD, r, b, p, ver);
                }
                else
                {
                    x = f.func2(MatrixC, MatrixA, MatrixB, MatrixD, r, b, p, ver);
                }
                double   sum = 0;
                double[] X   = new double[m];
                for (int i = 0; i < x.Length; i++)
                {
                    x[i] = Convert.ToInt32(x[i]);
                }
                X[0] = x[0] + x[1];
                X[1] = x[2] + x[3] + x[4];
                X[2] = x[5] + x[6];

                if (radioButton1.Checked)
                {
                    for (int i = 0; i < X.Length; i++)
                    {
                        sum += MatrixC[i] * X[i];
                    }
                }
                else
                {
                    for (int i = 0; i < X.Length; i++)
                    {
                        sum += MatrixC[i] * X[i];
                    }
                }
                richTextBox1.Text =
                    "x1 = " + X[0].ToString() + ";\n" +
                    " 1-м методом=" + x[0].ToString() + ";\n" +
                    " 2-м методом=" + x[1].ToString() + ";\n" +
                    "x2 = " + X[1].ToString() + ";\n" +
                    " 1-м методом=" + x[4].ToString() + ";\n" +
                    " 2-м методом=" + x[5].ToString() + ";\n" +
                    " 3-м методом=" + x[6].ToString() + ";\n" +
                    "x3 = " + X[2].ToString() + ";" +
                    " 1-м методом=" + x[5].ToString() + ";\n" +
                    " 2-м методом=" + x[6].ToString() + ";\n";
                textBox4.Text = sum.ToString();
                textBox6.Text = somefunc(MatrixA, MatrixB, MatrixD, x, 0, ver).ToString();
                textBox7.Text = somefunc(MatrixA, MatrixB, MatrixD, x, 1, ver).ToString();
                textBox8.Text = somefunc(MatrixA, MatrixB, MatrixD, x, 2, ver).ToString();
            }
            catch (Exception)
            {
                MessageBox.Show("Слишком большой шаг", "Ошибка");
            }
        }