Lan*_*don 3 python plot wolfram-mathematica matplotlib polar-coordinates
我需要以下以极坐标形式给出的非线性系统的相图......
\dot{r} = 0.5*(r - r^3)
\dot{\theta} = 1
我知道如何在 Mathematica 中做到这一点...
field1 = {0.5*(r - r^3), 1};
p1 = StreamPlot[Evaluate@TransformedField["Polar" -> "Cartesian", field1, {r, \[Theta]} -> {x, y}], {x, -3, 3}, {y, -3, 3}, Axes -> True, StreamStyle -> Gray, ImageSize -> Large];
Show[p1, AxesLabel->{x,y}, ImageSize -> Large]
Run Code Online (Sandbox Code Playgroud)
如何在 Python 中使用 pyplot.quiver 执行相同操作?
只是非常幼稚的实现,但可能会有所帮助......
import numpy as np
import matplotlib.pyplot as plt
def dF(r, theta):
return 0.5*(r - r**3), 1
X, Y = np.meshgrid(np.linspace(-3.0, 3.0, 30), np.linspace(-3.0, 3.0, 30))
u, v = np.zeros_like(X), np.zeros_like(X)
NI, NJ = X.shape
for i in range(NI):
for j in range(NJ):
x, y = X[i, j], Y[i, j]
r, theta = (x**2 + y**2)**0.5, np.arctan2(y, x)
fp = dF(r, theta)
u[i,j] = (r + fp[0]) * np.cos(theta + fp[1]) - x
v[i,j] = (r + fp[0]) * np.sin(theta + fp[1]) - y
plt.streamplot(X, Y, u, v)
plt.axis('square')
plt.axis([-3, 3, -3, 3])
plt.show()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11397 次 |
| 最近记录: |