# Simple optimization 3D plot

Because this is such a simple example I am not going to explain the calculations. I am strictly wondering why I do get errors when plotting it.

Plot3D[(Subscript[x, 1] - 2)^2 + (Subscript[x, 2] - 1)^2, {Subscript[
x, 1], -10, 10}, {Subscript[x, 2], -10, 10},
RegionFunction -> Function[{Subscript[x, 1], Subscript[x, 2]},
Subscript[x, 1]^2 - Subscript[x, 2] <=
0 && -Subscript[x, 1] - Subscript[x, 2] + 2 <= 2]]


Im not sure what I am doing wrong?

• Works without error in MMA 10.0.1 Dec 7, 2014 at 6:00

Plot3D[(Subscript[x, 1] - 2)^2 + (Subscript[x, 2] - 1)^2,
{Subscript[x, 1], -10, 10}, {Subscript[x, 2], -10, 10},
RegionFunction -> Function[{x, y}, x^2 - y <= 0 && -x - y + 2 <= 2]]


Note the error message generated by:

Function[{Subscript[x, 1], Subscript[x, 2]},
Subscript[x, 1]^2 - Subscript[x, 2] <=
0 && -Subscript[x, 1] - Subscript[x, 2] + 2 <= 2]


See also the explanation and examples in the docs on Function::flpar.

Update:

What If I only want to mark out that area but not remove the rest if the function...

Plot3D[{ConditionalExpression[(x - 2)^2 + (y - 1)^2, Not[x^2 - y <= 0 && -x - y + 2 <= 2]],
ConditionalExpression[(x - 2)^2 + (y - 1)^2, x^2 - y <= 0 && -x - y + 2 <= 2]},
{x, -10, 10}, {y, -10, 10}, PlotStyle -> {Blue, Red}]


• What If I only want to mark out that area but not remove the rest if the function. By for Eg. The patch that this plot is given being a different colour than the rest. Dec 7, 2014 at 0:34
• @ALEXANDER, please see the update.
– kglr
Dec 7, 2014 at 1:13