C C C C C

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

% This program is used for finding the temperatures at nodal

%points of a 2-D plate when temperatures at two sides are known

%and heat flux at the other two sides are zero. The user has to

%input values of the known temperatures as well as the size and

%number of elements of the plate.

syms i nex ney nnodex nnodey cord k j N G lengthx lengthy lx ly

syms K m l B A ii jj g F U V Ttop Tright R solution Node R2 y kt GR1

syms GR2 u v Rm G2 Gm2 Twall Re Rm Rm1 o

nex=input('x direction ');

ney=input('y direction ');

lx=input('total length ');

ly=input('total length ');

Ttop=input('top temperature ');

Tright=input('right temperature ');

lengthx=lx/nex;

lengthy=ly/ney;

nnodex=nex+1;

nnodey=ney+1;

ne=2*nex*ney;

n=nnodex*nnodey;

l=1;

for m=1:nnodex

for j=1:nnodey

cord(l,1)=(m-1)*lengthx;

cord(l,2)=(j-1)*lengthy;
l=l+1;

end

end

k=1;

for j=0:ney+1:(nex-1)*(ney+1)

for i= 1:ney

N(k,1)=i+j;

N(k,2)=i+j+ney+1;

N(k,3)=i+j+ney+2;

k=k+2;

end

end

k=2;

for j=0:ney+1:(nex-1)*(ney+1)

for i= 1:ney

N(k,1)=i+j+ney+2;

N(k,2)=i+j+1;

N(k,3)=i+j;

k=k+2;

end

end

disp(N)

B=[1,cord(1,1),cord(1,2);1,cord(1+ney+1,1),cord(1+ney+1,2);1,cord(1+ney+2,1),cord(1+ney+2,2);];

A=inv(B);

D=det(B);

for i=1:3
for j=1:3

K(i,j)=[A(2,i)*A(2,j)+A(3,i)*A(3,j)]*(D/2);

end

end

G = sparse(n,n);

for k=1:ne

for i=1:3

ii=N(k,i);

for j=1:3

jj=N(k,j);

G(ii,jj)=G(ii,jj)+K(i,j);

end

end

end

Gm=G;

disp(G)

for i=2*nnodex:nnodex:nnodex*nnodex

for j=1:n

Gm(i,j)=0;

end

Gm(i,i)=1;

end

for i=n-ney+1:n-1

for j=1:n

Gm(i,j)=0;

end
Gm(i,i)=1;

end

for i=1:n

R(i,1)=0;

end

for i=2*nnodex:nnodex:nnodex*nnodex

R(i,1)=Ttop;

end

for i=n-ney+1:n-1

R(i,1)=Tright;

end

for i=1:n

R(i,1)=0;

end

for i=2*nnodex:nnodex:nnodex*nnodex

R(i,1)=Ttop;

end

for i=n-ney+1:n-1

R(i,1)=Tright;

end

T = sym(zeros(n, 1));

for k = 1:n

T(k) = sym(sprintf('T%d', k));

end

solution=inv(Gm)*R;

disp('The temperatures are');

disp(solution);
gradient=G*solution;

gradient(:) = round(100000*gradient(:))/100000;

disp(gradient);

end

You might also like