Please need help to detect the error in my code...

1 Ansicht (letzte 30 Tage)
Ambreen
Ambreen am 12 Jun. 2011
% 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));

Akzeptierte Antwort

Matt Fig
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
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.
Ambreen
Ambreen am 12 Jun. 2011
hmmmm ok i will try all the ideas you gave ...but still confused what to do ..and i have to submit this code tomorrow in my university ...aaahh much worried !!!!
well thanx a lot !

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices 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!

Translated by