0
$\begingroup$

Say I have a function of four variables $f(x_1,x_2,x_3,x_4)$ and a constraint $g(x_1,x_2,x_3,x_4)$ (both are quite complicated, that's why I don't write them explicitly). I want to find the minimum value of $f$ constrained with $g$. How can I do it?

$\endgroup$
2
  • $\begingroup$ I suggest that you define a simple f and g, and try to solve that problem. If you have difficulty with that, show us what you have tried, and you may well get help. $\endgroup$
    – mikado
    Mar 7 at 18:28
  • 1
    $\begingroup$ Look in the documentation for Minimize, NMinimize, and FindMinimum. They each take constraints. $\endgroup$
    – Bob Hanlon
    Mar 7 at 19:14

1 Answer 1

1
$\begingroup$
b1 = Ball[{0, 0, 0, 0}, 3]
b2 = Ball[{1, 1, 1, 1}, 2]
region = RegionDifference[b1, b2]
BooleanRegion[#1 && ! #2 &, {Ball[{0, 0, 0, 0}, 4], 
  Ball[{1, 1, 1, 1}, 2]}]
points = RandomPoint[region, 1000];
And @@ Map[RegionMember[b1, #] &, points]
\[Not] (Or @@ Map[RegionMember[b2, #] &, points])
result = Minimize[w x^3 + y z^3, {w, x, y, z} \[Element] region]
point = {w, x, y, z} /. result[[2]]
RegionMember[region, point]
RegionMember[b1, point]
RegionMember[b2, point]
Ball[{0, 0, 0, 0}, 3]
Ball[{1, 1, 1, 1}, 2]
BooleanRegion[#1 &&  !#2 & , {Ball[{0, 0, 0, 0}, 3], 
   Ball[{1, 1, 1, 1}, 2]}]
True
True
{-((243*Sqrt[3])/16), {w -> 3/2, x -> -((3*Sqrt[3])/2), y -> 0, 
   z -> 0}}
{3/2, -((3*Sqrt[3])/2), 0, 0}
True
True
False

NMinimize is much faster than Minimize:

{4.71875, {-((243 Sqrt[3])/16), {w -> 3/2, x -> -((3 Sqrt[3])/2), 
   y -> 0, z -> 0}}}
{0.203125, {-26.305522272472924, {w -> 1.499999998583872, 
   x -> -2.598076232994641, y -> -8.937925613796142*^-9, 
   z -> -1.3744853098673136*^-8}}}

Of course, I may have missed something.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.