2D Heat Transfer Problem Not Yielding Plot
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi everyone, I am attempting to build a 4x4 grid and plot the temperature distribution, however my code is not yielding a graph. There are no errors in the code as far as matlab says. If someone could please point out the problem or help me fix it, I would greatly appreciate it.
%%
function [A,B,T,Temp]=FinDiffFourbyFour
Ttop=1000; %K
Tleft=500; %K
Tright=500; %K
Tbottom=500; %K
w=0.01; %10 cm
l=0.01; %10 cm
xsteps=4;
ysteps=4;
dx=l/(xsteps-1);
dy=w/(ysteps-1);
x=(0:dx:l);
y=(0:dy:w);
A=zeros(xsteps*ysteps,xsteps*ysteps);
B=zeros(xsteps*ysteps,1);
%Top
A(1,1)=1;
B(1)=Ttop;
A(2,2)=1;
B(2)=Ttop;
A(3,3)=1;
B(3)=Ttop;
A(4,4)=1;
B(4)=Ttop;
%Left
A(5,5)=1;
B(5)=Tleft;
A(9,9)=1;
B(9)=Tleft;
%Right
A(8,8)=1;
B(8)=Tright;
A(12,12)=1;
B(12)=Tright;
%Interior
A(6,6)=4;
A(6,2)=-1;
A(6,5)=-1;
A(6,7)=-1;
A(6,10)=-1;
B(6)=0;
A(7,7)=4;
A(7,1)=-1;
A(7,3)=-1;
A(7,6)=-1;
A(7,8)=-1;
B(7)=0;
A(10,10)=4;
A(10,6)=-1;
A(10,9)=-1;
A(10,11)=-1;
A(10,14)=-1;
B(10)=0;
A(11,11)=4;
A(11,7)=-1;
A(11,12)=-1;
A(11,15)=-1;
B(11)=0;
%Bottom
A(13,13)=1;
B(13)=Tbottom;
A(14,13)=1;
B(14)=Tbottom;
A(15,15)=1;
B(15)=Tbottom;
A(16,16)=1;
B(16)=Tbottom;
T=inv(A*B);
%turn back into matrix
for i=1:ysteps
for j=1:xsteps
Temp(i,j)=T(xsteps*ysteps-xsteps*i+j);
end
end
[C,h]=contour(x,y,T); %plot contour
clabel(C,h); %label contour levels
colorbar
xlabel('x-axis')
ylabel('y-axis')
zlabel('Temperature(K)')
title('4x4 Finite Difference Solution')
1 Kommentar
darova
am 17 Okt. 2019
Can you please explain this?
A(16,16)=1;
B(16)=Tbottom;
T=inv(A*B); % A - 2D matrix, B - vector
x,y - are vector of 1x4 size
[C,h]=contour(x,y,T); %plot contour
Antworten (1)
Anurag Pratap Singh
am 24 Jun. 2020
Hi Nickolai
I understand that you are facing problem in plotting the temperature distribution as a contour
I looked at your code and found you have not created matrices of x and y that will define you grid in the x,y plane.I suggest you could use meshgrid for that purpose.
Please refer to the https://www.mathworks.com/help/matlab/ref/contour.html#:~:text=contour(%20Z%20)%20creates%20a%20contour,coordinates%20in%20the%20plane%2C%20respectively.
documentation for making the contour for more information
0 Kommentare
Siehe auch
Kategorien
Mehr zu Contour Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!