python - why am I getting this error shape mismatch: two or more arrays have incompatible dimensions on axis 0 -
i've hat wave given initial conditions. x , y between 0.5 , 1, u = 2, otherwise u = 1. x , y vary 0 2.
the wave time dependent plotting pausing clearing 3d graph.
here code:
# import modules required import numpy np import matplotlib.pyplot plt import pylab py mpl_toolkits.mplot3d import axes3d #define grid x = np.linspace(0,2,21) y = np.linspace(0,2,21) u = np.ones((21,21)) c = 1 dt = 0.01 dx = 0.1 dy = 0.1 #initial conditions in range (21): if (0.5<=x[i]<=1): j in range (21): if (0.5<=y[j]<=1): u[i,j] = 2 #prop , plot = np.ones((21,21)) f in range (100): in range (21): j in range (21): up[i,j] = u[i,j] - ((c*dt)/(dx))*(u[i,j] - u[i-1,j]) - ((c*dt)/(dy))*(u[i,j] - u[i,j-1]) u = fig = plt.figure(figsize=(11,7), dpi=100) ax = fig.gca(projection='3d') x,y = np.meshgrid(x,y) surf = ax.plot_wireframe(x,y,u[:]) plt.show()
you getting error because ax.plot_wireframe uses np.broadcast_arrays expects input arrays have same shape. what's happening each iteration of for f in range (100): line x,y = np.meshgrid(x,y) changing shape of x , y. paste these lines code , see yourself.
print x.shape, y.shape x,y = np.meshgrid(x,y) print x.shape, y.shape try moving x,y = np.meshgrid(x,y) out of loop.
#prop , plot = np.ones((21,21)) x,y = np.meshgrid(x,y) f in range (100): in range (21): j in range (21): up[i,j] = u[i,j] - ((c*dt)/(dx))*(u[i,j] - u[i-1,j]) - ((c*dt)/(dy))*(u[i,j] - u[i,j-1]) u = fig = plt.figure(figsize=(11,7), dpi=100) ax = fig.gca(projection='3d') surf = ax.plot_wireframe(x,y,u[:]) plt.show()
Comments
Post a Comment