Department of Mathematics

 MTH243 (Calculus for Functions of Several Variables) MATLAB. Chapter 12: Functions of Several Variables Vladimir A. Dobrushkin,Lippitt Hall 202C, 874-5095,dobrush@uri.edu In this course we will use Mathematica computer algebra system (CAS), which is available in computer labs at URI. The Mathematica projects are created to help you learn new concepts. Mathematica 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. A student can also use free CASs: SymPy (based on Python), Maxima, or Sage.

## Section 12.5. Functions of three Variables

Example 1. A particular case of ellipsoid is a ball:
ContourPlot3D[ 1 == x^2 + y^2 + z^2, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}]
or
clc
clear
figure
fi0=0;
fi1=360;
R=1;
R0=0;
R1=1;
M=30;
dfi=(fi1-fi0)/M;
dR=(R1-R0)/M;
fi=[fi0:dfi:fi1];
aa=pi/180;
theta0=0;
theta1=360;
dtheta=(theta1-theta0)/M;
theta=[theta0:dtheta:theta1];
t=0;
tt=-1;
for j=1:M/2+1
tt=tt+1;
t=tt;
for i=1:M+1
t=t+1;
b(t)=t;
x(i)=R*sin(aa*fi(i))*cos(aa*theta(j));
y(i)=R*sin(aa*fi(i))*sin(aa*theta(j));
z(i)=R*cos(aa*fi(i));
%pause
v(1:6,b(t))=[ x(i) y(i) z(i) fi(i) theta(j) b(t)];
end
plot3(x,y,z)
axis equal
grid on
hold on

end
title('BONUS 12.69')
t=0;
tt=-1;
for j=1:M/2+1
tt=tt+1;
t=tt;
end
for i=1:M+1
t=t+1;
bb(t)=t;
xx(i)=R*sin(aa*fi(j))*cos(aa*theta(i));
yy(i)=R*sin(aa*fi(j))*sin(aa*theta(i));
zz(i)=R*cos(aa*fi(j));
%pause
ang=45;
RR = rotx(ang);
vv = [xx(i);yy(i);zz(i)];
%pause
yyy = RR*vv;
vvv(1:6,bb(t))=[ yyy(1) yyy(2) yyy(3) fi(j) theta(i) bb(t)];
plot3(xx,yy,zz)
plot3(vvv(1,bb(t)),vvv(2,bb(t)),vvv(3,bb(t)),'r*')
axis equal
grid on
hold on

end

ContourPlot3D[ x^2 + y^2 + z^2 == 1, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, Contours -> 3, MeshFunctions -> {#1 &}]
a = 3; b = 3; c = 3;
ContourPlot3D[ x^2/a^2 + y^2/b^2 + z^2/c^2 == 1, {x, -3, 3}, {y, -3, 3}, {z, -3, 3}, ContourStyle -> Green]
[x, y, z] = ellipsoid(0,0,0,5.9,3.25,3.25,30);
figure;
surf(x, y, z);
axis equal;
title('12.74 ELLIPSOID')
xlabel x
ylabel y
zlabel z

ContourPlot3D[-1 + x^2 + y^2 + z^2 == 0, {x, -4., 4.}, {y, -4., 4.}, {z, -4., 4.}, Axes -> True, BoxRatios -> {1., 1., 1.}, ViewPoint -> {-1.64646, -2.30505, -0.987878}, 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^2 == 1, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, Mesh -> None]
ParametricPlot3D[{Cos[t] Cos[s], 2 Sin[t] Cos[s], 3 Sin[s]}, {s, 0, 2 Pi}, {t, 0, 2 Pi}, PlotStyle -> Opacity[0.2]]

Example 2.

Example 3. Hyperboloid of one sheet

figure
[X,Y,Z] = meshgrid(-10:0.5:10,-10:0.5:10,-10:0.5:10);
a=1;
b=1;
c=1;
V = X.^2/a^2 + Y.^2/b^2 - Z.^2/c^2;
p=patch(isosurface(X,Y,Z,V,10));
set(p,'FaceColor','blue','EdgeColor','none');
daspect([1 1 1])
view(3);
camlight
title('12.75 Hyperboloid of one sheet')

ContourPlot3D[ x^2 + y^2 - z^2 == 1, {x, -3, 3}, {y, -3, 3}, {z, -3, 3}, MeshShading -> {LightBlue, Orange}, MeshFunctions -> {#2 &}]
a = 1.5; b = 2.0; c = 2.5;
ContourPlot3D[ x^2/a^2 + y^2/b^2 - z^2/c^2 == 1, {x, -3, 3}, {y, -3, 3}, {z, -2, 2}, ColorFunction -> Hue]
ContourPlot3D[ x^2 + y^2 - z^2 == 1, {x, -2, 2}, {y, -2, 2}, {z, -1, 1}, ContourStyle -> Purple]
ContourPlot3D[-1 + x^2 + y^2 - z^2 == 0, {x, -4., 4.}, {y, -4., 4.}, {z, -4., 4.}, Axes -> True, BoxRatios -> {1., 1., 1.}, ViewPoint -> {-1.64195, -2.50908, -0.092319}, PlotRange -> All, AxesLabel -> {"x", "y", "z"}, ContourStyle -> Directive[RGBColor[0.9, 0.8, 0.3], Specularity[RGBColor[0.2, 0.2, 0.7], 20]], Lighting -> "Neutral", ColorFunction -> None, BoxStyle -> GrayLevel[0.5, 0.7]]
ParametricPlot3D[{Cos[t] Cosh[s], Sin[t] Cosh[s], Sinh[s]}, {t, 0, 2 Pi}, {s, -1, 1}, PlotStyle -> Directive[Purple, Opacity[0.3]]]
ContourPlot3D[ x^2 + y^2 - z^2 == 1, {x, -3, 3}, {y, -3, 3}, {z, -3, 3}, MeshShading -> {Green, Red}, MeshFunctions -> {#3 &}]

Example 4.

Example 5.

Example. Now we plot a hyperboloid of two sheets:

figure
[X,Y,Z] = meshgrid(-10:0.5:10,-10:0.5:10,-10:0.5:10);
a=1;
b=1;
c=1;
V = X.^2/a^2 + Y.^2/b^2 - Z.^2/c^2;
p=patch(isosurface(X,Y,Z,V,-5));
set(p,'FaceColor','RED','EdgeColor','none');
daspect([1 1 1])
view(3);
camlight
title('12.76 Hyperboloid of two sheets')
/code>
 
 a = 1.5; b = 1.5; c = 1; ContourPlot3D[ x^2/a^2 + y^2/b^2 - z^2/c^2 == -1, {x, -3, 3}, {y, -3, 3}, {z, -2, 2}, ColorFunction -> Hue] ContourPlot3D[ x^2 + y^2 - z^2 == -1, {x, -3, 3}, {y, -3, 3}, {z, -3, 3}, ContourStyle -> LightBlue] ContourPlot3D[(4 + x^2 + y^2 - 4*z^2)/4 == 0, {x, -3., 3.}, {y, -3., 3.}, {z, -5., 5.}, Axes -> True, BoxRatios -> {2., 2., 1.}, ViewPoint -> {-2.5, -3.5, -0.5}, 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.5, 0.3], AspectRatio -> 1] We can also plot half of such hyperboloid: ParametricPlot3D[{Cos[t] Sinh[s], Sin[t] Sinh[s], Cosh[s]}, {t, 0, 2 Pi}, {s, -1, 1}, PlotRange -> 2, Mesh -> None] ContourPlot3D[ x^2 + y^2 - z^2 == -1, {x, -3, 3}, {y, -3, 3}, {z, -3, 3}, MeshShading -> {Blue, LightBlue}, MeshFunctions -> {#2 &}] Example.