2016-12-19 6 views
0

24 x 24マトリックスの熱伝播を計算し可視化したいと考えています。マトリックスには時間の経過とともに温度が一定の2つのホットスポットがあります。マトリックスの外縁も時間の経過とともに一定に保たれる。私は、MATLABに新しいですし、今まで私は、スクリプト、次の書かれている:私は2次元での熱伝達のための計算を考え出したが、Matlabのマトリックスにおける2D熱伝播

%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; 

シミュレーションがまだ動作しません。何か問題は見えますか?

答えて

1

部:

pause(0.2); 
contourf(PlateNew) 
colorbar 
title('Heat propagation in a plate'); 
PlateOld = PlateNew; 

for k = 1:cycleループでなければなりません。残りはうまくいくはずです。しかし、現時点でホットスポットは一定ではありません。あなたはエッジと同じようにする必要があります。あなたは( ":サイクルのk = 1のための" ループの最後で)41'thライン上

PlateOld = PlateNew; 

を設定し忘れるよう

よろしく、あなたのコードについては マイケル

+0

ありがとうございます。私はそれを考え出した! – Kris

1

は、見えます。

あなたのコードは、k番目の反復で設定された間違った外縁一定温度を生成するようです。最初の反復でPlateNew行列が空になるので、行列の1つの要素だけを満たすように

PlateNew(:,1) = 20; 
PlateNew(1,:) = 20; 

を生成します。 コードはCスタイルのようです。代わりに、MATLABはマトリックスでより効率的に操作できます。したがって、forループをより効率的に実装することができます(コードの21〜41行目を置き換えます)。

PlateNew = PlateOld; 
% the amount of cycles 
cycles = 50; 
% Calculation of the heat propagation 
for k = 1:cycles 
    %every cell gets 20 percent heat of four neighbouring cells 
    PlateNew = filter2(prop * [0 1 0; 1 1/prop-4 1; 0 1 0], PlateNew); 

    %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; 
end