Department of Mathematics

 MTH243 (Calculus for Functions of Several Variables) SAGE. Chapter 12: Functions of Several Variables Vladimir A. Dobrushkin,Lippitt Hall 202C, 874-5095,dobrush@uri.edu In this course we will use Sage computer algebra system (CAS), which is a free software. The Sage projects are created to help you learn new concepts. Sage is very useful in visualizing graphs and surfaces in three dimensions. Matlab (commercial software) is also available at engineeering labs. Its free version is called Octave. The university has a license for computer algebra system Mathematica, so it is free to use for its students. A student can also use free CASs: SymPy (based on Python), or Maxima.

## Section 12.1. Functions of two Variables

Vectors in the Wolfram Language are simply represented by lists:
v = { a, b, c }
where a, b, and c could be any expressions, numerical or algebraic. Therefore, Mathematica does pay attention whether a vector is a column vecor or a row vector. To specify the column (or row) vector, one should define it as a matrix

## Section 12.2. Graphs of Functions of two Variables

Example 1. We start plotting the graph of a paraboloid, which is defined by the function $$f (x, y) = x^2+y^2 .$$
sage: def f(x,y):
....: ....: ....:     return x*x+y*ysage: P = plot3d(f,(-5,5),(-5,5), adaptive=True, color=['red','yellow'])sage: from sage.plot.plot3d.plot3d import axessage: S = P + axes(6, color='black')sage: S.show()
We can also make it not symmetrical:
a=2; b=3; Plot3D[x^2 /a^2 + y^2 /b^2, {x, -3, 3}, {y, -4, 4}]

ContourPlot3D[z == x^2 + y^2, {x, -3, 3}, {y, -3, 3}, {z, 0, 5}]

ContourPlot3D[x^2 + y^2 == z, {x, -1, 1}, {y, -1, 1}, {z, 0, 1}, Contours -> {4, Dashed}]

Plot3D[x^2 + y^2, {x, -1.5, 1.5}, {y, -1.5, 1.5}, PlotRange -> All, BoxRatios -> Automatic, ColorFunction -> Hue]

ContourPlot3D[ z == ((x^2)/(1^2)) + ((y^2)/(1^2)), {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, AxesOrigin -> {0, 0, 0}, PlotRange -> {-1, 1}, AxesLabel -> {x, y, z}]

ContourPlot3D[ x^2 + y^2 - z == 0, {x, -1., 1.}, {y, -1., 1.}, {z, -1., 1.}, Axes -> True, BoxRatios -> {1., 1., 1.}, ViewPoint -> {-2.43972, -1.63989, 0.598757}, PlotRange -> All, AxesLabel -> {"x", "y", "z"}, ContourStyle -> Directive[RGBColor[1, 0.8, 0.3], Specularity[RGBColor[0.2, 0.2, 0.7], 20]], Lighting -> "Neutral", ColorFunction -> None, BoxStyle -> GrayLevel[0, 0.35]]

ContourPlot3D[x^2 + y^2 == z, {x, -1, 1}, {y, -1, 1}, {z, 0, 1}, Mesh -> None, Lighting -> "Neutral", TextureCoordinateFunction -> ({#1, #3} &), ContourStyle -> Texture[ExampleData[{"ColorTexture", "WavesPattern"}]]]

or using polar coordinates
ParametricPlot3D[{s Cos[t], 2 s Sin[t], s^2}, {s, 0, 2}, {t, 0, 2 Pi}, PlotStyle -> Thick]

Now we create a new graph by shifting the previous one up by 3 units: $$g (x, y) = x^2 + y^2 + 3$$
Plot3D[(x^2 + y^2 + 3), {x, -3, 3}, {y, -3, 3}, Axes -> True]
Another graph of $$h(x, y) = 5 - x^2 - y^2$$
Plot3D[(5 - x^2 - y^2), {x, -3, 3}, {y, -3, 3}, Axes -> True, PlotStyle -> Orange]
One more: $$k (x, y) = x^2 + (y - 1)^2$$
Plot3D[(x^2 + (y - 1)^2), {x, -3, 3}, {y, -3, 3}, PlotStyle -> None]
Example 2. Plotting the graph of the function $$G(x,y)=e^{-(x^2+y^2)}$$
Plot3D[(E^-(x^2 + y^2)), {x, -5, 5}, {y, -5, 5}, PlotStyle -> Opacity[.8]]
Cross Sections and the Graph of a Function where x=2
Plot3D[{(x^2 + y^2), (4 + y^2)}, {x, -3, 3}, {y, -3, 3}]
Example 2. Now we consider the hyperbolic parabaloid
figure;
x = [-10:.5:10];
y=[-10:.5:10];
[X, Y] = meshgrid(x,y);
Z = X.^2-Y.^2;
surf(X,Y,Z)
title('12.73 Hyperbolic Paraboloid')
xlabel y
ylabel x
zlabel z

Plot3D[-x^2 + y^2, {x, -1.5, 1.5}, {y, -1.5, 1.5}, PlotRange -> All, BoxRatios -> Automatic , ColorFunction -> Hue]
or
ContourPlot3D[-x^2/10 + y^2/10 == z, {x, -10, 10}, {y, -10, 10}, {z, -10, 10}, ColorFunction -> Function[{x, y, z}, Hue[z]]]
ContourPlot3D[-x^2 + y^2 - z == 0, {x, -4., 4.}, {y, -4., 4.}, {z, -4., 4.}, Axes -> True, BoxRatios -> {1., 1., 1.}, ViewPoint -> {-2.35989, -1.80482, -0.416584}, PlotRange -> All, AxesLabel -> {"x", "y", "z"}, ContourStyle -> Directive[RGBColor[0.5, 0.8, 0.3], Specularity[RGBColor[0.2, 0.2, 0.7], 20]], Lighting -> "Neutral", ColorFunction -> None, BoxStyle -> GrayLevel[0.7, 0.5]]
ParametricPlot3D[{s, t, s^2 - t^2}, {s, -1, 1}, {t, -1, 1}, PlotStyle -> Magenta]
ContourPlot3D[-x^2 + y^2 == z, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, Mesh -> 5, MeshFunctions -> {#1 &, #2 &}, MeshStyle -> {Dashed, Blue}]

Example 5. Graph the equation $$x^2 + y^2 =1$$ in 3-space.

figure
[x,y,z] = cylinder(10);
z(2, :) = 10;
surf(x,y,z, 'FaceColor', [1,0,0]);
title('12.79 Cylindrical Surface')

ContourPlot3D[(x^2 + y^2)^.5 == 1, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, MeshShading -> {White, Black, Blue}, MeshFunctions -> {#3 &}]
ContourPlot3D[x^2 + y^2 == 6, {x, -3, 3}, {y, -3, 3}, {z, -3, 3}, ColorFunction -> Function[{x, y, z}, Hue[z]]]
ContourPlot3D[(x^2 + y^2)^.5 == 1, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, MeshShading -> Table[RGBColor[r, g, b], {r, 0, 1, 1/5}, {g, 0, 1, 1/5}, {b, 0, 1, 1/5}], Mesh -> 5, Lighting -> "Neutral"]

Example 6 . Consider the equation of parabolic cylinder $$y= x^2$$ in 3-space when one variable is missing.

figure;
x = [-10:.5:10];
y=[5:.5:10];
[X, Y] = meshgrid(x,y);
Z = X.^2+Y.^2
surf(X,Y,Z)
xlabel x
ylabel y
zlabel z
title('12.80 Parabolic Cylinder')

ContourPlot3D[y == x^2, {x, -3, 3}, {y, 0, 3}, {z, -3, 3}, MeshShading -> {Blue, Orange}, MeshFunctions -> {#3 &}]
ContourPlot3D[y == .5*x^2, {x, -3, 3}, {y, 0, 3}, {z, -2, 2}, ColorFunction -> Hue]
Plot3D[y = 3 x^2, {x, -5, 5}, {y, -5, 5}, AspectRatio -> 1]
ContourPlot3D[y == x^2, {x, -3, 3}, {y, 0, 3}, {z, -3, 3}, MeshFunctions -> {#1 &}, MeshStyle -> Dashed, Mesh -> 5] Show[%, Background -> RGBColor[0.84, 0.92, 1.]]

sage: var('x,y')
(x, y)sage: plot3d(abs(x)*abs(y),(x,-5,5),(y,-5,5))
sage: def f(x,y):
....: ....: ....:     return math.sin(y*y+x*x)/(x*x+y*y+.0001)sage: P = plot3d(f,(-3,3),(-3,3), adaptive=True, color=rainbow(60, 'rgbtuple'), ....: max_bend=.1, max_depth=15)sage: P.show()
sage: def f(x,y):
....: ....: ....:     return x*x+y*ysage: P = plot3d(f,(-5,5),(-5,5), adaptive=True, color=['red','yellow'])sage: from sage.plot.plot3d.plot3d import axessage: S = P + axes(6, color='black')sage: S.show()
sage: plot3d(-1/(x*x+y*y+.0001),(x,-3,3),(y,-3,3))