Functions of two variables

Here is a simple function of two variables

In[1]:=

F[x_, y_] = x * y

Out[1]=

x y

Evaluated at a few points:

In[2]:=

F[0, 0] F[1, 2] F[3, 3] F[-1, 0]

Out[2]=

0

Out[3]=

2

Out[4]=

9

Out[5]=

0

The following plots our graph for values of x and y lying in the square: -1<x<1 and -1<y<1:

In[6]:=

Plot3D[F[x, y], {x, -1, 1}, {y, -1, 1}]

[Graphics:HTMLFiles/surfaces_9.gif]

Out[6]=

⁃SurfaceGraphics⁃

The BoxRatios→Automatic option makes each axis appear to be at the same scale

In[7]:=

Plot3D[F[x, y], {x, -1, 1}, {y, -1, 1}, BoxRatiosAutomatic]

[Graphics:HTMLFiles/surfaces_12.gif]

Out[7]=

⁃SurfaceGraphics⁃

We can use the ViewPoint option to change our point of view:

In[8]:=

Plot3D[F[x, y], {x, -1, 1}, {y, -1, 1}, BoxRatiosAutomatic, ViewPoint {2, 3, .125}]

[Graphics:HTMLFiles/surfaces_16.gif]

Out[8]=

⁃SurfaceGraphics⁃

Here

In[9]:=

For[i = 0, i<2 * Pi, i += Pi/20, Plot3D[F[x, y], {x, -1, 1}, {y, -1, 1}, BoxRatiosAutomatic, ViewPoint {3 Cos[i], 3 Sin[i], .125}, SphericalRegionTrue]]

[Graphics:HTMLFiles/surfaces_19.gif]

[Graphics:HTMLFiles/surfaces_20.gif]

[Graphics:HTMLFiles/surfaces_21.gif]

[Graphics:HTMLFiles/surfaces_22.gif]

[Graphics:HTMLFiles/surfaces_23.gif]

[Graphics:HTMLFiles/surfaces_24.gif]

[Graphics:HTMLFiles/surfaces_25.gif]

[Graphics:HTMLFiles/surfaces_26.gif]

[Graphics:HTMLFiles/surfaces_27.gif]

[Graphics:HTMLFiles/surfaces_28.gif]

[Graphics:HTMLFiles/surfaces_29.gif]

[Graphics:HTMLFiles/surfaces_30.gif]

[Graphics:HTMLFiles/surfaces_31.gif]

[Graphics:HTMLFiles/surfaces_32.gif]

[Graphics:HTMLFiles/surfaces_33.gif]

[Graphics:HTMLFiles/surfaces_34.gif]

[Graphics:HTMLFiles/surfaces_35.gif]

[Graphics:HTMLFiles/surfaces_36.gif]

[Graphics:HTMLFiles/surfaces_37.gif]

[Graphics:HTMLFiles/surfaces_38.gif]

[Graphics:HTMLFiles/surfaces_39.gif]

[Graphics:HTMLFiles/surfaces_40.gif]

[Graphics:HTMLFiles/surfaces_41.gif]

[Graphics:HTMLFiles/surfaces_42.gif]

[Graphics:HTMLFiles/surfaces_43.gif]

[Graphics:HTMLFiles/surfaces_44.gif]

[Graphics:HTMLFiles/surfaces_45.gif]

[Graphics:HTMLFiles/surfaces_46.gif]

[Graphics:HTMLFiles/surfaces_47.gif]

[Graphics:HTMLFiles/surfaces_48.gif]

[Graphics:HTMLFiles/surfaces_49.gif]

[Graphics:HTMLFiles/surfaces_50.gif]

[Graphics:HTMLFiles/surfaces_51.gif]

[Graphics:HTMLFiles/surfaces_52.gif]

[Graphics:HTMLFiles/surfaces_53.gif]

[Graphics:HTMLFiles/surfaces_54.gif]

[Graphics:HTMLFiles/surfaces_55.gif]

[Graphics:HTMLFiles/surfaces_56.gif]

[Graphics:HTMLFiles/surfaces_57.gif]

[Graphics:HTMLFiles/surfaces_58.gif]

In[10]:=

ContourPlot[F[x, y], {x, -1, 1}, {y, -1, 1}]

[Graphics:HTMLFiles/surfaces_60.gif]

Out[10]=

⁃ContourGraphics⁃

The Coutours option allows us to plot more level sets

In[11]:=

ContourPlot[F[x, y], {x, -1, 1}, {y, -1, 1}, PlotPoints130, Contours31]

[Graphics:HTMLFiles/surfaces_63.gif]

Out[11]=

⁃ContourGraphics⁃

Here we color the contours with colors

In[12]:=

ContourPlot[F[x, y], {x, -1, 1}, {y, -1, 1}, PlotPoints130, Contours31, ColorFunctionHue]

[Graphics:HTMLFiles/surfaces_66.gif]

Out[12]=

⁃ContourGraphics⁃

Here's an example where we render some pretty pictures with Mathematica

In[13]:=

RowBox[{F[x_, y_], :=, RowBox[{1, /, RowBox[{(, RowBox[{Cos[x] * Cos[y], +, 1.2}], )}]}]}]

The larger we make PlotPoints, the smoother the surface will appear, but the longer it will take to draw
Mesh->False takes away the black grid lines from our surface

In[14]:=

Plot3D[F[x, y], {x, -6, 6}, {y, -6, 6}, BoxRatiosAutomatic, PlotPoints200, PlotRangeAll, MeshFalse]

[Graphics:HTMLFiles/surfaces_70.gif]

Out[14]=

⁃SurfaceGraphics⁃

PlotPoints->100 makes the level sets appear smoother

In[15]:=

ContourPlot[F[x, y], {x, -6, 6}, {y, -6, 6}, PlotPoints100, ColorFunctionHue]

[Graphics:HTMLFiles/surfaces_73.gif]

Out[15]=

⁃ContourGraphics⁃

We can specify which contour lines to plot with the Contours Option
In the folowing plot, we choose level sets correspoinding to F[x,y]=.5, .75, and 1

In[16]:=

ContourPlot[F[x, y], {x, -6, 6}, {y, -6, 6}, PlotPoints100, ColorFunctionHue, Contours {.5, .75, 1}]

[Graphics:HTMLFiles/surfaces_76.gif]

Out[16]=

⁃ContourGraphics⁃

Contours can also be used to specify the number of contour lines to plot as below.
We also have increased PlotPoints which makes the level curves more smooth.
ContourLines->False removes the black level set lines from the image.

In[17]:=

ContourPlot[F[x, y], {x, -6, 6}, {y, -6, 6}, PlotPoints400, ColorFunctionHue, ContourLinesFalse, Contours200]

[Graphics:HTMLFiles/surfaces_79.gif]

Out[17]=

⁃ContourGraphics⁃


Created by Mathematica  (September 20, 2004)