我比较了 2 种方法来解决一维泊松方程。一种是有限差分法,来自http://www.cs.berkeley.edu/~demmel/cs267/lecture24/lecture24.html的“Successive Overrelaxation” ;另一种方法是 FFT 的光谱法,它的速度要快得多。以下是我生成图片中解决方案的matlab/octave代码。显然,传统的有限差分法(中图)更容易接受!为什么 FFT 方法看起来像这样?FFT解决方案是否可以正确执行?谢谢!!
以下是我的matlab代码:::
clear all;
x=1:1000;
vort=exp(-(x-600).^2/50^2);% right hand side of poisson eq
% construct the wave number series, dx = 1 in this case
kx=(x-1);
jj=find(kx>500);
kx(jj)=kx(jj)-1000;
kx=2*pi/1000*kx;
subplot(311);plot(x,vort);title('rhs of Poisson eq','fontsize',20)
% ------------S.O.R solver----------
psi=zeros(1,1000);
for n=1:100
for i=2:999
r=(psi(i-1)+psi(i+1)-vort(i))*0.5-psi(i);
psi(i)=psi(i)+1.2*r;
end
end
subplot(312);plot(x,psi);title('Successive Overrelaxation','fontsize',20)
% ------ FFT solver -----%
slice=-fft(vort)./(kx.^2);
slice(1)=0;
subplot(313);plot(real(ifft(slice)));;title('FFT method','fontsize',20)
