我已经写了一个程序,其中需要半径范围(R到5)和θ范围(0到2pi)。它将极坐标转换为笛卡尔坐标。然后我绘制了x,y笛卡尔坐标的散点图
自由流速度u(x方向)=1,v速度(y方向)=0。我想为我在上面获得的点绘制一个流图。我知道我必须使用网格网格函数。但是在尝试了很多之后,我无法将网格点映射到速度值
我想得到一个如下图所示的情节
代码如下:
import math
import numpy as np
from matplotlib import pyplot
R=1.15; # Radius of circle
Nr=75; # No of radial points
Ntheta=75; # No of theta points
x_start,x_end=-5,5;
y_start,y_end=-5,5;
theta=np.linspace(0,2*np.pi,Ntheta); # Array of theta points
radial=np.linspace(R,5,Nr); # Array of radius points
xc=-0.15; # Center of circle.
yc=0.0; # Center of circle.
X,Y=np.meshgrid(r,theta); # Meshgrid for stream plot
x=np.zeros((Nr*Ntheta,1),dtype=np.float64); # To store x cordinates
y=np.zeros((Nr*Ntheta,1),dtype=np.float64); # to store y cordinates
# Z-Plane Computation
cnt=0;
for i in range(Nr):
for j in range(Ntheta):
x[cnt,0]=radial[i]*np.cos(theta[j])+xc; # Calculation of Cartesian Cordinates
y[cnt,0]=radial[i]*np.sin(theta[j])+yc; # Calculation of Cartesian Cordinates
cnt+=1;
# Plot
fig=pyplot.figure(figsize=(10,10));
pyplot.scatter(x[:,0],y[:,0],s=1,color='k');
pyplot.xlim(-6,6);
pyplot.ylim(-6,6);
pyplot.scatter(xc,yc,s=80,color='g',marker='o');
pyplot.title('Z-Plane',fontsize=20);
pyplot.xlabel('x',fontsize=15);
pyplot.ylabel('y',fontsize=15);
pyplot.grid(color='k',which='both',axis='both',linestyle='--',linewidth=0.5);
# StreamLine Velocity
u_inf=1;
u_freestream= u_inf*np.ones((Nr,Ntheta),dtype=np.float64);
v_freestream= np.zeros((Nr,Ntheta),dtype=np.float64);
#plotting
pyplot.figure()
pyplot.streamplot(X,Y,u_freestream,v_freestream);
错误是
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-6-59df08985fbe> in <module>()
46 #plotting
47 pyplot.figure()
---> 48 pyplot.streamplot(X,Y,u_freestream,v_freestream);
49
50
3 frames
/usr/local/lib/python3.6/dist-packages/matplotlib/streamplot.py in __init__(self, x, y)
342
343 if not np.allclose(np.diff(x), self.width / (self.nx - 1)):
--> 344 raise ValueError("'x' values must be equally spaced")
345 if not np.allclose(np.diff(y), self.height / (self.ny - 1)):
346 raise ValueError("'y' values must be equally spaced")
ValueError: 'x' values must be equally spaced
我花了很多时间在{}上,我想尝试一下你的问题。这是我到目前为止得到的
我同意@swag2198的评论,所以我从笛卡尔网格开始。然后我找到了相应的极坐标网格
然后我意识到问题是缺少向量场方程。所以我在谷歌上搜索了一下,找到了the Wikipedia page for the problem。以下公式给出了向量字段$$V$$:,其中$$\psi$$为
然后我去了Mathematica,算出了$$\del\psi$。然后我用python编写了它
然后,我使用
streamplot
不绘制NaN
值的事实,从向量场中删除了磁盘和外部区域最后是绘图的最后一部分
以下是最终产品:
通过$$x<;相反方向的0$$半点,我不明白为什么会出现这种情况。也许,我在坐标变换或函数中犯了一些错误
以下是便于复制粘贴的完整代码:
相关问题 更多 >
编程相关推荐