-- surface function
z(x,y) = sin(sqrt(x^2+y^2))/sqrt(x^2+y^2)
n = 3*pi
xmin=-n; xmax=n -- desired range of x and y values
ymin=-n; ymax=n
nx=40; ny=40 -- desired resolution
-- sample the function z(x,y) on an evenly spaced grid
mapx(i) = (i-1)*(xmax-xmin)/(nx-1) + xmin
mapy(i) = (i-1)*(ymax-ymin)/(ny-1) + ymin
zgrid[ix,iy] = z(mapx(ix),mapy(iy)) dim[nx,ny]
Zmin= -.2; Zmax= 1
-- Display a 3D projection of the surface
viewsurf(zgrid,off):
MathPad can display a "3D" projection of surface by using viewsurf. To enable this function quit MathPad, move the XFun file "viewsurf" into MathPad's Active XFuns folder and relaunch.
The surface is specified by a 2D array of z values. The 2D array represents z samples spaced uniformly in x and y. To sample a function over some arbitrary range of x and y values, you can scale array index values to generate the desired x and y values.
When the mouse is clicked on a surface grid point, the corresponding z value is shown in an info line at the bottom of the plot.
viewsurf(zgrid,on)
. The surface is scaled to fit the plot window size at the time of evaluation. If the plot window is re-sized it may distort the projection. You can reevaluate the surface to restore correct scaling. To prevent distortion on printout you should use the zoom box and evaluate the surface with the plot window set to the printer aspect ratio.
The normal axis labels are not very meaningful for the surface projection. They are usually suppressed but can be controlled by the special variables Xticklabels=on; Yticklabels=on
Xmin=xmin; Xmax=xmax;
Ymin=ymin; Ymax=ymax
image zgrid