Department of Mathematics

 MTH243 (Calculus for Functions of Several Variables) SAGE. Chapter 16: Integrating 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 16.1. The Definite Integral

The definite integral of a function $$f (x, y)$$ over a rectangular domain $$R: \ a\le x \le b, \ c \le y \le d$$ is
$\int_R f\, {\text d} A = \int_R \, {\text d}x\,{\text d} y \, f(x,y) = \lim_{\Delta x , \Delta y \mapsto 0} \, f\left( u_{ij}, v_{ij} \right) \Delta x \, \Delta y$

down = {0, 0} + # {1.5, 1} & /@ Range[0, 10];
up = {0, 1} + # {1.5, 1} & /@ Range[0, 9];
ListLinePlot[Riffle[down, up], Filling -> Axis]

Plot[Floor[x], {x, 0, 15}, Filling -> Axis]
Another graph
raggedTriangle[pmin_?VectorQ, pmax_?VectorQ, p_: 5] := Module[{d = pmax - pmin, iv}, iv = Subdivide[#, 100/p] & /@ d; Polygon[ Append[TranslationTransform[pmin] /@ Most[Riffle[Transpose[iv], Transpose[MapAt[RotateLeft, iv, 2]]]], {First[pmax], Last[pmin]}]]]
Graphics[{{LightGreen, Rectangle[{1, 2}, {5, 3}]}, {Orange, raggedTriangle[{1, 2}, {5, 3}, 10]}}]
Example 2. Let R be the rectangle $$0 \le x \le 1$$ and $$0 \le y \le 1 .$$ Use Riemann sums to make upper and lower estimates of the volume of the region above R and under the graph of $$z = e^{-(x^2 + y^2 )} .$$
Example 3 . Let $$f (x,y) = x^2 y$$ and let R be the rectangle $$0 \le x \le 1 , \ 0 \le y \le 1 .$$ Show that the difference between upper and lower Riemann sums for f on R converges to 0, as $$\Delta x \ \mbox{ and } \ \Delta y$$ approach 0.

## Section 16.2. Iterated Integrals

Example 1.

Example 2.

Example 3. The density at the point $$(x, y)$$ of a trianglar metal plate, as shown in Figure, is $$\delta (x, y) .$$ Explress its mass as an iterated integral.

First, we plot triangles using Mathematica:

Plot[{0., Max[0, Min[2 x, 6 - x]]}, {x, -1, 7}, AspectRatio -> 1/2, Ticks -> {{0, 2, 4, 6}, {0, 2, 4}}, Filling -> Axis, FillingStyle -> Blue]
Graphics[Polygon[{{1, 0}, {0, Sqrt[3]}, {-1, 0}}]]
RegionPlot[2 x - y > 0 && -3 x - y > -15, {x, 0, 5}, {y, 0, 6}, PlotStyle -> LightBlue]
Plot[{0, Max[0, Min[2 x, 15 - 3 x]]}, {x, 0, 7}, AxesLabel -> {x, y}, Filling -> Bottom]
RegionPlot[ 2 x - y > -1 && -2 x - y > -5 && y > 1, {x, 0, 3}, {y, 0, 3}, PlotStyle -> Purple]
RegionPlot[-1 < x < 3 && -2 < y < 1 && -3/4 x - y > -.25, {x, -2, 5}, {y, -3, 3}, GridLines -> Automatic]
RegionPlot[x < 4 && y > 2 && 2 x - y > 0, {x, 0, 6}, {y, 0, 8}]
Show[Graphics[{PlotStyle -> {Thickness[1.5]}, Hue[0.8], Line[{{0, 0}, {1, 1}, {4, 1/2}, {0, 0}}]}], AspectRatio -> 1, Axes -> True, AxesStyle -> Thick, AxesOrigin -> {-0.5, -0.5}]
RegionPlot[x < 1 && 2 x - y > 0, {x, 0, 1}, {y, 0, 2}, PlotStyle -> Hue[0.2]]
RegionPlot[x > 0 && 3 x - y < 0 && x < 12, {x, 0, 6}, {y, 0, 12}]
R = Triangle[{{1, 1}, {1, 12}, {4, 12}}] Graphics[{EdgeForm[Dashed], Pink, R}, AspectRatio -> 0.4, Axes -> True, AxesStyle -> Thick, AxesOrigin -> {0, 0}]
If the boundary needs to be emphasized, then
ln = Show[ Graphics[{Thickness[.02], Hue[.6], Line[{{0, 0}, {1, 1}, {0, 1}, {0, 0}}]}]]
pol = Show[Graphics[{Hue[0.5], Polygon[{{0, 0}, {1, 1}, {0, 1}}]}]]
Show[pol, ln]
An arbitrary triangle could be plotted as follows
triangle[a_?NumericQ, b_?NumericQ, c_?NumericQ] :=
Block[{x, y, pt, sqr}, sqr = #.# &; pt[a1_, b1_, c1_] := Reduce[sqr[{x, y}] == b1^2 && sqr[{x, y} - {a1, 0}] == c1^2 && y > 0, {x, y}]; {(Polygon[{{0, 0}, {a, 0}, {x, y}}]), Text[Style[Framed[a, Background -> LightYellow], 11], {a/2, 0}], Text[Style[Framed[b, Background -> LightYellow], 11], {x/2, y/2}], Text[Style[Framed[c, Background -> LightYellow], 11], {(a + x)/2, y/2}]} /. ToRules[pt[a, b, c]]]

g[{s1_, s2_, s3_}] := Graphics[{EdgeForm[Thick], FaceForm[None], triangle[s1, s2, s3]}, ImagePadding -> 20, ImageSize -> {200, 200}]

GraphicsGrid[{{g[{Sqrt[5], 1, 2}]}}]
or
Graphics[{EdgeForm[Thick], FaceForm[None], triangle[Sqrt[5], 1, 2]}]

Example 4. Find the mass M of a metal plate R bounded by $$y=x \quad\mbox{and} \quad y= x^2 ,$$ with density given by $$\delta (x,y) = 1 + xy$$ kg/meter2 .

Plot[{x, x^2 }, {x, 0, 1.0}, Filling -> {1 ->{2}}, AspectRatio ->1]

Therefore, we need tools to plot a domain below or above a graph:
q[p_] = 10.2 p^2.0;
lowerBound = p /. Solve[q[p] == 100, p][[1]] // Quiet;
Show[Plot[q[p], {p, 0, 22}, PlotRange -> {0, Automatic}], Plot[q[p], {p, lowerBound, 20}, Filling -> 100], Graphics[{Line[{{0, 100}, {30, 100}}], Line[{{20, 0}, {20, 4000}}]}]]
boundleft = 2;
boundright = 8;
f[x_] = 25 - 15*x^2 + x^3;
g1 = Plot[f[x], {x, -2, 10}];
g2 = Plot[f[x], {x, boundleft, boundright}, Filling -> 0];
Show[g1, g2]
or
Plot[{25 - 15*x^2 + x^3, If[2 <= x <= 8, 0]}, {x, 0, 10}, PlotStyle -> {Automatic, None}, Filling -> {1 -> {2}}]
or we can fill bellow and above some horizontal line:
guess = -100;
Plot[{25 - 15*x^2 + x^3, If[2 <= x <= 8, 0]}, {x, 0, 10}, PlotStyle -> {Automatic, None}, Filling -> {1 -> {guess, Yellow}}]
Plot[{25 - 15*x^2 + x^3, If[2 <= x <= 8, 0]}, {x, 0, 10}, PlotStyle -> {Automatic, None}, Filling -> {1 -> Top}]
Plot[{25 - 15*x^2 + x^3, If[2 <= x <= 8, 0]}, {x, 0, 10}, PlotStyle -> {Automatic, None}, Filling -> {1 -> {Bottom, LightGreen}}]

Example 5.

## Section 16.4. Polar Coordinates

Example 1.

Example 2. Compute the integral of $$f (x, y) = 1 \left( x^2+y^2 \right)^{3/2}$$ over the wedge region

h[r_, $Theta]_] := 2 < r <= 5 && 0 \[Pi] < \[Theta] < \[Pi]/4 RegionPlot[ h[Sqrt[x^2 + y^2], Mod[ArcTan[x, y], 2 \[Pi]]], {x, -6, 6}, {y, -6, 6}, AspectRatio -> 1] or we can change the region to obtain the wedge region close to the horizontal axis: h[r_, \[Theta]_] := 2 < r <= 5 && 0 \[Pi] < \[Theta] < \[Pi]/4 RegionPlot[ h[Sqrt[x^2 + y^2], Mod[ArcTan[x, y], 2 \[Pi]]], {x, 0, 6}, {y, 0, 6}, AspectRatio -> 1, PlotStyle -> Yellow] Example 3. We start with plotting rectangle: RegionPlot[1 <= x <= 3 && -1 <= y <= 2, {x, 2, 4}, {y, -2, 3}, PlotStyle -> LightGreen] Show[Graphics[{RGBColor[0.1, 0.33, 0.2], Rectangle[{1, -1}, {3, 2}]}], Axes -> True] Show[Graphics[{RGBColor[0.2, 21, 4], Rectangle[{1, -1}, {3, 2}]}], Axes -> True] Show[ListLinePlot[{{1, 2}, {3, 2}}, Filling -> Bottom], ListLinePlot[{{3, 2}, {3, -1}}], ListLinePlot[{{3, -1}, {1, -1}}, Filling -> Top, PlotStyle -> Orange], ListLinePlot[{{1, -1}, {1, 2}}], PlotRange -> {{0, 3}, {-1, 2}}] Then we plot the circle: RegionPlot[x^2 + y^2 <= 9, {x, -4, 4}, {y, -4, 4}, PlotStyle -> LightYellow] RegionPlot[x^2 + y^2 <= 9, {x, -5, 5}, {y, -5, 5}, PlotTheme -> "Scientific"] Then we shpw how to put background: Show[ContourPlot[y == (-x^2 + 9)^.5, {x, -3, 3}, {y, -3, 3}, PlotTheme -> "Marketing"], ContourPlot[y == -(-x^2 + 9)^.5, {x, -3, 3}, {y, -3, 3}, PlotTheme -> "Marketing"]] Show[RegionPlot[y < (-x^2 + 9)^.5, {x, -3, 3}, {y, -3, 3}, PlotTheme -> "Marketing"], RegionPlot[y > -(-x^2 + 9)^.5, {x, -3, 3}, {y, -3, 3}, PlotTheme -> "Marketing"]] Show[Graphics[{RGBColor[1, 0.5, 0.5], Disk[{0, 0}, 3]}, Frame -> True, FrameTicks -> True, Background -> RGBColor[0.87, 0.94, 1]], Axes -> True] Our next figure is a slanted rectangle: RegionPlot[ x > 1 && y < 2 && x < 4 && 1/3 x - y < 1/3, {x, 0, 4}, {y, 0, 2}] or RegionPlot[ 0 <= x <= 2 && ((x/2) - 1) <= y <= 3, {x, -1, 3}, {y, -2, 3}] Show[Graphics[{RGBColor[3.3, 0.1, 0.5], Rectangle[{0, 0}, {2, 3}], Triangle[{{0, -1}, {0, 0}, {2, 0}}]}], Axes -> True] Show[ListLinePlot[{{0, 3}, {2, 3}}, Filling -> Axis, PlotStyle -> Orange], ListLinePlot[{{2, 3}, {2, 0}}], ListLinePlot[{{2, 0}, {0, -1}}, Filling -> Top], ListLinePlot[{{0, -1}, {0, 3}}], PlotRange -> {{0, 2}, {-1, 3}}] p1 = Rectangle[{0, 2}, {2, 3}]; p2 = Triangle[{{0, 0}, {0, 2}, {2, 2}}]; Show[Graphics[{Pink, p1}], Graphics[{Pink, p2}]] Finally, we plot a quarter of circular pipe: RegionPlot[x^2 + y^2 <= 4 && x^2 + y^2 > 1, {x, -2, 0}, {y, 0, 2}] or Show[RegionPlot[{x^2 + y^2 < 4 && x^2 + y^2 > 1}, {x, -2, 0}, {y, 0, 2}], ContourPlot[{x^2 + y^2 == 4, x^2 + y^2 == 1}, {x, -2, 0}, {y, 0, 2}]] or RegionPlot[ x^2 + y^2 <= 4 && x^2 + y^2 >= 1 && x <= 0 && y >= 0, {x, -2, 0}, {y, 0, 2}] Now we put another color: Graphics[{Blue, Disk[{0, 0}, 2], White, Disk[{0, 0}, 1]}, Frame -> True, FrameTicks -> True, PlotRange -> {{-2, 0}, {0, 2}}] Graphics[{Orange, Disk[{0, 0}, 1, {Pi/2, -Pi/2}]}] or quarter RegionPlot[x^2 + y^2 < 1 && x > 0 && y > 0, {x, 0, 1.1}, {y, 0, 1.1}] ## 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]
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.

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]}] 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}], 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] 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]]
ContourPlot3D[x^2 + y^2 + z^2, {x, -3, 3}, {y, -3, 3}, {z, -3, 3}, Contours -> 5]

## Section 16.7. Change of Variables

Crescent Moon:
Show[ContourPlot[{x^2 + y^2 == 16, x^2 + y^2/4 == 4}, {x, 0, 4}, {y, -4, 4}, AspectRatio -> 1.4], RegionPlot[{x^2 + y^2 == 16, x^2 + y^2/4 == 4}, {x, 0, 4}, {y, -4, 4}, AspectRatio -> 1.4], RegionPlot[x^2 + y^2/4 >= 4 && x^2 + y^2 < 16, {x, 0, 4}, {y, -4, 4}, AspectRatio -> 1.4]]
or
Show[ContourPlot[{x^2 + y^2 == 16, x^2 + y^2/4 == 4}, {x, 0, 4}, {y, -4, 4}], RegionPlot[ x^2 + y^2/4 >= 4 && x^2 + y^2 < 16, {x, 0, 4}, {y, -4, 4}], AspectRatio -> 1.4]