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

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

            // CHANGE IT BACK HERE TO 'OUT' INSTEAD OF 'REF'
            BaseNode mcLaurienRoot;

            plotter.CreateMcLaurienSeries(out mcLaurienRoot, order);  // output mclaurien series

            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 = " + order + ")"
                };
                myModel.Series.Add(mcLaurienSeries);
                myModel.Series.Add(graphSeries);
                plot.Model = myModel;

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