diff --git a/SCE/SCE/nlgs.cpp b/SCE/SCE/nlgs.cpp index 811cba6..4bd4481 100644 --- a/SCE/SCE/nlgs.cpp +++ b/SCE/SCE/nlgs.cpp @@ -9,26 +9,50 @@ long double nlgs::function(long double x) return (pow(x, 4) - x - 10); } -long double nlgs::round(long double x, int acc) +long double nlgs::function_fixedpoint(long double x) { - x = x * pow(10, acc); - int temp = x; - x = temp; - x = x / pow(10, acc); - return x; + return pow(x+10, 1/4); } -float nlgs::bisektion(long double A, long double B , int limit, int acc) +long double nlgs::function_derived(long double x) { - long double a = A; - long double b = B; - long double c; + return 4 * pow(x, 3) - 1; +} + + + +long double nlgs::bisektion(long double A, long double B , int limit) +{ + long double a = A, b = B, c; for (int i = limit; i--;) { c = (a + b) / 2; - c = round(c, acc); if (function(a)*function(c) > 0) { a = c; } if (function(c)*function(b) > 0) { b = c; } } + return c; } +long double nlgs::fixedpoint(long double start, int limit) +{ + long double x = start; + for(int i = limit ; i-- ;) + { + x = function_fixedpoint(x); + } + return x; +} + +long double nlgs::newton(long double start, int limit) +{ + long double x = start; + for (int i = limit; i--;) + { + x = x - function(x)/function_derived(x); + } + return x; +} + + + + diff --git a/SCE/SCE/nlgs.h b/SCE/SCE/nlgs.h index 0381292..c1edab5 100644 --- a/SCE/SCE/nlgs.h +++ b/SCE/SCE/nlgs.h @@ -3,12 +3,14 @@ class nlgs { private: long double function(long double); - long double round(long double, int); + long double function_fixedpoint(long double ); + long double function_derived(long double); + public: - float bisektion(long double, long double, int, int ); //a, b, number of iterations, accuracy - float fixedpoint(); - float newton(); - float secant(); + long double bisektion(long double, long double, int); //a, b, number of iterations + long double fixedpoint(long double, int); //start, number of iterations + long double newton(long double, int); //start, number of iterations + long double secant(); nlgs(){}; ~nlgs(){}; };