Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange output of a Mathematica function

Hi I am unable to understand the output of the following function.

ListPointPlot3D[Table[Sin[x^2 + y],
                      {x, 0, 3, 0.15}, {y, 0, 3, 0.15}],
                      AxesLabel -> {"X axis", "Y axis", "Z axis"}
               ]

enter image description here

I have told X and Y to be in the interval [0,3] But the diagram is showing an entirely different range for these variables from about [0,21].

How did this happen?

like image 817
smilingbuddha Avatar asked Mar 02 '26 10:03

smilingbuddha


2 Answers

You gave ListPointPlot3D a matrix of values. Each value of interpreted as a "height" (z-coordinate) and the matrix indices of the values as the x and y coordinates.

Perhaps you want

ListPointPlot3D[Join @@ Table[{x, y, Sin[x^2 + y]}, {x, 0, 3, 0.15}, {y, 0, 3, 0.15}]]

Mathematica graphics

or

Plot3D[Sin[x^2 + y], {x, 0, 3}, {y, 0, 3}]

Mathematica graphics

Also take a look at the docs of the Mesh option of Plot3D.

like image 92
Szabolcs Avatar answered Mar 05 '26 11:03

Szabolcs


You can use the DataRange option to specify the scope of the axes:

ListPointPlot3D[Table[Sin[x^2 + y], {y, 0, 3, 0.15}, {x, 0, 3, 0.15}],
   AxesLabel -> {"X axis", "Y axis", "Z axis"}, 
   DataRange -> {{0, 3}, {0, 3}}]

Mathematica graphics

Note that I also switched the x and y iterators in the Table, because Table[..., {x, ..}, {y, ...}] corresponds to Table[Table[..., {y, ...}], {x, ...}]. (You can see this is correct by changing one of the 0.15 step sizes to 1.)

like image 35
Brett Champion Avatar answered Mar 05 '26 09:03

Brett Champion



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!