Alternative chord method
This commit is contained in:
20
main.cpp
20
main.cpp
@@ -68,6 +68,26 @@ double chordMethod(double left, double right, double error, double (*f)(double x
|
||||
return right;
|
||||
}
|
||||
|
||||
double chordMethod2(double left, double right, double error, double (*f)(double))
|
||||
{
|
||||
double c;
|
||||
|
||||
while(std::fabs( f(right) - f(left) ) > error)
|
||||
{
|
||||
c = ( f(right) * left - f(left) * right) / ( f(right) - f(left) );
|
||||
|
||||
if( f(left) * f(c) > 0)
|
||||
{
|
||||
left = c;
|
||||
}
|
||||
else {
|
||||
right = c;
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// Включим языковые настройки для корректного отображения русских символов
|
||||
|
||||
Reference in New Issue
Block a user