From 292501f86ea3d51313c7419a32320afc4a25603c Mon Sep 17 00:00:00 2001 From: Nikolai Papin Date: Sat, 19 Oct 2024 16:17:03 +0300 Subject: [PATCH] Tweaks to chord method 2 --- main.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/main.cpp b/main.cpp index 1c28f41..125f0d9 100644 --- a/main.cpp +++ b/main.cpp @@ -70,22 +70,22 @@ double chordMethod(double left, double right, double error, double (*f)(double x double chordMethod2(double left, double right, double error, double (*f)(double)) { - double c; + double center; - while(std::fabs( f(right) - f(left) ) > error) + while(std::fabs(right - left) > error) { - c = ( f(right) * left - f(left) * right) / ( f(right) - f(left) ); + center = ( f(right) * left - f(left) * right) / ( f(right) - f(left) ); - if( f(left) * f(c) > 0) + if( f(left) * f(center) < 0) { - left = c; + right = center; } else { - right = c; + left = center; } } - return c; + return center; } int main()