《西安交通大学——温度场数值模拟(matlab).doc》由会员分享,可在线阅读,更多相关《西安交通大学——温度场数值模拟(matlab).doc(4页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、_温度场模拟matlab代码:clear,clc,clfL1=8;L2=8;N=9;M=9;% 边长为8cm的正方形划分为8*8的格子T0=500;Tw=100; % 初始和稳态温度a=0.05; % 导温系数tmax=600;dt=0.2; % 时间限10min和时间步长0.2sdx=L1/(M-1);dy=L2/(N-1);M1=a*dt/(dx2);M2=a*dt/(dy2);T=T0*ones(M,N);T1=T0*ones(M,N);t=0;l=0;k=0;Tc=zeros(1,600);% 中心点温度,每一秒采集一个点for i=1:9 for j=1:9 if(i=1|i=9|j
2、=1|j=9) T(i,j)=Tw;% 边界点温度为100 else T(i,j)=T0; end endendif(2*M1+2*M2=1) % 判断是否满足稳定性条件 while(ttmax+dt) t=t+dt; k=k+1; for i=2:8 for j=2:8 T1(i,j)=M1*(T(i-1,j)+T(i+1,j)+M2*(T(i,j-1)+T(i,j+1)+(1-2*M1-2*M2)*T(i,j); end end for i=2:8 for j=2:8 T(i,j)=T1(i,j); end end if(k=5) l=l+1; Tc(l)=T(5,5); k=0; end
3、 end i=1:9;j=1:9; x,y=meshgrid(i); figure(1); subplot(1,2,1); mesh(x,y,T(i,j)% 画出10min后的温度场 axis tight; xlabel(x,FontSize,14);ylabel(y,FontSize,14);zlabel(T/,FontSize,14) title(1min后二维温度场模拟图,FontSize,18) subplot(1,2,2); C,H=contour(x,y,T(i,j); clabel(C,H);axis square; xlabel(x,FontSize,14);ylabel(y,FontSize,14); title(1min后模拟等温线图,FontSize,18) figure(2); xx=1:600; plot(xx,Tc,k-,linewidth,2) xlabel(时间/s,FontSize,14);ylabel(温度/,FontSize,14);title(中心点的冷却曲线,FontSize,18)else disp(Error!) % 如果不满足稳定性条件,显示“Error!”end实验结果:4_