Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1 MATLAB Code
clc
clear
la=input('length of the material A in meters=');
ka=input('enter the thermal conductivity of the material A=');
lb=input('length of the material B in meters=');
kb=input('enter the thermal conductivity of the material B=');
lc=input('length of the material C in meters=');
kc=input('enter the thermal conductivity of the material C=');
tf=input('enter the temp of the fluid=');
t2=input('enter the temp at boundary 2=');
h=input('enter heat transfer coefficient between fluid and matl A=');
ma=input('no. of control volumes for material A=');
mb=input('no. of control volumes for material B=');
mc=input('no. of control volumes for material C=');
dxa=la/ma;
dxb=lb/mb;
dxc=lc/mc;
aea=ka/dxa;
awa=aea;
apa=aea+awa;
aea1=2*aea;
awa1=2*awa;
apa1=awa1+aea;
apa2=aea+aea1;
aeb=kb/dxb;
awb=aeb;
apb=aeb+awb;
aeb1=2*aeb;
awb1=2*awb;
apb1=awa1+aeb;
apb2=aeb+aeb1;
aec=kc/dxc;
awc=aec;
apc=aec+awc;
aec1=2*aec;
awc1=2*awc;
apc1=awc1+aec;
apc2=aec+aec1;
apab=awa+aeb;
apbc=awb+aec;
apo=awa1+h;
na=ma+2;
nb=mb+1;
nc=mc+1;
n=na+nb+nc;
old_m=zeros(n,n);
old_m(1,1)=apo;
for i=2:na
old_m(i,(i-1))=-awa;
old_m((i-1),i)=-aea;
old_m(i,i)=apa;
end
old_m(2,1)=-awa1;
old_m(1,2)=-aea1;
old_m((na-1),na)=-aea1;
old_m(2,2)=apa1;
old_m(na,na)=apab;
old_m((na-1),(na-1))=apa2;
for i=(na+1):(na+nb)
old_m(i,i)=apb;
old_m((i-1),i)=-aeb;
old_m(i,(i-1))=-awb;
end
old_m((na+1),(na+1))=apb1;
old_m((na+nb-1),(na+nb-1))=apb2;
old_m((na+1),na)=-awa1;
old_m((na+nb-1),(na+nb))=-aeb1;
old_m((na+nb),(na+nb))=apbc;
for i=(na+nb+1):(n-1)
old_m(i,i)=apc;
old_m((i-1),i)=-aec;
old_m(i,(i-1))=-awc;
end
old_m((na+nb+1),(na+nb+1))=apc1;
old_m((n-1),(n-1))=apc2;
old_m((na+nb+1),(na+nb))=-awc1;
old_m((n-1),n)=-aec1;
old_m(n,n)=1;
old_m
c=zeros(n,1);
c(1,1)=h*tf;
c(n,1)=t2;
T=inv(old_m)*c;
T
N=1:n;
plot(N,T,'o');
grid on;
%C matrix
c(1)=2*kw(1)*Ta;
c(m)=2*ke(m)*Tb;
new_m=inv(old_m)*c;
T1(1)=Ta;
T1(n)=Tb;
for i=2:n-1
T1(i)=new_m(i-1);
end
%convergence matrix
for i=1:n
T2(i)=sqrt(((Told(i)-T1(i))^2)/m);
end
A=max(T2);
%check for convergence
if A<conv
break
end
%redefine Told
for i=1:n
Told(i)=T1(i);
end
end
T1
N=1:n;
plot(N,T1);
grid on
hold on
xlabel('Node Points');
ylabel('Temperature');
plot(N,T1,'o');