Análisis Cualitativo de Sistemas Lineales


In [1]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

from sympy import *
from sympy.matrices import *
init_printing()

In [2]:
x, y = np.meshgrid(np.linspace(-2, 2.5, 15),
                   np.linspace(-1, 1, 15))

u = y
v = -np.sin(x) - y

plt.quiver(x, y, u, v)

plt.show()



In [3]:
x, y = np.meshgrid(np.linspace(-2, 2.5, 15),
                   np.linspace(-1, 1, 15))

u = y
v = -np.cos(x) - 0.5 * y

plt.quiver(x, y, u, v)
x, y = np.meshgrid([-np.pi/2.0,],
                   [0,])


plt.show()


Jacobiana


In [4]:
x, y, J = symbols('x y J')
from sympy.functions.elementary.trigonometric import cos

jacobian = Matrix([[diff(y, x), diff(y, y)],
     [diff(-cos(x) - 0.5 * y, x), diff(-cos(x) - 0.5 * y, y)]])
J = jacobian
J


Out[4]:
$$\left[\begin{matrix}0 & 1\\\sin{\left (x \right )} & -0.5\end{matrix}\right]$$

Lambdify para el quiver-plot


In [5]:
x,y,u,v = symbols('x y u v')
expr0 = (1 - x - y) * x
f = lambdify((u, v), expr0.subs({x:(1/4)+u, y:(3/4)-v}), "numpy")

expr1 = (4 -7 * x - 3 * y) * y
g = lambdify((u, v), expr1.subs({x:(1/4)+u, y:(3/4)-v}), "numpy")

In [6]:
expand(expr0.subs({x:(1/4)+u, y:(3/4)-v}))


Out[6]:
$$- u^{2} + u v - 0.25 u + 0.25 v$$

In [7]:
expand(expr1.subs({x:(1/4)+u, y:(3/4)-v}))


Out[7]:
$$7 u v - 5.25 u - 3 v^{2} + 2.25 v$$

In [8]:
i, j = np.meshgrid(np.linspace(-1, 1, 25),
                   np.linspace(-1, 1, 15))
u = f(i,j)
v = g(i,j)

plt.quiver(i, j, u, v)
plt.show()