mirror of
https://github.com/Hizenberg469/Algorithms-snippets.git
synced 2026-04-20 07:02:23 +03:00
Binomial Coefficient
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
double ternary_search(double l, double r) {
|
||||
double eps = 1e-9; //set the error limit here
|
||||
while (r - l > eps) {
|
||||
double m1 = l + (r - l) / 3;
|
||||
double m2 = r - (r - l) / 3;
|
||||
double f1 = f(m1); //evaluates the function at m1
|
||||
double f2 = f(m2); //evaluates the function at m2
|
||||
if (f1 < f2)
|
||||
l = m1;
|
||||
else
|
||||
r = m2;
|
||||
}
|
||||
return f(l); //return the maximum of f(x) in [l, r]
|
||||
double ternary_search(double l, double r) {
|
||||
double eps = 1e-9; //set the error limit here
|
||||
while (r - l > eps) {
|
||||
double m1 = l + (r - l) / 3;
|
||||
double m2 = r - (r - l) / 3;
|
||||
double f1 = f(m1); //evaluates the function at m1
|
||||
double f2 = f(m2); //evaluates the function at m2
|
||||
if (f1 < f2)
|
||||
l = m1;
|
||||
else
|
||||
r = m2;
|
||||
}
|
||||
return f(l); //return the maximum of f(x) in [l, r]
|
||||
}
|
||||
Reference in New Issue
Block a user