使用极坐标在Python中绘制相像

我需要以极性形式给出的以下非线性系统的相图...

\ 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,Axes -> True,StreamStyle -> Gray,ImageSize -> Large];
Show[p1,AxesLabel->{x,y},ImageSize -> Large]

使用极坐标在Python中绘制相像

如何在python中使用pyplot.quiver来做同样的事情?

benbenmail 回答:使用极坐标在Python中绘制相像

更正上一个答案:

  • x=r*cos(theta) 得到 dx = dr*cos(theta)-r*sin(theta)*dtheta = x*dr/r-y*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,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()

这给出了下面的情节。使用 densitystreamplot 选项增加绘图线的密度。

enter image description here

,

只是非常幼稚的实现,但可能会有所帮助...

NSStackView

enter image description here

本文链接:https://www.f2er.com/3163671.html

大家都在问