/* Include NR Code */ #include "nr3.h" #include "roots.h" /* Define Nonlinear Equation to Solve */ const double Beta = 0.7; double Func(double x); double Func(double x) { return x - 0.5 - 0.5 * (x >= 0.0) * (1.0 - exp(-x)) * (1.0 - Beta); } int main() { /* Solve ... */ /* Bisection Method */ try { cout << "rtbis, x: " << rtbis(Func,9.0,10.0,0.00000001) << "\n\n"; } catch(int i) { cout << "rtbis: FAILED\n\n"; } /* False Position Method */ try { cout << "rtflsp, x: " << rtflsp(Func,-10.0,10.0,0.00000001) << "\n\n"; } catch(int i) { cout << "rtflsp: FAILED\n\n"; } /* Secant Method */ try { cout << "rtsec, x: " << rtsec(Func,-10.0,10.0,0.00000001) << "\n\n"; } catch(int i) { cout << "rtsec: FAILED\n\n"; } /* Ridder's Method */ try { cout << "zriddr, x: " << zriddr(Func,-10.0,10.0,0.00000001) << "\n\n"; } catch(int i) { cout << "zriddr: FAILED\n\n"; } /* Brent's Method */ try { cout << "zbrent, x: " << zbrent(Func,-10.0,10.0,0.00000001) << "\n\n"; } catch(int i) { cout << "zbrent: FAILED\n\n"; } return 0; }