Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your problem is that X[i] and Y[i] are 1-d arrays that you pass in to H as n. I.e., n = [X[i], Y[i]]. Then you call complex(n[0], n[1]) which expects scalar arguments, not arrays. If you intend for n to be a 1-d array of complex numbers, you can write n = n[0] + 1j*n[1]. You still need modifications to the rest of your code, however. You're missing some imports and seem to have assumed "from numpy import *"</p> <p>Anyway, I've made enough modifications to get it to run and plot <em>something</em>, but I really doubt this is what you're looking for. You need to think about what function it is you're trying to plot.</p> <pre><code>from mpl_toolkits.mplot3d import axes3d import matplotlib.pyplot as plt from matplotlib import cm import numpy def H(n, f, l, delta, H_abs, H_ph): c0 = 2.99796e8 n0 = 1.00027 + 0j n1 = n[0] + 1j * n[1] Sum = 0 for i in range(1, delta+1): Sum = Sum + ((n0-n1)*numpy.exp(-1*2*numpy.pi*f*n1*l/c0)/(n1+n0))**i H_Theo = 4*n0*n1*numpy.exp(2*numpy.pi*f*l*(n0-n1)/c0)*(1+Sum)/(n0+n1) M = numpy.abs(H_Theo) - H_abs A = numpy.angle(H_Theo) - H_ph return abs(M) + abs(A) freq = 1213188709257.4814 l_real = 6.77e-4 d = 0 H_abs = 0.798653104536778 H_ph = 2.1845744701729926 n_test = numpy.arange(1.5, 2.5, 0.01).tolist() k_test = numpy.arange(-0.05, 0.05, 0.001).tolist() X = n_test Y = k_test X, Y = numpy.meshgrid(X, Y) errore = [] for i in range(len(n_test)): errore.append(H([X[i],Y[i]], freq, l_real, d, H_abs, H_ph)) Z = errore fig2 = plt.figure() az = fig2.gca(projection='3d') az.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3) cset = az.contour(X, Y, Z, zdir='z', offset=numpy.min(Z)-1, cmap=cm.coolwarm) cset = az.contour(X, Y, Z, zdir='x', offset=numpy.min(X)-1, cmap=cm.coolwarm) cset = az.contour(X, Y, Z, zdir='y', offset=numpy.max(Y)+0.05, cmap=cm.coolwarm) az.set_xlabel('n') az.set_xlim(numpy.min(X)-1, numpy.max(X)+1) az.set_ylabel('k') az.set_ylim(numpy.min(Y)-0.05, numpy.max(Y)+0.05) az.set_zlabel('Err') az.set_zlim(numpy.min(Z)-1, numpy.max(Z)+1) plt.show() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload