コード例 #1
0
        private void DrawExtrapolation()
        {
            if (PointsXY.Count == 5)
            {
                if (ApproxChart.Series.FindByName("Extrapolation") != null)
                {
                    ApproxChart.Series.Remove(ApproxChart.Series.FindByName("Extrapolation"));
                }
                Series series = new Series("Extrapolation");
                series.ChartType = SeriesChartType.Point;
                series.ChartArea = "Approximation functions";
                if (CheckBLagrange.Checked)
                {
                    Lagrange lagrange = new Lagrange(sortPointList(PointsXY));

                    series.Points.AddXY(0, lagrange.getResult(0));
                    series.Points.AddXY(6, lagrange.getResult(6));
                }
                if (CheckBLS.Checked)
                {
                    LeastSquares leastSquares = new LeastSquares(sortPointList(PointsXY));
                    series.Points.AddXY(0, leastSquares.getResult(0));
                    series.Points.AddXY(6, leastSquares.getResult(6));
                }
                ApproxChart.Series.Add(series);
            }
        }
コード例 #2
0
        private void main_MouseMove(object sender, MouseEventArgs e)
        {
            Point mousePosition = e.GetPosition(main);

            for (int i = 0; i < 5; i++)
            {
                if (userPoints[i].IsMoving)
                {
                    Point p = ConvertCanvasCoordsToChart(new Point(mousePosition.X, mousePosition.Y));
                    userPoints[i].Y = p.Y;
                    userPoints[i].Draw(main);
                }
            }
            if (mousePosition.X < 480)
            {
                info.Draw(mousePosition.X, mousePosition.Y);
            }

            double[] x = new double[5];
            double[] y = new double[5];
            for (int i = 0; i < 5; i++)
            {
                x[i] = userPoints[i].X;
                y[i] = userPoints[i].Y;
            }

            LeastSquares lsleastSquaresSolver = new LeastSquares(x, y);

            lsleastSquaresSolver.BottomTrainglePath();
            leastSquaresKoef = lsleastSquaresSolver.UpperTrainglePath();
            leastSquaresMethodLine.Points.Clear();
            lagrangePolynomialMethodLine.Points.Clear();
            for (int i = 0; i < 70; i++)
            {
                Point p1 = ConvertChartCoordsToCanvas(new Point(i * 0.1, GetFunctionValue(i * 0.1, leastSquaresKoef)));
                leastSquaresMethodLine.Points.Add(p1);

                Point p2 = ConvertChartCoordsToCanvas(new Point(i * 0.1, LagrangePolinomial.GetValue(i * 0.1, x, y)));
                lagrangePolynomialMethodLine.Points.Add(p2);
            }

            UpdateInputDataTable();
            UpdateLeastSquaresTable();
            UpdateLagrangePolynomialTable(LagrangePolinomial.GetValue(0, x, y), LagrangePolinomial.GetValue(6, x, y));
        }
コード例 #3
0
 private void DrawFunction()
 {
     if (buildFunction)
     {
         if (CheckBLagrange.Checked && PointsXY.Count == 5)
         {
             Lagrange lagrange = new Lagrange(sortPointList(PointsXY));
             if (ApproxChart.Series.FindByName("Lagrange") != null)
             {
                 ApproxChart.Series.Remove(ApproxChart.Series.FindByName("Lagrange"));
             }
             Series series = new Series("Lagrange");
             series.ChartType = SeriesChartType.Line;
             series.ChartArea = "Approximation functions";
             for (double x = 0; x < ApproxChart.ChartAreas[0].AxisX.Maximum; x += 0.01)
             {
                 series.Points.AddXY(x, lagrange.getResult(x));
             }
             ApproxChart.Series.Add(series);
         }
         if (CheckBLS.Checked && PointsXY.Count == 5)
         {
             LeastSquares leastSquares = new LeastSquares(sortPointList(PointsXY));
             if (ApproxChart.Series.FindByName("LeastSquares") != null)
             {
                 ApproxChart.Series.Remove(ApproxChart.Series.FindByName("LeastSquares"));
             }
             Series series = new Series("LeastSquares");
             series.ChartType = SeriesChartType.Line;
             series.ChartArea = "Approximation functions";
             for (double x = 0; x < ApproxChart.ChartAreas[0].AxisX.Maximum; x += 0.01)
             {
                 series.Points.AddXY(x, leastSquares.getResult(x));
             }
             ApproxChart.Series.Add(series);
         }
         DrawExtrapolation();
     }
 }