\documentclass[notes=show,10pt]{beamer}
\usepackage{mathpazo}			%% Beamer stuff
\usepackage{amsmath}			%% AMS math packages
\usepackage{amsfonts}			%%	-	special fonts
\usepackage{amssymb}			%%	-	special symbols
\usepackage{graphicx}			%% graphics
\usepackage{tcolorbox}			%% color boxes

\usepackage{hyperref}			%% for web links
\hypersetup{
%    bookmarks=true,         		% show bookmarks bar?
    unicode=false,          		% non-Latin characters in Acrobat’s bookmarks
    pdftoolbar=true,        		% show Acrobat’s toolbar?
    pdfmenubar=true,        	% show Acrobat’s menu?
    pdffitwindow=false,     		% window fit to page when opened
    pdfstartview={FitH},    		% fits the width of the page to the window
    pdfnewwindow=true,      	% links in new PDF window
    colorlinks=true,       			% false: boxed links; true: colored links
    linkcolor=blue,          		% color of internal links (change box color with linkbordercolor)
    citecolor=PineGreen,    		% color of links to bibliography
    filecolor=magenta,      		% color of file links
    urlcolor=cyan           		% color of external links
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%		TiKZ Ploting Stuff
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{tikz}				%% TikZ -graphics

\usetikzlibrary{arrows, positioning, calc, intersections}
\usetikzlibrary{decorations.pathreplacing, decorations.markings}

\usepackage{pgfplots}			%% fancy plotting

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	For 3d plotting, using the tikz-3dplot package so
%	that (x,y,z) coordinates are specified in normal order
%	and one can change the perspective for 3-d plots
%
%	To invoke, use
%
%	\begin{tikzpicture}[tdplot_main_coords,{other options}]
%		...
%	\end{tikzpicture}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{tikz-3dplot}		%% Enhanced 3d plotting

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%		Package forest to draw tree diagrams for chain rule
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{forest}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	adjustbox package to force minipage alignment
%
%	Two-column structure is
%
%	\adjustbox{valign=t}
%		{
%			\begin{minipage}{0.45\textwidth}
%			...
%			\end{minipage}
%		}
%	\adjustbox{valign=t}
%		{
%		
%			\begin{minipage}{0.45\textwidth}
%			...
%			\end{minipage}
%		}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{adjustbox}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%		Set Beamer theme
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usetheme{Dresden}
\usecolortheme{dolphin}

%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%		Hack to remove subsection bar from our
%		friends at Tex.StackExchange.Com
%
%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\beamer@theme@subsectionfalse

\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%
%		
%		Hack to make the nice little circles appear
%		from Tex.stackexchange.com
%
%		Reference: 
%
%		https://tex.stackexchange.com/questions/2072/beamer-navigation-circles-without-subsections
%
%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{remreset}
\makeatletter
\@removefromreset{subsection}{section}
\makeatother
\setcounter{subsection}{1}

%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%		Get rid of triangles, put in circles for 
%		itemize items
%
%%%%%%%%%%%%%%%%%%%%%%%%%%
\setbeamertemplate{items}[circle]

%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%		Clean up fonts
%
%%%%%%%%%%%%%%%%%%%%%%%%%%

\usefonttheme{professionalfonts}
\usefonttheme{serif}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%		tikz plotting options
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\pgfplotsset{my style/.append style={axis x line=middle, axis y line=
           middle, xlabel={}, ylabel={}, axis equal }}
           
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%		Math Operators
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\DeclareMathOperator{\comp}{comp}
\DeclareMathOperator{\proj}{proj}
\DeclareMathOperator{\Hess}{Hess}

\DeclareMathOperator{\curl}{curl}
\DeclareMathOperator{\diver}{div}
\DeclareMathOperator{\grad}{grad}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	Document begins here...
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
           
\begin{document}

\input{213-Lecture-Macros}		%% 	macros, settings, et.c


\title{Math 213 - Double Integrals}			%%	title page
\author{Peter A. Perry}
\institute{University of Kentucky}
\date{October 11, 2019}
\maketitle

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%	
%	Due Date Reminders
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
\frametitle{Reminders}

\begin{itemize}
\item	Homework B6 on 14.7 (closed set method) is due tonight
\item	Homework B7 on 14.8 (Lagrange multipliers) is due Monday!
\item	There is a drop-in review session for Exam II on Monday, October 14, 6:00-8:00 PM in KAS 213
\item	Exam II takes place on Wednesday, October 16, 5:00-7:00 PM
\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	Unit Outline
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
\frametitle{Unit II: Functions of Several Variables}
\begin{itemize}

\item[{13.3-4}] 	Lecture 11: Velocity and Acceleration

\medskip

\item[{14.1}] Lecture 12: Functions of Several Variables

\item[{14.3}] Lecture 13: Partial Derivatives
\item[{14.4}] Lecture 14: Linear Approximation
\item[{14.5}] Lecture 15: Chain Rule, Implicit Differentiation

\item[{14.6}] Lecture 16: Directional Derivatives and the Gradient


\medskip

\item[{14.7}] Lecture 17: Maximum and Minimum Values, I
\item[{14.7}] Lecture 18: Maximum and Minimum Values, II
\item[{14.8}] Lecture 19: Lagrange Multipliers
\

\medskip

\begingroup
\color{red}
\item[{15.1}]	Double Integrals
\endgroup
\item[{15.2}]	Double Integrals over General Regions
\item[{}]			Exam II Review
\end{itemize}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	Learning Goals
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
\frametitle{Learning Goals}
\begin{itemize}
\item		Understand why the volume under a surface can be computed
			as a double integral, a limit of double Riemann sums
\item		Understand how to compute double integrals over rectangles
			as \emph{iterated integrals}
\item		Understand how to find the \emph{average value} of a function 
			of two variables over a rectangular domain
\end{itemize}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%		New material begins here...
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\section{From Areas to Volumes}

\begin{frame}
\frametitle{Calculus I: Areas under Curves}
\begin{minipage}{0.40\textwidth}
\begin{tikzpicture}[scale=1.0]
\draw[thick,->,>=stealth]	(-0.5,0)	--	(3,0);
\draw[thick,->,>=stealth]	(0,-0.5)	--	(0,3);
\draw[thick]	plot[domain=0:3]	({\x},{0.25*\x*\x + 1});
%% 
\only<2>
{
\draw[black,fill=red!20,opacity=0.5]	
	(0.5,0)	--	++(0.25,0)	--	++(0,1.06)	--	++(-0.25,0)	--	(0.5,0);
\draw[black,fill=red!20,opacity=0.5]	
	(0.75,0)	--	++(0.25,0)	--	++(0,1.14)	--	++(-0.25,0)	--	(0.75,0);
\draw[black,fill=red!20,opacity=0.5]	
	(1,0)	--	++(0.25,0)	--	++(0,1.25)	--	++(-0.25,0)	--	(1,0);
\draw[black,fill=red!20,opacity=0.5]	
	(1.25,0)	--	++(0.25,0)	--	++(0,1.39)	--	++(-0.25,0)	--	(1.25,0);
\draw[black,fill=red!20,opacity=0.5]	
	(1.5,0)	--	++(0.25,0)	--	++(0,1.5625)	--	++(-0.25,0)	--	(1.5,0);
\draw[black,fill=red!20,opacity=0.5]	
	(1.75,0)	--	++(0.25,0)	--	++(0,1.766)	--	++(-0.25,0)	--	(1.75,0);
\draw[black,fill=red!20,opacity=0.5]	
	(2,0)	--	++(0.25,0)	--	++(0,2)	--	++(-0.25,0)	--	(2,0);
\draw[black,fill=red!20,opacity=0.5]	
	(2.25,0)	--	++(0.25,0)	--	++(0,2.26)	--	++(-0.25,0)	--	(2.25,0);
}
\only<3>
{
\draw[black,fill=cyan!20,opacity=0.5]	
	(0.5,0)	--	++(0.25,0)	--	++(0,1.14)	--	++(-0.25,0)	--	(0.5,0);
\draw[black,fill=cyan!20,opacity=0.5]	
	(0.75,0)	--	++(0.25,0)	--	++(0,1.25)	--	++(-0.25,0)	--	(0.75,0);
\draw[black,fill=cyan!20,opacity=0.5]	
	(1,0)	--	++(0.25,0)	--	++(0,1.39)	--	++(-0.25,0)	--	(1,0);
\draw[black,fill=cyan!20,opacity=0.5]	
	(1.25,0)	--	++(0.25,0)	--	++(0,1.5625)	--	++(-0.25,0)	--	(1.25,0);
\draw[black,fill=cyan!20,opacity=0.5]	
	(1.5,0)	--	++(0.25,0)	--	++(0,1.766)	--	++(-0.25,0)	--	(1.5,0);
\draw[black,fill=cyan!20,opacity=0.5]	
	(1.75,0)	--	++(0.25,0)	--	++(0,2)	--	++(-0.25,0)	--	(1.75,0);
\draw[black,fill=cyan!20,opacity=0.5]	
	(2,0)	--	++(0.25,0)	--	++(0,2.26)	--	++(-0.25,0)	--	(2,0);
\draw[black,fill=cyan!20,opacity=0.5]	
	(2.25,0)	--	++(0.25,0)	--	++(0,2.56)	--	++(-0.25,0)	--	(2.25,0);
}
\only<4>
{
\draw[black,fill=purple!20,opacity=0.5]	
	(0.5,0)	--	++(0.25,0)	--	++(0,1.09)	--	++(-0.25,0)	--	(0.5,0);
\draw[black,fill=purple!20,opacity=0.5]	
	(0.75,0)	--	++(0.25,0)	--	++(0,1.19)	--	++(-0.25,0)	--	(0.75,0);
\draw[black,fill=purple!20,opacity=0.5]	
	(1,0)	--	++(0.25,0)	--	++(0,1.32)	--	++(-0.25,0)	--	(1,0);
\draw[black,fill=purple!20,opacity=0.5]	
	(1.25,0)	--	++(0.25,0)	--	++(0,1.47)	--	++(-0.25,0)	--	(1.25,0);
\draw[black,fill=purple!20,opacity=0.5]	
	(1.5,0)	--	++(0.25,0)	--	++(0,1.66)	--	++(-0.25,0)	--	(1.5,0);
\draw[black,fill=purple!20,opacity=0.5]	
	(1.75,0)	--	++(0.25,0)	--	++(0,1.87)	--	++(-0.25,0)	--	(1.75,0);
\draw[black,fill=purple!20,opacity=0.5]	
	(2,0)	--	++(0.25,0)	--	++(0,2.13)	--	++(-0.25,0)	--	(2,0);
\draw[black,fill=purple!20,opacity=0.5]	
	(2.25,0)	--	++(0.25,0)	--	++(0,2.41)	--	++(-0.25,0)	--	(2.25,0);
}
%%
\node[below]	at 	(0.5,0)	{\scriptsize{$a$}};
\node[below]	at	(2.5,0)	{\scriptsize{$b$}};
\draw[thick,<->]	(1.5,-0.5)	--	(1.75,-0.5);
\node[below]	at	(1.625,-0.5)	{\scriptsize{$\Delta x$}};
%%
\end{tikzpicture}

\bigskip

\footnotesize
A Riemann sum with $n=8$ for $\int_a^b f(x) \, dx $
\end{minipage}
\qquad
\begin{minipage}{0.50\textwidth}
\footnotesize
The area under the graph of $y=f(x)$ between $x=a$ and $x=b$
is approximated by \emph{Riemann sums}
$$ \sum_{i=1}^n f(x_i^*) \,  \Delta x $$
where 
\begin{align*}
\Delta x&	=\frac{b-a}{n}\\[5pt]
x_i			&=	a + i \Delta x\\[5pt]
x_i^*			&\in  [x_{i-1},x_i]
\end{align*}
\begin{align*}
\uncover<2->
{
x_i^*&	=x_{i-1}		&&	\text{(left endpoint )}\\
}
\uncover<3->
{
x_i^*&=x_i				&&	\text{(right endpoint)}\\
}
\uncover<4->
{
x_i^* &= \dfrac{x_{i-1}+x_i}{2}	&&	\text{(midpoint)}
}
\end{align*}
\end{minipage}

\end{frame}

\begin{frame}
\frametitle{Calculus I: Areas under Curves}
\begin{minipage}{0.35\textwidth}
\begin{tikzpicture}[scale=1]
\draw[thick,->,>=stealth]	(-0.5,0)	--	(3,0);
\draw[thick,->,>=stealth]	(0,-0.5)	--	(0,3);
\draw[thick]	plot[domain=0:3]	({\x},{0.25*\x*\x + 1});
%% 
\draw[black,fill=purple!20,opacity=0.5]	
	(0.5,0)	--	++(0.25,0)	--	++(0,1.09)	--	++(-0.25,0)	--	(0.5,0);
\draw[black,fill=purple!20,opacity=0.5]	
	(0.75,0)	--	++(0.25,0)	--	++(0,1.19)	--	++(-0.25,0)	--	(0.75,0);
\draw[black,fill=purple!20,opacity=0.5]	
	(1,0)	--	++(0.25,0)	--	++(0,1.32)	--	++(-0.25,0)	--	(1,0);
\draw[black,fill=purple!20,opacity=0.5]	
	(1.25,0)	--	++(0.25,0)	--	++(0,1.47)	--	++(-0.25,0)	--	(1.25,0);
\draw[black,fill=purple!20,opacity=0.5]	
	(1.5,0)	--	++(0.25,0)	--	++(0,1.66)	--	++(-0.25,0)	--	(1.5,0);
\draw[black,fill=purple!20,opacity=0.5]	
	(1.75,0)	--	++(0.25,0)	--	++(0,1.87)	--	++(-0.25,0)	--	(1.75,0);
\draw[black,fill=purple!20,opacity=0.5]	
	(2,0)	--	++(0.25,0)	--	++(0,2.13)	--	++(-0.25,0)	--	(2,0);
\draw[black,fill=purple!20,opacity=0.5]	
	(2.25,0)	--	++(0.25,0)	--	++(0,2.41)	--	++(-0.25,0)	--	(2.25,0);
%%
\node[below]	at 	(0.5,0)	{\scriptsize{$a$}};
\node[below]	at	(2.5,0)	{\scriptsize{$b$}};
\end{tikzpicture}
\end{minipage}
\qquad
\begin{minipage}{0.55\textwidth}
\footnotesize
The exact area under the graph of $f(x)$ between $x=a$ and $x=b$
is
$$ \int_a^b f(x) \, dx $$

\bigskip
The Fundamental Theorem of Calculus states that, if $f$ is continuous on $[a,b]$, then
$$ \int_a^b f(x) \, dx = F(b) - F(a) $$
for any antiderivative $F$ of $f$. 

\bigskip
We extended these ideas to compute the \emph{net area} under the graph of a signed function and the \emph{average value} of a function $f$ over an interval $[a,b]$
\end{minipage}
\end{frame}

\begin{frame}
\frametitle{Calculus II: Volumes under Surfaces}
\begin{minipage}{0.4\textwidth}
\begin{tikzpicture}[scale=1.5]
\drawxyz{2}
%% 5x5 grid
\foreach \i in {1,2,3,4,5}
	{
	\foreach \j in {1,2,3,4,5}	
		{
			\draw[yellow]	
					({0.25*\i},0, {0.25*\j})
						--	++(0.25,0,0)	
						--	++(0,0,0.25)
						--	++(-0.25,0,0)
						--	++(0,0,-0.25);
		}
	}
%%	
%% Add surface for $f(x,y)= 1-0.025*[(6-4x)^2+(6-4y)^2]$ on the grid
%% [0.25,1.5] x [0.25,1.5] by drawing four bounding curves and 
%% shading
%% ...cheap but effective
%\fill[top color=blue!10,bottom color=blue]
\shade[top color=blue,bottom color=blue!5]
	plot[domain=0.25:1.5,variable=\y]	
			({\y}, {1+0.025*(6-4*\y)*(6-4*\y)}  , 1.5)	--
	plot[domain=1.5:0.25]
			(1.5,{1+0.025*(6-4*\x)*(6-4*\x)},{\x})	--
	plot[domain=1.5:0.25,variable=\y]
			({\y},{1.625 + 0.025*(6-4*\y)*(6-4*\y)},0.25) --
	plot[domain=0.25:1.5]
			(0.25,{1.625+0.025*(6-4*\x)*(6-4*\x)},{\x});
%% Outline it also
\draw[blue,thick]
	plot[domain=0.25:1.5,variable=\y]	
			({\y}, {1+0.025*(6-4*\y)*(6-4*\y)}  , 1.5)	--
	plot[domain=1.5:0.25]
			(1.5,{1+0.025*(6-4*\x)*(6-4*\x)},{\x})	--
	plot[domain=1.5:0.25,variable=\y]
			({\y},{1.625 + 0.025*(6-4*\y)*(6-4*\y)},0.25) --
	plot[domain=0.25:1.5]
			(0.25,{1.625+0.025*(6-4*\x)*(6-4*\x)},{\x});
%%
\node[right] at 	(1.6, 0, 1.6)	{\scriptsize{$R$}};
\node[right] at		(1.6, 1, 1)	{\scriptsize{$S$}};
\end{tikzpicture}

\end{minipage}
%%%%%%%%%%%%%%%%
\qquad
%%%%%%%%%%%%%%%%
\begin{minipage}{0.5\textwidth}
\footnotesize
\textbf{Problem} Find the volume between the rectangle
$$ R= [a,b] \times [c,d] $$ in the $xy$ plane
and the surface 
$$ S = \{ (x,y,z): (x,y) \in R, \, \, z=f(x,y) \} $$
if $f$ is a continuous function.

\medskip


\begin{enumerate}
\item		Divide the rectangle $R$ into an $n \times n$
			 `grid' of		subrectangles  $R_{i,j}$
\item		For each subrectangle $R_{i,j}$, make a box of height $f(x_i^*, y_j^*)$
\item		Add up the volumes of the $n^2$ boxes
\end{enumerate}
\end{minipage}
\end{frame}

\begin{frame}
\frametitle{Volumes Under Surfaces}
\begin{minipage}{0.4\textwidth}
\begin{tikzpicture}[scale=1.6]
\drawxyz{2.25}
%% 5x5 grid
\foreach \i in {1,2,3,4,5}
	{
	\foreach \j in {1,2,3,4,5}	
		{
			\draw[yellow]	
					({0.25*\i},0, {0.25*\j})
						--	++(0.25,0,0)	
						--	++(0,0,0.25)
						--	++(-0.25,0,0)
						--	++(0,0,-0.25);
		}
	}
%%	
\only<1-3>
{
\shade[top color=blue,bottom color=blue!5,opacity=0.5]
	plot[domain=0.25:1.5,variable=\y]	
			({\y}, {1+0.025*(6-4*\y)*(6-4*\y)}  , 1.5)	--
	plot[domain=1.5:0.25]
			(1.5,{1+0.025*(6-4*\x)*(6-4*\x)},{\x})	--
	plot[domain=1.5:0.25,variable=\y]
			({\y},{1.625 + 0.025*(6-4*\y)*(6-4*\y)},0.25) --
	plot[domain=0.25:1.5]
			(0.25,{1.625+0.025*(6-4*\x)*(6-4*\x)},{\x});
%% Outline it also
\draw[blue,thick]
	plot[domain=0.25:1.5,variable=\y]	
			({\y}, {1+0.025*(6-4*\y)*(6-4*\y)}  , 1.5)	--
	plot[domain=1.5:0.25]
			(1.5,{1+0.025*(6-4*\x)*(6-4*\x)},{\x})	--
	plot[domain=1.5:0.25,variable=\y]
			({\y},{1.625 + 0.025*(6-4*\y)*(6-4*\y)},0.25) --
	plot[domain=0.25:1.5]
			(0.25,{1.625+0.025*(6-4*\x)*(6-4*\x)},{\x});
%%
\node[right] at 	(1.6, 0, 1.6)	{\scriptsize{$R$}};
}
\uncover<2-3>
{
\fill[orange!50,opacity=0.5]	(0.5,0,0.5)	
						--	++(0.25,0,0)	
						--	++(0,0,0.25)
						--	++(-0.25,0,0)
						--	++(0,0,-0.25);
}

%%
\only<3>
{
\draw[black,fill=black]	(0.625,0,0.625)	circle(0.025cm);
\node[below] at (0.625,0,0.625)	{\scriptsize{$(x_i^*,y_j^*)$}};
}
%% draw box
\only<4-5>
{
%% front
\draw[black,fill=orange!50]	(0.5,0,0.75)	
						--	++(0.25,0,0)	
						--	++(0,1.8,0)	
						--	++(-0.25,0,0)	
						--	++(0,-1.8,0);
%% right side
\draw[black,fill=orange!30]	(0.75,0,0.75)	
						--	++(0,0,-0.25)
						--	++(0,1.8,0)
						--	++(0,0,0.25)
						--	++(0,-1.8,0);
%% top
\draw[black,fill=orange!10]	(0.5,1.8,0.75)
						--	++(0.25,0,0)
						--	++(0,0,-0.25)
						--	++(-0.25,0,0)
						--	++(0,0,0.25);
%% put back in surface but as a shadow of its 
%% former self
\shade[top color=blue,bottom color=blue!5,opacity=0.25]
	plot[domain=0.25:1.5,variable=\y]	
			({\y}, {1+0.025*(6-4*\y)*(6-4*\y)}  , 1.5)	--
	plot[domain=1.5:0.25]
			(1.5,{1+0.025*(6-4*\x)*(6-4*\x)},{\x})	--
	plot[domain=1.5:0.25,variable=\y]
			({\y},{1.625 + 0.025*(6-4*\y)*(6-4*\y)},0.25) --
	plot[domain=0.25:1.5]
			(0.25,{1.625+0.025*(6-4*\x)*(6-4*\x)},{\x});
%% Outline it also
\draw[blue,thin,dashed]
	plot[domain=0.25:1.5,variable=\y]	
			({\y}, {1+0.025*(6-4*\y)*(6-4*\y)}  , 1.5)	--
	plot[domain=1.5:0.25]
			(1.5,{1+0.025*(6-4*\x)*(6-4*\x)},{\x})	--
	plot[domain=1.5:0.25,variable=\y]
			({\y},{1.625 + 0.025*(6-4*\y)*(6-4*\y)},0.25) --
	plot[domain=0.25:1.5]
			(0.25,{1.625+0.025*(6-4*\x)*(6-4*\x)},{\x});
%%
\node[right] at 	(1.6, 0, 1.6)	{\scriptsize{$R$}};
}
%% this is a front to back box drawing 
%% which constitutes the crudest possible
%% hidden line removal algorithm known
%% to humankind
%%
%%	The discrete function is 
%%	1+ 0.02*((6-i)^2 + (7-j)^2) 
%%	where x=0.25*i, y = 0.25*j
\only<6>
{
\foreach \i in {1,2,3,4,5}
	{
		\foreach \j in {2,3,4,5,6}		%% end effect
			{
					%% front
					
					\draw[thin,black,fill=orange!50]	({0.25*\i},0,{0.25*\j})	
						--	++(0.25,0,0)	
						--	++(0,{1+0.025*((6-\i)*(6-\i)+(6-\j)*(6-\j)},0)	
						--	++(-0.25,0,0)	
						--	++(0,{-(1+0.025*((6-\i)*(6-\i)+(6-\j)*(6-\j))},0);
						
					%% right side
					
					\draw[thin,black,fill=orange!30]	({0.25*(\i+1)},0,{0.25*\j})	
						--	++(0,0,-0.25)
						--	++(0,{1+0.025*((6-\i)*(6-\i)+(6-\j)*(6-\j))},0)
						--	++(0,0,0.25)
						--	++(0,{-1-0.025*((6-\i)*(6-\i)+(6-\j)*(6-\j))},0);
						
					%% top
					
					\draw[thin,black,fill=orange!10]	({0.25*\i},{1+0.025*((6-\i)*(6-\i)+(6-\j)*(6-\j))},{0.25*\j})
						--	++(0.25,0,0)
						--	++(0,0,-0.25)
						--	++(-0.25,0,0)
						--	++(0,0,0.25);
	
			}
	}
%% put back in surface but as a shadow of its 
%% former self
\shade[top color=blue,bottom color=blue!5,opacity=0.25]
	plot[domain=0.25:1.5,variable=\y]	
			({\y}, {1+0.025*(6-4*\y)*(6-4*\y)}  , 1.5)	--
	plot[domain=1.5:0.25]
			(1.5,{1+0.025*(6-4*\x)*(6-4*\x)},{\x})	--
	plot[domain=1.5:0.25,variable=\y]
			({\y},{1.625 + 0.025*(6-4*\y)*(6-4*\y)},0.25) --
	plot[domain=0.25:1.5]
			(0.25,{1.625+0.025*(6-4*\x)*(6-4*\x)},{\x});
%% Outline it also
\draw[blue,thin,dashed]
	plot[domain=0.25:1.5,variable=\y]	
			({\y}, {1+0.025*(6-4*\y)*(6-4*\y)}  , 1.5)	--
	plot[domain=1.5:0.25]
			(1.5,{1+0.025*(6-4*\x)*(6-4*\x)},{\x})	--
	plot[domain=1.5:0.25,variable=\y]
			({\y},{1.625 + 0.025*(6-4*\y)*(6-4*\y)},0.25) --
	plot[domain=0.25:1.5]
			(0.25,{1.625+0.025*(6-4*\x)*(6-4*\x)},{\x});
}
\only<7>
{
\foreach \i in {2,3,4,5,6,7,8,9,10,11}
	{
		\foreach \j in {3,4,5,6,7,8,9,10,11,12}		%% end effect
			{
					%% front
					
					\draw[thin,black,fill=orange!50]	({0.125*\i},0,{0.125*\j})	
						--	++(0.125,0,0)	
						--	++(0,{1+0.025*((6-0.5*\i)*(6-0.5*\i)+(6-0.5*\j)*(6-0.5*\j)},0)	
						--	++(-0.125,0,0)	
						--	++(0,{-(1+0.025*((6-0.5*\i)*(6-0.5*\i)+(6-0.5*\j)*(6-0.5*\j))},0);
						
					%% right side
					
					\draw[thin,black,fill=orange!30]	({0.125*(\i+1)},0,{0.125*\j})	
						--	++(0,0,-0.125)
						--	++(0,{1+0.025*((6-0.5*\i)*(6-0.5*\i)+(6-0.5*\j)*(6-0.5*\j))},0)
						--	++(0,0,0.125)
						--	++(0,{-1-0.025*((6-0.5*\i)*(6-0.5*\i)+(6-0.5*\j)*(6-0.5*\j))},0);
						
					%% top
					
					\draw[thin,black,fill=orange!10]	({0.125*\i},{1+0.025*((6-0.5*\i)*(6-0.5*\i)+(6-0.5*\j)*(6-0.5*\j))},{0.125*\j})
						--	++(0.125,0,0)
						--	++(0,0,-0.125)
						--	++(-0.125,0,0)
						--	++(0,0,0.125);
			}
	}
%% put back in surface but as a shadow of its 
%% former self
\shade[top color=blue,bottom color=blue!5,opacity=0.25]
	plot[domain=0.25:1.5,variable=\y]	
			({\y}, {1+0.025*(6-4*\y)*(6-4*\y)}  , 1.5)	--
	plot[domain=1.5:0.25]
			(1.5,{1+0.025*(6-4*\x)*(6-4*\x)},{\x})	--
	plot[domain=1.5:0.25,variable=\y]
			({\y},{1.625 + 0.025*(6-4*\y)*(6-4*\y)},0.25) --
	plot[domain=0.25:1.5]
			(0.25,{1.625+0.025*(6-4*\x)*(6-4*\x)},{\x});
%% Outline it also
\draw[blue,thin,dashed]
	plot[domain=0.25:1.5,variable=\y]	
			({\y}, {1+0.025*(6-4*\y)*(6-4*\y)}  , 1.5)	--
	plot[domain=1.5:0.25]
			(1.5,{1+0.025*(6-4*\x)*(6-4*\x)},{\x})	--
	plot[domain=1.5:0.25,variable=\y]
			({\y},{1.625 + 0.025*(6-4*\y)*(6-4*\y)},0.25) --
	plot[domain=0.25:1.5]
			(0.25,{1.625+0.025*(6-4*\x)*(6-4*\x)},{\x});
}
\end{tikzpicture}
\end{minipage}
\qquad
\begin{minipage}{0.5\textwidth}
\footnotesize

\begin{itemize}
\uncover<2->
{
\item	Pick a rectangle $R_{i,j}$ in the grid, area $\Delta A$
}
\uncover<3->
{
\item	Pick $(x_i^*,y_j^*)$ in the rectangle
}
\uncover<4->
{
\item	Make a box of height 
$f(x_i^*, y_j^*)$ over $R_{i,j}$
}
\uncover<5->
{
\item	The volume of the box is
		$V_{ij} = f(x_i^*,y_j^*) \, \Delta A$
}
\uncover<6->
{
\item	The approximate volume under the surface is 
		$$ \sum_{i=1}^n \sum_{j=1}^n f(x_i^*,y_j^*) \, \Delta A$$
}

\end{itemize}

\uncover<7->
{ 
$ V= \lim_{n \to \infty} \sum_{i,j=1}^n f(x_i^*,y_j^*) \, \Delta A $
}

\end{minipage}
\end{frame}

\begin{frame}
\frametitle{Volumes By Integration}
\footnotesize
If  $R = [a,b] \times [c,d] $ and 
$$ S = \{ (x,y,z): z = f(x,y), \, (x,y) \in R \}$$
then the volume between $R$ and $S$ is 
$$
V 		= \lim_{n \to \infty} \sum_{i,j=1}^n f(x_i^*,y_j^*) \, \Delta A 	
			= \iint_R f(x,y) \, dA
$$
\begin{minipage}{0.4\textwidth}
\begin{tikzpicture}
\drawxyz{2.5}
\draw[thick,yellow]	(0,0,1)	--	(2,0,1)	--	(2,0,-1)	--	(0,0,-1)	--	(0,0,1);
%% surface
\draw[blue]		
			plot[domain=1:-1]  (2 ,{sqrt(1-\x*\x)} , {\x})	
			--	++(-2,0,0)	
			--	plot[domain=-1:1] (0, {sqrt(1-\x*\x)}, {\x})
			--	++(2,0,0);
\foreach \theta in {-10,0,10,20,30,40,50,60,70,80,90}
	{
			\draw[dashed,blue]
					(0,{cos(\theta)},{sin(\theta)})	--	++(2,0,0);
	}
\end{tikzpicture}

\end{minipage}
\qquad
\begin{minipage}{0.5\textwidth}
\footnotesize
Find $\diint_R f(x,y) \, dA$ if 
$$R=[-1,1] \times [0,2]$$ and 
$$f(x,y) = \sqrt{1-x^2}$$
Can you do this without calculus?
\end{minipage}
\end{frame}


\section{Iterated Integrals}

\begin{frame}
\frametitle{Iterated Integrals}
\footnotesize
When you studied one-variable calculus, you first found out how to compute antiderivatives and then you learned how to compute definite integrals using them

\bigskip
Now that you're studying two variable calculus, you'll first learn about \emph{iterated integrals} and then learn how to compute integrals over rectangles with them. 

\bigskip
Suppose $R$ is a rectangle $[a,b] \times [c,d]$  and $f$ is a continuous function on $R$. Then
$$ A(x) = \int_c^d f(x,y) \, dy $$ 
is a function of $x$. For example if $f(x,y) = x^2 y$ and $R=[1,2] \times [3,4]$,
then
$$ 
\int_3^4 (x^2 y) \, dy = \left. \frac{x^2 y^2}{2} \right|_{3}^4 = \frac{7}{2} x^2
$$
We then compute $\int_a^b A(x) \, dx$. For example
$$
\int_1^2 \frac{7}{2} x^2 \, dx = \left. \frac{7}{6} {x^3}\right|_{x=1}^{x=2} = \frac{49}{6}
$$



\end{frame}

\begin{frame}
\frametitle{Iterated Integrals}
If $f(x,y)$ is a continuous function on a rectangle $R=[a,b] \times [c,d]$,
the \textbf{iterated integral} of $f$ is
$$ \int_a^b \int_c^d f(x,y) \, dy \, dx = \int_a^b \left( \int_c^d f(x,y) \, dy \right) \, dx $$

\medskip

\hrulefill

\medskip

\begin{enumerate}
\item		Find $ \int_1^4 \int_0^2 \left(6x^2 y - 2x\right) \, dy \, dx$

\smallskip

\item		Find	$\int_1^3 \int_1^5 \dfrac{\ln y}{xy} \, dy \, dx$

\smallskip

\item		(Ringer) $ \int_0^1 \int_1^2 \left( x + e^{-y} \right) \, dx \, dy$
\end{enumerate}
\end{frame}

\begin{frame}
\frametitle{Fubini's Theorem}
\footnotesize
\begin{center}
\fcolorbox{cyan}{white}
{
\begin{minipage}{0.85\textwidth}
{\color{cyan}\textbf{Theorem}} If $f$ is continuous on the rectangle 
$$ R = \{ (x,y): a \leq x \leq b, \, \, c \leq y \leq d \} $$
then
$$ \diint_R f(x,y) \, dA = \int_a^b \int_c^d f(x,y) \, dy \, dx =	
	\int_c^d \int_a^b f(x,y) \, dx \, dy. $$
\end{minipage}
}
\end{center}

\medskip

Evaluate these double integrals.
\begin{enumerate}
\item	$\diint_R x \sec^2 y \, dA$, $R=[0,2]\times[0,\pi/4]$
\item	$\diint_R \dfrac{xy^2}{x^2+1} \, dA$, $R=[0,1] \times [-3,3]$
\item	$\diint_R \dfrac{1}{1+x+y} \, dA$, $R=[1,3] \times [1,2]$
\end{enumerate}
\end{frame}

\begin{frame}
\frametitle{Volumes by Iterated Integrals}
\footnotesize
\begin{enumerate}
\item	Find the volume of the solid that lies under the plane 
$$ 4x+6y-12z+15=0$$
and above the rectangle
$[-1,2] \times [-1,1]$

\bigskip

\item	Find the volume of the solid lying under the elliptic paraboloid 
$$ x^2/4+y^2/9 + z = 1$$
and above the rectangle $[-1,1] \times [-2,2]$

\end{enumerate}
\end{frame}

\section{General Regions}

\begin{frame}
\frametitle{Preview: Integrals over General Regions}

\footnotesize

\begin{minipage}{0.4\textwidth}
\begin{tikzpicture}[scale=0.7]
\draw[help lines] 	(0,0)	grid (4,4);
\draw[thick,->,>=stealth]	(0,0)	--	(5,0);
\draw[thick,->,>=stealth]	(0,0)	--	(0,5);
\node[right] at (5,0)		{\scriptsize{$x$}};
\node[above] at (0,5)	{\scriptsize{$y$}};
\draw[thick,cyan,fill=cyan!50, opacity=0.5]
	(1,1/3)	--	(3,1)	--	(3,4)	--	(1,4/3) -- (1,1);
\node[left]	at	(2,2.66)		{\scriptsize{$y=4x/3$}};
\node[right]	at	(2,0.5)	{\scriptsize{$y=x/3$}};
\node[below]	at	(1,0)		{\scriptsize{$1$}};
\node[below]	at	(3,0)		{\scriptsize{$3$}};
\uncover<2->
{
	\node[below]	at	(1.5,0)	{\scriptsize{$x$}};
	\draw[thick,densely dashed,cyan]	(1.5,0.5)	--	(1.5,2);
}
\end{tikzpicture}
\end{minipage}
\quad
\begin{minipage}{0.5\textwidth}
Find 
$$ \iint_D (x+3y) \, dA $$
if
$$ D = \{ 1 \leq x \leq 3, \, \, \, x/3 \leq y \leq 4x/3  \} $$

\vfill
\uncover<2->
{
\begin{multline*}
\iint_D (x+3y) \, dA =\\
 \int_{1}^{3} \left( \int_{x/3}^{4x/3} (x+3y) \, dy \right) \, dx
\end{multline*}
}
\end{minipage}
\end{frame}

\begin{frame}
\frametitle[Preview: Integrals over General Regions]
\footnotesize
\begin{minipage}{0.40\textwidth}
\begin{tikzpicture}[scale=0.5]
\draw[thick,->,>=stealth]	(-4,0)		--	(4,0);
\draw[thick,->,>=stealth]  (0,-3)	--	(0,3);
\node[above] at	(3.8,0)		{\scriptsize{$x$}};
\node[right]	at	(0,3)			{\scriptsize{$y$}};
\draw[white,fill=orange!30,opacity=0.5]	
	plot[domain=-1.414:1.414,variable=\y]	({2-\y*\y},{\y})	--
	plot[domain=1.414:-1.414,variable=\y]	({-2+\y*\y},{\y});
\draw[cyan,thick]		plot[domain=-1.414:1.414,variable=\y]	({2-\y*\y},{\y});
\draw[cyan,dashed]	plot[domain=1.414:2,variable=\y] 		({2-\y*\y},{\y});
\draw[cyan,dashed]	plot[domain=-1.414:-2,variable=\y] 		({2-\y*\y},{\y});
\draw[cyan,thick]		plot[domain=-1.414:1.414,variable=\y]	({-2+\y*\y},{\y});
\draw[cyan,dashed]	plot[domain=-2:-1.414,variable=\y]		({-2+\y*\y},{\y});
\draw[cyan,dashed]	plot[domain=2:1.414,variable=\y]			({-2+\y*\y},{\y});
\draw[help lines]		(-3,-2)	grid 	(3,2);
\end{tikzpicture}
\end{minipage}
\quad
\begin{minipage}{0.50\textwidth}
\footnotesize
Find 
$$ \iint_D  1 \, dA $$
if $D$ is the region enclosed by the curves
$$x=2-y^2$$ and $$x=-2+y^2.$$

\end{minipage}

\vfill
\footnotesize

\uncover<2->
{
	$$ D = \{ -\sqrt{2} \leq y \leq \sqrt{2}, \, -2+y^2 \leq x \leq 2+y^2 \} $$
}
\uncover<3->
{
	$$ \iint_D 1 \, dA = \int_{-\sqrt{2}}^{\sqrt{2}} \left( \int_{-2+y^2}^{2-y^2} 1 \, dx \right) \, dy $$
}
\end{frame}

\section{Average Values}

\begin{frame}
\frametitle{Average Values}
\footnotesize
The average value of $y=f(x)$ on $[a,b]$ is
$$ f_{\mathrm{av}} = \frac{1}{b-a} \int_a^b f(x) \, dx $$

\bigskip
The average value of $z=f(x,y)$ on a rectangle $R$ with area $A(R)$ is
$$ f_{\mathrm{av}} = \frac{1}{A(R)} \iint_R f(x,y) \, dA $$

\smallskip

\begin{minipage}{0.25\textwidth}
\begin{tikzpicture}[scale=0.4]
\draw[help lines]	(-2,-2) grid (2,6);
\draw[thick,->,>=stealth]	(-3,0)	--	(3,0);
\draw[thick,->,>=stealth]	(0,-3)	--	(0,7);
\draw[cyan,fill=cyan]	(-1,0)		circle(0.10cm);
\draw[cyan,fill=cyan]	(-1,5)		circle(0.10cm);
\draw[cyan,fill=cyan]	(1,5)		circle(0.10cm);
\draw[cyan,fill=cyan]	(1,0)		circle(0.10cm);
\draw[cyan,thick,fill=cyan!30,opacity=0.4]	(-1,0)	--	(-1,5)	--	(1,5)	--	(1,0)	--	(-1,0);
\end{tikzpicture}
\end{minipage}
\qquad
\begin{minipage}{0.65\textwidth}
Find the average value of $f(x,y)=x^2y$ over a rectangle with vertices
$(-1,0)$, $(-1,5)$, $(1,5)$, and $(1,0)$.


\end{minipage}

\end{frame}



\end{document}