Triple Integration#
Revised
20 Mar 2023
Imports & Environment#
import numpy as np
import matplotlib as mpl
from matplotlib import cm
import matplotlib.pyplot as plt
from matplotlib.ticker import LinearLocator
#mpl.projections.get_projection_names()
#plt.style.available
from scipy import integrate
[Example] \(\begin{aligned}\underset{R}{\iiint}(2xy)\,dV\,\,\,\text{where}\,R=\{(x,y,z)\mid 3x+2y+z=6,x,y,z\ge0\}\end{aligned}\)#
\( \begin{aligned} \underset{R}{\iiint}(2xy)\,dV \,\,\,\text{where}\,R=\{(x,y,z)\mid 3x+2y+z=6,x,y,z\ge0\} \end{aligned} \)
\( \begin{aligned} x=0,y=0\implies 3(0)+2(0)+z=6\implies z=6\\ x=0,z=0\implies 3(0)+2y+(0)=6\implies y=3\\ y=0,z=0\implies 3x+2(0)+(0)=6\implies x=2\\ \end{aligned} \)
\( \begin{aligned} &\underset{R}{\iiint}(2xy)\,dV \,\,\,\text{where}\,R=\{(x,y,z)\mid 3x+2y+z=6,x,y,z\ge0\}\\ &=\int_{x=0}^{x=2}\int_{y=0}^{y=-\frac{3}{2}x+3}\int_{z=0}^{z=6-3x-2y}(2xy)\,dz\,dy\,dx\\ &=\int_{x=0}^{x=2}\int_{y=0}^{y=-\frac{3}{2}x+3}(2xyz)\Big|_{z=0}^{z=6-3x-2y}\,dy\,dx\\ &=\int_{x=0}^{x=2}\int_{y=0}^{y=-\frac{3}{2}x+3}[2xy(6-3x-2y)-2xy(0)]\,dy\,dx\\ &=\int_{x=0}^{x=2}\int_{y=0}^{y=-\frac{3}{2}x+3}(12xy-6x^2y-4xy^2)\,dy\,dx\\ &=\int_{x=0}^{x=2}\left.\left[12x\left(\frac{1}{2}y^2\right)-6x^2\left(\frac{1}{2}y^2\right)-4x\left(\frac{1}{3}y^3\right)\right]\right|_{y=0}^{y=-\frac{3}{2}x+3}\,dx\\ &=\int_{x=0}^{x=2}\left.\left[6xy^2-3x^2y^2-\frac{4}{3}xy^3\right]\right|_{y=0}^{y=-\frac{3}{2}x+3}\,dx\\ &=\int_{x=0}^{x=2}\left[6x\left(-\frac{3}{2}x+3\right)^2-3x^2\left(-\frac{3}{2}x+3\right)^2-\frac{4}{3}x\left(-\frac{3}{2}x+3\right)^3\right]\,dx\\ &=\int_{x=0}^{x=2}\left[6x\left(\frac{9}{4}x^2-9x+9\right)-3x^2\left(\frac{9}{4}x^2-9x+9\right)-\frac{4}{3}x\left(\frac{9}{4}x^2-9x+9\right)\left(-\frac{3}{2}x+3\right)\right]\,dx\\ &=\int_{x=0}^{x=2}\left[\frac{54}{4}x^3-54x^2+54x-\frac{27}{4}x^4+27x^3-27x^2+\left(-\frac{36}{12}x^3+\frac{36}{3}x^2-\frac{36}{3}x\right)\left(-\frac{3}{2}x+3\right)\right]\,dx\\ &=\int_{x=0}^{x=2}\left[\frac{27}{2}x^3-54x^2+54x-\frac{27}{4}x^4+27x^3-27x^2+(-3x^3+12x^2-12x)\left(-\frac{3}{2}x+3\right)\right]\,dx\\ &=\int_{x=0}^{x=2}\left[\frac{27}{2}x^3-54x^2+54x-\frac{27}{4}x^4+27x^3-27x^2+\frac{9}{2}x^4-9x^3-18x^3+36x^2+18x^2-36x\right]\,dx\\ &=\int_{x=0}^{x=2}\left[-\frac{27}{4}x^4+\frac{9}{2}x^4+\frac{27}{2}x^3+27x^3-9x^3-18x^3-54x^2-27x^2+36x^2+18x^2+54x-36x\right]\,dx\\ &=\int_{x=0}^{x=2}\left[-\frac{9}{4}x^4+\frac{27}{2}x^3-27x^2+18x\right]\,dx\\ &=\left.\left[-\frac{9}{4}\left(\frac{1}{5}x^5\right)+\frac{27}{2}\left(\frac{1}{4}x^4\right)-27\left(\frac{1}{3}x^3\right)+18\left(\frac{1}{2}x^2\right)\right]\right|_{x=0}^{x=2}\\ &=\left.\left[-\frac{9}{20}x^5+\frac{27}{8}x^4-9x^3+9x^2\right]\right|_{x=0}^{x=2}\\ &=\left(-\frac{9}{20}(2)^5+\frac{27}{8}(2)^4-9(2)^3+9(2)^2\right)-\left(-\frac{9}{20}(0)^5+\frac{27}{8}(0)^4-9(0)^3+9(0)^2\right)\\ &=-\frac{9}{20}(2)^5+\frac{27}{8}(2)^4-9(2)^3+9(2)^2\\ &=-\frac{9}{20}(32)+\frac{27}{8}(16)-9(8)+9(4)\\ &=-\frac{72}{5}+54-72+36\\ &=-\frac{72}{5}+18\\ &=-\frac{72}{5}+\frac{90}{5}\\ &=\frac{18}{5} \end{aligned} \)
f=lambda z,y,x: 2*x*y
integrate.tplquad(f,0,2,0,lambda x:-(3/2)*x+3,0,lambda x,y:6-3*x-2*y)[0]
3.599999999999999
18/5
3.6
%matplotlib widget
fig=plt.figure()
ax =plt.subplot(projection='3d')
plt.style.use('ggplot');
X=np.arange(0,2,1e-2)
Y=np.arange(0,3,1e-2)
X,Y=np.meshgrid(X,Y)
Z=6-3*X-2*Y
Z[Z<0]=np.nan
# plot the surface
surf=ax.plot_surface(X,Y,Z,
cmap=cm.coolwarm,
linewidth=0,
antialiased=True) # opaque
ax.set_xlabel('$x$');
ax.set_xticks(np.arange(0,8,1));
ax.set_xlim(0,7);
#ax.invert_xaxis();
ax.set_ylabel('$y$');
ax.set_yticks(np.arange(0,8,1));
ax.set_ylim(0,7);
#ax.invert_yaxis();
ax.set_zlabel('$z$');
ax.set_zticks(np.arange(0,8,1));
ax.set_zlim(0,7);
ax.view_init(25,45);