Tweaks to chord method 2
This commit is contained in:
14
main.cpp
14
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 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 {
|
else {
|
||||||
right = c;
|
left = center;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return c;
|
return center;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
|||||||
Reference in New Issue
Block a user