I am loading a text file but some of my results are being shown as NaN. This is my code:
clear all;close all;test=0.001;imax=13;kmax=4;load('hcrdat.txt');q=hcrdat(:,1);d=hcrdat(:,2);r=hcrdat(:,3);%q=[250 250 100 50 100 25 25 25 45 70 80 30 20];
%d=[.4,.4,.3,.3,.3,.2,.2,.2,.3,.3,.3,.2,.2];
%r=[96.8,96.8,306,306,306,3098,3098,3098,306,312,306,9295,3098];
m=zeros(kmax,imax);iter=0;for n=1:500 iter=iter+1; difmax=0; %DISCHARGE CORRECTIONS IN EACH LOOP
for k=1:kmax sum1=0; sum2=0; for i=1:imax t=m(k,i); sum1=sum1+t*r(i)*q(i)^2; sum2=sum2+2*abs(t)*q(i)*r(i); end dq=-sum1/sum2; if abs(dq)>difmax difmax=abs(dq); end for i=1:imax q(i)=q(i)+m(k,i)*dq; %CHANGE OF ASSUMED DISCHARGE DIRECTION AND PROPER CORRECTIONS
if q(i)<0 q(i)=-q(i); end for kk=1:kmax m(kk,i)=-m(kk,i); end end end it=n; diff(it)=difmax; %CHECK FOR CONVERGENCE TO FINAL DISCHARGE VALUES
if difmax<test break endendfor i=1:imax % FLOW VELOCITIES IN THE VARIOUS BRANCHES
u(i)=q(i)/1000*1.273/d(i)^2; % HEAD LOSSES IN EACH BRANCH
dh(i)=r(i)*q(i)^2/1000000;end
= = = = = = = = = = = = = = = = = = =
The data in the text file (hcrdat.txt) is:
250, .4, 96.8250, .4, 96.8100, .3, 30650, .3, 306100, .3, 30625, .2, 309825, .2, 309825, .2, 309845, .3, 30670, .3, 61280, .3, 30630, .2, 929520, .2, 3098
= = = = = = = = = = = = = = = = = = =
My results for sum1, sum2 and dq are NaN and the problem is because q is being loaded as NaN.
Best Answer