Department of Mathematics

 MTH243 (Calculus for Functions of Several Variables) MATHEMATICA. Chapter 16: Integrating 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 16.5. Cylindrical and Spherical Coordinates

Cylindrical Coordinates

Each point in 3-space is represented using $$0 \le r < \infty , \ 0 \le \theta \le 2\pi , \ -\infty < z < \infty :$$

$\begin{split} x&= r\,\cos\theta , \\ y&= r\,\sin \theta , \\ z &= z , \end{split} \qquad \Longrightarrow \qquad {\text d}V = r\,{\text d}r\, {\text d}\theta \, {\text d}z .$
ContourPlot3D[ x^2 + y^2 + z^2, {x, -3, 3}, {y, -30, 30}, {z, -30, 30}, Contours -> 5]
ContourPlot3D[{x^2 + y^2 == 1, x^2 + y^2 == 2}, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, Mesh -> None]

Example 1. Plot a wedge of cheese cut from a cylinder 4 cm high and 6 cm in radius; this wedge subtends an angle of $$\pi /6$$ at the center.

csF[opts : OptionsPattern[]][angle_: {0, Pi/6}, radii_: {0, 6}, minmaxheight_: {0, 4}, style_: {EdgeForm[], Opacity[1], Orange}] := Graphics3D[{## & @@ style, ChartElementData["CylindricalSector3D"][{angle, radii, minmaxheight}, 0]}, opts]
csF[][{0, Pi/6}]
or
RegionPlot3D[ ImplicitRegion[ x^2 + y^2 <= 6^2 && 0 < z < 4 && 0 < y <= x Sin[Pi/6], {x, y, z}], PlotPoints -> 100]
RegionPlot3D[ 0 <= z <= 4 && x^2 + y^2 <= 6^2 && 0 <= ArcTan[x, y] <= Pi/6, {x, -.1, 6.1}, {y, -.1, 3.1}, {z, -.1, 4.1}, PlotPoints -> {100, 100, Automatic}, Mesh -> False]
Using another color, we have
radius = 6; height = 4; angle = 30 Degree;
RegionPlot3D[ x^2 + y^2 <= radius^2 && x >= 0 && 0 <= y <= ArcTan[angle] x && 0 <= z <= height, {x, 0, 6}, {y, 0, 6}, {z, 0, height}, Mesh -> None, PlotPoints -> 100, PlotRangePadding -> {Scaled[0.05], Scaled[0.05], Scaled[.1]}, Boxed -> False, Axes -> False, AspectRatio -> 0.5]
wedge = Module[{k = 3, circ, n, twoCircs, cyl, z = .6, startangle = Pi/3, endangle = Pi - Pi/2.5, zscale = 0}, circ = Table[{Cos[t], Sin[t], zscale}, {t, startangle, endangle, Pi/(6 k)}];
n = Length[circ];
twoCircs = Join[circ, Map[# + {0, 0, z} &, circ]];
cyl = GraphicsComplex[twoCircs, Polygon[Table[{m, m + 1, m + n + 1, m + n}, {m, n - 1}]], VertexNormals -> twoCircs];
N@{Polygon[Join[{{0, 0, 0}}, circ]], Translate[ Polygon[Join[{{0, 0, 0}}, circ]], {0, 0, z}], {EdgeForm[], cyl}, Polygon[{circ[[1]], {0, 0, 0}, {0, 0, z}, circ[[1]] + {0, 0, z}}], Polygon[{circ[[-1]], {0, 0, 0}, {0, 0, z}, circ[[-1]] + {0, 0, z}}]}]; Graphics3D[wedge]
R = RegionProduct[ DiscretizeRegion[Disk[{0, 0}, 1, {0, Pi/8}], MaxCellMeasure -> 0.01], Line[{{0.}, {0.5}}]] RegionPlot3D[R]
Now we plot the wedge of cheese with random holes:
RegionPlot3D[ Fold[RegionDifference, ImplicitRegion[ x^2 + y^2 <= 6^2 && 0 < z < 4 && 0 < y <= x Sin[Pi/6], {x, y, z}], Ball[#, 0.75] & /@ RandomPoint[ ImplicitRegion[ x^2 + y^2 <= 6^2 && 0 < z < 4 && 0 < y <= x Sin[Pi/6], {x, y, z}], 10]], PlotPoints -> 100]
Finally, we plot a quarter of cheese:
Graphics3D[Cylinder[{{0, 0, 0}, {0, 0, 5}}, 7], Axes -> True, PlotRange -> {{0, 7}, {0, 10}, All} ]
Graphics3D[Cylinder[{{0, 0, 0}, {0, 0, 5}}, 7], Axes -> True, PlotRange -> {{0, 7}, {0, 10}, All}, Background -> LightBlue ]
Graphics3D[Cylinder[{{0, 0, 0}, {0, 0, 4}}, 6], Axes -> True, PlotRange -> {{0, 6}, {0, 6}, All} , BaseStyle -> Opacity[.55], Lighting -> {{"Ambient", LightGreen}}]

Example 2. We use a special function to plot unusual figure:

SphericalPlot3D[ SphericalHarmonicY[2, 0, theta, phi] // Abs // Evaluate, {theta, 0,
Pi}, {phi, 0, 2*Pi}, PlotPoints -> 50, Boxed -> False, Axes -> False]

Example 3. A water tank in the shape of a hemisphere has radius a; Its base is its plane face. Find the volume V of water in the tank as a function of h, the depth of the water.

In Cartesian coordinates a sphere of radius a has the equation $$x^2 + y^2 + z^2 = a^2 .$$ In cylindrical coordinates, $$r^2 = x^2 + y^2 ,$$ so this equation becomes

$r^2 + z^2 = a^2 .$
SphericalPlot3D[1, {$Theta], 0, \[Pi]/2}, {\[Phi], 0, \[Pi]}] However, if we add a cuboit, we get e = SphericalPlot3D[4, {\[Theta], 0, \[Pi]/2}, {\[Phi], 3, 2 \[Pi]}] f = Graphics3D[Cuboid[{-2, -1, 2}]] Show[e, f] Show[SphericalPlot3D[{1}, {Theta, 0, Pi}, {Phi, 0, 3 Pi/2}], Graphics3D[Cylinder[{{0, 0, 0}, {0, 0, .0001}}, 1]], PlotRange -> {All, All, {0, 1}}] Show[SphericalPlot3D[{1}, {Theta, 0, Pi}, {Phi, 0, 3 Pi/2}, PlotStyle -> Gray], Graphics3D[Cylinder[{{0, 0, 0}, {0, 0, .0001}}, 1]], PlotRange -> {All, All, {0, 1}}] ParametricPlot3D[{Cos[u] Sin[v], Sin[u] Sin[v], Cos[v]}, {u, 0, \[Pi]}, {v, 0, \[Pi]}, Mesh -> None, Boxed -> False, Axes -> None] SphericalPlot3D[5, {\[Theta], 0, \[Pi]/2}, {\[Phi], 0, 2 \[Pi]}, ColorFunction -> Function[{x, y, z}, Hue[z]]] n = 20 Hemisphere := Graphics3D[{ParametricPlot3D[{Cos[t] Sin[p], Sin[t] Sin[p], Cos[p]}, {t, 0, 2 Pi}, {p, 0, Pi/2}, Boxed -> False, Axes -> False, DisplayFunction -> Identity][[1]], Polygon[Table[{Cos[2 Pi i/n], Sin[2 Pi i/n], 0}, {i, n}]]}] Show[Hemisphere] We plot a semisphere with a hole: a = SphericalPlot3D[4, {\[Theta], 0, \[Pi]/2}, {\[Phi], 1, 2 \[Pi]}] b = SphericalPlot3D[4, {\[Theta], .8, \[Pi]/2}, {\[Phi], 0, 2 \[Pi]}] Show[a, b] Spherical Coordinates Each point in 3-space is represented using $$0 \le \rho < \infty , \ 0 \le \phi \le \pi , \ 0 \le \theta \le 2\pi :$$ \[ \begin{split} x&= \rho\,\sin \phi \,\cos\theta , \\ y&= \rho\,\sin \phi \,\sin \theta , \\ z &= \rho \, \cos \phi , \end{split} \qquad \Longrightarrow \qquad {\text d}V = \rho^2 \,\sin \phi \,{\text d}\rho\, {\text d}\theta \, {\text d}\phi .$
SphericalPlot3D[{1, 2, 3}, {\[Theta], 0, Pi}, {\[Phi], 0, 3 Pi/2}]
SphericalPlot3D[{1, 2, 3}, {\[Theta], 0, Pi}, {\[Phi], 0, 3 Pi/2}, PlotStyle -> {Black, Yellow, White}]
SphericalPlot3D[{1, 2, 3}, {\[Theta], 0, Pi}, {\[Phi], 0, 3 Pi/2}, ColorFunction -> Hue]
Show[SphericalPlot3D[{200, LightGreen, 300}, {\[Theta], 0, Pi}, {\[Phi], 0, 3 Pi/2}], SphericalPlot3D[{100}, {\[Theta], 0, 2 Pi}, {\[Phi], 0, 3 Pi/2}, PlotStyle -> Red]]
c = SphericalPlot3D[4, {\[Theta], 0, \[Pi]}, {\[Phi], 1, 2 \[Pi]}]
d = SphericalPlot3D[2, {\[Theta], 0, Pi}, {\[Phi], 0, 2 Pi}]
Show[c, d]
ContourPlot3D[x^2 + y^2 + z^2, {x, -3, 3}, {y, -3, 3}, {z, -3, 3}, Contours -> 5]

a = SphericalPlot3D[{1}, {\[Theta], 0, 2 Pi}, {\[Phi], 0, 4 Pi/2}, PlotStyle -> Directive[Blue, Opacity[0.5], Specularity[White, 20]], Mesh -> None, PlotPoints -> 450];

b = SphericalPlot3D[{2}, {\[Theta], 0, Pi}, {\[Phi], 0, 5 Pi/3}, PlotStyle -> Directive[Blue, Opacity[0.5], Specularity[White, 20]], Mesh -> {{0}, {0}, {0}}, PlotPoints -> 50];

c = Graphics3D[Arrow[Tube[{{2, 2, 2}, {1, 0, 0}}, .03]]];
d = Graphics3D[Arrow[Tube[{{0, -3, 1}, {0, -2, 1}}, .03]]];
e = Graphics3D[Arrow[{{0, 0, 0}, {3, 0, 0}}]];
f = Graphics3D[Arrow[{{0, 0, 0}, {0, -3, 0}}]];
g = Graphics3D[Arrow[{{0, 0, 0}, {0, 0, 3}}]];
h = Graphics3D[Arrow[{{0, 0, 0}, {-3, 0, 0}}]];
i = Graphics3D[Arrow[{{0, 0, 0}, {0, 3, 0}}]];
j = Graphics3D[Arrow[{{0, 0, 0}, {0, 0, -3}}]];
k = Graphics3D[Text[P == 1, {2, 2, 2.2}]];
l = Graphics3D[Text[P == 2, {0, -3, 1}]];
m = Graphics3D[Text[x, {0, -3.1, 0}]];
n = Graphics3D[Text[y, {3.1, 0, 0}]];
o = Graphics3D[Text[z, {0, 0, 3.2}]];

az = Show[a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, PlotRange -> {{-3, 3}, {-3, 3}, {-3, 3}}, Axes -> {False, False, False}, Boxed -> False]