在Python中用极坐标绘制相图

2024-06-28 11:32:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要一个极坐标形式的非线性系统的相图。。。在

\dot{r}=0.5*(r-r^3)
\点{\theta}=1

我知道怎么用数学来做。。。在

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]

enter image description here

如何使用pyplot.箭袋在Python中?在


Tags: 系统数学dot形式largeevaluatefield1p1
1条回答
网友
1楼 · 发布于 2024-06-28 11:32:45

只是很幼稚的实现,但可能会有帮助。。。在

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()

enter image description here

相关问题 更多 >