# Optimization of a function over a geometric region

Say I have a function f[x,y,z], what is a good way to find its minimum or maximum value over a continuous region (e.g. a ConvexHullMesh)? Currently, I generate random points in said region and find their optimal value of f. But it's very inefficient, though the accuracy does increase with more points.

• "Currently, I generate random points in said region and find their optimal value of f." - you would probably be amused to know that the "RandomSearch" setting for the Method option of NMinimize[]/NMaximize[] does exactly that, except perhaps a bit more systematically than you. Mar 14, 2018 at 17:16
• @J.M. I am dumb, but thankful.hahua
– 2ub
Mar 14, 2018 at 18:06

You can just use Minimize/Maximize. Here is a sample convex hull mesh:

SeedRandom[1];
mesh = ConvexHullMesh[RandomReal[10, {20,3}]]


And here is a function:

f[x_, y_, z_] := Sin[x y z] x y z


And here are the minimum/maximum of f over mesh:

Minimize[f[x, y, z], {x,y,z} ∈ mesh]
Maximize[f[x, y, z], {x,y,z} ∈ mesh]


{-237.192, {x -> 6.31328, y -> 7.5132, z -> 5.00063}}

{221.485, {x -> 7.89306, y -> 6.12804, z -> 4.57911}}