Step-by-Step Fibonacci Bracket Shrinkage
Observe Kiefer's optimal reduction in real-time. Notice how one interior point is always reused, costing only one evaluation per step!
Evaluations Needed vs. Tolerance
Fibonacci search delivers the exact theoretical minimum sequential evaluations for any prescribed tolerance.
| Tolerance (tol) | Fibonacci Search (evals) | Golden Section (evals) | Brute-force Grid (100k steps) | Interval Width Reduction Factor | Theoretical Efficiency |
|---|
Extrapolated CO₂ Trajectory
Extrapolation of the fitted NOAA model \(CO_2(t) = C_0 + A \cdot e^{r (t - 1959)}\) for future milestone years.
Complete Fibonacci Search Iteration Log
C++17 Implementation & Live Binary Execution
Standard C++17 implementation with zero external dependencies. Click below to execute the compiled MinGW binary live!
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iostream>
#include <vector>
using Func = std::function<double(double)>;
struct SearchResult {
double x;
double fx;
double a;
double b;
int evals;
std::vector<std::pair<double, double>> history;
};
std::vector<long long> fibonacciNumbers(int n) {
std::vector<long long> F(n + 1);
F[0] = 0;
if (n >= 1) F[1] = 1;
for (int i = 2; i <= n; ++i) F[i] = F[i - 1] + F[i - 2];
return F;
}
SearchResult fibonacciSearch(const Func& f, double a, double b, double tol) {
const double L0 = b - a;
int n = 3;
while (fibonacciNumbers(n)[n] < 2.0 * L0 / tol) ++n;
const std::vector<long long> F = fibonacciNumbers(n);
SearchResult res;
res.history.push_back({a, b});
int k = n;
double x1 = a + static_cast<double>(F[k - 2]) / F[k] * (b - a);
double x2 = a + static_cast<double>(F[k - 1]) / F[k] * (b - a);
double f1 = f(x1);
double f2 = f(x2);
res.evals = 2;
while (k > 3) {
if (f1 < f2) {
b = x2;
x2 = x1;
f2 = f1;
--k;
x1 = a + static_cast<double>(F[k - 2]) / F[k] * (b - a);
f1 = f(x1);
} else {
a = x1;
x1 = x2;
f1 = f2;
--k;
x2 = a + static_cast<double>(F[k - 1]) / F[k] * (b - a);
f2 = f(x2);
}
++res.evals;
res.history.push_back({a, b});
}
res.x = 0.5 * (a + b);
res.fx = f(res.x);
++res.evals;
res.a = a;
res.b = b;
return res;
}