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(" |______________________|______________________|________________________________|"); }
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(" |______________________|______________________|"); }
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); }
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}"); } } }