# Can I do a ListDensityPlot with a equation? [closed]

If I only have this equation: 0.311235 - 0.0034967 x + 0.0725721 x^2 + 0.0124099 y - 0.0000277583 x y + 0.0726165 y^2

How can I do a density plot?

• Read(!) and try DensityPlot[ "your equation" ,{x,...},{y,...}] Oct 29, 2020 at 15:50

Three different ways to view the function:

f = 0.311235 - 0.0034967 x + 0.0725721 x^2 + 0.0124099 y - 0.0000277583 x y + 0.0726165 y^2;

ContourPlot[f, {x, -5, 5}, {y, -5, 5}]

Plot3D[f, {x, -5, 5}, {y, -5, 5}]

DensityPlot[f, {x, -5, 5}, {y, -5, 5}]

More specifically, the following code works:

fn[x_, y_] := 0.311235 - 0.0034967 x + 0.0725721 x^2 + 0.0124099 y - 0.0000277583 x y + 0.0726165 y^2;

data = Partition[Flatten[Table[{x, y, fn[x, y]}, {x, -5, 5, 1}, {y, -5, 5, 1}]], 3];

ListDensityPlot[data]

• You have a typo in the definition of data. Also, Partition is unnecessary if you Flatten to the appropriate level. data = Flatten[Table[{x, y, fn[x, y]}, {x, -5, 5, 1}, {y, -5, 5, 1}], 1]; This correction will make the plot resemble the others. Oct 29, 2020 at 16:25
• @ Bob Hanlon fixed, ty
– JEM
Oct 29, 2020 at 16:46