What should I do in order to remove this weird HEAT GRADIENT (flow line) ?
Show older comments
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

Accepted Answer
More Answers (1)
Image Analyst
on 24 Apr 2015
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 Comments
Calin Pastean
on 24 Apr 2015
Calin Pastean
on 24 Apr 2015
Image Analyst
on 24 Apr 2015
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).
Categories
Find more on Vector Fields in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!