pseudonym
11 Dec 2004, 1:54am
I hope some of you know Matlab, because this is starting to drive me nuts. The project is for my heat transfer class and the job is to do a program that calculates the change in temperature of a piece of metal. Now I believe that my equations are right, so thats not the problem, but when I run the program the second iteration causes many of the elements in the matrix to go from 513 (inital temp) to zero. So I end up with some funky matrix that looks like this (in much shortened form, in reality its 30x82 from this program and in the end it will be 460000x82. The first row is all 513 because that is inital temp, it should increase after the first iteration)
513 513 513 513 513 513 513
522 519 0 0 0 0 0
And so on. Every once in awhile the point in the matrix works but backwards and temperature decreases to a very low number rather than the increase I'm supposed to see. Anyways, I'm starting to think the problem is in the code because I can manually load the matrix and run the equations manually on the nodes where it zeroes out and it works fine. Can someone see a problem with this program? I believe its in the elseif statements and it must be a usage problem, but I'm not sure why it zeroes out nodes.
clear all
clc
format long
k=186;
rhoc=2907180;
deltx=.0009091;
delty=.0005;
deltt=.0008;
Tinfpre=893;
sigma=.0000000567;
epsilon=.8;
%Conduction(sidenodes)=(((2*deltt*(1.3*(Tinfpre-Tpre(m-1,n))^.33)+4*epsilon*sigma*((Tinfpre+Tpre(m-1,n))/2)^3))/(rhoc*deltx))*(Tinfpre-Tpre(m-1,n))
%Conduction(topnodes)= (((2*deltt*(1.3*(Tinfpre-Tpre(m-1,n))^.33)+4*epsilon*sigma*((Tinfpre+Tpre(m-1,n))/2)^3))/(rhoc*delty))*(Tinfpre-Tpre(m-1,n))
alpha=k/(rhoc);
taux=(deltt*alpha)/(deltx^2);
tauy=(deltt*alpha)/(delty^2);
for n=1:82
Tpre(1,n)=513;
end
for m=2:30
for n=1:82
if n==1
Tpre(m,n)=2*tauy*(Tpre(m-1,n+1)-Tpre(m-1,n))+2*taux*(Tpre(m-1,n+6)-Tpre(m-1,n))+Tpre(m-1,n);
elseif n==2,3,4,5
Tpre(m,n)=2*tauy*(Tpre(m-1,n-1)-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n+1)-Tpre(m-1,n))+2*taux*(Tpre(m-1,n+6)-Tpre(m-1,n))+Tpre(m-1,n);
elseif n==6
Tpre(m,n)=(((2*deltt*(1.3*(Tinfpre-Tpre(m-1,n))^.33)+4*epsilon*sigma*((Tinfpre+Tpre(m-1,n))/2)^3))/(rhoc*delty))*(Tinfpre-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n-1)-Tpre(m-1,n))+2*taux*(Tpre(m-1,n+6)-Tpre(m-1,n))+Tpre(m-1,n);
elseif n==12,18,24,30,36,42,48,54,60,66
Tpre(m,n)=(((2*deltt*(1.3*(Tinfpre-Tpre(m-1,n))^.33)+4*epsilon*sigma*((Tinfpre+Tpre(m-1,n))/2)^3))/(rhoc*delty))*(Tinfpre-Tpre(m-1,n))+2*taux*(Tpre(m-1,n-6)-Tpre(m-1,n))+2*taux*(Tpre(m-1,n+6)-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n-1)-Tpre(m-1,n))+Tpre(m-1,n);
elseif n==7,13,19,25,31,37,43,49,55,61
Tpre(m,n)=2*taux*(Tpre(m-1,n-6)-Tpre(m-1,n))+2*taux*(Tpre(m-1,n+6)-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n+1)-Tpre(m-1,n))+Tpre(m-1,n);
elseif n==8,9,10,11,14,15,16,17,20,21,22,23,26,27,28,29,32,33,34,35,38,39,40,41,44,45,46,47,50,51,52,53,56,57,58,59,62,63,64,65
Tpre(m,n)=(2*taux*(Tpre(m-1,n+6)-Tpre(m-1,n))+2*taux*(Tpre(m,n-6)-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n+1)-Tpre(m-1,n))+2*tauy*(Tpre(m,n-1)-Tpre(m-1,n)))+Tpre(m-1,n);
elseif n==67
Tpre(m,n)=2*taux*(Tpre(m-1,n-6)-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n+1)-Tpre(m-1,n))+Tpre(m-1,n);
elseif n==68,69,70,71
Tpre(m,n)=2*tauy*(Tpre(m-1,n-1)-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n+1)-Tpre(m-1,n))+2*taux*(Tpre(m-1,n-6)-Tpre(m-1,n))+Tpre(m-1,n);
elseif n==72
Tpre(m,n)=(((2*deltt*(1.3*(Tinfpre-Tpre(m-1,n))^.33)+4*epsilon*sigma*((Tinfpre+Tpre(m-1,n))/2)^3))/(rhoc*deltx))*(Tinfpre-Tpre(m-1,n))+2*taux*(Tpre(m-1,n-6)-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n-1)-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n+1)-Tpre(m-1,n))+Tpre(m-1,n);
elseif n==73,74,75,76,77,78,79,80,81
Tpre(m,n)=(((2*deltt*(1.3*(Tinfpre-Tpre(m-1,n))^.33)+4*epsilon*sigma*((Tinfpre+Tpre(m-1,n))/2)^3))/(rhoc*deltx))*(Tinfpre-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n+1)-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n-1)-Tpre(m-1,n))+Tpre(m-1,n);
elseif n==82
Tpre(m,n)=(((2*deltt*(1.3*(Tinfpre-Tpre(m-1,n))^.33)+4*epsilon*sigma*((Tinfpre+Tpre(m-1,n))/2)^3))/(rhoc*deltx))*(Tinfpre-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n-1)-Tpre(m-1,n))+Tpre(m-1,n);
end
end
end
end
x=1:30;
plot(x,Tpre);
axis([0 30 -100 800]);
Also, heres a pic of what the nodes do. Notice some of them actually increase like they should, but others just drop. The culprits are under the one that drops instantly to 0. Why the zero out I have no clue. Any help is appreciated!!
513 513 513 513 513 513 513
522 519 0 0 0 0 0
And so on. Every once in awhile the point in the matrix works but backwards and temperature decreases to a very low number rather than the increase I'm supposed to see. Anyways, I'm starting to think the problem is in the code because I can manually load the matrix and run the equations manually on the nodes where it zeroes out and it works fine. Can someone see a problem with this program? I believe its in the elseif statements and it must be a usage problem, but I'm not sure why it zeroes out nodes.
clear all
clc
format long
k=186;
rhoc=2907180;
deltx=.0009091;
delty=.0005;
deltt=.0008;
Tinfpre=893;
sigma=.0000000567;
epsilon=.8;
%Conduction(sidenodes)=(((2*deltt*(1.3*(Tinfpre-Tpre(m-1,n))^.33)+4*epsilon*sigma*((Tinfpre+Tpre(m-1,n))/2)^3))/(rhoc*deltx))*(Tinfpre-Tpre(m-1,n))
%Conduction(topnodes)= (((2*deltt*(1.3*(Tinfpre-Tpre(m-1,n))^.33)+4*epsilon*sigma*((Tinfpre+Tpre(m-1,n))/2)^3))/(rhoc*delty))*(Tinfpre-Tpre(m-1,n))
alpha=k/(rhoc);
taux=(deltt*alpha)/(deltx^2);
tauy=(deltt*alpha)/(delty^2);
for n=1:82
Tpre(1,n)=513;
end
for m=2:30
for n=1:82
if n==1
Tpre(m,n)=2*tauy*(Tpre(m-1,n+1)-Tpre(m-1,n))+2*taux*(Tpre(m-1,n+6)-Tpre(m-1,n))+Tpre(m-1,n);
elseif n==2,3,4,5
Tpre(m,n)=2*tauy*(Tpre(m-1,n-1)-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n+1)-Tpre(m-1,n))+2*taux*(Tpre(m-1,n+6)-Tpre(m-1,n))+Tpre(m-1,n);
elseif n==6
Tpre(m,n)=(((2*deltt*(1.3*(Tinfpre-Tpre(m-1,n))^.33)+4*epsilon*sigma*((Tinfpre+Tpre(m-1,n))/2)^3))/(rhoc*delty))*(Tinfpre-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n-1)-Tpre(m-1,n))+2*taux*(Tpre(m-1,n+6)-Tpre(m-1,n))+Tpre(m-1,n);
elseif n==12,18,24,30,36,42,48,54,60,66
Tpre(m,n)=(((2*deltt*(1.3*(Tinfpre-Tpre(m-1,n))^.33)+4*epsilon*sigma*((Tinfpre+Tpre(m-1,n))/2)^3))/(rhoc*delty))*(Tinfpre-Tpre(m-1,n))+2*taux*(Tpre(m-1,n-6)-Tpre(m-1,n))+2*taux*(Tpre(m-1,n+6)-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n-1)-Tpre(m-1,n))+Tpre(m-1,n);
elseif n==7,13,19,25,31,37,43,49,55,61
Tpre(m,n)=2*taux*(Tpre(m-1,n-6)-Tpre(m-1,n))+2*taux*(Tpre(m-1,n+6)-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n+1)-Tpre(m-1,n))+Tpre(m-1,n);
elseif n==8,9,10,11,14,15,16,17,20,21,22,23,26,27,28,29,32,33,34,35,38,39,40,41,44,45,46,47,50,51,52,53,56,57,58,59,62,63,64,65
Tpre(m,n)=(2*taux*(Tpre(m-1,n+6)-Tpre(m-1,n))+2*taux*(Tpre(m,n-6)-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n+1)-Tpre(m-1,n))+2*tauy*(Tpre(m,n-1)-Tpre(m-1,n)))+Tpre(m-1,n);
elseif n==67
Tpre(m,n)=2*taux*(Tpre(m-1,n-6)-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n+1)-Tpre(m-1,n))+Tpre(m-1,n);
elseif n==68,69,70,71
Tpre(m,n)=2*tauy*(Tpre(m-1,n-1)-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n+1)-Tpre(m-1,n))+2*taux*(Tpre(m-1,n-6)-Tpre(m-1,n))+Tpre(m-1,n);
elseif n==72
Tpre(m,n)=(((2*deltt*(1.3*(Tinfpre-Tpre(m-1,n))^.33)+4*epsilon*sigma*((Tinfpre+Tpre(m-1,n))/2)^3))/(rhoc*deltx))*(Tinfpre-Tpre(m-1,n))+2*taux*(Tpre(m-1,n-6)-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n-1)-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n+1)-Tpre(m-1,n))+Tpre(m-1,n);
elseif n==73,74,75,76,77,78,79,80,81
Tpre(m,n)=(((2*deltt*(1.3*(Tinfpre-Tpre(m-1,n))^.33)+4*epsilon*sigma*((Tinfpre+Tpre(m-1,n))/2)^3))/(rhoc*deltx))*(Tinfpre-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n+1)-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n-1)-Tpre(m-1,n))+Tpre(m-1,n);
elseif n==82
Tpre(m,n)=(((2*deltt*(1.3*(Tinfpre-Tpre(m-1,n))^.33)+4*epsilon*sigma*((Tinfpre+Tpre(m-1,n))/2)^3))/(rhoc*deltx))*(Tinfpre-Tpre(m-1,n))+2*tauy*(Tpre(m-1,n-1)-Tpre(m-1,n))+Tpre(m-1,n);
end
end
end
end
x=1:30;
plot(x,Tpre);
axis([0 30 -100 800]);
Also, heres a pic of what the nodes do. Notice some of them actually increase like they should, but others just drop. The culprits are under the one that drops instantly to 0. Why the zero out I have no clue. Any help is appreciated!!