【发布时间】:2016-12-19 02:12:37
【问题描述】:
我想计算和可视化 24 x 24 矩阵中的热传播。矩阵中有两个热点,其温度随时间保持恒定。随着时间的推移,矩阵的外边缘也保持不变。我是 MATLAB 新手,到目前为止我已经编写了以下脚本:
%declaration and initialization of matrix with
%24 x 24 cells, start temp. = 20°C
PlateOrg (1:24, 1:24) = 20;
% size of matrix
[height, width] = size(PlateOrg);
cells = height * width;
% percent that is given from one cell to its neighbouring cells
prop = 0.2;
%These are the hot-spots, they heat up the neighbouring cells
%but do not heat up themselves any higher -> their
%temperature is constant over the simulation
PlateOrg(4,4:20) = 100;
PlateOrg(5:9,20) = 80;
PlateOrg(11:19,4) = 50;
PlateOrg(20,4:20) = 60;
%First Contourf 2D-Diagram with start temperatures
contourf(PlateOrg);
PlateOld = [];
PlateOld = PlateOrg;
PlateNew = [];
% the amount of cycles
cycles = 50;
% Calculation of the heat propagation
for k = 1:cycles
%the outer edges stay constant at temp. = 20°C
%for the whole simulation
PlateNew(:,1) = 20;
PlateNew(1,:) = 20;
PlateNew(24,:) = 20;
PlateNew(:,24) = 20;
%every cell gets 20 percent heat of four neighbouring cells
for i=2:height-1
for j=2:width-1
PlateNew(i,j)=...
(1-4*prop)*PlateOld(i,j)+prop*...
(PlateOld(i,j-1)+PlateOld(i,j+1)+...
PlateOld(i-1,j)+PlateOld(i+1,j));
end
end
end
pause(0.2);
contourf(PlateNew)
colorbar
title('Heat propagation in a plate');
PlateOld = PlateNew;
我计算出了二维热传播的计算方法,但模拟仍然无法正常工作。有什么问题吗?
【问题讨论】:
标签: matlab matrix propagation