Exemplo n.º 1
0
        private void calculateMcLaurienByLimitButton_Click(object sender, EventArgs e)
        {
            int n = int.Parse(mcLaurienOrderTextBox.Text); // get the order for the maclaurien

            if (!(n >= 1 && n <= 8))                       // check for the right input
            {
                MessageBox.Show("Please input a number that is bigger than 1 and less than 8!");
                return;
            }

            /*
             *  k=0 -> n
             *
             *  sum ( (-1)^(k)*(n!/(k! * (n-k)!))*f(X0 + h*( (n-2k)/2 )) ) / h^n
             *
             *  where 'n' is the order for derivative and X0 is the f^n(x0)
             */


            BaseNode mcLaurienRoot;

            plotter.CreateMcLaurienSeriesByLimits(out mcLaurienRoot, n);
            mcLaurienRoot = plotter.SimplifyTree(mcLaurienRoot);
            plotter.GetGraphImage(graphPictureBox, mcLaurienRoot);

            List <DataPoint> mcLaurienPoints = new List <DataPoint> ();
            FunctionSeries   mcLaurienSeries = new FunctionSeries {
                Title = "McLaurien"
            };
            List <DataPoint> graphPoints = new List <DataPoint> ();
            FunctionSeries   graphSeries = new FunctionSeries {
                Title = "Graph"
            };

            try {
                var boundaries     = Boundaries(xValueTextbox.Text);
                var realBoundaries = GetNewRangeBasedUponOldOne(plotter.Root, mcLaurienRoot, boundaries[0], boundaries[1]);

                for (double i = realBoundaries.lower; i < realBoundaries.upper; i += 0.3)
                {
                    mcLaurienPoints.Add(new DataPoint(i, plotter.ProcessTree(i, mcLaurienRoot)));
                }

                for (int i = boundaries[0]; i < boundaries[1]; i++)
                {
                    graphPoints.Add(new DataPoint(i, plotter.ProcessTree(i, plotter.Root)));
                }

                mcLaurienSeries.Points.AddRange(mcLaurienPoints);
                graphSeries.Points.AddRange(graphPoints);
                myModel = new PlotModel()
                {
                    Title = "McLaurien Series (order = " + n + ")"
                };
                myModel.Series.Add(mcLaurienSeries);
                myModel.Series.Add(graphSeries);
                plot.Model = myModel;

                plotGraph_called = true;
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }