\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 - Lagrange Multipliers}			%%	title page
\author{Peter A. Perry}
\institute{University of Kentucky}
\date{October 9, 2019}
\maketitle

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

\begin{frame}
\frametitle{Reminders}

\begin{itemize}
\item	Homework B6 on 14.7 (maxima and minima) is due Friday
\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, 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
\begingroup
\color{red}
\item[{14.8}] Lecture 19: Lagrange Multipliers
\endgroup

\medskip

\item[{15.1}]	Double Integrals
\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 the geometrical idea behind Lagrange's Multiplier Method
\item		Use the Lagrange Multiplier Method to solve max/min problems with one constraint
\item		Use the Lagrange Multiplier Method to solve max/min problems with two constraints
\end{itemize}
\end{frame}

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

\begin{frame}
\frametitle{A Word from Our Sponsor}

\begin{minipage}{0.65\textwidth}
\footnotesize
Pierre-Louis Lagrange (1736-1810) was born in Italy but lived and worked for much of his life in France. Working in the generation following Newton (1642--1727), he made fundamental contributions in the calculus of variations, in celestial mechanics, in the solution of polynomial equations, and in power series representation of functions. 

\medskip

Lagrange lived through the French revolution, during which time the chemist Lavoisier was beheaded. Of Lavoisier's death, Lagrange remarked:

\begin{quotation}
It took the mob only a moment to remove his head; a century will not suffice to reproduce it. 
\end{quotation}

\end{minipage}
\qquad
\begin{minipage}{0.20\textwidth}
\includegraphics[scale=0.25]{Images/Lagrange.jpeg}

\vfill
\vfill

\end{minipage}

\vfill
\begin{center}
\tiny{Image credit: \href{http://www-groups.dcs.st-and.ac.uk/history/Biographies/Lagrange.html}{http://www-groups.dcs.st-and.ac.uk/history/Biographies/Lagrange.html}}
\end{center}
\end{frame}

\section{The Geometric Idea}

\begin{frame}
\frametitle{Reminder: Level curves and the Gradient}
\begin{minipage}{0.4\textwidth}

\begin{tikzpicture}[scale=0.6]
\drawxy{2}
\foreach \k in {0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2}
{
	\begin{scope}
	\clip (-2,-2) rectangle (2,2);
	\draw[red!50]	plot[domain=-2:2,variable=\y] ({sqrt(\k*\k+\y*\y)},{\y});
	\draw[red!50]	plot[domain=-2:2,variable=\y]	({-sqrt(\k*\k+\y*\y)},{\y});
	\end{scope}	
}
%% level curves of x^2-y^2 = -k^2
\foreach \k in {0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2}
{
	\begin{scope}
	\clip (-2,-2) rectangle (2,2);
	\draw[blue!50]	plot[domain=-2:2] 	({\x} ,{sqrt(\k*\k+\x*\x)});
	\draw[blue!50]	plot[domain=-2:2]	({\x} ,{-sqrt(\k*\k+\x*\x)});
	\end{scope}	
}
\end{tikzpicture}

\bigskip


\begin{tikzpicture}[scale=0.6]
\drawxy{2}
%% level curves of x^2+y^2=k^2
\foreach \r in {0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25}
{
	\begin{scope}
	\clip	(-2,-2)		rectangle	(2,2);
	\draw[gray!50,smooth]		plot[domain=0:360]		({\r*cos(\x)},{\r*sin(\x)});
	\end{scope}
}
\end{tikzpicture}

\end{minipage}
\qquad
\begin{minipage}{0.5\textwidth}
\footnotesize
Remember that \emph{the gradient is normal to the level curves of a function}

\bigskip

At left are the level curves of:

\begin{itemize}
\item	$f(x,y) = x^2 - y^2$
\item	$g(x,y) = x^2 + y^2$
\end{itemize}

\bigskip

\begin{itemize}
\uncover<2->
{
\item	Which way does the gradient point for each picture?
}


\uncover<3->
{
\item	Are there any points where $\nabla f$ and $\nabla g$ are parallel?
}

\uncover<4->
{
\item	What about the respective tangent lines at any such points?
}
\end{itemize}

\end{minipage}
\end{frame}



\begin{frame}
\begin{minipage}{0.4\textwidth}
\begin{center}

\begin{tikzpicture}[scale=0.8]
\drawxy{2}
%% level curves of x^2+y^2=k^2
\foreach \r in {0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25}
{
	\begin{scope}
	\clip	(-2,-2)		rectangle	(2,2);
	\draw[gray!50,smooth]		plot[domain=0:360]		({\r*cos(\x)},{\r*sin(\x)});
	\end{scope}
}
%% level curves of x^2 - y^2 = k^2
\foreach \k in {0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2}
{
	\begin{scope}
	\clip (-2,-2) rectangle (2,2);
	\draw[red!50]	plot[domain=-2:2,variable=\y] ({sqrt(\k*\k+\y*\y)},{\y});
	\draw[red!50]	plot[domain=-2:2,variable=\y]	({-sqrt(\k*\k+\y*\y)},{\y});
	\end{scope}	
}
%% level curves of x^2-y^2 = -k^2
\foreach \k in {0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2}
{
	\begin{scope}
	\clip (-2,-2) rectangle (2,2);
	\draw[blue!50]	plot[domain=-2:2] 	({\x} ,{sqrt(\k*\k+\x*\x)});
	\draw[blue!50]	plot[domain=-2:2]	({\x} ,{-sqrt(\k*\k+\x*\x)});
	\end{scope}	
}
%% emphasize the level curve corresponding to the constraint
\draw[red,thick,dashed,smooth]		plot[domain=0:360]		({cos(\x)},{sin(\x)});
%% indicate extrema on slide 2
\uncover<2->
{
	\draw[red,fill=red]	(-1,0)		circle(0.10cm);
	\draw[red,fill=red]	(1,0)		circle(0.10cm);
	\draw[red,fill=blue]	(0,1)		circle(0.10cm);
	\draw[red,fill=blue]	(0,-1)		circle(0.10cm);
}
\end{tikzpicture}

\bigskip

\begin{tikzpicture}[scale=0.5]
\begin{axis}[xlabel={$x$},ylabel={$y$}, title={$f(x) =x^2-y^2$}, view={45}{60},domain=-2:2]
\addplot3[surf]{x^2-y^2};
\addplot3+[no markers,samples=50,samples y=0,variable=\t,very thick,dashed,domain=0:6.28318] ({cos(\t r)},{sin(\t r)},{(cos(\t r))^2-(sin(\t r))^2});
%% mark maxima and minima
\only<2>
{
	\addplot3+[only marks,mark=*,mark options={scale=2, fill=red},text mark as node=true] coordinates{ (1,0,1) (-1,0,1) };
	\addplot3+[only marks,mark=*,mark options={scale=2, fill=blue},text mark as node=true] coordinates{ (0,1,-1) (0,-1,-1) };
}
\end{axis}
\end{tikzpicture}

\end{center}
\end{minipage}
\qquad
\begin{minipage}{0.5\textwidth}
\footnotesize
\textbf{Problem}  Find the absolute minimum and maximum value of 
$$ f(x,y) = x^2 - y^2 $$
if
$$ x^2 + y^2 = 1$$

\bigskip

In this problem:
\smallskip
\begin{itemize}
\item the function $f(x,y)$ is the \emph{objective function} 
\item the equation $x^2+y^2 = 1$ is the \emph{constraint}
\end{itemize}

\bigskip

Where do extreme values occur?

\medskip

\uncover<2->
{
{\color{red} Maxima:} $f(1,0) = f(-1,0) = 1$

\smallskip

{\color{blue} Minima:} $f(0,1) = f(0,-1) = -1$
}

\end{minipage}
\end{frame}

\begin{frame}
\frametitle{Lagrange's Condition}
\begin{minipage}{0.4\textwidth}
\begin{center}

\begin{tikzpicture}[scale=0.8]
\drawxy{2}
%% level curves of x^2+y^2=k^2
\foreach \r in {0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25}
{
	\begin{scope}
	\clip	(-2,-2)		rectangle	(2,2);
	\draw[gray!50,smooth]		plot[domain=0:360]		({\r*cos(\x)},{\r*sin(\x)});
	\end{scope}
}
%% level curves of x^2 - y^2 = k^2
\foreach \k in {0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2}
{
	\begin{scope}
	\clip (-2,-2) rectangle (2,2);
	\draw[red!50]	plot[domain=-2:2,variable=\y] ({sqrt(\k*\k+\y*\y)},{\y});
	\draw[red!50]	plot[domain=-2:2,variable=\y]	({-sqrt(\k*\k+\y*\y)},{\y});
	\end{scope}	
}
%% level curves of x^2-y^2 = -k^2
\foreach \k in {0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2}
{
	\begin{scope}
	\clip (-2,-2) rectangle (2,2);
	\draw[blue!50]	plot[domain=-2:2] 	({\x} ,{sqrt(\k*\k+\x*\x)});
	\draw[blue!50]	plot[domain=-2:2]	({\x} ,{-sqrt(\k*\k+\x*\x)});
	\end{scope}	
}
%% emphasize the level curve corresponding to the constraint
\draw[red,thick,dashed,smooth]		plot[domain=0:360]		({cos(\x)},{sin(\x)});
%% indicate extrema on slide 2
%\uncover<2->
{
	\draw[red,fill=red]	(-1,0)		circle(0.10cm);
	\draw[red,fill=red]	(1,0)		circle(0.10cm);
	\draw[red,fill=blue]	(0,1)		circle(0.10cm);
	\draw[red,fill=blue]	(0,-1)		circle(0.10cm);
}
\end{tikzpicture}

\bigskip

\begin{tikzpicture}[scale=0.5]
\begin{axis}[xlabel={$x$},ylabel={$y$}, title={$f(x) =x^2-y^2$}, view={45}{60},domain=-2:2]
\addplot3[surf]{x^2-y^2};
\addplot3+[no markers,samples=50,samples y=0,variable=\t,very thick,dashed,domain=0:6.28318] ({cos(\t r)},{sin(\t r)},{(cos(\t r))^2-(sin(\t r))^2});
%% mark maxima and minima
%\only<2>
{
	\addplot3+[only marks,mark=*,mark options={scale=2, fill=red},text mark as node=true] coordinates{ (1,0,1) (-1,0,1) };
	\addplot3+[only marks,mark=*,mark options={scale=2, fill=blue},text mark as node=true] coordinates{ (0,1,-1) (0,-1,-1) };
}
\end{axis}
\end{tikzpicture}

\end{center}
\end{minipage}
\qquad
\begin{minipage}{0.5\textwidth}
\footnotesize
\textbf{Problem}  Find the absolute minimum and maximum value of 
$$ f(x,y) = x^2 - y^2 $$
if
$$ g(x,y) = x^2 + y^2 = 1$$

\bigskip


Extreme values occur where $\nabla f $ and $\nabla g$ are parallel, i.e., where
$$ \nabla f = \lam \nabla g $$

\bigskip

Why does this work?
\end{minipage}
\end{frame}

\begin{frame}
\frametitle{Why Is $\nabla f = \lam \nabla g$ at an Extremum?}
\footnotesize
\textbf{Problem} Find the absolute minimum and maximum of $f(x,y)$ subject to 
a constraint $g(x,y) = c$. 

\bigskip

\begin{itemize}

\item		The constraint restricts $(x,y)$ to a level curve $(x(t),y(t))$ of $g$

\smallskip

\item		So we want to minimize $\phi(t) = f(x(t),g(t))$, a function of one variable

\smallskip

\item		By the chain rule, the condition $\phi'(t)=0$ is the same as
			$$ (\nabla f)(x(t),y(t)) \cdot (x'(t),y'(t)) = 0 $$
			
\smallskip

\item		That is, $\nabla f$ is perpendicular to the tangent line to the level curve

\smallskip

\item		That is, $\nabla f$ is parallel to $\nabla g$

\end{itemize}

\vfill

The number $\lambda$ is called a \emph{Lagrange Multiplier}

\end{frame}

\section{Lagrange Method: One Constraint}

\begin{frame}
\frametitle{Lagrange Multipliers: One Constraint, Two Variables}
\footnotesize
\fcolorbox{cyan}{white}
{
\begin{minipage}{0.85\textwidth}
To find the maximum and minimum values of $f(x,y)$ subject to the constraint $g(x,y)=k$:
\begin{enumerate}
\item[(a)]	Find all $(x,y,\lam)$ so that
				$$ \nabla f(x,y) = \lam \nabla g(x,y) $$
				$$ g(x,y) = k $$
\item[(b)]	Test the solutions $(x,y)$ to find the maximum and minimum values
\end{enumerate}
\end{minipage}
}

\vfill
\begin{enumerate}
\item		Find the maximum and minimum values of $f(x,y) = x^2-y^2$ subject to the constraint $x^2+y^2=1$. 
\item		Find the maximum and minimum values of $f(x,y) =3x+y$ subject to the constraint $x^2+y^2 = 10$
\end{enumerate}

\end{frame}

\begin{frame}
\frametitle{Lagrange Multipliers: One Constraint, Three Variables}
\footnotesize
\fcolorbox{cyan}{white}
{
\begin{minipage}{0.85\textwidth}
To find the maximum and minimum values of $f(x,y,z)$ subject to the constraint $g(x,y,z)=k$:
\begin{enumerate}
\item[(a)]	Find all $(x,y,z,\lam)$ so that
				$$ \nabla f(x,y,z) = \lam \nabla g(x,y,z) $$
				$$ g(x,y,z) = k $$
\item[(b)]	Test the solutions $(x,y,z)$ to find the maximum and minimum values
\end{enumerate}
\end{minipage}
}

\vfill
\begin{enumerate}
\item		Find the maximum and minimum values of $f(x,y,z) = e^{xyz}$ subject to the constraint $2x^2 + y^2+ z^2 = 24$
\end{enumerate}
\end{frame}

\section{Lagrange Method: Two Constraints}

\begin{frame}
\frametitle{Lagrange Multipliers: Two Constraints, Three Variables}
\footnotesize
\fcolorbox{cyan}{white}
{
\begin{minipage}{0.85\textwidth}
To find the maximum and minimum values of $f(x,y,z)$ subject to the constraint $g(x,y,z)=k, h(x,y,z) = \ell$:
\begin{enumerate}
\item[(a)]	Find all $(x,y,z,\lam,\mu)$ so that
				$$ \nabla f(x,y,z) = \lam \nabla g(x,y,z)+ \mu \nabla h(x,y,z)$$
				$$ g(x,y,z) = k $$
				$$ h(x,y,z) = \ell$$
\item[(b)]	Test the solutions $(x,y,z)$ to find the maximum and minimum values
\end{enumerate}
\end{minipage}
}

\vfill

Find the extreme values of $f(x,y,z)=x+y+z$ subject to the constraints
\begin{align*}
x^2 + z^2 &=	2\\
x+y	&=	1
\end{align*}
\end{frame}


\begin{frame}
\frametitle{Why Does the Two-Constraint Method Work?}
\footnotesize
Find the maximum and minimum values of $f(x,y,z)$ subject to the constraints
\begin{align*}
g(x,y,z)	&=	k	\\
h(x,y,z)	&=	\ell	
\end{align*}

\vfill

\begin{itemize}

\item		The surfaces $S_1 = \{ (x,y,z) : g(x,y,z) = k\}$ and $S_2 = \{(x,y,z) : h(x,y,z) = \ell\}$ intersect in a curve $C$

\item		We know that $\nabla f(x,y,z)$ is orthogonal to $C$ if $f$ has an extremum at $(x,y,z)$

\item		We know that $\nabla g(x,y,z)$ and $\nabla h(x,y,z)$ are also orthogonal to $C$

\item		Hence, there are numbers $\lam$ and $\mu$ so that
			$$ \nabla f (x,y,z) = \lam \nabla g (x,y,z) + \mu \nabla h (x,y,z) $$

\end{itemize}	
\end{frame}

\begin{frame}
\frametitle{Summary}
\begin{itemize}
\item	We learned the Lagrange multiplier method for solving maximum/minimum problems with one constraint (one Lagrange multiplier)
\item	We learned the Lagrange multiplier method for solving maximum/minimum problems with two constraints
\end{itemize}
\end{frame}



\end{document}