I am trying to plot a simple function
F[x_, y_] := 1/x If[y < x^2 + 2 x && y > Abs[x^2 - 2 x], 1 - 1/4 (x - y/x)^2, If[y > 0 && y < -x^2 + 2 x, y, 0]]
in a simple way:
g1 = Plot3D[F[x, y], {x, 0, 2.5}, {y, 0, 11}, BoxRatios -> {3, 3, 2.2},PlotPoints ->{30, 30}, PlotRange -> {0, 1.5}, MeshFunctions -> {#1 &}, Lighting -> "Neutral", Filling -> Bottom, FillingStyle -> Opacity[1]];
g2 = Plot3D[F[x, y], {x, 0, 2.5}, {y, 0, 11}, BoxRatios -> {3, 3, 2.2},PlotPoints -> {30, 30}, PlotRange -> {0, 1.5}, MeshFunctions -> {#1 &}, Lighting -> {{"Ambient", White}}, Filling -> Bottom, FillingStyle -> Opacity[1]];
gr = GraphicsRow[ Show[#, Boxed -> False, Axes -> None, ViewPoint -> {1.8, 2.5, 1.3}] & /@ {g1, g2}, ImageSize -> Full]
and find a lot of artefacts, see below:
The problems I marked here can be reduced somehow by increasing the number of PlotPoints. However, I never manage to get rid of them (artefacts, not points) completely. Most disturbing things are:
- A curve running across the plane (on both plots). As I understood there should only the Mesh lines be visible;
- Discontinuous vertical line in the second plot;
- Strange shadows on the top of first plot.
Any help is greatly appreciated.
MaxRecursion -> 10
greatly reduces the problem $\endgroup$PlotPoints -> {80, 80}, BoundaryStyle -> None, MaxRecursion -> 5
(or higher values forPlotPoints
andMaxRecursion
)? $\endgroup$Piecewise
rather thanIf
:F[x_, y_] := Piecewise[{{(1 - 1/4 (x - y/x)^2)/x, y < x^2 + 2 x && y > Abs[x^2 - 2 x]}, {y/x, y > 0 && y < -x^2 + 2 x}}]
. Note thatMaximize[{F[x, y], 0 <= x <= 2.5, 0 <= y <= 11}, {x, y}]
gives{1.97433, {x -> 0.0256689, y -> 0.050679}}
. Since the maximum is greater than your specifiedPlotRange
, you are clipping thePlot
and causing the artifact near the maximum. UsePlotRange -> All
$\endgroup$