Explicity method for diffusion problem

I am totally new in matlab and I have to write the explicit method for diffusion in matlab. I have did what i know and learned in matlab by different resources.
Could you guys check the code and see if it is good.
l=0.2; % length in meter
nx=40; % number of thickness step
nt=10; % number of time step
dx=l/(nx-1);
dt=0.1;
T_in=22; % C
h_out=34; % W./m2
h_in=10;
T_out=34; % outdoor temperature
abs=0.2; % wall absorbility
Gt=1140; % radiation
k=0.7; % conductivity
Cp=0.84; %capacity
roh=1600; % density
alfa=k/(Cp*roh);
Te=T_out*(abs*Gt/h_out); % soalr temperture or ambient temp
Bo=h_out*dx/k;
Bi=h_in*dx/k;
f=alfa*dt/(dx*dx);
T(i)=T(i,m);
for i=1:nt
Tnew=zeros(1,nx);
for m=2:(nx-1)
Tnew(m)=T(m)+1;
T(i+1,1)=Ts-Bi*(Te-Ts)+(1/(2*f))*Ts;
T(i+1,2)=(1/(f*2))*(T(i+1,1))-(1/f)*(T(i,1)-Ts);
T(i+1,m+1)=(1/(f*2))*T(i+1,m)-(1/f)*(T(i,m)-T(i+1,m-1));
T(i+1,MM+1)=T(i+1,MM)-Bo*(T_in-T(i+1,MM))+(1/(2*f))*(T(i+1,MM)-T(i,MM));
end
end
1/f;
T(MM,:);
figure(1)
plot(T(1,:),'r')
hold on
plot(T(3,:),'y')
hold on
plot(T(5,:),'g')
hold on
plot(T(7,:),'b')
hold off
legend('1secs','3secs','5secs','7secs')

Answers (0)

Categories

Find more on Physics in Help Center and File Exchange

Asked:

on 16 Mar 2014

Edited:

on 16 Mar 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!