Please need help to detect the error in my code...
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
% TO WRITE A CODE FOR LAPLACE HEAT FLOW EQUATION FOR ANY ORDER nxn OF GRID,USING ITERATION METHOD ,TO FIND TEMP. AT UNKNOWN POINTS OF GRID
s1=input('Enter the temperature for the top of the 3x3 grid in degress:');
s2=input('Enter the temperature for the bottom of the 3x3 grid in degress:');
s3=input('Enter the temperature for the left of the 3x3 grid in degress:');
s4=input('Enter the temperature for the right of the 3x3 grid in degress:');
n=input('Enter n ');
for b=0:n-1
a=0;
s1=U(a,b);
% assigning respective temps. to boundry points
for a=0:n-1
b=n;
U(a,b)=s4;
for b=1:n
a=n;
U(a,b)=s3;
for a=1:n
b=0;
U(a,b)=s4;
for a=1:n-1
for b=1:n-1 %assigning zero as initial value to the % unknown internal points of grid
U(a,b)=0;
for k=0:200
for a=1:n-1
for b=1:n-1
U_it(a,b)=(1/4)*(U(a+1,b)+U(a-1,b)+U(a,b+1)+U(a,b-1));
disp('------------Iteartion ---------------');
k=k+1;
disp(U_it_(a,b));
if (abs(U(a,b)-U_it(a,b))<0.000001) %condition
U(a,b)=U_it(a,b);
break %stop iterations here
else
U(a,b)=U_it(a,b); %continue doing this process
end
end
end
end
end
end
end
end
end
end
fprintf('temp. at the unknown point is %g ',U(a,b));
0 Kommentare
Akzeptierte Antwort
Matt Fig
am 12 Jun. 2011
The error is that you are indexing into the array U with 0. There may be logical errors involved as well. You have nested loops with the same loop index (a and b). Usually this is not desired. Did you really mean to do this? Are 9 layers of nesting really necessary for your problem?
17 Kommentare
Matt Fig
am 12 Jun. 2011
I think you will ultimately end up with at most two WHILE loops, assuming you have some convergence criterion.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!