3D the Grid
If we have a function of two variables
, we need three axes to display the graph.
When plotting in 2D we use evenly spaced x-values and function values of these stored in a y-vector.
When plotting in 3D we need evenly spaced x- and y-values, spaced on a grid where each function value z is taken of a point (x, y) on the grid. In order to achieve this we use the command
meshgrid.
>>> x=linspace(-2,2,5) x = -2 -1 0 1 2 >>> y=linspace(-2,2,5) y = -2 -1 0 1 2 >>> [xx,yy]=meshgrid(x,y) xx = -2 -1 0 1 2 -2 -1 0 1 2 -2 -1 0 1 2 -2 -1 0 1 2 -2 -1 0 1 2 yy = -2 -2 -2 -2 -2 -1 -1 -1 -1 -1 0 0 0 0 0 1 1 1 1 1 2 2 2 2 2
Each point on the grid is made by taken an element from the xx-matrix as the
x-value and the corresponding element from the yy-matrix as the y-value. All
in all there are 25 points in this grid.
by Malin Christersson under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 Sweden License