Last active
March 10, 2022 12:06
-
-
Save nicoguaro/05cf6bf9593efeb56dc156d26a2a4111 to your computer and use it in GitHub Desktop.
Phase portrait for a system with a strange critical point.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Phase portrait for the system | |
x '= y | |
y' = -(x**2 - a**2)*(1 + x) | |
@author: Nicolás Guarín-Zapata | |
@date: April 2021 | |
""" | |
import numpy as np | |
import matplotlib.pyplot as plt | |
plt.rcParams["mathtext.fontset"] = "cm" | |
a = 0.0 | |
y, x = np.mgrid[-1:1:201j, -1.5:0.5:201j] | |
u = y | |
v = -(x**2 - a**2)*(1 + x) | |
plt.streamplot(x, y, u, v, color="#111111") | |
V = y**2/2 + (3*x**4 + 4*x**3 - 6*a**2*x**2 - 12*a**2*x)/12 | |
levels = np.linspace(-0.1, 0.7, 21) | |
plt.contourf(x, y, V, levels) | |
plt.contour(x, y, V, [0], colors="#eeeeee") | |
plt.axis("image") | |
plt.xlim(-1.5, 0.5) | |
plt.ylim(-1, 1) | |
plt.xlabel(r"$x$", size=14) | |
plt.ylabel(r"$y$", size=14) | |
plt.yticks([-1, -0.5, 0.0, 0.5, 1.0]) | |
plt.xticks([-1.5, -1.0, -0.5, 0.0, 0.5]) | |
plt.savefig("phase_portrait.png", dpi=300) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment