使用极坐标在Python中绘制相像 [英] Plotting phase portraits in Python using polar coordinates
本文介绍了使用极坐标在Python中绘制相像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要以极性形式给出的以下非线性系统的相图...
I need a phase portrait of the following nonlinear system given in polar form...
\dot{r} = 0.5*(r - r^3)
\dot{\theta} = 1
\dot{r} = 0.5*(r - r^3)
\dot{\theta} = 1
我知道如何在Mathematica中做到这一点...
I know how to do it in 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]
如何在python中使用pyplot.quiver做同样的事情?
How can I do the same using pyplot.quiver in Python?
推荐答案
更正上一个答案:
- 从
x=r*cos(theta)
得到dx = dr*cos(theta)-r*sin(theta)*dtheta = x*dr/ry*dtheta
, - 从
y = r * sin(theta)
中获得dy = dr * sin(theta)+ r * cos(theta)* dtheta = y * dr/r + x *dtheta
, - 一个人可以使用numpy的矢量化操作来避免所有循环
def dF(r, theta):
return 0.5*r*(1 - r*r), 1+0*theta
X, Y = np.meshgrid(np.linspace(-3.0, 3.0, 30), np.linspace(-3.0, 3.0, 30))
R, Theta = (X**2 + Y**2)**0.5, np.arctan2(Y, X)
dR, dTheta = dF(R, Theta)
C, S = np.cos(Theta), np.sin(Theta)
U, V = dR*C - R*S*dTheta, dR*S+R*C*dTheta
plt.streamplot(X, Y, U, V, color='r', linewidth=0.5, density=1.6)
plt.axis('square')
plt.axis([-3, 3, -3, 3])
plt.show()
这给出了下面的图.使用streamplot
的density
选项来增加绘图线的密度.
This gives the plot below. Use the density
option of streamplot
to increase the density of plot lines.
这篇关于使用极坐标在Python中绘制相像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文