# Why this region is bad?

I want to draw a region but the result of Mathematica is not good. Why?

Clear[x1, x2]
g1[x1_, x2_] := x1^4 - x2 + 1;
g2[x1_, x2_] := -x1^3 + x2 - 1;
f[x1_, x2_] :=
Which[g1[x1, x2] <= 0 && g2[x1, x2] <= 0, (x1 + 1)^2 + (x2 + 1)^2];
fextend[x1_, x2_] := (x1 + 1)^2 + (x2 + 1)^2;

RegionPlot[
g1[x1, x2] <= 0 && g2[x1, x2] <= 0, {x1, -0.5, 1.2}, {x2, -2, 2.1},
PlotStyle -> {Directive[Black, Opacity[0.4]]}, ImageSize -> Large]


The good region is

But the result that Mahematica 10 windows 64 bits shows is:

How can you improve the result?

I was trying but the only solution that I encountered is use Plot instead of RegionPlot.

Similar to that trouble is this other in Plot3D, as you can see

g1[x1_, x2_] := x1^4 - x2 + 1;
g2[x1_, x2_] := -x1^3 + x2 - 1;
f[x1_, x2_] :=
Which[g1[x1, x2] <= 0 && g2[x1, x2] <= 0, (x1 + 1)^2 + (x2 + 1)^2];
p3d = Plot3D[f[x1, x2], {x1, -1.5, 1.25}, {x2, -1.5, 2.25},
MeshFunctions -> {#3 &}, Mesh -> 10,
AxesLabel -> {x1, x2, "f(x1,x2)"}, LabelStyle -> {20, Bold},
ColorFunction -> ColorData[{"TemperatureMap", "Reverse"}],
ImageSize -> Large, PlotLegends -> Automatic, PlotPoints -> 300];
punto = Graphics3D[{Black, PointSize[0.020], Point[{0, 1, f[0, 1]}]}];
Show[p3d, punto]


What´s the solution in this case to avoid all that black lines in the limit of region?

• Because of the same reason as in 44825 – Kuba Dec 2 '14 at 11:34
• @kuba Yes, I solve the problem with PlotPoints->200 I couldn´t imagine that the trouble is for that reason, with a simple function. Thank you. – Mika Ike Dec 2 '14 at 11:45
• @kuba This is solved!! Can you mark as solved?. I can´t mark as solved till 2 days. – Mika Ike Dec 2 '14 at 12:28
• What is the point of the definitions of f and fextend? They seem to have nothing to do with the question. They should probably be removed from the question. – Michael E2 Dec 2 '14 at 17:11

\$Version


"10.0 for Mac OS X x86 (64-bit) (September 10, 2014)"

Clear[x1, x2];
g1[x1_, x2_] := x1^4 - x2 + 1;
g2[x1_, x2_] := -x1^3 + x2 - 1;
f[x1_, x2_] := Which[
g1[x1, x2] <= 0 && g2[x1, x2] <= 0,
(x1 + 1)^2 + (x2 + 1)^2];


Instead of increasing the number of PlotPoints with RegionPlot, use ImplicitRegion

RegionPlot[
ImplicitRegion[
g1[x1, x2] <= 0 && g2[x1, x2] <= 0,
{x1, x2}],
PlotRange -> {{-0.5, 1.2}, {-2, 2.1}}]


Instead of using Which to limit the range of the function, use RegionFunction

p3d = Plot3D[(x1 + 1)^2 + (x2 + 1)^2,
{x1, -1.5, 1.25}, {x2, -1.5, 2.25},
MeshFunctions -> {#3 &},
Mesh -> 10,
AxesLabel -> {x1, x2, "f(x1,x2)"},
LabelStyle -> {20, Bold},
ColorFunction -> ColorData[{"TemperatureMap", "Reverse"}],
ImageSize -> Large,
PlotLegends -> Automatic,
RegionFunction ->
Function[
{x1, x2, z},
g1[x1, x2] <= 0 && g2[x1, x2] <= 0],
PlotPoints -> 300];
punto = Graphics3D[{
Black,
PointSize[0.020],
Point[{0, 1, f[0, 1]}]}];
Show[p3d, punto, PlotRange -> All]