0
$\begingroup$

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?

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

1 Answer 1

1
$\begingroup$

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}]

enter image description here

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

enter image description here

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

enter image description here

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]

enter image description here

$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$
    – Bob Hanlon
    Oct 29, 2020 at 16:25
  • $\begingroup$ @ Bob Hanlon fixed, ty $\endgroup$
    – JEM
    Oct 29, 2020 at 16:46

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