python - Wireframe plots -


the program calculates reflection coefficient of multilayer system, depending on thickness of 50 layers (d1, d2). if take 2 numbers (d1,d2), works correct. need wireframe plots, d1, d2 takes meaning in range, error: "valueerror: input must square array" in line 13. how can fix it?

from math import pi import numpy np import matplotlib.pyplot plt  def r(n1, n2, d1, d2, lamda):     phy1 = (-2*pi*n1*d1/lamda)     phy2 = (-2*pi*n2*d2/lamda)     dpd1 = 0.5*np.array([[2*np.cos(phy1),   2j*np.sin(phy1)/n1],    [n1*2j*np.sin(phy1),  2*np.cos(phy1) ]])     dpd2 = 0.5*np.array([[2*np.cos(phy2),   2j*np.sin(phy2)/n2],   [n2*2j*np.sin(phy2),  2*np. cos(phy2) ]])     d0 = 0.5 * np.array([[1, 1], [1, -1]])     ds = np.array([[1, 1], [n1, -n1]])     dpd = np.dot(dpd1, dpd2)     dpd = np.linalg.matrix_power(dpd, 50)     m = np.dot(d0, dpd)     m = np.dot(m, ds)     return(abs(m[1,0]/m[0,0])**2)  x = np.arange(0, 10, 1) y = np.arange(0, 10, 1) x, y = np.meshgrid(x, y) z = r(0.99910053+0.00183184j,  0.92373900+0.00644652j, x, y, 13.5) fig = plt.figure() ax = fig.gca(projection='3d') surf = ax.plot_wireframe(x, y, z, antialiased=true) 

i don't know how without loop. here solution:

from math import pi import numpy np import matplotlib.pyplot plt mpl_toolkits.mplot3d import axes3d  def r(n1, n2, d1, d2, lamda):     phy1 = (-2*pi*n1*d1/lamda)     phy2 = (-2*pi*n2*d2/lamda)     dpd1 = 0.5*np.array([[2*np.cos(phy1),   2j*np.sin(phy1)/n1],    [n1*2j*np.sin(phy1),  2*np.cos(phy1) ]])     dpd2 = 0.5*np.array([[2*np.cos(phy2),   2j*np.sin(phy2)/n2],   [n2*2j*np.sin(phy2),  2*np. cos(phy2) ]])     dpd = np.dot(dpd1, dpd2)     dpd = np.linalg.matrix_power(dpd, 50)     d0 = 0.5 * np.array([[1, 1], [1, -1]])     ds = np.array([[1, 1], [n1, -n1]])     m = np.dot(d0, dpd)     m = np.dot(m, ds)     return(abs(m[1,0]/m[0,0])**2)  x = np.arange(0, 10, 1) y = np.arange(0, 10, 1) x, y = np.meshgrid(x, y) z = np.zeros(x.shape).ravel() i, (x, y) in enumerate(zip(x.ravel(), y.ravel())):     z[i] = r(0.99910053+0.00183184j,  0.92373900+0.00644652j, x, y, 13.5) fig = plt.figure() ax = fig.gca(projection='3d') surf = ax.plot_wireframe(x, y, z.reshape(x.shape), antialiased=true) plt.show() 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -