# Find the minimum of an expression with multiple constraints

I need help to find a value for "d" which the expr has the minimum value at that "d" value. Constraints are added to the code

ClearAll[c, x1, y1, x2, y2, d, expr]
c = 5;
expr = -x1*y1*c + x2*y2*c + d*x1*x2;
FindMinimum[{expr,
x2*y2 + 2*c*y2 - d*x1*x2 < 0 &&
-x1*y1 + 2*c*y1 - d*x1*x2 < 0 &&
x1 + x2 == 1 &&
y1 + y2 == 1 &&
x1 > 0 &&
x2 > 0 &&
y1 >= 0 &&
y2 >= 0}, {d}]


The code above doesn't give me any values for "d" and I don't get any errors. I don't know what the problem is with this code.

To minimize symbolically,Minimize works here.

ClearAll[c, x1, y1, x2, y2, d, expr]
c = 5;
expr = -x1*y1*c + x2*y2*c + d*x1*x2;
Minimize[{expr,
x2*y2 + 2*c*y2 - d*x1*x2 < 0 && -x1*y1 + 2*c*y1 - d*x1*x2 < 0 &&
x1 + x2 == 1 && y1 + y2 == 1 && x1 > 0 && x2 > 0 && y1 >= 0 &&
y2 >= 0}, {d}]


• This indicates that d is Indeterminate Dec 30, 2019 at 18:49
• Hi @Xminer thanks for your help. The code you provided works. -@BobHanlon you are right "d" is Inderterminate and I need to give initial values for x1, x2, y1 and, y2.
– Nini
Dec 30, 2019 at 19:49
ClearAll["Global*"]

c = 5;


Eliminate unnecessary variables {x2, y2}

expr = -x1*y1*c + x2*y2*c + d*x1*x2 /. {x2 -> 1 - x1, y2 -> 1 - y1} //
Simplify

(* 5 + (-5 + d) x1 - d x1^2 - 5 y1 *)

var = Variables[Level[expr, {-1}]];

cons = x2*y2 + 2*c*y2 - d*x1*x2 < 0 && -x1*y1 + 2*c*y1 - d*x1*x2 < 0 &&
1 > x1 > 0 && 1 >= y1 >= 0 /. {x2 -> 1 - x1, y2 -> 1 - y1} // Simplify;

min = FindMinimum[Evaluate[List @@ (expr && cons)], var,
WorkingPrecision -> 15]

(* {2.10526275527238, {d -> 1.46032188433906*10^7, x1 -> 0.999999675630191,
y1 -> 0.526316126809388}} *)

expr /. min[[2]]

(* 2.1052628 *)

• Hi @Bob Hanlon, I ran your code and I get different value for "d" following is the results that I get: {2.10535857973380, {d -> 269407.8237226680, x1 -> 0.999982417241665, y1 -> 0.5263157407680821}}
– Nini
Dec 30, 2019 at 20:02
• I copied, pasted, and executed the code above and got the results as shown above. I am using version 12.0 on macOS 10.15.2 Dec 30, 2019 at 20:10
• still I get the same results, {2.10535857973380, {d -> 269407.8237226680, x1 -> 0.999982417241665, y1 -> 0.5263157407680821}}. I am using version 8 of Mathematica
– Nini
Dec 30, 2019 at 20:42
• Version 8 is pretty old. Perhaps you are using a 32-bit version rather than 64-bit. The minimum appears to occur as d grows unbounded so any small deviation in {x1, y1} would cause large changes in d. Dec 30, 2019 at 22:10

With variable substitution d -> 1/dd (together with the variable elimination by @Bob Hanlon) you can easily get an analytical solution (for values at the boundary).

c = 5;

expr = -x1*y1*c + x2*y2*c + d*x1*x2 /. {x2 -> 1 - x1, y2 -> 1 - y1} //
Simplify

cons = x2*y2 + 2*c*y2 - d*x1*x2 < 0 && -x1*y1 + 2*c*y1 - d*x1*x2 < 0 &&
1 > x1 > 0 && 1 >= y1 >= 0 /. {x2 -> 1 - x1, y2 -> 1 - y1} //
Simplify

mi = Minimize[{expr, cons} /. d -> 1/dd, {dd, x1, y1}, Reals]

(*   Minimize::wksol: Warning: There is no minimum in the region in which the objective function is defined and the constraints are satisfied; returning a result on the boundary. >>   *)

(*   {40/19, {dd -> 0, x1 -> 1, y1 -> 10/19}}   *)

• Hi @Akku14 the code works. Thank you. Is there a way to have contour plot to show the minimum values of d for different values of x1 and y1 on two axises?
– Nini
Jan 2, 2020 at 16:09
• The minimal allowed d for certain x1,y1 according to cons? mind = Minimize[{d, cons}, {d}, Reals] Absolute allowed min of d mindabs = Minimize[{d, cons}, {d, x1, y1}, Reals] // N . gr = Graphics3D[{PointSize[Large], Red, Point[{x1, y1, d} /. mindabs[[2]]]}]; pl = Plot3D[mind[[1]], {x1, 0, 1}, {y1, 0, 1}, PlotPoints -> 100 ]; cp = ContourPlot[mind[[1]], {x1, 0, 1}, {y1, 0, 1}, Contours -> {21, 40, 60, 80, 100}, ContourShading -> None, MaxRecursion -> 3, Epilog -> {PointSize[Large], Red, Point[{x1, y1} /. mindabs[[2]]]}] Show[pl, gr] . Jan 3, 2020 at 6:44
• Get the minimum of expr for all possible d mimi = Minimize[{expr, cons}, {d}, Reals] Plot3D[mimi[[1]], {x1, 0, 1}, {y1, 0, 1}] and the known overall minimum Minimize[mimi[[1, 1, 1]], {x1, y1}, Reals]` Jan 3, 2020 at 7:06