예제 #1
0
        public Point Task1(Form form, Point location)
        {
            double a = 0.9;

            double[] f = new double[] { 4 * a, -4.4 * a, -1, 1 };

            double[] firstDerivative  = Poly.GetPolyDerivative(f);
            double[] secondDerivative = Poly.GetPolyDerivative(firstDerivative);

            double[] xs      = Range.Make(-5, 5, 0.1);
            double[] breakXs = Poly.PolySolvePrimitive(secondDerivative, 0);

            (double[] mins, double[] maxs) = FindExtremumsUniform(f, -4, 4, 0.01);

            Console.WriteLine("MINS: " + string.Join(" ", mins));
            Console.WriteLine("MAXS: " + string.Join(" ", maxs));

            Plot plot = new Plot();

            plot.PlotSignalXY(xs, Poly.Val(f, xs), Color.Red, 7, label: "Original signal");
            plot.PlotSignalXY(xs, Poly.Val(firstDerivative, xs), Color.Green, 5, label: "First Derivative");
            plot.PlotSignalXY(xs, Poly.Val(secondDerivative, xs), Color.Blue, 3, label: "Second Derivative");

            plot.PlotScatter(
                breakXs.Concat(breakXs).Concat(breakXs).ToArray(),
                Poly.Val(f, breakXs).Concat(Poly.Val(firstDerivative, breakXs)).Concat(Poly.Val(secondDerivative, breakXs)).ToArray(),
                Color.Yellow, label: "Unimodal break points", markerSize: 3, lineStyle: LineStyle.Dot
                );

            plot.PlotScatter(mins, Poly.Val(f, mins), Color.Cyan, markerSize: 7, label: "Min points", lineStyle: LineStyle.Dot);
            plot.PlotScatter(maxs, Poly.Val(f, maxs), Color.LightGreen, markerSize: 7, label: "Max points", lineStyle: LineStyle.Dot);

            plot.Legend();

            return(plot.AddToForm(form, location));
        }