In [1]:
"""
IPython Notebook v4.0 para python 2.7
Librerías adicionales: numpy, matplotlib
Contenido bajo licencia CC-BY 4.0. Código bajo licencia MIT. (c) Sebastian Flores.
"""
# Configuracion para recargar módulos y librerías
%reload_ext autoreload
%autoreload 2
from IPython.core.display import HTML
HTML(open("style/mat281.css", "r").read())
Out[1]:
In [2]:
from matplotlib import pyplot as plt
import numpy as np
x = np.linspace(1E-8,np.pi/6,1000)
y = x*np.sin(1./x)
plt.plot(x, y)
plt.plot(x, x)
plt.plot(x, -x)
plt.show()
In [3]:
from mat281_code import black_box
black_box.iplot()
In [9]:
# Calculando el promedio
x = np.array([1.2, 2.2, 2.6, 3.1, 3.1, 3.2, 3.3, 3.6, 3.6, 4.3])
print(x.mean())
print x.min(), x.std()
In [10]:
# Calculando el promedio
x = np.array([1.2, 2.2, 2.6, 3.1, 3.1, 3.2, 3.3, 3.6, 3.6, 4.3])
x_mean = x.mean()
print("Promedio angular: {0:.2f} [rad] ó {1:.2f} [deg]".format(x_mean, x_mean*180/np.pi))
In [11]:
plt.figure(figsize=(14,3))
plt.plot(x, 0*x, 'go', alpha=0.75)
plt.plot([x.mean(), x.mean()], [-1,1], '-g', lw=2.0)
plt.gca().set_yticks([])
plt.show()
In [12]:
cos_mean = np.cos(x).mean()
sin_mean = np.sin(x).mean()
trig_mean = np.arctan2(sin_mean, cos_mean)
print("Promedio espacial: {0:.2f} [rad] ó {1:.2f} [deg]".format(trig_mean, trig_mean*180/np.pi))
In [13]:
plt.figure(figsize=(12,12))
aux_th = np.arange(0,1000.)*2*np.pi/1000.
r = (cos_mean**2 + sin_mean**2)**.5
plt.plot(0, 0, 'k.', alpha=0.25)
plt.plot(np.cos(aux_th), np.sin(aux_th), 'k-', alpha=0.25)
plt.plot(np.cos(x), np.sin(x), 'b*', alpha=0.75, ms=16)
plt.plot(np.cos(x_mean), np.sin(x_mean), 'go', alpha=1.0, ms=16, label=r"$(\cos(\overline{\theta}),\sin(\overline{\theta}))$")
plt.plot(cos_mean, sin_mean, 'rs', alpha=1.0, ms=16, label=r"$(\overline{\cos(\theta}),\overline{\sin(\theta}))$")
plt.plot(cos_mean/r, sin_mean/r, 'rs', alpha=0.5, ms=16, label=r"$(\overline{\cos(\theta}),\overline{\sin(\theta}))$")
plt.xlim([-1.1, 1.1])
plt.ylim([-1.1, 1.1])
plt.legend(loc="lower right", fontsize=20, numpoints=1)
plt.xlabel(r"$x=cos(\theta)$ [$L$]")
plt.ylabel(r"$x=sin(\theta)$ [$L$]")
Out[13]:
Ejemplo real: