|
reference.wolfram.com/language/ref/QuadraticOptimization.html
Minimize $2 x^2+20 y^2+6 x y+5 x$ subject to the constraint $-x+y\ge2$:
- obj = 2 x^2 + 20 y^2 + 6 x y + 5 x;
- res = QuadraticOptimization[obj, -x + y >= 2, {x, y}]
复制代码
$\{x \rightarrow-1.73214, y \rightarrow 0.267857\}$
The optimal point lies in a region defined by the constraints and where is smallest:- Show[Plot3D[obj, {x, -2, 0}, {y, 0, 1}, Sequence[
- RegionFunction -> Function[{x, y, z}, -x + y >= 2],
- MeshFunctions -> {#3& }, Mesh -> 15,
- BoundaryStyle -> Directive[Red, Thick], BoxRatios -> 1,
- ImageSize -> Small]],
- Graphics3D[{Blue, PointSize[0.05], Point[{x, y, obj} /. res]}]]
复制代码 |
|
Minimize $x^2+y^2$ subject to the equality constraint $x+y=2$ and the inequality constraints $1 \leq y \leq 2$:
- res = QuadraticOptimization[
- x^2 + y^2, {x + y == 2, 1 <= y <= 2}, {x, y}]
复制代码
$\{x \rightarrow 1 ., y \rightarrow 1.\}$
The optimal point lies where a level curve of $x^2+y^2$ is tangent to the equality constraint:- Show[RegionPlot[Evaluate[x^2 + y^2 <= (x^2 + y^2 /. res)],
- Sequence[{x, 1/2, 3/2}, {y, 1/2, 3/2}, Epilog -> {Blue,
- PointSize[0.04],
- Point[
- ReplaceAll[{x, y}, res]]}]],
- ContourPlot[x + y == 2, {x, 0.5, 1.5}, {y, 0.5, 1.5},
- ContourStyle -> Black]]
复制代码 |
|
Minimize $2 x^2+20 y^2+6 x y+5 x$ subject to the constraint $-x+y \geq 2, x \in \mathbb{Z}, y \in \mathbb{R}$ :
- obj = 2 x^2 + 20 y^2 + 6 x y + 5 x;
- res = QuadraticOptimization[
- obj, -x + y >= 2, {x \[Element] Integers, y \[Element] Reals}]
复制代码 $\{x \rightarrow-2, y \rightarrow 0.3\}$ |
|