What should I do in order to remove this weird HEAT GRADIENT (flow line) ?

1 回表示 (過去 30 日間)
Calin Pastean
Calin Pastean 2015 年 4 月 23 日
コメント済み: Star Strider 2015 年 4 月 24 日
I am trying to plot the heat flow through a plate, but for some odd reason I am getting a weird flow line on the cold side (lower right corner). Could somebody check the code for me? I have added a screenshot of the plot I am getting.
Also, How could I add a "hole" in this plot? An area which cannot be affected by the heat flow.
%Predefined Variables
dx = 1;
dy = 1;
%Plate dimensions
plate_length = 64;
plate_height = 96;
%Heated & Cooled points
heated_length = 32;
heated_height = 32;
cooled_length = 16;
cooled_height = 16;
heated_temp = 100;
cooled_temp = -100;
%Grid
x = 0:dx:plate_length;
y = 0:dy:plate_height;
nx = length(x);
ny = length(y);
[x_arr, y_arr] = meshgrid(x,y);
temp=zeros(ny, nx);
%Heating & Cooling Points
heated_top = find((y_arr == plate_height) & (x_arr <= heated_length));
heated_left = find((y_arr >= plate_height-heated_height) & (x_arr == 0));
heated_points = union(heated_top, heated_left);
cooled_bottom = find((y_arr == 0) & (x_arr >= plate_length-cooled_length));
cooled_right = find((y_arr <= cooled_height) & (x_arr == plate_length));
cooled_points = union(cooled_bottom, cooled_right);
temp(heated_points) = heated_temp;
temp(cooled_points) = cooled_temp;
%Iteration
for k=1:1:30
inner_x = 2:nx-1;
inner_y = 2:ny-1;
x_diff = temp(inner_y, inner_x+1) + temp(inner_y, inner_x-1);
y_diff = temp(inner_y+1, inner_x) + temp(inner_y-1, inner_x);
old_inner = temp(inner_y, inner_x);
temp(inner_y, inner_x) = (x_diff +y_diff)/4;
%Plotting
contourf(x_arr,y_arr,temp);
%surf(x_arr,y_arr,temp);
%contour(x_arr,y_arr,temp);
%hold on;
drawnow;
end

採用された回答

Star Strider
Star Strider 2015 年 4 月 24 日
you can specify the levels at which to draw the contours.
From the documentation for contourf:
  • contourf(Z,v) draws a filled contour plot of matrix Z with contour lines at the data values specified in the monotonically increasing vector v. To display a single contour line at a particular value, define v as a two-element vector with both elements equal to the desired contour level. For example, to draw a single contour of level k, use contourf(Z,[k k]). Specifying the vector v sets the LevelListMode property to manual.
  2 件のコメント
Calin Pastean
Calin Pastean 2015 年 4 月 24 日
I was going to use imshow, but sadly, after a double check of the code requirements, it turns out contours of the heat flow are a must.
If you could elaborate slightly more, I would be very thankful. I am quite new to MATLab and the documentation is quite confusing. (probably because of the lack of sleep though)
Star Strider
Star Strider 2015 年 4 月 24 日
The ‘v’ vector has to be monotonically increasing, but it doesn’t have to be regularly-spaced. If you can determine the values of the contours at the top left and lower right, you can define ‘v’ to include only them.
You can also set the number of contours, so that would be my first option. I would then experiment with ‘v’ if defining the number of the contours didn’t work.
I understand sleep deprivation only too well. You have my sympathies!
On a completely different note, if you ever need to find the zeros of a bivariate function, setting ‘v’ to [0; 0] will plot them and produce the (x,y) values if you want them. You can get the (x,y) values for all the contours by asking for them with an output argument from contour and its friends.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2015 年 4 月 24 日
It seems to be just an artifact of where contour is drawing the lines. Why don't you use an image instead, like with imshow:
%Predefined Variables
dx = 1;
dy = 1;
%Plate dimensions
plate_length = 64;
plate_height = 96;
%Heated & Cooled points
heated_length = 32;
heated_height = 32;
cooled_length = 16;
cooled_height = 16;
heated_temp = 100;
cooled_temp = -100;
%Grid
x = 0:dx:plate_length;
y = 0:dy:plate_height;
nx = length(x);
ny = length(y);
[x_arr, y_arr] = meshgrid(x,y);
temp=zeros(ny, nx);
%Heating & Cooling Points
heated_top = find((y_arr == plate_height) & (x_arr <= heated_length));
heated_left = find((y_arr >= plate_height-heated_height) & (x_arr == 0));
heated_points = union(heated_top, heated_left);
cooled_bottom = find((y_arr == 0) & (x_arr >= plate_length-cooled_length));
cooled_right = find((y_arr <= cooled_height) & (x_arr == plate_length));
cooled_points = union(cooled_bottom, cooled_right);
temp(heated_points) = heated_temp;
temp(cooled_points) = cooled_temp;
inner_x = 2:nx-1;
inner_y = 2:ny-1;
%Iteration
for k=1:30
x_diff = temp(inner_y, inner_x+1) + temp(inner_y, inner_x-1);
y_diff = temp(inner_y+1, inner_x) + temp(inner_y-1, inner_x);
old_inner = temp(inner_y, inner_x);
temp(inner_y, inner_x) = (x_diff +y_diff)/4;
% Display temp image.
subplot(1,2,1);
imshow(temp, [], 'InitialMagnification', 800);
axis on;
axis image;
colormap(hot(256));
colorbar;
%Plotting
subplot(1,2,2);
contourf(x_arr,y_arr,temp);
drawnow;
end
  3 件のコメント
Calin Pastean
Calin Pastean 2015 年 4 月 24 日
Also, I am currently working on adding the hole in the plate, and I am afraid that the contour line will interact badly with it.
Image Analyst
Image Analyst 2015 年 4 月 24 日
If you look at the actual data values of temp, you will see there is really no big change in values around that line - it's like 1e-8 and 0. It's purely an artifact of where it had to draw the line to get the required number of contour lines in there. You could try to change the number of contour lines if you didn't want to display it as an image and wanted to use contour instead. You can change the number of colors in hot() to make it more quantized if you want. Then the only difference will be that image won't have black lines separating the "level" or posterized regions of the image (contour draws black lines between the colors while imshow does not).

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by