필터 지우기
필터 지우기

I am getting NaN values after some iterations in my loop

조회 수: 2 (최근 30일)
Lovelesh Lovelesh
Lovelesh Lovelesh 2021년 5월 3일
댓글: Matt J 2021년 5월 3일
I get NaN values after few iterations using fourier transform this happens every time I add the fourier transform of V*psi into the equation for that I am using fft fxn
X=(-M/2:M/2-1)*dx;
dk=2*pi/(M*dx);
K=(-M/2:M/2-1)*dk;
psi=(1/sqrt(2)).*randn(1,M)+(i/sqrt(2)).*randn(1,M);
V=(X.^2)/2;
Tmax=40;
dt=0.004;
Nt=round(Tmax/dt);
Fpsi=zeros(Nt+1,M);
FVpsi=zeros(Nt,M);
Fpsisq=zeros(Nt,M);
for t=1:Nt
Fpsi(t,:)=fft(psi(t,:));
FVpsi(t,:)=fft(V.*psi(t,:));
Fpsisq(t,:)=fft((abs(psi(t,:)).^2).*psi(t,:));
Fpsi(t+1,:)=Fpsi(t,:)+dt.*(K.*K.*Fpsi(t,:)+FVpsi+g.*Fpsi);
psi(t+1,:)=ifft(Fpsi(t+1,:));
end

답변 (1개)

Matt J
Matt J 2021년 5월 3일
To find out where they are first introduced, you can use,
>> dbstop if naninf
  댓글 수: 2
Lovelesh Lovelesh
Lovelesh Lovelesh 2021년 5월 3일
But it do not give the right results then because iterations becomes very less
Matt J
Matt J 2021년 5월 3일
It's supposed to stop before finishing.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by