Tweaks to chord 2

This commit is contained in:
2024-10-19 16:17:03 +03:00
parent d4f41ea729
commit dff8f1e8d2

View File

@@ -70,22 +70,23 @@ 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;
else
{
left = center;
}
}
return c;
return center;
}
int main()