MAT329 Graphing Example:

Here’s a little piece of code, using the Module function, to graph the function and its contours side by side.

Andy Long, Fall, 2015

plotNcontour[f_,a_,b_,c_,d_,range_]:=
Module[
{p1,p2},
p1=Plot3D[f[x,y],{x,a,b},{y,c,d},PlotRange->range];
p2=ContourPlot[f[x,y],{x,a,b},{y,c,d}];
{p1,p2}
]
f[x_,y_]:=Sin[x*y]
plotNcontour[f,-Pi,Pi,-Pi,Pi,Automatic]
f[x_,y_]:=Exp[x]Cos[y]
plotNcontour[f,-2,2,-2Pi,2Pi,{-10,10}]
f[x_,y_]:=Sin[x-y]
plotNcontour[f,-Pi,Pi,-Pi,Pi,Automatic]
f[x_,y_]:=Sin[x]-Sin[y]
plotNcontour[f,-2Pi,2Pi,-2Pi,2Pi,Automatic]
f[x_,y_]:=(1-x^2)(1-y^2)
plotNcontour[f,-Pi,Pi,-Pi,Pi,Automatic]
f[x_,y_]:=(x-y)/(1+x^2+y^2)
plotNcontour[f,-Pi,Pi,-Pi,Pi,Automatic]