matlab code for a 2D steady state using the energy balance method, derive the finite difference equations for the interior and boundary nodes

36 visualizaciones (últimos 30 días)
how can i get a matlab code for a 2D steady state conduction problem using finite differencing method?
A two dimensional square plate is subject to prescribed temperature boundary condition at
three sides (T1) and a uniform heat flux into the plate at the bottom surface ( q )
Using the energy balance method, derive the finite difference equations for the interior and boundary nodes.
Determine the temperature field in the plate, in the form of both nodal values and
temperature contours. Assume the size of the plate, thermal conductivity, and heat flux to
be 10×10 cm2, 20W/m.K, and 2000 W/m2, respectively. The prescribed constant
temperature (T1) is assumed to be 25C
i want to check the heat flow at each of the nodes and edges.
i have got this code. how can i modify it to do what i want?
close all
clear all
clc
n=10;
w=10;
h=10;
x=linspace(0,w,n);
y=linspace(0,h,n);
T=zeros(n);
%Boundary Conditions
q = 2000 ; % W/m^2 - surface heat flux
T(1,1:n)= 25; %Top
T(n,1:n)=q ; %Bottom
T(1:n,1)=25 ; %Left
T(1:n,n)=25 ; %Right
% Inputs
ks = 20 ; % W/mK - Thermal conductivity of the material
%q = 2000 ; % W/m^2 - surface heat flux
dx = w/(n-1) ; % m - grid spacing - kown from underlying grid
dy = dx ; % the Finite differenc stencil is for dx = dy
%q''=20 W/m*k
%thermal conductivity = 2000 w/m^2
tol=1e-7;
error=1;
k=0;
while error > tol
k=k+1;
Told=T;
for i=2:n-1
for j=2:n-1
T(i,j) = ( 2 * T(i-1,j) + T(i,j-1) + T(i,j+1) + ( 2 * q * dx / ks ) ) / 4 ;
end
end
error = max(max(abs(Told-T)));
end
subplot(3,1,1),contour(x,y,T),colormap
title('Temperature (Steady State)'),xlabel('x'),ylabel('y'),colorbar
subplot(3,1,2),pcolor(x,y,T),shading interp,
title('Temperature (Steady State)'),xlabel('x'),ylabel('y'),colorbar
subplot(3,1,3)
surf(T')
xlabel('x')
ylabel('y')
zlabel('T')
colorbar

Respuestas (1)

Sanju
Sanju el 9 de En. de 2024
Hi @wes7,
I understand that you want to check the heat flow at each node and edge which requires calculation of the heat flux at each grid point. The heat flux (q) can be computed using Fourier's Law:
q=−k *∂x/∂T​
where k is the thermal conductivity, T is the temperature, and ∂x/∂T​ is the temperature gradient.
To modify the code to calculate the heat flow at each node and edge, you can add additional calculations within the nested loops. Here's an example implementation of the code,
% Calculate heat flow in x-direction
qx(i, j) = -ks * (T(i, j+1) - T(i, j-1)) / (2 * dx);
% Calculate heat flow in y-direction
qy(i, j) = -ks * (T(i+1, j) - T(i-1, j)) / (2 * dy);
In the modified code, I have added two arrays” qx and “qy” to store the heat flow in the x-direction and y-direction, respectively. These arrays are calculated within the nested loops using finite difference approximations.
You can create a new figure plot for Heat Flow at each node and edge using the “quiver” function as follows,
% Plot Heat Flow in both x & y direction
figure
quiver(x, y, qx, qy)
title('Heat Flow'), xlabel('x'), ylabel('y')
The following will be the sample output for the Heat flow at each node & edge,
Please refer to the below documentation on “quiver” function if required,
Hope this Helps!
Thanks.

Community Treasure Hunt

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

Start Hunting!

Translated by