<jupyter_start><jupyter_text>$\newcommand{\RR}{\mathbb{R}}$$\newcommand{\bv}[1]{\begin{bmatrix} 1 \end{bmatrix}}$$\renewcommand{\vec}{\mathbf}$  One-minute Review Other coordinates  - **Polar coordinates** $(r,\theta)$   $$\iint_\mathcal R f(x,y)\,dxdy = \iint_\mathcal R f(r\cos \theta, r \sin \theta)\,r\,dr\,d\theta$$  - **Cylindrical coordinates** $(r,\theta, z)$   $$\iiint_\mathcal E f(x,y,z)\,dxdydz = \iiint_\mathcal E f(r\cos \theta, r \sin \theta,z)\,r\,dz\,dr\,d\theta$$  - **Spherical coordinates** $(\rho, \phi, \theta)$   $$\iiint_\mathcal E f(x,y,z)\,dxdydz $$ $$= \iiint_\mathcal E f(\rho \sin \phi \cos \theta, \rho \sin \phi \sin \theta, \rho \cos \phi ) \, \rho^2 \sin \phi \, d\rho \, d\phi \, d\theta $$where the bounds of integration for $\mathcal R$ or $\mathcal E$ are translated appropriately.    APMA E2000 Lecture 16 - Multiple Integrals/Applications   - Objectives    - Applications of integration:      - Center of mass      - Moment of inertia      - Probability       - Resources    - Content      - Stewart: §15.4–5      - New Strang: [§5.6](https://openstax.org/books/calculus-volume-3/pages/5-6-calculating-centers-of-mass-and-moments-of-inertia)    - Practice      - [Exercises and Solutions](../exercises/L16-Exercises-Solutions.ipynb)      - Mooculus: [Mass and Moments](https://ximera.osu.edu/mooculus/calculus3/computationsAndInterpretations/digInMassMomentsAndCenterOfMass)    - Extras      - CalcBLUE: [Integrals](https://www.math.upenn.edu/~ghrist/BLUE.htmlVOL3)       - [Triple Integral Visualizer](https://drew.youngren.nyc/3Demos/iiint/index.html)<jupyter_code>IFrame("https://pollev-embeds.com/multiple_choice_polls/0oh7b1SSSh6rR1j4IJZS6/respond", width="800px", height="600px")<jupyter_output><empty_output><jupyter_text>Applications of IntegrationThe basic principal behind applying integration is that the desired quantity, the desideratum, is obtained by integrating its elements. Put succinctly, $$\spadesuit = \int d\spadesuit$$    A Word on Density"Density" often stands in for mass density which has units of mass/volume, like $\frac{{\rm g}}{{\rm ml}}$. But think of it more generally as $$\frac{\rm stuff}{\rm unit\ of\ measure}$$Further, these can vary continuously throughout a medium or space. Thus, we integrate to find the total amount of "stuff".     Examples   - Resistivity $\rho(x)$ along a wire, $\frac{\Omega}{{\rm m}}$. $$\Omega = \int_0^\ell \rho(x)\, dx$$   - Probability density function $\rho(x,y)$ of two random variables. $$P(E) = \iint_E \rho(x,y)\, dA$$   - Concentration of chemicals, like $[\text{H}_2\text{CO}_3] = \rho(x,y,z)$. $$\text{total carbonic acid} = \iiint_D \rho(x,y,z)\,dV$$      Masses and MomentsConsider a two mass system in one dimension. That is suppose a mass $m_1$ is at position $x_1$ and mass $m_2$ is at position $x_2$.The total mass is of course$$M = m_1 + m_2.$$ The **center of mass** is the point $\bar x$ that balances the torque. That is,$$m_1(x_1 - \bar x) + m_2(x_2 - \bar x) =0$$ $$\bar x = \frac{m_1x_1 + m_2x_2}{m_1 + m_2}$$ $$ = \frac{m_1}{M}x_1 + \frac{m_2}{M}x_2$$<jupyter_code>@interact
def _(xbar=(0,1,.01), point=True):
    plt.figure(figsize=(8,3))
    plt.plot([0,1],[0,0],zorder=-1)
    if point:
        plt.scatter([1],[0],s=390,zorder=2)
        plt.scatter([0],[0],s=130)
        if xbar == .75:
            plt.fill([xbar - .02, xbar + .02, xbar],[1/4, 1/4 ,0], color='r')
    else:
        t = linspace(0,1,200)
        plt.fill_between(t, exp(-16*(t - 2/3)**2)*.4, alpha=.5)
        if .65 <= xbar <= .66:
            plt.fill([0.6544410013183013
 - .02, 0.6544410013183013
 + .02, 0.6544410013183013
],[1/4, 1/4 ,0], color='r')

    plt.fill([xbar - .02, xbar + .02, xbar],[-1/2, -1/2 ,0])
    plt.xlim(-.1,1.1)
    plt.ylim(-.6,.6)
    flush_figures();<jupyter_output><empty_output><jupyter_text>Continuous CaseIf the mass is spread out with a density function $\mu(x)$ (in mass/length), then the center of mass $\bar{x}$ is the point that gives a 0 moment, i.e. $$\int_a^b (x - \bar{x})\mu(x)\,dx = 0$$ or $$\bar{x} = \frac{\int_a^b x \,\mu(x)\,dx}{\int_a^b \mu(x)\,dx}$$where the denominator is the total mass.     Masses and Moments                                                                                                                      Let consider a planar region $\mathcal D$ (a "lamina") with continuously varying density (mass per unit area) $\mu(x,y)$. The the total mass is given by $$M = \iint_D \mu(x,y)\,dA$$  The **center of mass** $(\bar{x},\bar y)$ is the "(weighted) average position" of the mass in the object. More concisely, $$(\bar{x},\bar y) = \left(\frac{\iint_\mathcal D x \mu(x,y)\,dA}{\iint_\mathcal D \mu(x,y)\,dA},\frac{\iint_\mathcal D y \mu(x,y)\,dA}{\iint_\mathcal D  \mu(x,y)\,dA}\right)$$     ExampleFind the center of mass of the unit square $[0,1]\times [0,1]$ whose density is given by $\mu(x,y) = x+2y^2$<jupyter_code>@interact
def _(show=False):
    x = y = np.linspace(0,1,100)
    x,y = np.meshgrid(x,y)

    plt.figure(figsize=(9.5,8))
    plt.pcolormesh(x,y,x+2*y**2,cmap='rainbow',shading='gouraud')
    plt.xlim([0,1.1])
    plt.ylim([0,1.1])
    plt.colorbar();
    if show:
        plt.scatter([0.5714285714285716], [0.6428571428571429],zorder=2)
    flush_figures()

M = dblquad(lambda y,x: x+2*y**2,0,1,0,1)[0]
xbar = 1/M*dblquad(lambda y,x: (x+2*y**2)*x,0,1,0,1)[0]

ybar = 1/M*dblquad(lambda y,x: (x+2*y**2)*y,0,1,0,1)[0]
(xbar, ybar), M<jupyter_output><empty_output><jupyter_text>Moment(s) of InertiaThe **moment of inertia** $I$ of a massive body is a measure of its "resistance to rotation" about a given axis. Angular momentum is  $L=I\omega$, the product of the moment of inertia and the angular velocity.The figure skater pulls her body in to reduce her moment of intertia. As angular momentum is conserved, she spins faster.    Formula$I$ is a measurement of how far the mass is spread from the axis. It is the second moment of the density distribution. If we take a body $\mathcal D$ in the plane with area density $\mu(x,y)$, and consider it rotating about the origin, then$$ I = \iint_\mathcal D (x^2+y^2)\mu (x,y)\,dA $$that is, the distance to the axis squared, weighted by mass.     ExerciseLet's compute the moment of inertia of the square above about:  - the origin  - the $y$-axis<jupyter_code>dblquad(lambda y,x: (x**2 + y**2)*(x + y),0,1,0,1)
dblquad(lambda y,x: (x**2)*(x + y),0,1,0,1)
@interact(t=(0.,2*pi,pi/10))
def _(t=0):
    x = linspace(0,1)
    x,y = meshgrid(x,x)
    plt.figure(figsize=(6,6))
    ax = plt.subplot(projection='3d')
    ax.plot_surface(x*cos(t) - y*sin(t),x*sin(t) + y*cos(t),0*x)
    ax.plot_surface(x*cos(2*t),y,x*sin(2*t))
    ax.plot([0,0],[-1,1],[0,0],'--k')
    ax.plot([0,0],[0,0],[-1,1],'--k')
    for c in 'xyz':
        getattr(ax,f"set_{c}lim")([-1,1]);    
        getattr(ax,f"set_{c}label")(f"${c}$",size=16)
    flush_figures()<jupyter_output><empty_output><jupyter_text>ProbabilityTwo (real) random variables $X$ and $Y$ have a joint probability density function $\rho(x,y)$. This is simply a function on the plane with $\mu(x,y) \geq 0$ and $$\iint_{\RR^2} \mu(x,y)\,dA = 1.$$An **event** $E \subset \RR^2$ is just a subset of the sample space, and its probability is $$P(E) = \iint_E \mu(x,y)\,dA$$.    ExampleWhat is the probability that 2 numbers randomly chosen between 0 and 1 have a product greater than $\frac12$?<jupyter_code>x = y = np.linspace(0,1,50)
x,y = np.meshgrid(x,y)
plt.contourf(x,y,x*y ,levels=[0,1/2,1]);<jupyter_output><empty_output><jupyter_text><jupyter_code>dblquad(lambda y,x: 1, 1/2,1,lambda x: 1/(2*x),1)[0]
1/2-log(2)/2<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18723794549266248, 'fraction_numerical': 0.0440251572327044, 'mean_word_length': 3.612084592145015, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 25, 'https://': 5, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '291238', 'license': 'MIT', 'n_tokens_mistral': 3055, 'n_tokens_neox': 2877, 'n_words': 739, 'path': 'lec/mvc-L16.ipynb', 'repo_name': 'drewyoungren/mvc', 'size': '7632'}