Минимально воспроизводимый пример:
Код: Выделить всё
import numpy as np
import matplotlib.pyplot as pl
def min_pot(x: np.ndarray, y: np.ndarray):
xbig, ybig = np.meshgrid(x, y)
r = np.sqrt(np.square(xbig) + np.square(ybig))
r0 = np.unravel_index(np.argmin(r, axis=None), r.shape)
test = np.exp(-r)*np.reciprocal(r)
test[r0] = 2*test[r0[0]+1, r0[0]] - test[r0[0]+2, r0[0]] #this suppresses the r=0 singularity
return test
x_min = np.linspace(-20, 20, num=1001)
y_min = np.linspace(-20, 20, num=1001)
real_a = min_pot(x_min, y_min)
shift_a = np.fft.ifftshift(real_a)
fourier_a = np.fft.fftshift(np.fft.fft2(np.fft.fftshift(real_a), norm="forward"))
kx = np.fft.fftshift(np.fft.fftfreq(len(x_min), d=(x_min[1]-x_min[0])))
#we represent a cut in the x axis
analytic = np.power(np.square(kx) + 1, -.5)
max_real = np.amax(fourier_a[fourier_a.shape[0]//2, :].real # normalization to compare curve shapes better
fig, ax = pl.subplots(1, 1)
ax.plot(kx, fourier_a[fourier_a.shape[0]//2, :].real/max_real), label='Real fft')
ax.plot(kx, fourier_a[fourier_a.shape[0]//2, :].imag/max_imag), label='Imag. fft')
ax.plot(kx, analytic, label='Analytic')
pl.legend()
pl.show()

Кто-нибудь знает, что я делаю неправильно?>