Beispiel #1
0
/*
 +-----------------------------+
 |     Monte Carlo method      |
 +-----------------------------+
 */

        private void methodMonteCarlo()
        {
            LevelLine ll = new LevelLine(chart3);
            double    extremum;

            MonteCarlo mc = new MonteCarlo();

            extremum = mc.monteCarlo();
            List <Extremums> extremumCoordinatesList = mc.getExtremumsList();

            dataGridView1.RowCount              = extremumCoordinatesList.Count;
            dataGridView1.ColumnCount           = 3;
            dataGridView1.ColumnHeadersVisible  = true;
            dataGridView1.Columns[0].HeaderText = "X1";
            dataGridView1.Columns[1].HeaderText = "X2";
            dataGridView1.Columns[2].HeaderText = "MIN";

            for (int i = 0; i < extremumCoordinatesList.Count; i++)
            {
                ll.drawLine(extremumCoordinatesList[i].getExtremum());

                dataGridView1.Rows[i].Cells[0].Value = extremumCoordinatesList[i].getX1();
                dataGridView1.Rows[i].Cells[1].Value = extremumCoordinatesList[i].getX2();
                dataGridView1.Rows[i].Cells[2].Value = extremumCoordinatesList[i].getExtremum();
                if (extremumCoordinatesList[i].getExtremum() == extremum)
                {
                    this.label1.Text = extremumCoordinatesList[i].getExtremum().ToString();
                    this.label2.Text = extremumCoordinatesList[i].getX1().ToString();
                    this.label3.Text = extremumCoordinatesList[i].getX2().ToString();
                    ll.pointExtremum(extremumCoordinatesList[i].getX1(), extremumCoordinatesList[i].getX2());
                }
            }
        }
Beispiel #2
0
/*
 +-----------------------------+
 |     Hooke Jeeves method      |
 +-----------------------------+
 */

        private void methodHookeJeeves(Double _startX1, Double _startX2, Double _step, Double _accuracy)
        {
            chart3.Series.Clear();
            LevelLine   ll          = new LevelLine(chart3);
            HookeJeeves hookeJeeves = new HookeJeeves();
            Extremums   ec          = hookeJeeves.extremumFunction(_startX1, _startX2, _step, _accuracy);
            String      answer      = "Экстремум " + ec.getExtremum().ToString() + " x1= " + ec.getX1() + " x2 = " + ec.getX2();

            MessageBox.Show(answer);
            textBox1.Visible = true;
            textBox1.Text    = answer;

            List <Extremums> extremumCoordinatesList = hookeJeeves.getExtremumsList();

            Series series      = new Series("way");
            Series seriesPoint = new Series("point");

            series.ChartType   = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            series.Color       = System.Drawing.Color.Black;
            series.BorderWidth = 3;

            dataGridView1.RowCount              = extremumCoordinatesList.Count;
            dataGridView1.ColumnCount           = 3;
            dataGridView1.Columns[0].HeaderText = "X1";
            dataGridView1.Columns[1].HeaderText = "X2";
            dataGridView1.Columns[2].HeaderText = "MIN";

            for (double extremum = 0; extremum < 4; extremum += 0.25)
            {
                ll.drawLine(extremum);
            }

            for (int i = 0; i < extremumCoordinatesList.Count; i++)
            {
                dataGridView1.Rows[i].Cells[0].Value = extremumCoordinatesList[i].getX1();
                dataGridView1.Rows[i].Cells[1].Value = extremumCoordinatesList[i].getX2();
                dataGridView1.Rows[i].Cells[2].Value = extremumCoordinatesList[i].getExtremum();
                double x1 = extremumCoordinatesList[i].getX1();
                double x2 = extremumCoordinatesList[i].getX2();
                series.Points.AddXY(x1, x2);

                if (extremumCoordinatesList[i].getExtremum() == ec.getExtremum())
                {
                    this.label1.Text = Math.Round(extremumCoordinatesList[i].getExtremum(), 2).ToString();
                    this.label2.Text = Math.Round(extremumCoordinatesList[i].getX1(), 2).ToString();
                    this.label3.Text = Math.Round(extremumCoordinatesList[i].getX2(), 2).ToString();
                    ll.pointExtremum(extremumCoordinatesList[i].getX1(), extremumCoordinatesList[i].getX2());
                }
            }
            chart3.Series.Add(series);
        }