62 long double a = 0.0L, b = 0.0L, x0 = 0.0L, tol = 1e-14L;
63 std::string method_name;
71 std::map<std::string, std::function<
long double(
long double,
long double,
long double,
int, std::vector<std::string> &,
int)>> methods = {
72 {
"Bisection Method", [](
long double a,
long double b,
long double tol,
int max_iter, std::vector<std::string> &iterations,
int decimal_places) ->
long double
74 return bisection(a, b, tol, max_iter, iterations, decimal_places);
76 {
"Hybrid Method", [](
long double a,
long double b,
long double tol,
int max_iter, std::vector<std::string> &iterations,
int decimal_places) ->
long double
78 return hybrid_method(a, b, tol, max_iter, iterations, decimal_places);
80 {
"Brent Method", [](
long double a,
long double b,
long double tol,
int max_iter, std::vector<std::string> &iterations,
int decimal_places) ->
long double
82 return brent_method(a, b, tol, max_iter, iterations, decimal_places);
84 {
"Ridder Method", [](
long double a,
long double b,
long double tol,
int max_iter, std::vector<std::string> &iterations,
int decimal_places) ->
long double
86 return ridder_method(a, b, tol, max_iter, iterations, decimal_places);
89 if (method_name ==
"Newton-Raphson Method")
91 std::vector<std::string> iterations;
94 summary[method_name].emplace_back(info);
97 std::cout <<
"\nMethod: " << method_name <<
"\n";
98 std::cout <<
"Initial guess: x0 = " << std::fixed << std::setprecision(info.decimal_places) << x0 <<
"\n";
99 std::cout <<
"Root: " << std::fixed << std::setprecision(info.decimal_places) << root <<
"\n";
100 std::cout <<
"Iterations:\n";
101 for (
const auto &iter : iterations)
103 std::cout << iter <<
"\n";
105 std::cout <<
"Iterations Count: " << iterations.size() <<
"\n";
107 else if (method_name ==
"Problem Steps Mode")
112 else if (method_name ==
"Compare All Methods")
120 auto it = methods.find(method_name);
121 if (it != methods.end() && it->second !=
nullptr)
127 std::cerr <<
"Method not found or not implemented.\n";
132 if (method_name !=
"Problem Steps Mode" && method_name !=
"Compare All Methods")
134 std::cout <<
"\n--- Summary of All Results ---\n";
135 for (
const auto &method :
summary)
137 std::cout <<
"\nMethod: " << method.first <<
"\n";
139 for (
const auto &info : method.second)
141 std::cout <<
" Root " << idx++ <<
": " << std::fixed << std::setprecision(info.decimal_places) << info.root
142 <<
" | Iterations: " << info.iterations <<
"\n";
150 std::cout <<
"\nDo you want to run the program again? (y/n): ";
153 }
while (choice ==
'y' || choice ==
'Y');
156 std::cout <<
"\nPress Enter to exit...";
157 std::cin.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
long double bisection(long double a, long double b, long double tol, int max_iter, std::vector< std::string > &iterations, int decimal_places)
long double hybrid_method(long double a, long double b, long double tol, int max_iter, std::vector< std::string > &iterations, int decimal_places)
long double ridder_method(long double a, long double b, long double tol, int max_iter, std::vector< std::string > &iterations, int decimal_places)
long double brent_method(long double a, long double b, long double tol, int max_iter, std::vector< std::string > &iterations, int decimal_places)
void plot_function(long double x_min, long double x_max, long double y_min, long double y_max, int width, int height, long double label_interval)
void run_method_user_selection(const std::string &method_name, std::function< long double(long double, long double, long double, int, std::vector< std::string > &, int)> method_func, long double a, long double b, long double tol, int max_iter)