In [1]:
%matplotlib inline
import numpy as np
from matplotlib import pyplot as plt
plt.style.use('bmh')
from time import time
In [2]:
def tangent(x, y, f, l = 0.1):
# Returns a line centered at x, y
# with slope found from dy/dx = f(x, y)[1]/f(x,y)[0]
# and length l
dx, dy = f([x, y])
if dx == 0:
# if dy is also 0, then return a point
if dy == 0:
return np.array([x, x]), np.array([y, y])
# Otherwise, slope is infinite, return a vertical
else:
return np.array([x, x]), np.array([y - l/2, y + l/2])
else:
# Slope is finite, return a line segment
# of length, and with that slope
s = np.sqrt((2*dx)**2 + (2*dy)**2) / l
return np.array([x - dx/s, x + dx/s]), np.array([y - dy/s, y + dy/s])
In [3]:
def f(x):
# Modify A to get the different types of fixed point
A = np.array([
[1, -2],
[2, -2]
])
dx = A[0,0]*x[0] + A[0,1]*x[1]
dy = A[1,0]*x[0] + A[1,1]*x[1]
return np.array([dx, dy])
def f(x):
dx = x[0] + np.exp(-x[1])
dy = -x[1]
return np.array([dx, dy])
def f(X):
x = X[0]
y = X[1]
dx = x**2*y
dy = x**2 - y**2
return np.array([dx, dy])
# Define grid points
Nx = 31
Ny = 31
X = np.linspace(-2, 2, Nx)
Y = np.linspace(-2, 2, Ny)
fig = plt.figure(figsize = (8, 8))
for i in range(Nx):
for j in range(Ny):
# For each gridpoint, plot a short straight line
# The star in the function call below unpacks the arguments,
# passing them one by one to the plot function.
plt.plot(*tangent(X[i], Y[j], f, l = 0.07), lw = 1, c = '#A60628')
plt.xlim(-2, 2)
plt.ylim(-2, 2)
Out[3]:
In [ ]: