Integration#


Revised

14 Jun 2023


Programming Environment#

Hide code cell source
import numpy             as np
import pandas            as pd
import matplotlib        as mpl
import matplotlib.pyplot as plt
from   matplotlib           import gridspec
from   mpl_toolkits.mplot3d import axes3d
from   ipywidgets           import interactive
plt.style.use('ggplot');

import sympy as smp
from   sympy import *

import plotly
import plotly.figure_factory as ff
import plotly.graph_objects  as go

from IPython.display import display, Math

from   datetime import datetime as d
import locale                   as l
import platform                 as p
import sys                      as s

pad = 20
print(f"{'Executed'.upper():<{pad}}: {d.now()}")
print()
print(f"{'Platform'        :<{pad}}: "
      f"{p.mac_ver()[0]} | "
      f"{p.system()} | "
      f"{p.release()} | "
      f"{p.machine()}")
print(f"{''                :<{pad}}: {l.getpreferredencoding()}")
print()
print(f"{'Python'          :<{pad}}: {s.version}")
print(f"{''                :<{pad}}: {s.version_info}")
print(f"{''                :<{pad}}: {p.python_implementation()}")
print()
print(f"{'Matplotlib'      :<{pad}}: {mpl   .__version__}")
print(f"{'NumPy'           :<{pad}}: {np    .__version__}")
print(f"{'Pandas'          :<{pad}}: {pd    .__version__}")
print(f"{'Plotly'          :<{pad}}: {plotly.__version__}")
print(f"{'SymPy'           :<{pad}}: {smp   .__version__}")
EXECUTED            : 2024-05-21 15:45:44.114647

Platform            : 14.4.1 | Darwin | 23.4.0 | arm64
                    : UTF-8

Python              : 3.11.9 | packaged by conda-forge | (main, Apr 19 2024, 18:34:54) [Clang 16.0.6 ]
                    : sys.version_info(major=3, minor=11, micro=9, releaselevel='final', serial=0)
                    : CPython

Matplotlib          : 3.8.4
NumPy               : 1.26.4
Pandas              : 2.2.2
Plotly              : 5.21.0
SymPy               : 1.12

Definite Integration#

\(\begin{aligned}\frac{1}{4}=\int_0^\frac{\pi}{2}\sin^3\theta\cos\theta\,d\theta\end{aligned}\)#

\( \begin{aligned} &\int_{\theta=0}^{\theta=\frac{\pi}{2}}\sin^3\theta\cos\theta\,d\theta \\ u&=\sin\theta \\ du&=\cos\theta\,d\theta \\ \theta&=0 \implies u=0 \\ \theta&=\frac{\pi}{2} \implies u=1 \\ &\int_{\theta=0}^{\theta=\frac{\pi}{2}}\sin^3\theta\cos\theta\,d\theta =\int_{u=0}^{u=1}u^3\,du =\left.\left(\frac{1}{4}u^4\right)\right|_{u=0}^{u=1} =\frac{1}{4} \end{aligned} \)


\(\begin{aligned}\frac{4}{3}=\int_0^\pi\sin^3\phi\,d\phi\end{aligned}\)#

\( \begin{aligned} \int_{\phi=0}^{\phi=\pi}\sin^3\phi\,d\phi &=\int_{\phi=0}^{\phi=\pi}\sin\phi\sin^2\phi\,d\phi =\int_{\phi=0}^{\phi=\pi}\sin\phi(1-\cos^2\phi)\,d\phi =\int_{\phi=0}^{\phi=\pi}\sin\phi-\sin\phi\cos^2\phi\,d\phi \\ &=\int_{\phi=0}^{\phi=\pi}\sin\phi\,d\phi-\int_{\phi=0}^{\phi=\pi}\sin\phi\cos^2\phi\,d\phi \\ &=2-\int_{\phi=0}^{\phi=\pi}\sin\phi\cos^2\phi\,d\phi &&2=\int_{\phi=0}^{\phi=\pi}\sin\phi\,d\phi \\ u&=\cos\phi \\ -du&=\sin\phi\,d\phi \\ \phi&=0 \implies u=1 \\ \phi&=\pi \implies u=-1 \\ \int_{\phi=0}^{\phi=\pi}\sin^3\phi\,d\phi &=2+\int_{u=1}^{u=-1}u^2\,du \\ &=2+\left.\left(\frac{1}{3}u^3\right)\right|_{u=1}^{u=-1} \\ &=2-\frac{2}{3} \\ &=\frac{4}{3} \end{aligned} \)


\(\begin{aligned}\frac{1}{3}-\frac{1}{3\sqrt[3]{2}}=\int_0^\frac{\pi}{4}\cos^2\theta\sin\theta\,d\theta\end{aligned}\)#

\( \begin{aligned} &\int_0^\frac{\pi}{4}\cos^2\theta\sin\theta\,d\theta \\ u&=\cos\theta \\ du&=-\sin\theta\,d\theta \iff -du=\sin\theta\,d\theta \\ \theta&=0 \implies u=1 \\ \theta&=\frac{\pi}{4} \implies u=\frac{1}{\sqrt{2}} \\ &\int_0^\frac{\pi}{4}\cos^2\theta\sin\theta\,d\theta =\int_\frac{1}{\sqrt{2}}^1u^2\,du =\left.\left(\frac{1}{3}u^3\right)\right|_\frac{1}{\sqrt{2}}^1 =\frac{1}{3}-\frac{1}{3}\left(\frac{1}{\sqrt{2}}\right)^3 =\frac{1}{3}-\frac{1}{3\sqrt[3]{2}} \approx0.2155 \end{aligned} \)

((1/3)-(1/(3*2**(3/2))))
0.21548220313557542

\(\begin{aligned}\frac{7}{3}=\int_0^\frac{\pi}{3}\sec^4\theta\sin\theta\,d\theta\end{aligned}\)#

\( \begin{aligned} \int_0^\frac{\pi}{3}\sec^4\theta\sin\theta\,d\theta &=\int_0^\frac{\pi}{3}\frac{1}{\cos^4\theta}\sin\theta\,d\theta \\ u&=\cos\theta \\ du&=-\sin\theta\,d\theta \iff -du=\sin\theta\,d\theta \\ \theta&=0 \implies u=1 \\ \theta&=\frac{\pi}{3} \implies u=\frac{1}{2} \\ \int_0^\frac{\pi}{3}\sec^4\theta\sin\theta\,d\theta &=\int_\frac{1}{2}^1u^{-4}\,du \\ &=\left.\left(-\frac{1}{3}u^{-3}\right)\right|_\frac{1}{2}^1 =-\frac{1}{3}(1)^{-3}+\frac{1}{3}\left(\frac{1}{2}\right)^{-3} =\frac{7}{3} \end{aligned} \)


\(\begin{aligned}\int_0^{\ln(4)} \frac{e^x}{\sqrt{e^{2x} + 9}} \,dx\end{aligned}\)#

\( \begin{aligned} \int_0^{\ln(4)} \frac{e^x}{\sqrt{e^{2x} + 9}} \,dx \end{aligned} \)

x = smp.symbols('x')

integrand    = smp.exp(x) / smp.sqrt(smp.exp(2*x) + 9)
ind_integral = smp.integrate(integrand, x)
def_integral = smp.integrate(integrand, (x, 0, smp.log(4)))

display(Math(
  r"\begin{aligned}"
  r"\text{integrand}&:"
  f"{smp.latex(integrand)}"
  r"\\"
  r"\text{indefinite integral}&:"
  f"{smp.latex(ind_integral)} + C"
  r"\\"
  r"\text{definite integral}&:"
  f"{smp.latex(def_integral)}"
  r"\end{aligned}"
))
\[\begin{split}\displaystyle \begin{aligned}\text{integrand}&:\frac{e^{x}}{\sqrt{e^{2 x} + 9}}\\\text{indefinite integral}&:\operatorname{asinh}{\left(\frac{e^{x}}{3} \right)} + C\\\text{definite integral}&:- \operatorname{asinh}{\left(\frac{1}{3} \right)} + \operatorname{asinh}{\left(\frac{4}{3} \right)}\end{aligned}\end{split}\]

\(\begin{aligned}\int_1^t x^{10}e^x \,dx\end{aligned}\)#

\( \begin{aligned} \int_1^t x^{10}e^x \,dx \end{aligned} \)

x, t = smp.symbols('x t')

integrand    = x**10 * smp.exp(x)
ind_integral = smp.integrate(integrand, x)
def_integral = smp.integrate(integrand, (x, 1, t))

display(Math(
  r"\begin{aligned}"
  r"\text{integrand}&:"
  f"{smp.latex(integrand)}"
  r"\\"
  r"\text{indefinite integral}&:"
  f"{smp.latex(ind_integral)} + C"
  r"\\"
  r"\text{definite integral}&:"
  f"{smp.latex(def_integral)}"
  r"\end{aligned}"
))
\[\begin{split}\displaystyle \begin{aligned}\text{integrand}&:x^{10} e^{x}\\\text{indefinite integral}&:\left(x^{10} - 10 x^{9} + 90 x^{8} - 720 x^{7} + 5040 x^{6} - 30240 x^{5} + 151200 x^{4} - 604800 x^{3} + 1814400 x^{2} - 3628800 x + 3628800\right) e^{x} + C\\\text{definite integral}&:\left(t^{10} - 10 t^{9} + 90 t^{8} - 720 t^{7} + 5040 t^{6} - 30240 t^{5} + 151200 t^{4} - 604800 t^{3} + 1814400 t^{2} - 3628800 t + 3628800\right) e^{t} - 1334961 e\end{aligned}\end{split}\]

Improper Integration#

\(\begin{aligned}\int_0^\infty \frac{16\tan^{-1}(x)}{1 + x^2} \,dx\end{aligned}\)#

\( \begin{aligned} \int_0^\infty \frac{16\tan^{-1}(x)}{1 + x^2} \,dx \end{aligned} \)

x = smp.symbols('x')

integrand    = 16*smp.atan(x) / (1 + x**2)
ind_integral = smp.integrate(integrand, x)
def_integral = smp.integrate(integrand, (x, 0, smp.oo))

display(Math(
  r"\begin{aligned}"
  r"\text{integrand}&:"
  f"{smp.latex(integrand)}"
  r"\\"
  r"\text{indefinite integral}&:"
  f"{smp.latex(ind_integral)} + C"
  r"\\"
  r"\text{definite integral}&:"
  f"{smp.latex(def_integral)}"
  r"\end{aligned}"
))
\[\begin{split}\displaystyle \begin{aligned}\text{integrand}&:\frac{16 \operatorname{atan}{\left(x \right)}}{x^{2} + 1}\\\text{indefinite integral}&:8 \operatorname{atan}^{2}{\left(x \right)} + C\\\text{definite integral}&:2 \pi^{2}\end{aligned}\end{split}\]

Indefinite Integration#

\(\begin{aligned}\int \csc(x) \cot(x) \,dx\end{aligned}\)#

\( \begin{aligned} \int \csc(x) \cot(x) \,dx \end{aligned} \)

# remember to add the "+ C"
smp.integrate(
  smp.csc(x)*smp.cot(x),
  x,
)
\[\displaystyle - \frac{1}{\sin{\left(x \right)}}\]

\(\begin{aligned}\int 4\sec(3x) \tan(3x) \,dx\end{aligned}\)#

\( \begin{aligned} \int 4\sec(3x) \tan(3x) \,dx \end{aligned} \)

# remember to add the "+ C"
smp.integrate(
  4*smp.sec(3*x)*smp.tan(3*x),
  x,
)
\[\displaystyle \frac{4}{3 \cos{\left(3 x \right)}}\]

\(\begin{aligned}\int \left( \frac{2}{\sqrt{1 - x^2}} - \frac{1}{x^\frac{1}{4}} \right) \,dx\end{aligned}\)#

\( \begin{aligned} \int \left( \frac{2}{\sqrt{1 - x^2}} - \frac{1}{x^\frac{1}{4}} \right) \,dx \end{aligned} \)

# remember to add the "+ C"
smp.integrate(
  2/smp.sqrt(1-x**2) - 1/x**smp.Rational(1,4),
  x,
)
\[\displaystyle - \frac{4 x^{\frac{3}{4}}}{3} + 2 \operatorname{asin}{\left(x \right)}\]

\(\begin{aligned}\int \frac{(1 + \sqrt{x})^\frac{1}{3}}{\sqrt{x}} \,dx\end{aligned}\)#

\( \begin{aligned} \int \frac{(1 + \sqrt{x})^\frac{1}{3}}{\sqrt{x}} \,dx \end{aligned} \)

integrand = (1 + smp.sqrt(x))**smp.Rational(1, 3) / smp.sqrt(x)
integrand
\[\displaystyle \frac{\sqrt[3]{\sqrt{x} + 1}}{\sqrt{x}}\]
smp.integrate(integrand, x)
\[\displaystyle \frac{3 \sqrt{x} \sqrt[3]{\sqrt{x} + 1}}{2} + \frac{3 \sqrt[3]{\sqrt{x} + 1}}{2}\]

\(\begin{aligned}\int x(1 - x^2)^\frac{1}{4} \,dx\end{aligned}\)#

\( \begin{aligned} \int x(1 - x^2)^\frac{1}{4} \,dx \end{aligned} \)

x = smp.symbols('x')

integrand = x*(1 - x**2)**smp.Rational(1, 4)
integral  = smp.integrate(integrand, x)

display(Math(
  r"\begin{aligned}"
  r"\text{integrand}&:"
  f"{smp.latex(integrand)}"
  r"\\"
  r"\text{integral}&:"
  f"{smp.latex(integral)} + C"
  r"\end{aligned}"
))
\[\begin{split}\displaystyle \begin{aligned}\text{integrand}&:x \sqrt[4]{1 - x^{2}}\\\text{integral}&:\frac{2 x^{2} \sqrt[4]{1 - x^{2}}}{5} - \frac{2 \sqrt[4]{1 - x^{2}}}{5} + C\end{aligned}\end{split}\]

\(\begin{aligned}\int \frac{(2x - 1)\cos(\sqrt{3(2x - 1)^2 + 6})}{\sqrt{3(2x - 1)^2 + 6}} \,dx\end{aligned}\)#

\( \begin{aligned} \int \frac{(2x - 1)\cos(\sqrt{3(2x - 1)^2 + 6})}{\sqrt{3(2x - 1)^2 + 6}} \,dx \end{aligned} \)

x = smp.symbols('x')

integrand = (2*x - 1)*smp.cos(smp.sqrt(3*(2*x - 1)**2 + 6)) / smp.sqrt(3*(2*x - 1)**2 + 6)
integral  = smp.integrate(integrand, x)

display(Math(
  r"\begin{aligned}"
  r"\text{integrand}&:"
  f"{smp.latex(integrand)}"
  r"\\"
  r"\text{integral}&:"
  f"{smp.latex(integral)} + C"
  r"\end{aligned}"
))
\[\begin{split}\displaystyle \begin{aligned}\text{integrand}&:\frac{\left(2 x - 1\right) \cos{\left(\sqrt{3 \left(2 x - 1\right)^{2} + 6} \right)}}{\sqrt{3 \left(2 x - 1\right)^{2} + 6}}\\\text{integral}&:\frac{\sin{\left(\sqrt{3 \left(2 x - 1\right)^{2} + 6} \right)}}{6} + C\end{aligned}\end{split}\]

Terms#

  • [W] Anti Derivative

  • [W] Antidifference (Indefinite Sum)

  • [W] Improper Integral

  • [W] Indefinite Integral


Bibliography#

  • [Y] Mr. P Solver. (26 May 2021). “1st Year Calculus, But in PYTHON”. YouTube.