Please need help to detect the error in my code...
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
% 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 comentarios
Respuesta aceptada
Matt Fig
el 12 de Jun. de 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 comentarios
Matt Fig
el 12 de Jun. de 2011
I think you will ultimately end up with at most two WHILE loops, assuming you have some convergence criterion.
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!