Understanding the inner workings of approximation search is crucial in solving problems related to fitting polynomials, parametric functions, and transcendental equations. This approach allows you to estimate values and parameters effectively, even when dealing with functions that are not strictly monotonic.
Approximation search mimics the concept of binary search, but it doesn't impose the constraint of the searched function being strictly monotonic. Here's how it works:
Here's a simplified C implementation of approximation search:
class approx { public: void init(double a0, double a1, double da, int n, double *e) { a0 = min(a0, a1); a1 = max(a0, a1); // Ensure a0 < a1 da = abs(da); this->n = n; e = e; e0 = -1.0; i = 0; a = a0; aa = a0; done = false; stop = false; } void step() { if ((e0 < 0.0) || (e0 > *e)) { e0 = *e; aa = a; } // Better solution if (stop) { i++; if (i >= n) { done = true; a = aa; return; } // Final solution a0 = aa - fabs(da); a1 = aa + fabs(da); a = a0; da *= 0.1; a0 += da; a1 -= da; stop = false; } else { a += da; if (a > a1) { a = a1; stop = true; } // Next point } } };
Suppose you want to find the value of x such that y = f(x) is closest to y0. Here's how to use the approx class:
approx aa; double ee, x, y, x0, y0 = your_target_value; for (aa.init(0.0, 10.0, 0.1, 6, &ee); !aa.done; aa.step()) { x = aa.a; y = f(x); ee = abs(y - y0); }
The above is the detailed content of How Can Approximation Search Efficiently Find Values and Parameters for Non-Monotonic Functions?. For more information, please follow other related articles on the PHP Chinese website!