% insulatedslab.m Last modified 7/31/2008 % Conduction of heat in a slab insulated on the % right hand face (x = L) and a suddenly applied % temperature TH on the left face (x = 0)and % initial temperature of T0. % The diffusivity is kappa=k/(rho*c) % This m-file was written at the University of Wyoming in the Electrical % and Computer Engineering Department and is to be distributed without % cost. clear all set(0,'DefaultAxesFontSize',12); set(0,'DefaultTextFontSize',12); xoverL=linspace(0,1,101);roverR(1,1)=.0001; nterm=20;% number of terms in the Fourier series solution. for i=1:nterm phi(i,:)=sin(((2*i-1)*pi/2)*xoverL); alpha(1,i)=((2*i-1)*pi/2)^2; end tau=linspace(0,.6,201); framedata=[]; for k=1:201%time loop sum=zeros(1,101); for i=1:nterm sum=sum+(1/(2*i-1))*phi(i,:)*exp(-alpha(1,i)*tau(1,k)); end T= ones(1,101)-sum*(4/pi); framedata=[framedata;T]; end framedata(1,:)=zeros(1,101); framedata(1,1)=1; figure(1);clf;% Plot T(x,t) vs x for various t axis([-.2 1.2 -.2 1.2]) hold on plot([0 0],[-.2,1.2]); hold on plot([1 1],[-.2,1.2]); hold on plot(xoverL,framedata(1,:),'k') hold on xlabel('Dimensionless Distance, x/L') hold on patch([1 1 1.2 1.2 1],[-.2 1.2 1.2 -.2 -.2],'m') hold on text(1.1, 0,'Perfect Insulation','Rotation',90) hold on ylabel('Dimensionless Temperature, [T(x,t)-T_0]/[T_H-T_0]') for k=21:20:201% time loop plot(xoverL,framedata(k,:),'k') hold on end text(.15,.05,['\kappat/L^2 = ' num2str(0)]) text(.3,.2,num2str(0.06)) text(.4,.3,num2str(0.12)) text(0.6,.8,num2str(0.6)) set(gca,'Box','on') hold off text(.1,1.13,'Press Enter to Continue') pause figure(2);clf;%Plot T(x,t) vs t for various x axis([0 .6 -.2 1.2]); hold on plot(tau,ones(1,201)) hold on for j=1:10:101% space loop plot(tau,framedata(:,j)) hold on end text(.02,.95,['x/L = ' num2str(0)]) text(.03,.783,['x/L = ' num2str(0.1)]) text(.17,.15,['x/L = ' num2str(1)]) xlabel('Dimensionless Time, \kappat/L^2') ylabel('Dimensionless Temperature, [T(x,t)-T_0]/[T_H-T_0]') text(.02,1.1,'Press Enter to Continue') set(gca,'Box','on') hold off pause figure(3);clf;%now do animation axis([-.2 1.2 -.2 1.2]) hold on plot([0 0],[-.2,1.2]); plot([1 1],[-.2,1.2]); box on xlabel('Dimensionless Distance, x/L') hold on ylabel('Dimensionless Temperature, [T(x,t)-T_0]/[T_H-T_0]') hold on patch([1 1 1.2 1.2 1],[-.2 1.2 1.2 -.2 -.2],'m') hold on text(1.1, 0,'Perfect Insulation','Rotation',90) hold on L=plot(xoverL, framedata(1,:),'k','EraseMode','xor'); hold on texthandl=text(.4,1.1,'Press Enter to Animate'); pause set(texthandl,'String',' '); for k=2:201% time loop set(L,'Ydata',framedata(k,:)) pause(.05) end hold on plot(xoverL,framedata(1,:),'k') hold off set(texthandl,'String','Press Enter to Continue'); pause figure(4);clf;%3-D Plot of T(r,t) vs x and t tau1=linspace(0,.6,201); [X,Y]=meshgrid(xoverL,tau1); mesh(X,Y,framedata)%(1:201,:)) colormap(cool) text(.1,0,-.2,'Distance, x/L','Rotation',-22) text(1,.2,-.2,'Time, \kappat/L^2','Rotation',18) zlabel('[T(x,t) - T_0]/[T_H - T_0]') view(50,30) axis([0 1 0 .6 0 1]) text(1,.15,.1,'Press Enter to Continue','Rotation',18)