need help with fft/ifft scaling

7 views (last 30 days)
weddle32
weddle32 on 16 Jan 2015
I am currently trying to solve a 3D poisson equation using spectral methods in 2 directions and finite difference in the third but am having some scaling problems.
To try and fix this i have reverted back to a very simple 1D poisson equation which i solve using finite difference. However i transform to fourier space to try and recreate my problem in a simpler way. code attached below
%define number of grid points
N=64;
%divide up grid
x=((0:N-1)/N)*2*pi;
%set step length
dx=2*pi/N;
%define RHS of poisson equation, u_xx=f
f=-sin(x);
%define analytic solution to compare with
f_comparison=sin(x);
%set error tolerance to be used in finite difference method
checker=10;
%set initial length of u array
u=zeros(1,N);
%set initial length of u_new array, used in updating gauss seidel
u_new=zeros(1,N);
%calculate fft of the rhs of poisson equation
f_hat=fftn(f);
%enter loop
while checker > 1*10^(-10);
%calculate fft of u_new
u_new_hat=fftn(u_new);
for a=1:N
q1=a+1;
q2=a-1;
%maintain periodic boundary conditions
if q2==0
q2=N;
end
if q1==N+1
q1=1;
end
%update using simple second order finite difference stencil
u_new_hat(a)=(0.5)*(u_new_hat(q1)+u_new_hat(q2)-((dx^2)*(f_hat(a))));
end
%calculate ifft to obtain result
u_new=real(ifftn(u_new_hat));
%calculate error tolerance
u_checker=abs(u_new-u);
%update maximun error to see if we can exit while loop
checker=max(u_checker)
%update solution
u=u_new;
end
%calculate scaling discrepency
ddd=f_comparison./u;
even with this very simple code i am still getting an incorrect answer compared to the analytic solution but am not sure why.
Does anyone have any eidea what might be causing this as i have tried multiple different scalings but seem to be getting nowhere
thanks

Answers (0)

Categories

Find more on Argument Definitions in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!