import numpy as np;
import matplotlib.pyplot as plt;
plt.rcParams.update({"text.usetex":True});
%config InlineBackend.figure_format = "svg"
from ipywidgets import interactive
from scipy.integrate import solve_ivp
Let's now consider flows which are not just constrained to a line. Flows in higher dimensions have a larger space to move about in the parameter space and can lead to interesting dynamics. First, we will look at some kinds of flows by drawing their vector plot. On top of the vector plot, we can also plot the trajectory. The trajectory is essentially how the phase space parameters change in time. It is different from the time series as time does not appear explicitly.
omega = 1; p = 0.2;
x = np.linspace(-3, 3, 20); v = np.linspace(-3, 3, 20);
X, V = np.meshgrid(x, v);
U = V; W = -omega**2*X - p*V;
plt.quiver(X, V, U, W);
ax = plt.gca(); ax.set_aspect(1);
x1 = np.linspace(-3, 3, 100); v1 = np.linspace(-3, 3, 100);
X1, V1 = np.meshgrid(x1, v1);
U1 = V1; W1 = -omega**2*X1 - p*V1;
seedpoints = np.array([[0, 1.5], [2.5, 0]]);
plt.streamplot(X1, V1, U1, W1, start_points=seedpoints.T, integration_direction='forward')
<matplotlib.streamplot.StreamplotSet at 0x18eb7b3ae20>
We can also make the plots interactive by wrapping them inside a function. The plot below draws a set of "linear flows".
def effect_a(a=1):
x = np.linspace(-3, 3, 20); y = np.linspace(-3, 3, 20);
X, Y = np.meshgrid(x, y);
U = a*X; V = -Y;
plt.quiver(X, Y, U, V);
ax = plt.gca(); ax.set_aspect(1);
x1 = np.linspace(-3, 3, 500); y1 = np.linspace(-3, 3, 500);
X1, Y1 = np.meshgrid(x1, y1);
F = np.log(np.abs(X1)) + a*np.log(np.abs(Y1));
plt.contour(X1, Y1, F, 11);
w = interactive(effect_a, a = (-2, 1.5, 0.05));
w
x = np.linspace(-3, 3, 20); y = np.linspace(-3, 3, 20);
X, Y = np.meshgrid(x, y);
U = X + Y;
V = 4*X - 2*Y;
plt.quiver(X, Y, U, V);
ax = plt.gca(); ax.set_aspect(1);
x1 = np.linspace(-3, 3, 100); y1 = np.linspace(-3, 3, 100);
X1, Y1 = np.meshgrid(x1, y1);
U1 = X1 + Y1;
V1 = 4*X1 - 2*Y1;
#seedpoints = np.array([[0, 1.5], [2.5, 0]]);
plt.streamplot(X1, Y1, U1, V1, integration_direction='forward', density=0.7)
plt.plot(x1, x1, '--k');
plt.plot(x1, -4*x1, '-k');
plt.ylim(-3, 3);