# Weird fluctuations in DensityPlot

I have a really long multi parameter Lorentzian function:

f = (38.4 g1^2 g2^2 Sqrt[κ2^2])/(16 g2^4 (1/10000 + 4 ω^2) + (κ2^2 + 4 ω^2) (16 g1^4 + 8 g1^2 (1/100 - 4 ω^2) + (1/10000 + 4 ω^2) (1 + 4 ω^2)) + 8 g2^2 ((κ2 - 4 ω^2) (1/10000 + 4 ω^2) + 4 g1^2 (κ2/100 + 4 ω^2))) + (9.6 g1^2 (κ2^2 + 4 ω^2))/(16 g2^4 (1/10000 + 4 ω^2) + (κ2^2 + 4 ω^2) (16 g1^4 + 8 g1^2 (1/100 - 4 ω^2) + (1/10000 + 4 ω^2) (1 + 4 ω^2)) + 8 g2^2 ((κ2 - 4 ω^2) (1/10000 + 4 ω^2) + 4 g1^2 (κ2/100 + 4 ω^2))) + (12.02 (16 g2^4 + 8 g2^2 (κ2 - 4 ω^2) + (1 + 4 ω^2) (κ2^2 + 4 ω^2)))/(16 g2^4 (1/10000 + 4 ω^2) + (κ2^2 + 4 ω^2) (16 g1^4 + 8 g1^2 (1/100 - 4 ω^2) + (1/10000 + 4 ω^2) (1 + 4 ω^2)) + 8 g2^2 ((κ2 - 4 ω^2) (1/10000 + 4 ω^2) + 4 g1^2 (κ2/100 + 4 ω^2)))


with the parameters: g1,g2,ω,κ2. I intend to do a density plot with x = g2, y = ω, and z = f with fixed values of g1 and κ2:

DensityPlot[(f/.{g1->10,κ2->10}),{g2,0,20},{ω,-25,25},AxesOrigin->{0,0},PlotRange->All,PlotLegends->Automatic]


And I'm returned with The shape of the curves are as predicted. Notice that when g2 = 20there is a smooth transition in gradient intensity between the blue and yellow. However, near g2 = 0the curves appear to be box-shaped with crosses along the line. I suspect that it's a numerical error. I further plotted it with a smaller g2 range:

DensityPlot[(f/.{g1->10,κ2->10}),{g2,0,5},{ω,-25,25},AxesOrigin->{0,0},PlotRange->All,PlotLegends->Automatic]


It's clear that there must be some kind of numerical error or instability in the curves, but I'm unsure of how to remedy this. Any help would be appreciated.

• Why haven't you already tried to increase the PlotPoints setting? – J. M. will be back soon Oct 9 '18 at 17:09
• @J.M.issomewhatokay. I'm an idiot. Thanks. – kowalski Oct 9 '18 at 17:13
• To help maintain precision, use Rationalize and Simplify in the definition of f. Compare LeafCount /@ {f, f // Rationalize // Simplify}. In addition to or instead of increasing PlotPoints you could increase MaxRecursion. – Bob Hanlon Oct 9 '18 at 17:26