This question is usually asked in two layers:
f(x). Your goal is to find the minimum value of this function within a given range.Given a strictly convex function f(x) and an integer interval [a, b], find the minimum value of f(x) within this interval.
f(x) = x^2, a = 1, b = 3
1 at x = 1.f(x) = (x - 2)^2, a = 0, b = 4
0 at x = 2.1 <= a < b <= 10^9f(x) is a strictly convex function.f(x) is strictly convex, the minimum value must occur at one of the endpoints or at a single point within the interval.Given a strictly convex function f(x, y) and a 2D bounded rectangle [a, b] x [c, d], find the minimum value of f(x, y) within this rectangle.
f(x, y) = (x - 1)^2 + (y - 2)^2, a = 0, b = 2, c = 1, d = 3
0 at (x, y) = (1, 2).f(x, y) = (x^2 + y^2), a = -1, b = 1, c = -2, d = 2
0 at (x, y) = (0, 0).1 <= a < b <= 10^91 <= c < d <= 10^9f(x, y) is a strictly convex function.f(x, y) is strictly convex, the minimum value must occur at one of the corners of the rectangle or at a single point within the rectangle.To solve the 1D version, you can use binary search. Here's a Python function to find the minimum value:
python def find_min_1d(f, a, b, tol=1e-10): while b - a > tol: mid = (a + b) / 2 if f(mid) < f(a): a = mid else: b = mid return (a + b) / 2
To solve the 2D version, you can extend the binary search approach to two dimensions. Here's a Python function to find the minimum value:
python def find_min_2d(f, a, b, c, d, tol=1e-10): while b - a > tol and d - c > tol: mid_x = (a + b) / 2 mid_y = (c + d) / 2 if f(mid_x, mid_y) < f(a, mid_y): if f(mid_x, mid_y) < f(mid_x, c): a = mid_x else: c = mid_y else: if f(mid_x, mid_y) < f(b, mid_y): b = mid_x else: d = mid_y return (a + b) / 2, (c + d) / 2
These functions should help you find the minimum value of a strictly convex function within a given range or rectangle.