Пример #1
0
        public void DrawApproximation(IList <Tuple <double, double> > points)
        {
            gp.Title.Text       = "График аппроксимации";
            gp.YAxis.Title.Text = "N(eps)";
            gp.XAxis.Title.Text = "eps";

            gp.CurveList.Clear();

            //Рисуем точки
            PointPairList list = new PointPairList();

            foreach (Tuple <double, double> point in points)
            {
                list.Add(point.Item1, point.Item2);
            }

            LineItem scatterLine = gp.AddCurve("", list, Color.DarkBlue, SymbolType.Triangle);

            scatterLine.Line.IsVisible    = false;
            scatterLine.Symbol.Fill.Color = Color.DarkBlue;
            scatterLine.Symbol.Fill.Type  = FillType.Brush;

            //Рисуем апроксимацию

            LessSquare.GetCoefficient(points, out double k, out double b);

            PointPairList fList = new PointPairList();

            double xMin = ((int)points[0].Item1) - 1;
            double xMax = ((int)points[points.Count - 1].Item1) + 1;
            double yMin = ((int)points[0].Item2) - 1;
            double yMax = ((int)points[points.Count - 1].Item2) + 1;

            for (double x = xMin; x < xMax; x++)
            {
                fList.Add(x, LinearFunction(x, k, b));
            }

            LineItem line = gp.AddCurve("", fList, Color.Red, SymbolType.None);

            gp.XAxis.Scale.Min = xMin;
            gp.XAxis.Scale.Max = xMax;
            gp.YAxis.Scale.Min = yMin;
            gp.YAxis.Scale.Max = yMax;

            Graph.AxisChange();
            Graph.Invalidate();
        }
        private double GetAproximationByLessSquareMethod(List <Tuple <double, double> > points)
        {
            LessSquare.GetCoefficient(points, out double k, out double b);

            return(k);
        }