1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- from scattnlay import scattcoeffs
- import numpy as np
- size = np.arange(0.25, 100.25, 0.25)
- x = np.ones((len(size), 5), dtype = np.float64)
- x[:, 0] = 0.1**(1.0/3.0)*size
- x[:, 1] = 0.36**(1.0/3.0)*size
- x[:, 2] = 0.404**(1.0/3.0)*size
- x[:, 3] = 0.7706**(1.0/3.0)*size
- x[:, 4] = size
- m = np.ones((len(size), 5), dtype = np.complex128)
- m[:, 0] *= 1.8 + 1.7j
- m[:, 1] *= 0.8 + 0.7j
- m[:, 2] *= 1.2 + 0.09j
- m[:, 3] *= 2.8 + 0.2j
- m[:, 4] *= 1.5 + 0.4j
- terms, an, bn = scattcoeffs(x, m, 105)
- result = np.vstack((x[:, 4], an[:, 0].real, an[:, 0].imag, an[:, 1].real, an[:, 1].imag, an[:, 2].real, an[:, 2].imag,
- bn[:, 0].real, bn[:, 0].imag, bn[:, 1].real, bn[:, 1].imag, bn[:, 2].real, bn[:, 2].imag)).transpose()
- try:
- import matplotlib.pyplot as plt
- plt.figure(1)
- for i in range(3):
- plt.subplot(310 + i + 1)
- plt.plot(x[:, 4], an[:, i].real, label = "Re(a$_%i$)" % (i + 1))
- plt.plot(x[:, 4], bn[:, i].real, label = "Re(b$_%i$)" % (i + 1))
- plt.plot(x[:, 4], an[:, i].imag, label = "Im(a$_%i$)" % (i + 1))
- plt.plot(x[:, 4], bn[:, i].imag, label = "Im(b$_%i$)" % (i + 1))
- plt.ylabel('n = %i' % (i + 1))
- plt.legend()
- plt.xlabel('X')
-
- plt.show()
- finally:
- np.savetxt("scattcoeffs.txt", result, fmt = "%.5f")
- print result
|