L - Calclab

Spring 2004 Math 253/501–503
12 Multivariable Differential Calculus
12.1 Functions of Several Variables
c
Thu, 29/Jan
2004,
Art Belmonte
730/14
Find the domain and range of f (x, y, z) = p
1
x2
+
y2
+ z2 − 1
.
Solution
Summary
• For the domain, we require x 2 + y 2 + z 2 − 1 > 0, so that we
may take square roots and not divide by zero. This implies
x 2 + y 2 + z 2 > 1. Thus the domain of f is the set of all
points in space outside the sphere of radius 1 centered at the
origin.
• function of n variables: a rule that assigns a unique real
number f (x) = f (x 1 , . . . , x n ) to each ordered n-tuple
x = [x 1 , . . . , x n ] in a subset D (the domain) of Rn .
• plots of w = f (x):
• The range of f is the collection of all its function values. The
denominator in the definition of f is always positive, but
may be arbitrarily large or small. Thus the range of f is the
set of all positive numbers.
– For n = 1, these are curves y = f (x) in the x y-plane.
– For n = 2, these are surfaces z = f (x, y) in x yz-space.
– For n > 2, these are hypersurfaces w = f (x)
embedded in (n + 1)-space.
• level hypersurface of f : where f (x) = k, a constant
730/18
– For n = 2, the graphs of f (x, y) = k are called
level curves.
Find and sketch the domain of f (x, y) =
– For n = 3, the graphs of f (x, y, z) = k are called
level surfaces.
x 2 + y2
.
x 2 − y2
Solution
Hand Examples
The functional expression is defined provided the denominator
(x − y)(x + y) is not zero. Hence the domain of f is the entire
x y-plane except for the lines y = x and y = −x. These lines are
excluded from the domain. Here is a picture.
730/3
3x y
. Evaluate F(1, 1), F(−1, 2), F(t, 1),
+ 2y 2
F(−1, y), and F x, x 2 .
Let F(x, y) =
x2
Stewart 730/18
3
2
Solution
y
1
By hand, just plug and chug. With a TI-89 or MATLAB, define a
function and blaze away! (I’ll do the TI-89 in class with you. See
the corresponding MATLAB example.)
F(1, 1) =
F(−1, 2) =
F(t, 1) =
F(−1, y) =
F x, x
2
=
0
−1
−2
3(1)(1)
3
= =1
2
2
3
(1) + 2(1)
2
3(−1)(2)
−6
=−
=
2
2
9
3
(−1) + 2(2)
3(t)(1)
3t
= 2
(t)2 + 2(1)2
t +2
3(−1)(y)
3y
=− 2
2
2
(−1) + 2(y)
2y + 1
2
3(x) x
3x 3
3x
=
2 = 2
4
2
2
x + 2x
1 + 2x 2
(x) + 2 x
−3
−3
−2
−1
0
x
1
2
3
MATLAB Examples
s730x03 [730/3 revisited]
3x y
. Evaluate F(1, 1), F(−1, 2), F(t, 1),
+ 2y 2
F(−1, y), and F x, x 2 .
Let F(x, y) =
1
x2
Solution
(d) A fourth way is to use MATLAB’s surf command with a
rectangular domain. Again, note the degradation in the graph
when the surface becomes vertical.
Here we define F in an external function M-file. Then we use a
script M-file to record our work.
%====================
function z = F(x,y)
z = 3*x*y / (x^2 + 2*y^2);
%====================
% Stewart 730/3
%
format rat
syms t x y
a = F(1,1)
a =
1
b = F(-1,2)
b =
-2/3
c = F(t,1); pretty(c)
(e) A fifth way is with my hvsd command followed by surf.
This enables one to use a non-rectangular domain that results
in less degradation. Still, you’re trying to fit a rectangular peg
into an elliptical hole, with the “pinching” at the boundary
that this entails.
(f) Finally, we see the sixth way: parametric surface plotting!
This is the real deal from Chapter 14 of Stewart (Section 14.6
in particular). This gives the nicest plot at the expense of
having to come up with a surface parameterization, in this
case ellipsoidal or scaled spherical coordinates. This is
beyond your current knowlege, but we’ll cover it in the
fullness of time.
t
3 -----2
t + 2
d = F(-1,y); pretty(d)
y
-3 -------2
1 + 2 y
e = simple(F(x,x^2)); pretty(e)
Here are the six sets of diary files and plots.
x
3 -------2
1 + 2 x
%
%
% Stewart 730/38a: Via contour
%
x = linspace(-4, 4); y = linspace(-1, 1);
[X,Y] = meshgrid(x,y);
Z = sqrt(16 - X.^2 - 16.*Y.^2);
v = [0.5 1.5 2.5 3.0 3.5 3.8];
[cs, h] = contour(X,Y,Z,v);
clabel(cs,h,v)
%
echo off; diary off
s730x38
16 − x 2 − 16y 2 .
echo off; diary off
Solution
Stewart 730/38a: via contour
0.5
1.5
1
We illustrate six ways to do this, discussing the merits and
drawbacks of each.
3
5
5
2.5
2.
0.5
1.
0.5
y
3.5
3.8
0
3.5
0.5
3
2.5
(a) The first way is to draw a contour plot. This is like a
topographical map. The idea is to take traces (cross sections)
z = f (x, y) = k and project them onto the x y-plane to form
level curves of the function f . The MATLAB contour
command does a nice job of this. The drawback is that it’s a
2-D plot. You must imagine levels forming hills or valleys.
0.5
p
3.8
3
−0.5
2.5
1.5
−1
−4
(b) The second way is to use the impl command mentioned on
page 104 of Cooper. This basically raises the contours from
(a) up or down in space, giving you a “skeletal” view of the
surface—not a real surface, but good enough for government
work, I suppose. At least the figure is rendered in 3-D space.
−2
1.5
Plot the function f (x, y) =
05
0
x
2
4
%
% Stewart 730/38b: Via impl
%
F = inline(’x.^2 + 16.*y.^2 + z.^2’, ’x’, ’y’, ’z’);
span = [-4 4 -1 1 0 4];
impl(F, span, 16);
ans =
The max over this domain is 48.00000
ans =
The min over this domain is 0.00000
grid on; axis equal
%
(c) The third way is to use the ezsurf command in MATLAB’s
Symbolic Math Toolbox. Like an errant youth, surfaces “go
bad” when they go vertical, as evidenced by the degradation
in the graph near the x y-plane. Still, ezsurf is easy to use.
echo off; diary off
2
Stewart 730/38e: via hvsd and surf with elliptical domain
Stewart 730/38b: via impl
4
3
2
z
z
3
4
1
−1
y
2
0
1
0
−2
0
4
1
2
0
1
2
0
x
−4
−2
0
−1
y
%
% Stewart 730/38c: Via ezplot3
%
syms x y
f = sqrt(16 - x^2 - 16*y^2);
ezsurf(f); grid on; axis equal
%
x
−4
%
% Stewart 730/38f: Parametric surface;
% ellipsoidal (scaled spherical) coordinates
%
p = linspace(0, pi/2, 19); t = linspace(0, 2*pi, 73);
[P,T] = meshgrid(p,t);
X = 4 .* sin(P) .* cos(T);
Y =
sin(P) .* sin(T);
Z = 4 .* cos(P);
surf(X,Y,Z); grid on; axis equal
%
echo off; diary off
Stewart 730/38c: via ezsurf
echo off; diary off
Stewart 730/38f: parametric surface with elliptical coordinates
z
3
2
4
1
3
2
z
0
0.5
0
−0.5
y
2
−2
x
4
1
2
0
%
% Stewart 730/38d: Via surf; rectangular domain; loose mesh
%
x = linspace(-4, 4, 40); y = linspace(-1, 1, 40);
[X,Y] = meshgrid(x,y);
Z = sqrt(16 - X.^2 - 16.*Y.^2);
Z = clip(Z, [0,4]); % "Clip her wings." -- La Femme Nikita
surf(X,Y,Z); grid on; axis equal
%
1
−2
0
y
−1
−4
x
s730x44
echo off; diary off
Stewart 730/38d: via surf with rectangular domain
Draw a contour map of the function f (x, y) = x 2 − y 2 .
[Additionally, describe its level curves and sketch the surface.]
z
3
Solution
2
4
1
2
0
1
−2
0
y
The level curves of f are f (x, y) = x 2 − y 2 = k, where k is
constant. These are hyperbolas (or straight lines if k = 0). Here
are codes for a contour map and a surface plot, followed by pix.
0
−1
−4
x
%
% Stewart 730/38e: Via surf; elliptical domain; looser mesh
%
syms x y
s = sqrt(1 - x^2/16);
[Z Y X] = hvsd(sqrt(16 - x^2 - 16*y^2), ...
[y -s s 30], [x -4 4 30]);
surf(X,Y,Z); grid on; axis equal
%
%
% Stewart 730/44a: Via contour
%
x = linspace(-4, 4); y = x;
[X,Y] = meshgrid(x,y);
Z = X.^2 - Y.^2;
contour(X,Y,Z,10);
grid on; axis equal; axis([-4 4 -4 4])
%
echo off; diary off
echo off; diary off
3
Stewart 730/44: contour plot
4
3
2
y
1
0
−1
−2
−3
−4
−4
−2
0
x
2
4
%
% Stewart 730/44d: Via surf; rectangular domain; loose mesh
%
x = linspace(-4, 4, 20); y = x;
[X,Y] = meshgrid(x,y);
Z = X.^2 - Y.^2;
surf(X,Y,Z); grid on
%
echo off; diary off
Stewart 730/44d: surface plot
20
z
10
0
−10
−20
5
5
0
y
0
−5
−5
x
4