Пример #1
0
        public List <Tuple <double, double> > getMaxError(double X0, double Y0, double UPPER_BOUND, int num_segments, int method)
        {
            List <Tuple <double, double> > Points = new List <Tuple <double, double> >();

            for (int i = 1; i <= num_segments; i++)
            {
                List <Tuple <double, double> > PointsOfMethod = new List <Tuple <double, double> >();
                List <Tuple <double, double> > Solution       = new List <Tuple <double, double> >();

                if (method == 1)
                {
                    PointsOfMethod = euler.solve(X0, Y0, UPPER_BOUND, i);
                }
                else if (method == 2)
                {
                    PointsOfMethod = improved_euler.solve(X0, Y0, UPPER_BOUND, i);
                }
                else
                {
                    PointsOfMethod = runge_kutta.solve(X0, Y0, UPPER_BOUND, i);
                }

                Points.Add(Tuple.Create((double)i, getMax(PointsOfMethod)));
            }

            return(Points);
        }
Пример #2
0
        public void drawPlot(Chart chart1, double X0, double Y0, double UPPER_BOUND, int num_segments, int method)
        {
            List <Tuple <double, double> > ApproxSolutionPoints1 = new List <Tuple <double, double> >();
            List <Tuple <double, double> > ApproxSolutionPoints2 = new List <Tuple <double, double> >();
            List <Tuple <double, double> > ApproxSolutionPoints3 = new List <Tuple <double, double> >();

            MyEquation equation = new MyEquation();

            Euler         euler          = new Euler();
            ImprovedEuler improved_euler = new ImprovedEuler();
            RungeKutta    runge_kutta    = new RungeKutta();

            if (method == 1)
            {
                ApproxSolutionPoints1 = euler.solve(X0, Y0, UPPER_BOUND, num_segments);

                for (int i = 0; i <= num_segments; i++)
                {
                    double localError = Math.Abs(ApproxSolutionPoints1.ElementAt(i).Item2 - equation.exactSolution(ApproxSolutionPoints1.ElementAt(i).Item1));
                    chart1.Series[0].Points.AddXY(ApproxSolutionPoints1.ElementAt(i).Item1, localError);
                }

                chart1.Series[0].IsVisibleInLegend = true;
                chart1.Series[0].Name = "Euler's\nmethod";
            }
            else if (method == 2)
            {
                ApproxSolutionPoints1 = improved_euler.solve(X0, Y0, UPPER_BOUND, num_segments);

                for (int i = 0; i <= num_segments; i++)
                {
                    double localError = Math.Abs(ApproxSolutionPoints1.ElementAt(i).Item2 - equation.exactSolution(ApproxSolutionPoints1.ElementAt(i).Item1));
                    chart1.Series[0].Points.AddXY(ApproxSolutionPoints1.ElementAt(i).Item1, localError);
                }

                chart1.Series[0].IsVisibleInLegend = true;
                chart1.Series[0].Name = "Improved Euler's\nmethod";
            }
            else if (method == 3)
            {
                ApproxSolutionPoints1 = runge_kutta.solve(X0, Y0, UPPER_BOUND, num_segments);

                for (int i = 0; i <= num_segments; i++)
                {
                    double localError = Math.Abs(ApproxSolutionPoints1.ElementAt(i).Item2 - equation.exactSolution(ApproxSolutionPoints1.ElementAt(i).Item1));
                    chart1.Series[0].Points.AddXY(ApproxSolutionPoints1.ElementAt(i).Item1, localError);
                }

                chart1.Series[0].IsVisibleInLegend = true;
                chart1.Series[0].Name = "Runge-Kutta\nmethod";
            }
            else
            {
                ApproxSolutionPoints1 = euler.solve(X0, Y0, UPPER_BOUND, num_segments);
                ApproxSolutionPoints2 = improved_euler.solve(X0, Y0, UPPER_BOUND, num_segments);
                ApproxSolutionPoints3 = runge_kutta.solve(X0, Y0, UPPER_BOUND, num_segments);

                for (int i = 0; i <= num_segments; i++)
                {
                    double localError = Math.Abs(ApproxSolutionPoints1.ElementAt(i).Item2 - equation.exactSolution(ApproxSolutionPoints1.ElementAt(i).Item1));
                    chart1.Series[0].Points.AddXY(ApproxSolutionPoints1.ElementAt(i).Item1, localError);
                }

                for (int i = 0; i <= num_segments; i++)
                {
                    double localError = Math.Abs(ApproxSolutionPoints2.ElementAt(i).Item2 - equation.exactSolution(ApproxSolutionPoints2.ElementAt(i).Item1));
                    chart1.Series[1].Points.AddXY(ApproxSolutionPoints2.ElementAt(i).Item1, localError);
                }

                for (int i = 0; i <= num_segments; i++)
                {
                    double localError = Math.Abs(ApproxSolutionPoints3.ElementAt(i).Item2 - equation.exactSolution(ApproxSolutionPoints3.ElementAt(i).Item1));
                    chart1.Series[2].Points.AddXY(ApproxSolutionPoints3.ElementAt(i).Item1, localError);
                }

                chart1.Series[0].IsVisibleInLegend = true;
                chart1.Series[1].IsVisibleInLegend = true;
                chart1.Series[2].IsVisibleInLegend = true;

                chart1.Series[0].Name = "Euler's\nmethod";
                chart1.Series[1].Name = "Improved Euler's\nmethod";
                chart1.Series[2].Name = "Runge-Kutta\nmethod";
            }

            // Design of charts

            chart1.ChartAreas[0].AxisX.LabelStyle.Format = "0.00";

            chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.LightGray;
            chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.LightGray;
        }