MaxValue
Details and Options
- MaxValue is also known as supremum.
- MaxValue finds the global maximum of f subject to the constraints given.
- MaxValue is typically used to find the largest possible values given constraints. In different areas, this may be called the best strategy, best fit, best configuration and so on.
- Maximize returns a list of the form {fmax,{x->xmax,y->ymax,…}}.
- If f and cons are linear or polynomial, MaxValue will always find the global supremum.
- The constraints cons can be any logical combination of:
-
lhs==rhs equations lhs>rhs, lhs≥rhs, lhs<rhs, lhs≤rhs inequalities (LessEqual,…) lhsrhs, lhsrhs, lhsrhs, lhsrhs vector inequalities (VectorLessEqual,…) Exists[…], ForAll[…] quantified conditions {x,y,…}∈rdom region or domain specification - MaxValue[{f,cons},x∈rdom] is effectively equivalent to MaxValue[{f,cons∧x∈rdom},x].
- For x∈rdom, the different coordinates can be referred to using Indexed[x,i].
- Possible domains rdom include:
-
Reals real scalar variable Integers integer scalar variable Vectors[n,dom] vector variable in
Matrices[{m,n},dom] matrix variable in 
ℛ vector variable restricted to the geometric region 
- By default, all variables are assumed to be real.
- MaxValue will return exact results if given exact input. With approximate input, it automatically calls NMaxValue.
- MaxValue will return the following forms:
-
fmax finite maximum -∞ infeasible, i.e. the constraint set is empty ∞ unbounded, i.e. the values of f can be arbitrarily large - MaxValue gives the supremum of values of f. It may not be attained for any values of x, y, ….
- N[MaxValue[…]] calls NMaxValue for optimization problems that cannot be solved symbolically.
Examples
open all close allBasic Examples (5)
Find the maximum value of a univariate function:
MaxValue[-2x ^ 2 - 3x + 5, x]Find the maximum value of a multivariate function:
MaxValue[1 - (x y - 3) ^ 2, {x, y}]Find the maximum value of a function subject to constraints:
MaxValue[{x - 2y, x ^ 2 + y ^ 2 ≤ 1}, {x, y}]Find the maximum value as a function of parameters:
MaxValue[a x ^ 2 + b x + c, x]Find the maximum value of a function over a geometric region:
MaxValue[x + y, {x, y}∈Disk[]]Plot3D[{x + y, %}, {x, y}∈Disk[], PlotStyle -> Opacity[0.7]]Scope (36)
Basic Uses (7)
Maximize
over the unconstrained reals:
MaxValue[Sin[x] + Cos[x], x]Maximize
subject to constraints
:
MaxValue[{x + 2y, x ^ 2 + 2y ^ 2 ≤ 3 && x + y == 2 && x ≥ 1}, {x, y}]Constraints may involve arbitrary logical combinations:
MaxValue[{x y, x ^ 2 + y ^ 2 ≤ 1 || (x + 1) ^ 2 + (y - 1) ^ 2 ≤ 2}, {x, y}]MaxValue[{x + y, x ≤ y ^ 2}, {x, y}]MaxValue[{x + y, x ^ 2 + y ^ 2 < 0}, {x, y}]The supremum value may not be attained:
MaxValue[-Exp[x], x]Plot[-Exp[x], {x, -3, 3}]Use a vector variable and a vector inequality:
MaxValue[{{-1, -1}.v, {{1, 2}, {1, 0}}.v{3, -1}}, v]Univariate Problems (7)
Unconstrained univariate polynomial maximization:
MaxValue[-x ^ 4 + 2x ^ 3 + 5x - 7, x]Constrained univariate polynomial maximization:
MaxValue[{-3x ^ 2 - x + 9, 2x ^ 3 + 5x - 7 ≥ 0}, x]MaxValue[-E ^ (2E ^ x) + Log[x ^ 2 + 1] + 20x, x]Analytic functions over bounded constraints:
MaxValue[{AiryAi[x + Sin[x]] + Cos[x ^ 2], -5 ≤ x ≤ 5}, x]Plot[{AiryAi[x + Sin[x]] + Cos[x ^ 2], %}, {x, -5, 5}]MaxValue[{BesselJ[2, x] / Gamma[x + 1] + (x + 1) ^ Sin[x], 0 ≤ x ≤ 10}, x]Plot[{BesselJ[2, x] / Gamma[x + 1] + (x + 1) ^ Sin[x], %}, {x, 0, 10}]MaxValue[{Sin[x], -1 / 2 ≤ Cos[x] ≤ 1 / 2}, x]Combination of trigonometric functions with commensurable periods:
MaxValue[Sin[E ^ (x / 3) - 3 x] + 2 Cos[2 E ^ (x / 3) - 6 x + 1] ^ 2, x]Combination of periodic functions with incommensurable periods:
MaxValue[Sin[Sqrt[3] x] - Exp[Cos[3 x] + 2], x]Plot[{Sin[Sqrt[3] x] - Exp[Cos[3 x] + 2], %}, {x, -50, 50}]MaxValue[{Floor[x + UnitStep[x - 1]] - x, Ceiling[Abs[x]] < 5}, x]Unconstrained problems solvable using function property information:
MaxValue[SinhIntegral[DawsonF[x]], x]MaxValue[BesselJ[7 / 4, x ^ 2 + x + 1], x]Multivariate Problems (9)
Multivariate linear constrained maximization:
MaxValue[{2x + 3y - z, 1 ≤ x + y + z ≤ 2 && 1 ≤ x - y + z ≤ 2 && x - y - z == 3}, {x, y, z}]Linear-fractional constrained maximization:
MaxValue[{(2x + y - z) / (5x - 7y + 3), 0 ≤ x + y + z ≤ 1 && 1 ≤ x - y + z ≤ 2 && x - y - z == 3}, {x, y, z}]Unconstrained polynomial maximization:
MaxValue[x ^ 2 - 2y - 1 - (x ^ 2 - 2y) ^ 2, {x, y}]Constrained polynomial optimization can always be solved:
MaxValue[{x y - 1, x ^ 2 + y ^ 2 ≤ 1}, {x, y}]The maximum value may not be attained:
MaxValue[{1 - x ^ 2, x y ≥ 1}, {x, y}]The objective function may be unbounded:
MaxValue[{x, x y ≤ 1}, {x, y}]There may be no points satisfying the constraints:
MaxValue[{x, x ^ 2 + y ^ 2 < 0}, {x, y}]Quantified polynomial constraints:
MaxValue[{-(x + 7)^2 - (y - 8)^2, Subscript[∀, z]Subscript[∃, w]3 z^2 w + (x + y) z^4 - 1 == (x^3 - x y + y^2 - 1) w^2}, {x, y}]MaxValue[{-x - Sqrt[x + y] , x Sqrt[y] ≥ 1}, {x, y}]Bounded transcendental maximization:
MaxValue[{E ^ x + Log[y], x Log[y] == 2 && -10 ≤ x ≤ 10 && 1 / 10 ≤ y ≤ 10}, {x, y}]MaxValue[{-Max[x - y, Abs[y]], Min[x - 2, x - y ^ 2] ≥ Abs[x y - 1]}, {x, y}]MaxValue[v.{1, -1}, {VectorGreaterEqual[{{{1, 0}, {0, 1}, {-1, -2}}.v, {0, 0, -2}}, "ExponentialCone"]}, v]Maximize concave objective function
such that
is positive semidefinite and
:
MaxValue[{Log[x + y], (| | |
| ----- | ----- |
| x + y | 1 |
| 1 | x - y |)Underscript[, {"SemidefiniteCone", 2}]0 && 1 ≤ x ≤ 10 && -1 ≤ y ≤ 1}, {x, y}]Plot the function and the maximum value over the region:
Plot3D[{Log[x + y], %}, {x, 1, 10}, {y, -1, 1}, ...]Parametric Problems (4)
Parametric linear optimization:
MaxValue[{8x + 7y, -6 x - 4 y ≤ 8 - 5 a - 7 b && 7 x + 5 y ≤ a + 4 b && -x + y ≤ 6 + 4a - 5 b && -4 x + 7 y ≤ -1 - 2 a - 7 b && 5 y ≤ 6 - 9 b}, {x, y}]The maximum value is a continuous function of parameters:
Plot3D[%, {a, -3, 3}, {b, 0, 3}]Parametric quadratic optimization:
MaxValue[{-(x - 1) ^ 2 - (2y - 1) ^ 2, x + 2y ≤ a + b && 2x - y ≤ a - b + 1 && x - 2y ≤ 2a - b + 1}, {x, y}]The maximum value is a continuous function of parameters:
Plot3D[%, {a, -5, 5}, {b, -5, 5}]Unconstrained parametric polynomial maximization:
MaxValue[-x ^ 4 + a x ^ 2 + b, x]Constrained parametric polynomial maximization:
MaxValue[{-x ^ 2 - y ^ 2, x ^ 3 + y ^ 2 == a}, {x, y}]Optimization over Integers (3)
MaxValue[{x ^ 3 Log[x] - E ^ x, x > 0}, x, Integers]MaxValue[Sin[2x] + Cos[3x], x, Integers]Show[{ListPlot[Table[Sin[2x] + Cos[3 x], {x, 0, 10000}]], Graphics[{Red, Line[{{0, %}, {10000, %}}]}]}]MaxValue[{2x + 3y - z, 1 ≤ x + y + z ≤ 2 && 1 ≤ x - y + z ≤ 2 && x - y - z == 3}, {x, y, z}, Integers]Polynomial maximization over the integers:
MaxValue[{-x ^ 2 - x y + 1, x y ≥ 1}, {x, y}, Integers]Optimization over Regions (6)
Find the maximum value of a function over a geometric region:
ℛ = Cylinder[{{1, 2, 3}, {3, 2, 1}}, 1];MaxValue[z, {x, y, z}∈ℛ]Graphics3D[{Opacity[0.5], {Green, ℛ}, {Red, InfinitePlane[{{0, 0, %}, {1, 0, %}, {0, 1, %}}]}}]Find the maximum distance between points in two regions:
Subscript[ℛ, 1] = Disk[];
Subscript[ℛ, 2] = Line[{{-(1/2), -(1/2)}, {-(1/2), (1/2)}, {(1/2), (1/2)}, {(1/2), -(1/2)}, {-(1/2), -(1/2)}}];MaxValue[(x - u)^2 + (y - v)^2, {{x, y}∈Subscript[ℛ, 1], {u, v}∈Subscript[ℛ, 2]}]Find the maximum
such that the triangle and ellipse still intersect:
Subscript[ℛ, 1] = Triangle[{{0, 0}, {1, 0}, {0, 1}}];
Subscript[ℛ, 2] = Circle[{(1/3), (1/3)}, {2 r, r}];MaxValue[{r, {x, y}∈Subscript[ℛ, 1] && {x, y}∈Subscript[ℛ, 2]}, {r, x, y}]Graphics[{{LightBlue, Subscript[ℛ, 1]}, {Green, Subscript[ℛ, 2]} /. r -> %}]Find the maximum
for which
contains the given three points:
Subscript[ℛ, 3] = Disk[{a, b}, {r, 2 - r}];MaxValue[{r, ({0, 0} | {1, 0} | {0, 1})∈Subscript[ℛ, 3]}, {a, b, r}]Use
to specify that
is a vector in
:
ℛ = Sphere[];MaxValue[x.{1, 2, 3}, x∈ℛ]Find the maximum distance between points in two regions:
Subscript[ℛ, 1] = Triangle[{{0, 0}, {1, 0}, {0, 1}}];
Subscript[ℛ, 2] = Disk[{2, 2}, 1];MaxValue[EuclideanDistance[x, y], {x∈Subscript[ℛ, 1], y∈Subscript[ℛ, 2]}]//RootReduceOptions (2)
Method (1)
Specify that MaxValue should use cylindrical algebraic decomposition:
maxcad = MaxValue[{x ^ 2 - y ^ 3 + 2x y, x ^ 2 + y ^ 2 == 1}, {x, y}, Method -> "CAD"]maxlm = MaxValue[{x ^ 2 - y ^ 3 + 2x y, x ^ 2 + y ^ 2 == 1}, {x, y}, Method -> "LagrangeMultipliers"]maxdef = MaxValue[{x ^ 2 - y ^ 3 + 2x y, x ^ 2 + y ^ 2 == 1}, {x, y}]RootReduce[maxcad] === RootReduce[maxlm] === RootReduce[maxdef]WorkingPrecision (1)
Finding the exact maximum can take a long time:
TimeConstrained[MaxValue[{x ^ 2 + y ^ 2 + z ^ 2, x ^ 2 - 3 x y z + 9 z ^ 2 + y ^ 2 == E && x y z ≤ Pi}, {x, y, z}], 60]With WorkingPrecision->200, you get an exact maximum value, but it might be incorrect:
MaxValue[{x ^ 2 + y ^ 2 + z ^ 2, x ^ 2 - 3 x y z + 9 z ^ 2 + y ^ 2 == E && x y z ≤ Pi}, {x, y, z}, WorkingPrecision -> 200]//TimingApplications (13)
Basic Applications (4)
Find the maximal area among rectangles with a unit perimeter:
MaxValue[{x y, 2x + 2y == 1 && x > 0 && y > 0}, {x, y}]Find the maximal area among triangles with a unit perimeter:
triangle = a > 0 && b > 0 && c > 0 && a + b > c && a + c > b && b + c > a;
s = 1 / 2(a + b + c);MaxValue[{Sqrt[s(s - a)(s - b)(s - c)], triangle && a + b + c == 1}, {a, b, c}]Find the maximum height reached by a projectile:
MaxValue[ {v Sin[α] t - 5 t ^ 2, t ≥ 0 && 0 < Sin[α] ≤ 1 && v > 0}, t]Refine[%, 0 < Sin[α] ≤ 1 && v > 0]Find the maximum range of a projectile:
MaxValue[{v Cos[α] t, v Sin[α] t - 5 t ^ 2 == 0 && t ≥ 0 && v > 0 && 0 ≤ Sin[α] ≤ 1 && 0 ≤ Cos[α] ≤ 1 && Sin[α] ^ 2 + Cos[α] ^ 2 == 1}, {Sin[α], Cos[α], t}]Refine[%, v > 0]The infinity norm of a function f[x] is given by MaxValue[{Norm[f[x]],x∈},x] where is the domain of interest for f[x]. Find the infinity norm of
over the interval {-3,3}:
f = x^2 - x + 1;
𝒟 = Interval[{-3, 3}];MaxValue[{Norm[{f}], {x}∈𝒟}, x]Plot[{f, -13, 13}, {x, -3, 3}, Filling -> {2 -> {3}}]Find the infinity norm for
over Rectangle[{-1,-1},{1,1}]:
f = x^2 + x y;
𝒟 = Rectangle[{-1, -1}, {1, 1}];MaxValue[{Norm[{f}], {x, y}∈𝒟}, {x, y}]Plot3D[{f, -2, 2}, {x, y}∈𝒟, PlotStyle -> {White, Opacity[0.3], Opacity[0.3]}, Mesh -> None]Geometric Distances (9)
The largest distance of a point in a region ℛ to a given point p is given by MaxValue[EuclideanDistance[p,q],q∈ℛ]. Find the largest distance of a point in the unit Disk[] to the point {1,1} :
p = {1, 1};
q = {q1, q2};
ℛ = Disk[];d = MaxValue[EuclideanDistance[p, q], q∈ℛ]//RootReduceGraphics[{{LightBlue, EdgeForm[Gray], ℛ}, {Green, Circle[p, d]}, {Red, Point[p]}}]Find the largest distance of a point in the standard unit simplex Simplex[2] to the point {1,3/4}:
p = {1, 3 / 4};
q = {q1, q2};
ℛ = Simplex[{{0, 0}, {1, 0}, {0, 1}}];d = MaxValue[EuclideanDistance[p, q], q∈ℛ]Graphics[{{LightBlue, EdgeForm[Gray], ℛ}, {Green, Circle[p, d]}, {Red, Point[p]}}]Find the largest distance of a point in the standard unit sphere Sphere[] to the point {1,1,1}:
p = {1, 1, 1};
q = {q1, q2, q3};
ℛ = Sphere[];d = MaxValue[EuclideanDistance[p, q], q∈ℛ]//RootReduceGraphics3D[{{Opacity[0.5], ℛ}, {Opacity[0.3], Green, Sphere[p, d]}, {Red, Point[p]}}]Find the largest distance of a point in the standard unit simplex Simplex[3] to the point {-1/3,1/3,1/3}:
p = {-1 / 3, 1 / 3, 1 / 3};
q = {q1, q2, q3};
ℛ = Simplex[{{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1}}];d = MaxValue[EuclideanDistance[p, q], q∈ℛ]Graphics3D[{{Opacity[0.5], ℛ}, {Opacity[0.3], Green, Sphere[p, d]}, {Red, Point[p]}}]The diameter of a region ℛ is the maximum distance between two points in ℛ. It can be computed through MaxValue[EuclideanDistance[p,q],{p∈ℛ,q∈ℛ}]. Find the diameter of Circle[]:
ℛ = Circle[];MaxValue[EuclideanDistance[p, q], {p∈ℛ, q∈ℛ}]Find the diameter of the standard unit simplex Simplex[2]:
ℛ = Simplex[{{0, 0}, {1, 0}, {0, 1}}];MaxValue[EuclideanDistance[p, q], {p∈ℛ, q∈ℛ}]Find the diameter of the standard unit cube Cuboid[]:
ℛ = Cuboid[];MaxValue[EuclideanDistance[p, q], {p∈ℛ, q∈ℛ}]The largest distance of points p∈ and q∈ can be found through MaxValue[EuclideanDistance[p,q],{p∈,q∈}]. Find the largest distance of points in Disk[{0,0}] and Rectangle[{3,3}]:
𝒫 = Disk[{0, 0}]; 𝒬 = Rectangle[{3, 3}];MaxValue[EuclideanDistance[p, q], {p∈𝒫, q∈𝒬}]Find the largest distance of points in Line[{{0,0,0},{1,1,1}}] and Ball[{5,5,0},1]:
𝒫 = Line[{{0, 0, 0}, {1, 1, 1}}]; 𝒬 = Ball[{5, 5, 0}, 1];MaxValue[EuclideanDistance[p, q], {p∈𝒫, q∈𝒬}]Properties & Relations (4)
Maximize gives both the value of the maximum and the maximizer point:
Maximize[{x - 2y, x ^ 2 + y ^ 2 ≤ 1}, {x, y}]MaxValue gives an exact global maximum value of the objective function:
f = Expand[-Product[(x - i)(x - 100 - i), {i, 5}]];MaxValue[f, x]Plot[f, {x, 0, 100}, Epilog -> {Green, Dashing[Medium], Line[{{0, %}, {100, %}}]}]NMaxValue attempts to find a global maximum numerically, but may find a local maximum:
NMaxValue[f, x]Plot[f, {x, 0.5, 5.5}, Epilog -> {Red, Dashing[Medium], Line[{{0.5, %}, {5.5, %}}]}]FindMaxValue finds local maxima depending on the starting point:
FindMaxValue[f, {x, #}]& /@ {1, 50}Plot[f, {x, 0, 100}, Epilog -> {Dashing[Medium], {Red, Line[{{0, %[[1]]}, {100, %[[1]]}}]}, {Green, Line[{{0, %[[2]]}, {100, %[[2]]}}]}}]MaxValue can solve linear programming problems:
MaxValue[{2x + 3y - z, 1 ≤ x + y + z ≤ 2 && 1 ≤ x - y + z ≤ 2 && x - y - z == 3}, {x, y, z}]LinearProgramming can be used to solve the same problem given in matrix notation:
c = {2, 3, -1};
m = {{1, 1, 1}, {1, 1, 1}, {1, -1, 1}, {1, -1, 1}, {1, -1, -1}};
b = {{1, 1}, {2, -1}, {1, 1}, {2, -1}, {3, 0}};c.LinearProgramming[-c, m, b, -Infinity]Use RegionBounds to compute the bounding box:
f = x^4 + 3 x^2 y + 2 x^2 y^2 - y^3 + y^4 ≤ 0;
ℛ = ImplicitRegion@@{f, {x, y}}RegionBounds[ℛ]Use MaxValue and MinValue to compute the same bounds:
{{x1, x2}, {y1, y2}} = {MinValue[#, {x, y}∈ℛ], MaxValue[#, {x, y}∈ℛ]}& /@ {x, y}Show[{Graphics[{LightBlue, Rectangle[{x1, y1}, {x2, y2}]}], RegionPlot[f, {x, x1 - 1, x2 + 1}, {y, y1 - 1, y2 + 1}]}]Possible Issues (1)
MaxValue requires that all functions present in the input be real-valued:
MaxValue[{-x - y, Sqrt[x] - Sqrt[y] == 0}, {x, y}]Values for which the equation is satisfied but the square roots are not real are disallowed:
{Sqrt[x] - Sqrt[y] == 0, Sqrt[x], Sqrt[y]} /. {x -> -1, y -> -1}Related Guides
History
Introduced in 2008 (7.0) | Updated in 2014 (10.0) ▪ 2021 (12.3)
Text
Wolfram Research (2008), MaxValue, Wolfram Language function, https://reference.wolfram.com/language/ref/MaxValue.html (updated 2021).
CMS
Wolfram Language. 2008. "MaxValue." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/MaxValue.html.
APA
Wolfram Language. (2008). MaxValue. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MaxValue.html
BibTeX
@misc{reference.wolfram_2026_maxvalue, author="Wolfram Research", title="{MaxValue}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/MaxValue.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_maxvalue, organization={Wolfram Research}, title={MaxValue}, year={2021}, url={https://reference.wolfram.com/language/ref/MaxValue.html}, note=[Accessed: 12-June-2026]}