From: Abe Devinko on
Hi all

I wrote a matlab code to find 2D temperature distribution in a plate that is 0.4m wide by 0.7m tall. There are 40 nodes all together. I used the energy balance method and determined the temperature on each node using the matrix inversion method. Now I have temperature of each of the 40 nodes in T, and wish to plot a temperature distribution in the plate per location. How would I go about doing that?

I know I will have to store the temperature profile in a 2D matrix, and then create a meshgrid according to dimensions of the plate (my delta is 0.1 in x and y direction). Here's the diagram of the problem.
[IMG] http://i25.tinypic.com/2v0zi8m.jpg [/IMG]

I know i have to use meshgrid command to have temp for each node displayed at the right location on the plate, but I am not very familiar with how to do it.

Here's my code.

clc
clear all
%Block & mesh size
Lx = 0.4; % Width of block in x-direction (m)
Ly = 0.7; % Height of block in y-direction (m)
Ex = Lx/0.1; % Number of elements in x-direction
Ey = Ly/0.1; % Number of elements in y-direction
dx = Lx/Ex; % Spacing in x-direction
dy = Ly/Ey; % Spacing in y-direction
Nx = Ex+1; % Number of nodes in x-direction
Ny = Ey+1; % Number of nodes in y-direction
x = 0:dx:Lx; % Grid in x-direction
y = 0:dy:Ly; % Grid in y-direction

%Allocate storage space
N = Nx*Ny; a = zeros(N,N); b = zeros(N,1);

%Material Properties & Constants
k = 50; % Thermal conductivity of block (W/m-K)
h = 1000; % Heat transfer coeff (W/m^2-K)
Tinf = 293.15; % Air temperature on top of block (K)
Tw = 423.15; % Wall temperature of left and right edges (K)
qdot = 5e5; % Uniform heat generation inside the block (W/m^3)
Bi = (h*dx)/k; % Biot number
c = (-qdot*dx^2)/k;
d = 2*Bi*Tinf;

%node(1)
a(1,1)=-2*(Bi+1);
a(1,2)=1;
a(1,6)=1;
b(1)=c-d;

%node(5)
a(5,5)=-2*(Bi+2);
a(5,4)=2;
a(5,10)=2;
b(5)=c-d;
..
..
..
..
%node(40)
a(40,40)=-4;
a(40,35)=2;
a(40,39)=2;
b(40)=c;

T=a\b;

Now I am lost in how to create a temperature distribution plot in the plate.
I could create a new matrix, say u = zeros(Ny,Nx); and that will give me an 8 x 5 matrix.
From: Abe Devinko on
"Abe Devinko" <abe_cooldude(a)yahoo.com> wrote in message <i1hgb0$p0d$1(a)fred.mathworks.com>...
> Hi all
>
> I wrote a matlab code to find 2D temperature distribution in a plate that is 0.4m wide by 0.7m tall. There are 40 nodes all together. I used the energy balance method and determined the temperature on each node using the matrix inversion method. Now I have temperature of each of the 40 nodes in T, and wish to plot a temperature distribution in the plate per location. How would I go about doing that?
>
> I know I will have to store the temperature profile in a 2D matrix, and then create a meshgrid according to dimensions of the plate (my delta is 0.1 in x and y direction). Here's the diagram of the problem.
> [IMG] http://i25.tinypic.com/2v0zi8m.jpg [/IMG]
>
> I know i have to use meshgrid command to have temp for each node displayed at the right location on the plate, but I am not very familiar with how to do it.
>
> Here's my code.
>
> clc
> clear all
> %Block & mesh size
> Lx = 0.4; % Width of block in x-direction (m)
> Ly = 0.7; % Height of block in y-direction (m)
> Ex = Lx/0.1; % Number of elements in x-direction
> Ey = Ly/0.1; % Number of elements in y-direction
> dx = Lx/Ex; % Spacing in x-direction
> dy = Ly/Ey; % Spacing in y-direction
> Nx = Ex+1; % Number of nodes in x-direction
> Ny = Ey+1; % Number of nodes in y-direction
> x = 0:dx:Lx; % Grid in x-direction
> y = 0:dy:Ly; % Grid in y-direction
>
> %Allocate storage space
> N = Nx*Ny; a = zeros(N,N); b = zeros(N,1);
>
> %Material Properties & Constants
> k = 50; % Thermal conductivity of block (W/m-K)
> h = 1000; % Heat transfer coeff (W/m^2-K)
> Tinf = 293.15; % Air temperature on top of block (K)
> Tw = 423.15; % Wall temperature of left and right edges (K)
> qdot = 5e5; % Uniform heat generation inside the block (W/m^3)
> Bi = (h*dx)/k; % Biot number
> c = (-qdot*dx^2)/k;
> d = 2*Bi*Tinf;
>
> %node(1)
> a(1,1)=-2*(Bi+1);
> a(1,2)=1;
> a(1,6)=1;
> b(1)=c-d;
>
> %node(5)
> a(5,5)=-2*(Bi+2);
> a(5,4)=2;
> a(5,10)=2;
> b(5)=c-d;
> .
> .
> .
> .
> %node(40)
> a(40,40)=-4;
> a(40,35)=2;
> a(40,39)=2;
> b(40)=c;
>
> T=a\b;
>
> Now I am lost in how to create a temperature distribution plot in the plate.
> I could create a new matrix, say u = zeros(Ny,Nx); and that will give me an 8 x 5 matrix.

SORRY DOUBLE POST! My internet is acting up!
From: TideMan on
On Jul 13, 10:49 pm, "Abe Devinko" <abe_coold...(a)yahoo.com> wrote:
> Hi all
>
> I wrote a matlab code to find 2D temperature distribution in a plate that is 0.4m wide by 0.7m tall. There are 40 nodes all together. I used the energy balance method and determined the temperature on each node using the matrix inversion method. Now I have temperature of each of the 40 nodes in T, and wish to plot a temperature distribution in the plate per location. How would I go about doing that?
>
> I know I will have to store the temperature profile in a 2D matrix, and then create a meshgrid according to dimensions of the plate (my delta is 0.1 in x and y direction). Here's the diagram of the problem.
> [IMG]http://i25.tinypic.com/2v0zi8m.jpg[/IMG]
>
> I know i have to use meshgrid command to have temp for each node displayed at the right location on the plate, but I am not very familiar with how to do it.
>
> Here's my code.
>
> clc
> clear all
> %Block & mesh size
> Lx = 0.4;           % Width of block in x-direction (m)
> Ly = 0.7;           % Height of block in y-direction (m)
> Ex = Lx/0.1;        % Number of elements in x-direction
> Ey = Ly/0.1;        % Number of elements in y-direction
> dx = Lx/Ex;         % Spacing in x-direction
> dy = Ly/Ey;         % Spacing in y-direction
> Nx = Ex+1;          % Number of nodes in x-direction
> Ny = Ey+1;          % Number of nodes in y-direction
> x = 0:dx:Lx;        % Grid in x-direction
> y = 0:dy:Ly;        % Grid in y-direction  
>
> %Allocate storage space
> N = Nx*Ny;      a = zeros(N,N);         b = zeros(N,1);
>
> %Material Properties & Constants
> k = 50;            % Thermal conductivity of block (W/m-K)
> h = 1000;          % Heat transfer coeff (W/m^2-K)
> Tinf = 293.15;     % Air temperature on top of block (K)
> Tw = 423.15;       % Wall temperature of left and right edges (K)
> qdot = 5e5;        % Uniform heat generation inside the block (W/m^3)
> Bi = (h*dx)/k;     % Biot number
> c = (-qdot*dx^2)/k;
> d = 2*Bi*Tinf;
>
> %node(1)
> a(1,1)=-2*(Bi+1);
> a(1,2)=1;
> a(1,6)=1;
> b(1)=c-d;
>
> %node(5)
> a(5,5)=-2*(Bi+2);
> a(5,4)=2;
> a(5,10)=2;
> b(5)=c-d;
> .
> .
> .
> .
> %node(40)
> a(40,40)=-4;
> a(40,35)=2;
> a(40,39)=2;
> b(40)=c;
>
> T=a\b;
>
> Now I am lost in how to create a temperature distribution plot in the plate.
> I could create a new matrix, say u = zeros(Ny,Nx); and that will give me an 8 x 5 matrix.

Most of this is irrelevant to the question you have asked.
It's immaterial to us how you generate your matrix of temperatures,
say T(Ny,Nx)
And if the data are equispaced, you don't need to use meshgrid, you
can just use the x and y vectors that you've generated.
contourf(y,x,T)
From: Abe Devinko on
TideMan <mulgor(a)gmail.com> wrote in message <20120ef2-a2be-428e-abeb-dc2e63e6685e(a)y21g2000pro.googlegroups.com>...
> On Jul 13, 10:49 pm, "Abe Devinko" <abe_coold...(a)yahoo.com> wrote:
> > Hi all
> >
> > I wrote a matlab code to find 2D temperature distribution in a plate that is 0.4m wide by 0.7m tall. There are 40 nodes all together. I used the energy balance method and determined the temperature on each node using the matrix inversion method. Now I have temperature of each of the 40 nodes in T, and wish to plot a temperature distribution in the plate per location. How would I go about doing that?
> >
> > I know I will have to store the temperature profile in a 2D matrix, and then create a meshgrid according to dimensions of the plate (my delta is 0.1 in x and y direction). Here's the diagram of the problem.
> > [IMG]http://i25.tinypic.com/2v0zi8m.jpg[/IMG]
> >
> > I know i have to use meshgrid command to have temp for each node displayed at the right location on the plate, but I am not very familiar with how to do it.
> >
> > Here's my code.
> >
> > clc
> > clear all
> > %Block & mesh size
> > Lx = 0.4;           % Width of block in x-direction (m)
> > Ly = 0.7;           % Height of block in y-direction (m)
> > Ex = Lx/0.1;        % Number of elements in x-direction
> > Ey = Ly/0.1;        % Number of elements in y-direction
> > dx = Lx/Ex;         % Spacing in x-direction
> > dy = Ly/Ey;         % Spacing in y-direction
> > Nx = Ex+1;          % Number of nodes in x-direction
> > Ny = Ey+1;          % Number of nodes in y-direction
> > x = 0:dx:Lx;        % Grid in x-direction
> > y = 0:dy:Ly;        % Grid in y-direction  
> >
> > %Allocate storage space
> > N = Nx*Ny;      a = zeros(N,N);         b = zeros(N,1);
> >
> > %Material Properties & Constants
> > k = 50;            % Thermal conductivity of block (W/m-K)
> > h = 1000;          % Heat transfer coeff (W/m^2-K)
> > Tinf = 293.15;     % Air temperature on top of block (K)
> > Tw = 423.15;       % Wall temperature of left and right edges (K)
> > qdot = 5e5;        % Uniform heat generation inside the block (W/m^3)
> > Bi = (h*dx)/k;     % Biot number
> > c = (-qdot*dx^2)/k;
> > d = 2*Bi*Tinf;
> >
> > %node(1)
> > a(1,1)=-2*(Bi+1);
> > a(1,2)=1;
> > a(1,6)=1;
> > b(1)=c-d;
> >
> > %node(5)
> > a(5,5)=-2*(Bi+2);
> > a(5,4)=2;
> > a(5,10)=2;
> > b(5)=c-d;
> > .
> > .
> > .
> > .
> > %node(40)
> > a(40,40)=-4;
> > a(40,35)=2;
> > a(40,39)=2;
> > b(40)=c;
> >
> > T=a\b;
> >
> > Now I am lost in how to create a temperature distribution plot in the plate.
> > I could create a new matrix, say u = zeros(Ny,Nx); and that will give me an 8 x 5 matrix.
>
> Most of this is irrelevant to the question you have asked.
> It's immaterial to us how you generate your matrix of temperatures,
> say T(Ny,Nx)
> And if the data are equispaced, you don't need to use meshgrid, you
> can just use the x and y vectors that you've generated.
> contourf(y,x,T)

I tried that, and it's giving me an error z must be size 2x2 or greater.
The reason I posted the whole thing was so to give background info. I have a plate, and on the plate, which is 0.4 wide by 0.7 tall (equispaced delta = 0.1), I have a temperature corresponding at each of the 40 (nodes) location, meaning @ (x,y) point.

For example, at location (0,0), the top-left corner in the picture, I have temperature, which is stored in T.
At say location (0.2,0.1), which is node 8 in the picture, I have another temp.
And so on.
So I am guessing I would need to first define the plate dimensions (0.4x0.7) with spacing of 0.1 in some kind of matrix, and then define nodes at each location, and then temperature profile in a 2D matrix.
I don't know if I am even thinking this the right way, and if I am, I still don't know how to implement this into matlab.

I wish I was good and smarter at programming matlab :(
From: Sergey Holmogorov on
"Abe Devinko" <abe_cooldude(a)yahoo.com> wrote in message <i1hg93$lds$1(a)fred.mathworks.com>...
> Hi all
>
> I wrote a matlab code to find 2D temperature distribution in a plate that is 0.4m wide by 0.7m tall. There are 40 nodes all together. I used the energy balance method and determined the temperature on each node using the matrix inversion method. Now I have temperature of each of the 40 nodes in T, and wish to plot a temperature distribution in the plate per location. How would I go about doing that?
>
> I know I will have to store the temperature profile in a 2D matrix, and then create a meshgrid according to dimensions of the plate (my delta is 0.1 in x and y direction). Here's the diagram of the problem.
> [IMG] http://i25.tinypic.com/2v0zi8m.jpg [/IMG]
>
> I know i have to use meshgrid command to have temp for each node displayed at the right location on the plate, but I am not very familiar with how to do it.
>
> Here's my code.
>
> clc
> clear all
> %Block & mesh size
> Lx = 0.4; % Width of block in x-direction (m)
> Ly = 0.7; % Height of block in y-direction (m)
> Ex = Lx/0.1; % Number of elements in x-direction
> Ey = Ly/0.1; % Number of elements in y-direction
> dx = Lx/Ex; % Spacing in x-direction
> dy = Ly/Ey; % Spacing in y-direction
> Nx = Ex+1; % Number of nodes in x-direction
> Ny = Ey+1; % Number of nodes in y-direction
> x = 0:dx:Lx; % Grid in x-direction
> y = 0:dy:Ly; % Grid in y-direction
>
> %Allocate storage space
> N = Nx*Ny; a = zeros(N,N); b = zeros(N,1);
>
> %Material Properties & Constants
> k = 50; % Thermal conductivity of block (W/m-K)
> h = 1000; % Heat transfer coeff (W/m^2-K)
> Tinf = 293.15; % Air temperature on top of block (K)
> Tw = 423.15; % Wall temperature of left and right edges (K)
> qdot = 5e5; % Uniform heat generation inside the block (W/m^3)
> Bi = (h*dx)/k; % Biot number
> c = (-qdot*dx^2)/k;
> d = 2*Bi*Tinf;
>
> %node(1)
> a(1,1)=-2*(Bi+1);
> a(1,2)=1;
> a(1,6)=1;
> b(1)=c-d;
>
> %node(5)
> a(5,5)=-2*(Bi+2);
> a(5,4)=2;
> a(5,10)=2;
> b(5)=c-d;
> .
> .
> .
> .
> %node(40)
> a(40,40)=-4;
> a(40,35)=2;
> a(40,39)=2;
> b(40)=c;
>
> T=a\b;
>
> Now I am lost in how to create a temperature distribution plot in the plate.
> I could create a new matrix, say u = zeros(Ny,Nx); and that will give me an 8 x 5 matrix.

Hi, you should use following:
meshc(X,Y,Z)
where matrices X, Y dimension (Ny,Nx) and matrix Z include temperature's level for each node.