Printing final result after iteration
2 views (last 30 days)
Show older comments
Why is this displaying the result after each iteration rather than the final result only after the specified three iterations? How can I edit it to only print the matrix after the 3rd iteration? Thank you!!
clear;
HOLD=zeros(23,23);
HNEW=zeros(23,23);
R=zeros(23,23);
%Initial Value of matrix
for i=1:23
for j=1:23
HOLD(i,j)=10;
HNEW(i,j)=10;
end
end
R(22,2)=-0.2;
for RepeatNumber = 1 : 3
%implement implicit method
for i=2:22
for j=2:22
H2(i,j)=0.25*(HNEW(i,j+1)+HNEW(i,j-1)+HNEW(i-1,j)+HNEW(i-1,j-1));
HNEW(i,j)=(1/((100*100*0.002/4/300/0.1)+1))*(H2(i,j)+100*100*0.002/4/300/0.1*HOLD(i,j)+100*100*R(i,j)/4/300);
end
end
for i=2:22
for j=2:22
HOLD(i,j)=HNEW(i,j);
end
end
%No Flow Boundarys
for j=1:23
HOLD(1,:)=HOLD(3,:);
HOLD(23,:)=HOLD(21,:);
end
for i=1:23
HOLD(:,1)=HOLD(:,3);
HOLD(:,23)=HOLD(:,21);
end
%Need to repeat from line 14 a specified number of times.
end
for i=2:22
for j=2:22
HFINAL(i,j)=HOLD(i,j)
end
end
0 Comments
Accepted Answer
Joseph Cheng
on 28 Mar 2014
put the ; at the end of your HFINAL(i,j)=HOLD(i,j);
then after the for RepeatNumber =1:3 loop is finished do
disp('Final Matrix:');
disp(HFINAL);
0 Comments
More Answers (1)
Subhash
on 18 Aug 2022
While solving the maximize problem program is running succesfulynow how to display final results
0 Comments
See Also
Categories
Find more on Operators and Elementary Operations 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!