示例#1
0
 static void RungeStepTable(double a, double b, double y0, List <double> epsList, int r)
 {
     Console.WriteLine($"\n\t\t\t Finding step with Runge Principle\n");
     Console.WriteLine(" |  Expected error, ε   |      Step value      |  Avg error with Runge-Kutta, Δ |");
     foreach (double eps in epsList)
     {
         double stepByRunge = CauchyProblem.RungePrinciple(a, b, y0, eps, r);
         double error       = AvgError(CauchyProblem.RungeKuttaMethod(a, b, stepByRunge, y0));
         Console.WriteLine($" | {eps,-20} | {stepByRunge,-20} |    {error,-27} |");
     }
     Console.WriteLine(" |______________________|______________________|________________________________|");
 }
示例#2
0
        static void AdamsTable(double a, double b, double h, double y0, double eps, double divider)
        {
            Console.WriteLine($"\n\t Multistep Adams method, ε = {eps}\n");
            Console.WriteLine(" |  Average error, Δ    |      Step value      |");
            var    points = CauchyProblem.AdamsMethod(a, b, h, y0);
            double error  = AvgError(points);

            Console.WriteLine($" | {error,-20} | {h,-20} |");
            while (error > eps)
            {
                points = CauchyProblem.AdamsMethod(a, b, h /= divider, y0);
                error  = AvgError(points);
                Console.WriteLine($" | {error,-20} | {h,-20} |");
            }
            Console.WriteLine(" |______________________|______________________|");
        }
示例#3
0
        static double RungeKuttaTable(double a, double b, double h, double y0, double eps, double divider)
        {
            Console.WriteLine($"\n\t Runge-Kutta method, ε = {eps}\n");
            Console.WriteLine(" |  Average error, Δ    |      Step value      |");
            var    points = CauchyProblem.RungeKuttaMethod(a, b, h, y0);
            double error  = AvgError(points);

            Console.WriteLine($" | {error,-20} | {h,-20} |");
            while (error > eps)
            {
                points = CauchyProblem.RungeKuttaMethod(a, b, h /= divider, y0);
                error  = AvgError(points);
                Console.WriteLine($" | {error,-20} | {h,-20} |");
            }
            Console.WriteLine(" |______________________|______________________|");
            return(error);
        }
示例#4
0
        static void WriteCSV(double a, double b, double y0, double h)
        {
            var points = CauchyProblem.RungeKuttaMethod(a, b, h, y0);

            using (var sw = new StreamWriter("RungeKuttaPoints.csv"))
            {
                foreach (Point p in points)
                {
                    sw.WriteLine($"{p.X};{p.Y}");
                }
            }
            points = CauchyProblem.AdamsMethod(a, b, h, y0);
            using (var sw = new StreamWriter("AdamsPoints.csv"))
            {
                foreach (Point p in points)
                {
                    sw.WriteLine($"{p.X};{p.Y}");
                }
            }
        }