Beispiel #1
0
    private void drawPlot(Func <double, double> func, double x0, double h, int count)
    {
        var polynomial = NewtonMethod.Interpolate(func, x0, h, count);

        //Отступ, чтобы отрезок интерполяции занимал 75% графика (отступы - 12.5% каждый)
        double offsetNodes = count * 0.125;
        double left        = x0 - offsetNodes * h;
        double right       = x0 + (offsetNodes + count - 1) * h;

        if (left > right)
        {
            double temp = left;
            left  = right;
            right = temp;
        }

        var myModel = new PlotModel {
            Title = "График"
        };

        myModel.Series.Add(new FunctionSeries(func, left, right, 0.1, "f(x)"));
        myModel.Series.Add(new FunctionSeries(polynomial.ValueAt, left, right, 0.1, "P(x)"));

        var scatterSeries = new ScatterSeries {
            MarkerType = MarkerType.Circle
        };

        for (int i = 0; i < count; i++)
        {
            double xn = x0 + i * h;
            scatterSeries.Points.Add(new ScatterPoint(xn, func(xn), 5, 255));
        }
        myModel.Series.Add(scatterSeries);

        plotView.Model = myModel;
    }