Hi every body, I write this code and I want to find a new Sol and Soll in iteration 1000 or more but the problem that the answer go to Nan?!

1 view (last 30 days)
clc
clear all
Npoiv=25;
Npoip=9;
Sol=zeros(75,1);
Soll=zeros(9,1);
deltt=0.01;
Reyn=1;
vis=1;
ntime=500;
SysM=rand(75,75);
SysD=rand(75,75);
SysF=rand(75,75);
SysL=rand(9,75);
SysLT=SysL';
SysK=rand(9,9);
for i=1:Npoiv
Sol(i)=0.000034;
Sol(i+Npoiv)=0;
Sol(i+2*Npoiv)=0.000033;
end
for i=1:Npoip
Soll(i)=0.0988;
end
for i=1:ntime
p=Soll;
SysM1=SysM*Sol;
SysD1=SysD*Sol;
SysL1=SysLT*Soll;
SysF1=SysF*Sol;
SysT=(deltt/2*Reyn)*(SysL1-(vis*SysD1)-(Reyn*SysF1))+SysM1;
a1=inv(SysM)*SysT;
SysD2=SysD*a1;
SysF2=SysF*a1;
SysT1=(deltt/Reyn)*(SysL1-(vis*SysD2)-(Reyn*SysF2))+SysM1;
a2=inv(SysM)*SysT1;
SysL2=SysL*a2;
SysK1=SysK*Soll;
SysN1=-(2*Reyn/deltt).*SysL2+SysK1;
Soll=inv(SysK)*SysN1;
SysM2=SysM*a2;
SysL3=SysLT*(Soll-p);
SysN=(deltt/2*Reyn)*SysL3+SysM2;
Sol=inv(SysM)*SysN;
ntime=i;
end
  1 Comment
Jan
Jan on 17 Jun 2022
Most likely not the cause of the problem, but a general hint: Do not use inv() explicitly. Replace
a1=inv(SysM)*SysT
% by
a1 = SysM \ SysT
Why do you set the final value of the loop ntime to the current loop index in each iteration?
ntime=i; % ???

Sign in to comment.

Answers (1)

Jan
Jan on 17 Jun 2022
Use the debugger to find the iteration, which causes the NaNs:
dbstop if naninf
Then Matlab stops, when the first NaN occurs. Now you can check the current values.

Community Treasure Hunt

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

Start Hunting!