In [2]:
%pylab inline
%qtconsole
from mpl_toolkits.mplot3d import Axes3D
from ipywidgets import interact, interactive
from IPython.display import clear_output, display, HTML


Populating the interactive namespace from numpy and matplotlib

Numeros complejos


In [10]:
x = arange(-1,1,0.11)
y = arange(-10,10,0.11)
X, Y = meshgrid(x, y)
z = X+ 1j*Y
w = exp(z)
fig = figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X,Y,real(w))
ax.set_title('Parte Real')
fig = figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X,Y,imag(w))
ax.set_title('Parte Imaginaria')
fig = figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X,Y,abs(w))
ax.set_title('Modulo')


Out[10]:
<matplotlib.text.Text at 0x7f785f0d7490>

Mapa para visualizar funciones complejas


In [28]:
subplot(121)
for yp in linspace(-pi,pi,10):
    x = arange(-1,1,0.1)
    y = [yp]*len(x)
    plot(x,y,'r')

for xp in arange(-1,1,0.2):
    y = arange(-pi,pi,0.1)
    x = [xp]*len(y)
    plot(x,y,'b')
xlabel('Real')
ylabel('Imaginario')

subplot(122)
for yp in linspace(-pi,pi,10):
    x = arange(-1,1,0.1)
    y = [yp]*len(x)
    plot(exp(x)*cos(y),exp(x)*sin(y), 'r')

for xp in arange(-1,1,0.2):
    y = arange(-pi,pi,0.01)
    x = [xp]*len(y)
    plot(exp(x)*cos(y),exp(x)*sin(y),'b')
xlabel('Real')
ylabel('Imaginario')


Out[28]:
<matplotlib.text.Text at 0x7eff56151190>

¿Que pasa si sumamos funciones trigonometricas con fases al azar?


In [44]:
R = 1
t = arange(0,10,0.01)
y = zeros(t.shape)
for i in range(100):
    y = y+ cos(2*pi*t + rand()*2*pi) 
plot(y)
ylim((-10,10))


Out[44]:
(-10, 10)

La suma aleatorio $$\sum_{i=1}^{100} cos(x + \phi_i)$$

Relaciones de funciones trigonometricas


In [33]:
def plot_cosine(A, B):
    fig = figure()
    ax = fig.add_axes([0, 0, 1, 1])
    w = 5.
    t = arange(0,10,0.01)
    y = A*cos(w*t) + B*sin(w*t) 
    # prepare the axes limits
    ax.set_xlim((0, 10))
    ax.set_ylim((-10, 10))
    ax.plot(t, y)

In [37]:
wid = interactive(plot_cosine, A=(-10.,10.), B=(-10.,10.))
display(wid)


Autovalores y autovectores.


In [31]:
M = matrix([
        [1, 0 ,1],
        [2, 3 ,4],
        [3, 1, 1]
    ])
eig(M)


Out[31]:
(array([ 4.62619807,  1.51513805, -1.14133612]),
 matrix([[ 0.09238773,  0.33818572, -0.3513954 ],
         [ 0.93767193, -0.92481376, -0.55707428],
         [ 0.33501621,  0.17421233,  0.75245566]]))