0
$\begingroup$

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

enter image description here

But the result that Mahematica 10 windows 64 bits shows is: enter image description here

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?

enter image description here

$\endgroup$
  • $\begingroup$ Because of the same reason as in 44825 $\endgroup$ – Kuba Dec 2 '14 at 11:34
  • $\begingroup$ @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. $\endgroup$ – Mika Ike Dec 2 '14 at 11:45
  • $\begingroup$ @kuba This is solved!! Can you mark as solved?. I can´t mark as solved till 2 days. $\endgroup$ – Mika Ike Dec 2 '14 at 12:28
  • $\begingroup$ 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. $\endgroup$ – Michael E2 Dec 2 '14 at 17:11
3
$\begingroup$
$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}}]

enter image description here

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]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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