\begin{aligned}\iint_{R_0}x\mathrm{d}A&=S_{R_0}x_0\\\iint_{R_1}x\mathrm{d}A&=S_{R_1}x_1\\\iint_{R_2}x\mathrm{d}A&=S_{R_2}x_2,\end{aligned}

# MIT OCW

## 18.02 Multivariable Calculus

### Double Integrals

#### Geometry and Definition

Like a regular integral, the double integral $\iint_{R}f(x,y)\mathrm{d}A$ represents the volume under the surface on the region $R$ where $\mathrm{d}A$ is a small piece of the region.
So we can have a summation like the following $$\iint_{R}f(x,y)\mathrm{d}A=\lim_{\Delta A_i\to 0}\sum f(x,y)\Delta A_i.$$

#### Convertion to Double "Integral"

In pratice, we will not calculate double integral by definition, and now we try to convert it to two single integrals.
The idea is to divide the volume into several slices along $x$ direction, and the volume of these slices are changing with $x$, so the slice determined by $x$ should be $$S(x)=\int_{y_{\min}(x)}^{y_{\max}(x)}f(x,y)\mathrm{d}y$$, and now we activate $x$, so the double integral becomes \begin{aligned}\iint_{R}f(x,y)\mathrm{d}A&=\int_{x_{\min}}^{x_{\max}}S(x)\mathrm{d}x\\&=\int_{x_{\min}}^{x_{\max}}\int_{y_{\min}(x)}^{y_{\max}(x)}f(x,y)\mathrm{d}y\mathrm{d}x.\end{aligned}
e.g. Calculate the integral of $z=1-x^2-y^2$ on the region $0\leq x\leq 1,0\leq y\leq 1$.
Solution \begin{aligned}\iint_{R}1-x^2-y^2\mathrm{d}y\mathrm{d}x&=\int_0^1\int_0^1 1-x^2-y^2\mathrm{d}y\mathrm{d}x\\&=\int_0^1\left[y-x^2y-\frac13y^3\right]^1_0\mathrm{d}x\\&=\int_0^1\frac23-x^2\mathrm{d}x\\&=\left[\frac23x-\frac13x^3\right]^1_0\\&=\frac13.\end{aligned}
e.g. Calculate the volume of $z=1-x^2-y^2$ above the $xy$ plane.
Solution Here the region is actually $x^2+y^2\leq 1$, and according to symmetric graph, we only need to calculate the quarter of the region and multiply $4$.
\begin{aligned}\iint_{R}1-x^2-y^2\mathrm{d}y\mathrm{d}x&=4\int_0^1\int_0^{\sqrt{1-x^2}} 1-x^2-y^2\mathrm{d}y\mathrm{d}x\\&=4\int_0^1\left[y-x^2y-\frac13y^3\right]^{\sqrt{1-x^2}}_0\mathrm{d}x\\&=4\int_0^1(1-x^2)\sqrt{1-x^2}-\frac13(1-x^2)\sqrt{1-x^2}\mathrm{d}x\\&=4\int_0^1\frac23(1-x^2)\sqrt{1-x^2}\mathrm{d}x\\(x=\sin(\theta))&=\frac83\int_{\frac\pi2}^0\cos^4(\theta)\mathrm{d}\theta\\&=\frac\pi2.\end{aligned}

#### Swap Orders

Last time we converted the volume into slices along $x$ direction, why not the other direction? Actually, it's feasible. And in theory, these two directions both work. The form along the other direction can be written as \begin{aligned}\iint_{R}f(x,y)\mathrm{d}A&=\int_{y_{\min}}^{y_{\max}}T(x)\mathrm{d}x\\&=\int_{y_{\min}}^{y_{\max}}\int_{x_{\min}(y)}^{x_{\max}(y)}f(x,y)\mathrm{d}x\mathrm{d}y.\end{aligned}
e.g. Evaluate $\int_0^1\int_{x}^{\sqrt{x}}\frac{e^y}{y}\mathrm{d}y\mathrm{d}x$.
Solution The region to be integrated is like the following.

Here the expression is to make $y$ dependent on $x$, and now we swap the order and make $x$ dependent on $y$ that is \begin{aligned}\int_0^1\int_{x}^{\sqrt{x}}\frac{e^y}{y}\mathrm{d}y\mathrm{d}x&=\int_0^1\int_{y^2}^{y}\frac{e^y}{y}\mathrm{d}x\mathrm{d}y\\&=\int_0^1\left[\frac{e^y}{y}x\right]^{y}_{y^2}\mathrm{d}y\\&=\int_0^1 e^y(1-y)\mathrm{d}y\\&=\left[2e^y-ye^y\right]^1_0\\&=e-2.\end{aligned}

#### Polar Coordinates

In fact, sometimes it becomes easier when dealing the same problem in polar coordinates. The idea is to express $\mathrm{d}A$ in polar coordinates like the following picture.

From the picture, it can be seen that the small piece of region becomes $$\mathrm{d}A=r\mathrm{d}r\mathrm{d}\theta.$$
e.g. Calculate the volume of $z=1-x^2-y^2$ above the $xy$ plane.
Solution The expression can be converted to $z=1-r^2$ and the region becomes $R:r\leq 1$, so the integral becomes \begin{aligned}\iint_{R}1-r^2\mathrm{d}A&=\int_0^{2\pi}\int_0^1(1-r^2)r\mathrm{d}r\mathrm{d}\theta\\&=\int_0^{2\pi}\left[\frac{r^2}{2}-\frac{r^4}{4}\right]^1_0\mathrm{d}\theta\\&=\int_0^{2\pi}\frac14\mathrm{d}\theta\\&=\left[\frac14\theta\right]^{2\pi}_0\\&=\frac\pi2.\end{aligned}

#### Application

• Get the area of a region on the plane
Given a region $R$ on the plane, we'd like to get its area. It's equivalent to evaluate $\iint_{R}\mathrm{d}A$, where $\mathrm{d}A$ depends on the type.
Variant Get the total mass of a flat object with the density $\delta$ function: $\iint_{r}\delta\mathrm{d}A$.
• Average
Like the single integral, an average of the function $f$ on a region $R$ can be defined as $$\bar{f}=\frac1{S_R}\iint_{R}f\mathrm{d}A,$$ where $S_R$ is the area of the region $R$.
Variant Weighted average: $$\tilde{f}=\frac1{M_R}\iint_{R}f\cdot\delta\mathrm{d}A,$$ where $M_R=\iint_{R}\delta\mathrm{d}A$.
Variant Center of mass of a flat object (in Cartesian plane): $$\bar{x}=\frac1{M_R}\iint_{R}x\cdot\delta\mathrm{d}A,\bar{y}=\frac1{M_R}\iint_{R}y\cdot\delta\mathrm{d}A,$$ where $M_R=\iint_{R}\delta\mathrm{d}A$.

# MIT OCW

## 18.02 Multivariable Calculus

### Non-independent Variables

#### Review of Implicit Differentiation

Like the implicit differentiation in single variable calculus, there are times we cannot solve a variable as a function dependent on others (especially the powers are larger than $2$).
e.g. Given the implicit function $y^3+xy+5=0$, what is $\frac{\mathrm{d}y}{\mathrm{d}x}$?
Solution Apply derivatives at both sides we get $$3y^2\cdot\frac{\mathrm{d}y}{\mathrm{d}x}+\left(1\cdot y+x\cdot\frac{\mathrm{d}y}{\mathrm{d}x}\right)=0,$$ and the answer is $$\frac{\mathrm{d}y}{\mathrm{d}x}=-\frac{y}{3y^2+x}.$$

#### Multivariable Function

When there are not only two variables in a formula, and it's not easy to solve a variable as a function dependent on others, is there similar tricks? The answer is to use the total differential.
e.g. Given an equation $x^3+yz+z^3=8$, find $\frac{\partial z}{\partial x}$ and $\frac{\partial z}{\partial y}$ at point $(2,3,1)$.
Solution Consider a function $f(x,y,z)=x^2+yz+z^3=8$ and its total differential $$\mathrm{d}f=2x\mathrm{d}x+z\mathrm{d}y+(y+3z^2)\mathrm{d}z,$$ since $f(x,y,z)=8$ so $$\mathrm{d}f=2x\mathrm{d}x+z\mathrm{d}y+(y+3z^2)\mathrm{d}z=0.$$
And let's think about the actual meaning of partial derivatives $\frac{\partial z}{\partial x}$ and $\frac{\partial z}{\partial y}$, it keeps a variable active and others constant, so to get $\frac{\partial z}{\partial x}$, we can set $\mathrm{d}y=0$, since $y$ is considered constant and get $$3x^2\mathrm{d}x+(y+3z^2)\mathrm{d}z=0,$$ so plug the point into it and we have $$4\mathrm{d}x+6\mathrm{d}z=0,$$ so $$\frac{\partial z}{\partial x}=-\frac23,$$ and similarly $$\frac{\partial z}{\partial y}=-\frac16.$$

##### Relationship with Implicit Differentiation

When I carefully reviewed the equation above, I was ignited by the meaning of the partial derivative and find a bridge between the method and implicit differentiation.
When we are computing $\frac{\partial z}{\partial x}$, we only care about the variation of $x$ and $z$, so we can treat anything else as constants and the problem is again solved by implicit differentiation that is $$\frac{\mathrm{d}}{\mathrm{d}x}(x^2+yz+z^3)=\frac{\mathrm{d}}{\mathrm{d}x}8,$$ and here $y$ is a number not a variable, we can get $$2x+yz'+3z^2z'=0,$$ so $$z'=-\frac{2x}{3z^2+y},$$ namely $$\frac{\partial z}{\partial x}=-\frac{2x}{3z^2+y}.$$

#### Notation Traps

Consider a function $f(x,y)=x+y$ and set $x=u,y=u+v$, so $f(u,v)=2u+v$. Compute $\frac{\partial f}{\partial x}=1,\frac{\partial f}{\partial u}=2$, but $x=u$, what is the contradiction?
Actually it's a trap from notation, because when we write $\frac{\partial f}{\partial x}$, we are assuming that $x$ is active and $y$ is constant. On the other hand, when we write $\frac{\partial f}{\partial u}$, we are assuming that $u$ is active and $v$ is constant. The common variation of $x=u$ is the same, but what we keep constant is different in these two notations. So here are another notation to clearify what we keep constant: $\left(\frac{\partial f}{\partial x}\right)_y$ indicates that $x$ is active and $y$ is constant.

#### Application

e.g. Given a right triangle with area $A$, like the following:

find $\frac{\partial A}{\partial \theta}$.
Solution We can write the expression $$A=\frac12ab\sin(\theta),$$ the key point here is that we have a constraint: a right triangle. So here exist the notation traps.

• Treat $a,b$ are independent variables
Then the answer is just the partial derivative which keeps both $a$ and $b$ constant: $\left(\frac{\partial A}{\partial \theta}\right)_{a,b}=\frac12ab\cos(\theta).$
• Treat $a,b$ are non-independent
The constraint here is exactly $a=b\cos(\theta)$, and there are another two ways: either $a$ or $b$ is constant.
• Treat $a$ constant
Method 1 (Total Differential) Now we compute the differential \begin{aligned}\mathrm{d}A&=\frac{\partial A}{\partial a}\mathrm{d}a+\frac{\partial A}{\partial b}\mathrm{d}b+\frac{\partial A}{\partial \theta}\mathrm{d}\theta\\&=\frac12b\sin(\theta)\mathrm{d}a+\frac12a\sin(\theta)\mathrm{d}b+\frac12ab\cos(\theta)\mathrm{d}\theta,\end{aligned} and another differential derived from the constraint \begin{aligned}\mathrm{d}a&=\frac{\partial a}{\partial b}\mathrm{d}b+\frac{\partial a}{\partial \theta}\mathrm{d}\theta\\&=\cos(\theta)\mathrm{d}b-b\sin(\theta)\mathrm{d}\theta.\end{aligned}
Here we're keeping $a$ constant, so $\mathrm{d}a=0$, and get the differential relationship between $b$ and $\theta$ that is $$\cos(\theta)\mathrm{d}b-b\sin(\theta)\mathrm{d}\theta=0,$$ namely $$\mathrm{d}b=b\tan(\theta)\mathrm{d}\theta.$$
Substitute $\mathrm{d}b$ and $\mathrm{d}a=0$ into the previous differential, we can get $$\mathrm{d}A=\frac12ab\sin(\theta)\tan(\theta)\mathrm{d}\theta+\frac12ab\cos(\theta)\mathrm{d}\theta,$$
so we have $$\mathrm{d}A=\frac12ab\left(\sin(\theta)\tan(\theta)+\cos(\theta)\right)\mathrm{d}\theta,$$ therefore $$\left(\frac{\partial A}{\partial \theta}\right)_{a}=\frac12ab\sec(\theta).$$
Method 2 (Chain Rule) We can have \begin{aligned}\left(\frac{\partial A}{\partial \theta}\right)_{a}&=\left(\frac{\partial A}{\partial \theta}\right)_{a}\left(\frac{\partial \theta}{\partial \theta}\right)_{a}+\left(\frac{\partial A}{\partial a}\right)_{a}\left(\frac{\partial a}{\partial \theta}\right)_{a}+\left(\frac{\partial A}{\partial b}\right)_{a}\left(\frac{\partial b}{\partial \theta}\right)_{a}\\&=\frac{\partial A}{\partial \theta}+\frac{\partial A}{\partial b}\frac{\partial b}{\partial \theta}=\frac12ab\cos(\theta)+\left(\frac12a\sin(\theta)\right)\cdot\left(a\tan(\theta)\sec(\theta)\right)\\&=\frac12ab\cos(\theta)+\frac12a\sec(\theta)\cdot\sin(\theta)\tan(\theta)\\&=\frac12ab\sec(\theta).\end{aligned}
• Treat $b$ constant
Omitted.

### Partial Differential Equations

Phenomenon in reality is generally governed by partial differential equations, like heat equation in 3D space $$\frac {\partial u}{\partial t}=\alpha \left({\frac {\partial ^{2}u}{\partial x^{2}}}+{\frac {\partial ^{2}u}{\partial y^{2}}}+{\frac {\partial ^{2}u}{\partial z^{2}}}\right).$$

# MIT OCW

## 18.02 Multivariable Calculus

### Lagrange Multiplier

We've known the method to maximize or minimize a multivariable function, but what happens if there are some constraint? The critical point usually does not fulfill the constraint, so we have to maximize or minimize in another way.

#### Introduction

e.g. Find the closest point to origin on $xy=3$.
Idea We are going to minimize $f(x,y)=x^2+y^2$ subject to $xy=3$. These are the level surfaces of $f(x,y)$ and $g(x,y)=xy=3$.

When the level surface $f(x,y)=c$ becomes smaller and smaller, until it has no intersection with the $xy=3$, then we have almost achieved the goal. We can find that at the maximum or minimum $f_0$, the level surface $f(x,y)=f_0$ is tangent to the level surface $g(x,y)=3$.

It means that the gradient at $f(x,y)$ is parallel to $g(x,y)$, namely, $\nabla f=\lambda\nabla g$, where $\lambda$ is an unknown. So, we have such system of equations \left\{\begin{aligned}2x=\lambda y\\2y=\lambda x\\xy=3\end{aligned}\right., and we get the point is $(\sqrt3,\sqrt3)$ or $(-\sqrt3,-\sqrt3)$.

#### Lagrange Multiplier

Now we conclude the method, given a function $f(x,y)$ and a constraint $g(x,y)=c$, then to maximize or minimize the function, we need to solve the system of equations \left\{\begin{aligned}\frac{\partial f}{\partial x}&=\lambda\frac{\partial g}{\partial x}\\\frac{\partial f}{\partial y}&=\lambda\frac{\partial g}{\partial y}\\g(x,y)&=c\end{aligned}\right..

#### Geometry

Why it is correct? If there is no constraint $g(x,y)=c$, we just solve $f_x=f_y=0$, and it means when we move on a horizontal surface near the point, the function doesn't change.
Now we have a constraint, similarly, we just find a point where we move along the constraint surface that the function doesn't change too. So $\nabla_{\hat\mathbf{u}}f=0$, where $\hat\mathbf{u}$ is any direction on the constraint surface, in other words, $\nabla f\cdot\hat\mathbf{u}=0$. Since the gradient $\nabla g$ is also normal to the constraint surface, we have $\nabla f\parallel\nabla g$.

#### Application

e.g. Find a best solution to minimizing the surface area of a pyramid with a given triangular base $a_1,a_2,a_3$ and a given height $h$.
Solution We can plot the pyramid in $xy$ plane.

And it looks like the following in 3D space.

To determine the position of the vertex $D$ more easily, we project the vertex on the $xy$ plane.

And take the distance from the projection to three sides $a_1,a_2,a_3$ as $d_1,d_2,d_3$, and we can express the surface area $S$ and the base area $A$: \begin{aligned}S=\frac12a_1\sqrt{d_1^2+h^2}+\frac12a_2\sqrt{d_2^2+h^2}+\frac12a_3\sqrt{d_3^2+h^2}\\A=\frac12a_1d_1+\frac12a_2d_2+\frac12a_3d_3\end{aligned}.
And apply the Lagrange Multiplier \left\{\begin{aligned}\frac{\partial S}{\partial d_1}=\lambda\frac{\partial A}{\partial d_1}\\\frac{\partial S}{\partial d_2}=\lambda\frac{\partial A}{\partial d_2}\\\frac{\partial S}{\partial d_3}=\lambda\frac{\partial A}{\partial d_3}\end{aligned}\right., and found that $d_1=d_2=d_3$, so the vertex is just above the incenter of the triangular base.

# MIT OCW

## 18.02 Multivariable Calculus

The chain rule for a multivariable function $f(x,y,z)$, where $x=x(t),y=y(t),z=z(t)$ is $$\frac{\mathrm{d}f}{\mathrm{d}t}=\frac{\partial f}{\partial x}\frac{\mathrm{d}x}{\mathrm{d}t}+\frac{\partial f}{\partial y}\frac{\mathrm{d}y}{\mathrm{d}t}+\frac{\partial f}{\partial z}\frac{\mathrm{d}z}{\mathrm{d}t}.$$
But now, when the gradient $\nabla f=\left(\frac{\partial f}{\partial x},\frac{\partial f}{\partial y},\frac{\partial f}{\partial z}\right)$ is introduced, the formula has another form $$\frac{\mathrm{d}f}{\mathrm{d}t}=\nabla f\cdot\frac{\mathrm{d}\mathbf{r}}{\mathrm{d}t},$$ where $\mathbf{r}(t)=(x(t),y(t),z(t))$.

#### Relationship with Level Surfaces

The gradient $\nabla f$ is normal to the level surface $F(x,y,z)=c$, also to the tangent plane of the level surface.
Proof Given a function $f(x,y,z)$, and take any curve $\mathbf{r}(t)=(x(t),y(t),z(t))$ on the level surface $f(x,y,z)=c$. According to the chain rule, $$\frac{\mathrm{d}f}{\mathrm{d}t}=\nabla f\cdot\frac{\mathrm{d}\mathbf{r}}{\mathrm{d}t},$$ where $f$ now is on the level surface, so $$\frac{\mathrm{d}f}{\mathrm{d}t}=0,$$ that is $$\nabla f\cdot\frac{\mathrm{d}\mathbf{r}}{\mathrm{d}t}=0.$$

#### Application

##### Tangent Planes

e.g. Solve the tangent plane for $x^2+y^2-z^2=4$ at $(2,1,1)$.
Solution 1 Consider a three-variable function $f(x,y,z)=x^2+y^2-z^2$, then it becomes a level surface $f=4$, since the gradient is normal to the tangent plane of the level surface, so the normal vector of the tangent plane is $$\mathbf{n}=\left(\frac{\partial f}{\partial x},\frac{\partial f}{\partial y},\frac{\partial f}{\partial z}\right)_{(2,1,1)}=(4,2,-2),$$ so we have a equation like $$4x+2y-2z=k,$$ and plug the point into it, we get the tangent plane $$4x+2y-2z=8.$$
Solution 2 Another point of view is at the total differential, near the point that is $$\mathrm{d}f=\frac{\partial f}{\partial x}_{(2,1,1)}\mathrm{d}x+\frac{\partial f}{\partial y}_{(2,1,1)}\mathrm{d}y+\frac{\partial f}{\partial z}_{(2,1,1)}\mathrm{d}z,$$ since we are moving on the level, thus $\mathrm{d}z$ is actually $0$, which gives us $$\frac{\partial f}{\partial x}_{(2,1,1)}\mathrm{d}x+\frac{\partial f}{\partial y}_{(2,1,1)}\mathrm{d}y+\frac{\partial f}{\partial z}_{(2,1,1)}\mathrm{d}z=0,$$ which means $$4(x-x_0)+2(y-y_0)-2(z-z_0)=0,$$ namely $$4(x-2)+2(y-1)-2(z-1).$$

##### Directional Derivative

Sometimes, we care not only the derivative on $\hat\mathbf{i}$ and $\hat\mathbf{j}$ but on some other direction $\hat\mathbf{u}$.
The directional derivative is defined as $$\nabla|_{\hat\mathbf{u}}f=\nabla f\cdot\hat\mathbf{u},$$ it's natural because near some point $$\frac{\mathrm{d}f}{\mathrm{d}s}=\nabla f\cdot\frac{\mathrm{d}r}{\mathrm{d}s},$$ where $s$ is a tiny segment on the direction $\hat\mathbf{u}$, that becomes $$\frac{\mathrm{d}f}{\mathrm{d}s}=\nabla f\cdot\hat\mathbf{u}.$$

#### Geometry

According to the directional derivative, we can write it in a geometric form $$\nabla|_{\hat\mathbf{u}}f=|\nabla f||\hat\mathbf{u}|\cos(\theta),$$ where $\theta$ is the angle between $\nabla f$ and $\hat\mathbf{u}$.

• When $\theta=0$, the directional derivative is maximal, so the function increases fastest in the direction of $\nabla f$;
• When $\theta=\pi$, the directional derivative is minimal, so the function decreases fastest in the opposite direction of $\nabla f$;
• When $\theta=\frac\pi2$, the directional derivative is $0$, so the function does not change and stay on a level surface.
So, the gradient points at the direction where the function has a max rate of change.