# Sharp jagged lines in Plot3D

I have the following function of five parameters of which I would like to construct a 3D density plot using Plot3D

d = 4 (12 g1^2 + 12 g2^2 + 12 g3^2 - Γ^2 + Γ κ1 - κ1^2 + (Γ + κ1) κ2 - κ2^2)^3 + (36 g1^2 (Γ + κ1 - 2 κ2) + (36 g3^2 - (Γ + κ1 - 2 κ2) (2 Γ - κ1 - κ2)) (Γ - 2 κ1 + κ2) + 36 g2^2 (-2 Γ + κ1 + κ2))^2


I then do

solg3 = g3 /.Solve[d == 0, g3] /. {Γ -> 0.01, κ1 -> 1, κ2 -> 20};


And plot

Plot3D[solg3, {g1, 0, 2.5}, {g2, 0, 8}, ImageSize -> Large, PlotRange -> All, RegionFunction -> Function[{g1, g2, solg3}, solg3 >= 0]]


I am returned with At this point, I am seeing a lot of jagged lines on the contour and I'm not sure why this is happening. Firstly, it can be seen that there are six solutions to solg3 but I only want positive values of g3 hence there are only three contours. However, I'm puzzled by the appearance of those jagged lines on the lower edges of the contour surface. Why is this happening? And why are there gaps? Is it saying that g3 is complex in those regions?

• try the option MaxRecursion with a large value (say MaxRecursion -> 10) and increase PlotPoints (say PlotPoints->200) – kglr Jun 13 '19 at 21:09
• If you don't know this, the LeafCount of solg3 is about 2800. peek at the FullForm of your function to see what you are expecting it to precisely plot. Simplify makes it even worse! Is there any way you can simplify that function 50 or 100 fold? PlotPoints->5 makes it less jagged, but I'm expecting that won't be acceptable either. – Bill Jun 13 '19 at 21:26
• @kglr The plot is still simplifying past 20 minutes. I do not think that having MaxRecursion of 10 and PlotPoints of 200 is tractable. Any other ideas? – kowalski Jun 13 '19 at 21:33
• @Bill That is the best I can do in simplifying d. And PlotPoints of 5 is not enough. Any other suggestions? – kowalski Jun 13 '19 at 21:35

Looks like a job for ContpurPlot3D:

dd = d /. {Γ -> 0.01, κ1 -> 1, κ2 -> 20};
ContourPlot3D[
dd == 0,
{g1, 0, 2.5}, {g2, 0, 8}, {g3, 0, 4},
AxesLabel -> {"g1", "g2", "g3"},
MaxRecursion -> 5
] The result is still a bit jagged (at other places; try also different values of MaxRecursion), but much less.

• Thanks this looks like what I'm looking for! My question is, given that the solution to dd == 0 has 6 solutions, shouldn't I be seeing 6 different contours? Or at least 3 of them since the other 3 is simply the negative of the former. – kowalski Jun 14 '19 at 15:13
• ContourPlot3D employs purely numerical techniques (most likely bisection techniques for root finding). This is why it cannot distinguish the algebraic branches of the solition set. ContourPlot3D does apply different colors for different levelsets, though. – Henrik Schumacher Jun 14 '19 at 15:18
• The equations might have six solutions in the complex numbers. Notice however, that (i) we limit the search range by {g1, 0, 2.5}, {g2, 0, 8}, {g3, 0, 4} and that (ii) ContourPlot3D ignores all nonreal solutions. – Henrik Schumacher Jun 14 '19 at 15:19
• I will have to look up on applying the colors separately for separate contours on the plot. I would, ideally, match the colors that I obtained from Plot3D but I'm skeptical of the plot regions, especially the jagged ones. – kowalski Jun 14 '19 at 15:26