0

在我的函数圆柱流函数中,我得到了
(-V_inf*y[i,j]-(C_s/(2*pi))*log(sqrt((x[i,j]-S_1[0])**2+(y[i,j]-S_1[1])**2))
IndexError: too many indices for array 的输出

有人可以帮助解决这个问题吗?

import sympy as s
import matplotlib.pyplot as plt
import numpy as np
from sympy import sqrt
from sympy import log

S_1=[13.966 ,0.2359]
S_2=[13.7464 ,0.7247]
S_3=[14.0353 ,1.062]
S_4=[14.3243 ,1.2803]
S_5=[14.0657, 1.2803]
S_6=[13.8827 ,1.8382]
S_7=[13.67 ,2.2322]
S_8=[13.1772, 2.6921]
S_9=[12.2791 ,2.8433]
S_10=[11.6264 ,2.8433]
S_11=[11.3163 ,2.4508]
S_12=[11.3127 ,1.9264]
S_13=[11.2179 ,1.4682]
S_14=[11.3474 ,1.0634]
S_15=[11.3127 ,0.5757]
S_16=[11.1604 ,0.1907]

P_1=[7.9398 ,0.5117]
P_2=[7.4442 ,0.9823]
P_3=[6.9758 ,1.4271]
P_4=[6.5624 ,1.8197]
P_5=[6.1236 ,2.2364]
P_6=[5.7148 ,2.6248]
P_7=[4.9071 ,1.9994]
P_8=[4.1875 ,1.4424]
P_9=[3.3127 ,0.7654]
P_10=[2.5914 ,0.2072]

pi=s.pi

x = np.arange(0,20,0.1)
y = np.arange(0,10,0.05)



X,Y = np.meshgrid(x,y)
V_inf=25
C_s=2
C_p=3.25


for i in range(1,21):
        for j in range(1,11):

             (-V_inf*y[i,j]-(C_s/(2*pi))*log(sqrt((x[i,j]-S_1[0])**2+(y[i,j]-S_1[1])**2))
                   +(C_s/(2*pi))*log(sqrt((x[i,j]-S_1[0])**2+(y[i,j]+S_1[1])**2))
                     -(C_s/(2*pi))*log(sqrt((x[i,j]-S_2[0])**2+(y[i,j]-S_2[1])**2))
                +(C_s/(2*pi))*log(sqrt((x[i,j]-S_2[1])**2+(y[i,j]+S_2[1])**2))
                -(C_s/(2*pi))*log(sqrt((x[i,j]-S_3[0])**2+(y[i,j]-S_3[1])**2))
                    +(C_s/(2*pi))*log(sqrt((x[i,j]-S_3[0])**2+(y[i,j]+S_3[1])**2))
                -(C_s/(2*pi))*log(sqrt((x[i,j]-S_4[0])**2+(y[i,j]-S_4[1])**2))
                    +(C_s/(2*pi))*log(sqrt((x[i,j]-S_4[0])**2+(y[i,j]+S_4[1])**2))
                -(C_s/(2*pi))*log(sqrt((x[i,j]-S_5[0])**2+(y[i,j]-S_5[1])**2))
                    +(C_s/(2*pi))*log(sqrt((x[i,j]-S_5[0])**2+(y[i,j]+S_5[1])**2))
                -(C_s/(2*pi))*log(sqrt((x[i,j]-S_6[0])**2+(y[i,j]-S_6[1])**2))
                    +(C_s/(2*pi))*log(sqrt((x[i,j]-S_6[0])**2+(y[i,j]+S_6[1])**2))
                -(C_s/(2*pi))*log(sqrt((x[i,j]-S_7[0])**2+(y[i,j]-S_7[1])**2))
                    +(C_s/(2*pi))*log(sqrt((x[i,j]-S_7[0])**2+(y[i,j]+S_7[1])**2))
                -(C_s/(2*pi))*log(sqrt((x[i,j]-S_8[0])**2+(y[i,j]-S_8[1])**2))
                    +(C_s/(2*pi))*log(sqrt((x[i,j]-S_8[0])**2+(y[i,j]+S_8[1])**2))
                -(C_s/(2*pi))*log(sqrt((x[i,j]-S_9[0])**2+(y[i,j]-S_9[1])**2))
                    +(C_s/(2*pi))*log(sqrt((x[i,j]-S_9[0])**2+(y[i,j]+S_9[1])**2))
                -(C_s/(2*pi))*log(sqrt((x[i,j]-S_10[0])**2+(y[i,j]-S_10[1])**2))
                     +(C_s/(2*pi))*log(sqrt((x[i,j]-S_10[0])**2+(y[i,j]+S_10[1])**2))
                -(C_s/(2*pi))*log(sqrt((x[i,j]-S_11[0])**2+(y[i,j]-S_11[1])**2))
                     +(C_s/(2*pi))*log(sqrt((x[i,j]-S_11[0])**2+(y[i,j]+S_11[1])**2))
                -(C_s/(2*pi))*log(sqrt((x[i,j]-S_12[0])**2+(y[i,j]-S_12[1])**2))
                     +(C_s/(2*pi))*log(sqrt((x[i,j]-S_12[0])**2+(y[i,j]+S_12[1])**2))
                -(C_p/(2*pi))*log(sqrt((x[i,j]-P_1[0])**2+(y[i,j]-P_1[1])**2))
                    +(C_p/(2*pi))*log(sqrt((x[i,j]-P_1[0])**2+(y[i,j]+P_1[1])**2))
                -(C_p/(2*pi))*log(sqrt((x[i,j]-P_2[0])**2+(y[i,j]-P_2[1])**2))
                    +(C_p/(2*pi))*log(sqrt((x[i,j]-P_2[0])**2+(y[i,j]+P_2[1])**2))
                -(C_p/(2*pi))*log(sqrt((x[i,j]-P_3[0])**2+(y[i,j]-P_3[1])**2))
                    +(C_p/(2*pi))*log(sqrt((x[i,j]-P_3[0])**2+(y[i,j]+P_3[1])**2))
                -(C_p/(2*pi))*log(sqrt((x[i,j]-P_4[0])**2+(y[i,j]-P_4[1])**2))
                    +(C_p/(2*pi))*log(sqrt((x[i,j]-P_4[0])**2+(y[i,j]+P_4[1])**2))
                -(C_p/(2*pi))*log(sqrt((x[i,j]-P_5[0])**2+(y[i,j]-P_5[1])**2))
                    +(C_p/(2*pi))*log(sqrt((x[i,j]-P_5[0])**2+(y[i,j]+P_5[1])**2))
                -(C_p/(2*pi))*log(sqrt((x[i,j]-P_6[0])**2+(y[i,j]-P_6[1])**2))
                    +(C_p/(2*pi))*log(sqrt((x[i,j]-P_6[0])**2+(y[i,j]+P_6[1])**2))
                -(C_p/(2*pi))*log(sqrt((x[i,j]-P_7[0])**2+(y[i,j]-P_7[1])**2))
                    +(C_p/(2*pi))*log(sqrt((x[i,j]-P_7[0])**2+(y[i,j]+P_7[1])**2))
                -(C_p/(2*pi))*log(sqrt((x[i,j]-P_8[0])**2+(y[i,j]-P_8[1])**2))
                    +(C_p/(2*pi))*log(sqrt((x[i,j]-P_8[0])**2+(y[i,j]+P_8[1])**2))
                -(C_p/(2*pi))*log(sqrt((x[i,j]-P_9[0])**2+(y[i,j]-P_9[1])**2))
                    +(C_p/(2*pi))*log(sqrt((x[i,j]-P_9[0])**2+(y[i,j]+P_9[1])**2))
                -(C_p/(2*pi))*log(sqrt((x[i,j]-P_10[0])**2+(y[i,j]-P_10[1])**2))
                +(C_p/(2*pi))*log(sqrt((x[i,j]-P_10[0])**2+(y[i,j]+P_10[1])**2))
                -(C_s/(2*pi))*log(sqrt((x[i,j]-S_13[0])**2+(y[i,j]-S_13[1])**2))
                +(C_s/(2*pi))*log(sqrt((x[i,j]-S_13[0])**2+(y[i,j]+S_13[1])**2))
                -(C_s/(2*pi))*log(sqrt((x[i,j]-S_14[0])**2+(y[i,j]-S_14[1])**2))
                +(C_s/(2*pi))*log(sqrt((x[i,j]-S_14[0])**2+(y[i,j]+S_14[1])**2))
                -(C_s/(2*pi))*log(sqrt((x[i,j]-S_15[0])**2+(y[i,j]-S_15[1])**2))
                +(C_s/(2*pi))*log(sqrt((x[i,j]-S_15[0])**2+(y[i,j]+S_15[1])**2))
                -(C_s/(2*pi))*log(sqrt((x[i,j]-S_16[0])**2+(y[i,j]-S_16[1])**2))
                +(C_s/(2*pi))*log(sqrt((x[i,j]-S_16[0])**2+(y[i,j]+S_16[1])**2)))
        psi+=psi



def velocity_field(psi):
    u=s.lambdify((x,y), psi.diff(y), 'numpy')
    v=s.lambdify((x,y), -psi.diff(x), 'numpy')
    return u,v


def plot_streamlines(ax, u, v,xlim=(-1,1), ylim=(-1,1)):
    x0, x1=xlim
    y0, y1=ylim
    Y,X= np.ogrid[y0:y1:100j,x0:x1:100j]
    ax.streamplot(X,Y,u(X,Y),v(X,Y),color='red')
def format_axes(ax):
    ax.set_aspect('equal')
    ax.figure.subplots_adjust(bottom=0, top=1, left=0, right=1)
    ax.xaxis.set_ticks([])
    ax.yaxis.set_ticks([])
    for spine in ax.spines.values():
        spine.set_visible(False)
psi=cylinder_stream_fct()
u,v=velocity_field(psi)
xlim=ylim=(-3,3)
fig, ax=plt.subplots(figsize=(4, 4))
plot_streamlines(ax, u, v, xlim, ylim)
c=plt.Circle((0,0), radius=1,facecolor='none')
ax.add_patch(c)

format_axes(ax)
plt.show()
4

1 回答 1

0

根据https://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html,排列函数返回一维列表,所以当然 y[i,j] 是无效的。此外,如果你想得到列表 y 的第 i 个元素的第 j 个,它应该是 y[i][j]

于 2019-11-23T12:29:03.503 回答