HW1#
Revised
Jan 2023
Imports & Environment#
Show code cell source
# %load 'i.py'
import numpy as np
import numpy.random as npr
import pandas as pd
import matplotlib as mpl
from matplotlib import cm
from matplotlib.patches import Ellipse
import matplotlib.pyplot as plt
plt.style.use('ggplot');
from matplotlib.ticker import LinearLocator
import plotly
import plotly.express as px
import plotly.graph_objects as go
import sympy as sy
from sympy.geometry import Point, Line
from sympy import (diff,
dsolve,
Eq,
expand,
factor,
Function,
init_printing,
Integer,
Integral,
integrate,
latex,
limit,
Matrix,
Poly,
Rational,
solve,
Symbol,
symbols)
S =Symbol
ss=symbols
x,y,z,t,u,v=ss(names='x y z t u v')
init_printing(use_unicode=True)
import math
import numexpr
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"{'Numexpr' :<{pad}}: {numexpr.__version__}")
print(f"{'NumPy' :<{pad}}: {np.__version__}")
print(f"{'Pandas' :<{pad}}: {pd.__version__}")
print(f"{'Plotly' :<{pad}}: {plotly.__version__}")
print(f"{'SymPy' :<{pad}}: {sy.__version__}")
print()
from pprint import PrettyPrinter
pp = PrettyPrinter(indent=2)
pp.pprint([name for name in dir()
if name[0] != '_'
and name not in ['In', 'Out', 'exit', 'get_ipython', 'quit']])
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 44
41 init_printing(use_unicode=True)
43 import math
---> 44 import numexpr
46 from datetime import datetime as d
47 import locale as l
ModuleNotFoundError: No module named 'numexpr'
[1A]
SOLUTION
\( \begin{aligned} 16.3863 \approx \int_1^4\sqrt{4+\frac{1}{x^2}+4x^2}\,dx \end{aligned} \)
PROBLEM
\( \begin{aligned} \int_1^4\sqrt{4+\frac{1}{x^2}+4x^2}\,dx &=\int_1^4\sqrt{4x^2+4+\frac{1}{x^2}}\,dx\\ &=\int_1^4\sqrt{(2x)^2+2x\frac{1}{x}+2x\frac{1}{x}+\left(\frac{1}{x}\right)^2}\,dx\\ &=\int_1^4\sqrt{\left(2x+\frac{1}{x}\right)\left(2x+\frac{1}{x}\right)}\,dx\\ &=\int_1^4\sqrt{\left(2x+\frac{1}{x}\right)^2}\,dx\\ &=\int_1^4\left(2x+\frac{1}{x}\right)\,dx\\ &=2\int_1^4x\,dx+\int_1^4\frac{1}{x}\,dx\\ &=x^2\Big|_1^4+\ln(|x|)\Big|_1^4\\ &=15+\ln(4)\\ &\approx16.3863\\ \end{aligned} \)
15+np.log(4)
16.38629436111989
[1A]
SOLUTION
$
\begin{aligned}
16.3863
\approx
\int_1^4\sqrt{4+\frac{1}{x^2}+4x^2}\,dx
\end{aligned}
$
PROBLEM
$
\begin{aligned}
\int_1^4\sqrt{4+\frac{1}{x^2}+4x^2}\,dx
&=\int_1^4\sqrt{4x^2+4+\frac{1}{x^2}}\,dx\\
&=\int_1^4\sqrt{(2x)^2+2x\frac{1}{x}+2x\frac{1}{x}+\left(\frac{1}{x}\right)^2}\,dx\\
&=\int_1^4\sqrt{\left(2x+\frac{1}{x}\right)\left(2x+\frac{1}{x}\right)}\,dx\\
&=\int_1^4\sqrt{\left(2x+\frac{1}{x}\right)^2}\,dx\\
&=\int_1^4\left(2x+\frac{1}{x}\right)\,dx\\
&=2\int_1^4x\,dx+\int_1^4\frac{1}{x}\,dx\\
&=x^2\Big|_1^4+\ln(|x|)\Big|_1^4\\
&=15+\ln(4)\\
&\approx16.3863\\
\end{aligned}
$
[1B]
SOLUTION
\( \begin{aligned} 0.6095 \approx \int_0^1\sqrt{t^2+t^4}\,dt \end{aligned} \)
PROBLEM
\( \begin{aligned} \int_0^1\sqrt{t^2+t^4}\,dt &=\int_0^1\sqrt{t^2(1+t^2)}\,dt &=\int_0^1t\sqrt{1+t^2}\,dt\\ \end{aligned} \)
\( u=t^2+1\implies du=2t\,dt\implies\frac{du}{2t}=dt \)
\(t=0\implies u=(0)^2+1=1\)
\(t=1\implies u=(1)^2+1=2\)
\( \begin{aligned} =\int_1^2t\sqrt{u}\frac{du}{2t} &=\int_1^2\frac{t}{2t}\sqrt{u}\,du\\ &=\frac{1}{2}\int_1^2\sqrt{u}\,du\\ &=\frac{1}{3}u^\frac{3}{2}\Big|_1^2\\ &=\frac{1}{3}2^\frac{3}{2}-\frac{1}{3}\\ &\approx0.6095\\ \end{aligned} \)
(np.sqrt(8)-1)/3
0.6094757082487301
[1B]
SOLUTION
$
\begin{aligned}
0.6095
\approx
\int_0^1\sqrt{t^2+t^4}\,dt
\end{aligned}
$
PROBLEM
$
\begin{aligned}
\int_0^1\sqrt{t^2+t^4}\,dt
&=\int_0^1\sqrt{t^2(1+t^2)}\,dt
&=\int_0^1t\sqrt{1+t^2}\,dt\\
\end{aligned}
$
$
u=t^2+1\implies du=2t\,dt\implies\frac{du}{2t}=dt
$
$t=0\implies u=(0)^2+1=1$
$t=1\implies u=(1)^2+1=2$
$
\begin{aligned}
=\int_1^2t\sqrt{u}\frac{du}{2t}
&=\int_1^2\frac{t}{2t}\sqrt{u}\,du\\
&=\frac{1}{2}\int_1^2\sqrt{u}\,du\\
&=\frac{1}{3}u^\frac{3}{2}\Big|_1^2\\
&=\frac{1}{3}2^\frac{3}{2}-\frac{1}{3}\\
&\approx0.6095\\
\end{aligned}
$
[1C]
SOLUTION
\( \begin{aligned} \pi=\int_0^{2\pi}\cos^2(\theta)\,d\theta \end{aligned} \)
PROBLEM
\( \begin{aligned} \int_0^{2\pi}\cos^2(\theta)\,d\theta\,\,\,\text{where}\,\,\,\cos^2(\theta)=\frac{\cos(2\theta)+1}{2} \end{aligned} \)
\( \begin{aligned} =\int_0^{2\pi}\frac{\cos(2\theta)+1}{2}\,d\theta &=\frac{1}{2}\int_0^{2\pi}(\cos(2\theta)+1)\,d\theta\\ &=\frac{1}{2}\int_0^{2\pi}\cos(2\theta)\,d\theta+\frac{1}{2}\int_0^{2\pi}1\,d\theta\\ \end{aligned} \)
\(u=2\theta\implies du=2\,d\theta\implies\frac{du}{2}=d\theta\)
\(\theta=0\implies u=2(0)=0\)
\(\theta=2\pi\implies u=2(2\pi)=4\pi\)
\( \begin{aligned} =\frac{1}{2}\int_0^{4\pi}\cos(u)\frac{du}{2}+\frac{1}{2}\int_0^{4\pi}\frac{du}{2} &=\frac{1}{4}\int_0^{4\pi}\cos(u)\,du+\frac{1}{4}\int_0^{4\pi}\,du\\ &=\frac{1}{4}\sin(u)\Big|_0^{4\pi}+\frac{1}{4}u\Big|_0^{4\pi}\\ &=\pi\\ \end{aligned} \)
[1C]
SOLUTION
$
\begin{aligned}
\pi=\int_0^{2\pi}\cos^2(\theta)\,d\theta
\end{aligned}
$
PROBLEM
$
\begin{aligned}
\int_0^{2\pi}\cos^2(\theta)\,d\theta\,\,\,\text{where}\,\,\,\cos^2(\theta)=\frac{\cos(2\theta)+1}{2}
\end{aligned}
$
$
\begin{aligned}
=\int_0^{2\pi}\frac{\cos(2\theta)+1}{2}\,d\theta
&=\frac{1}{2}\int_0^{2\pi}(\cos(2\theta)+1)\,d\theta\\
&=\frac{1}{2}\int_0^{2\pi}\cos(2\theta)\,d\theta+\frac{1}{2}\int_0^{2\pi}1\,d\theta\\
\end{aligned}
$
$u=2\theta\implies du=2\,d\theta\implies\frac{du}{2}=d\theta$
$\theta=0\implies u=2(0)=0$
$\theta=2\pi\implies u=2(2\pi)=4\pi$
$
\begin{aligned}
=\frac{1}{2}\int_0^{4\pi}\cos(u)\frac{du}{2}+\frac{1}{2}\int_0^{4\pi}\frac{du}{2}
&=\frac{1}{4}\int_0^{4\pi}\cos(u)\,du+\frac{1}{4}\int_0^{4\pi}\,du\\
&=\frac{1}{4}\sin(u)\Big|_0^{4\pi}+\frac{1}{4}u\Big|_0^{4\pi}\\
&=\pi\\
\end{aligned}
$
[1D]
SOLUTION
\( \begin{aligned} \frac{2}{3} =\int_0^\frac{\pi}{2}\sin^3(x)\,dx \end{aligned} \)
PROBLEM
\( \begin{aligned} \int_0^\frac{\pi}{2}\sin^3(x)\,dx &=\int_0^\frac{\pi}{2}\sin^2(x)\sin(x)\,dx\,\,\,\text{where}\,\,\,\sin^2(x)=1-\cos^2(x)\\ &=\int_0^\frac{\pi}{2}(1-\cos^2(x))\sin(x)\,dx \end{aligned} \)
\(u=\cos(x)\implies du=-\sin(x)\,dx\implies-\frac{du}{\sin(x)}=dx\)
\(x=0\implies u=\cos(0)=1\)
\(x=\frac{\pi}{2}\implies u=\cos(\frac{\pi}{2})=0\)
\( \begin{aligned} =\int_1^0(1-u^2)\sin(x)\left(-\frac{du}{\sin(x)}\right) &=\int_1^0(u^2-1)\,du\\ &=\int_1^0u^2\,du-\int_1^01\,du\\ &=\frac{1}{3}u^3\Big|_1^0-u\Big|_1^0\\ &=\frac{2}{3} \end{aligned} \)
[1D]
SOLUTION
$
\begin{aligned}
\frac{2}{3}
=\int_0^\frac{\pi}{2}\sin^3(x)\,dx
\end{aligned}
$
PROBLEM
$
\begin{aligned}
\int_0^\frac{\pi}{2}\sin^3(x)\,dx
&=\int_0^\frac{\pi}{2}\sin^2(x)\sin(x)\,dx\,\,\,\text{where}\,\,\,\sin^2(x)=1-\cos^2(x)\\
&=\int_0^\frac{\pi}{2}(1-\cos^2(x))\sin(x)\,dx
\end{aligned}
$
$u=\cos(x)\implies du=-\sin(x)\,dx\implies-\frac{du}{\sin(x)}=dx$
$x=0\implies u=\cos(0)=1$
$x=\frac{\pi}{2}\implies u=\cos(\frac{\pi}{2})=0$
$
\begin{aligned}
=\int_1^0(1-u^2)\sin(x)\left(-\frac{du}{\sin(x)}\right)
&=\int_1^0(u^2-1)\,du\\
&=\int_1^0u^2\,du-\int_1^01\,du\\
&=\frac{1}{3}u^3\Big|_1^0-u\Big|_1^0\\
&=\frac{2}{3}
\end{aligned}
$