plot temperature distribution for plane wall initially at 20 degrees and cooled by liquid of 20 degrees on right side that is subjected to large heat flux on left side for 0.2 seconds every 1 second in matlab

Here is how you can plot the temperature distribution for a plane wall initially at 20 degrees and cooled by liquid of 20 degrees on right side that is subjected to a large heat flux on the left side for 0.2 seconds every 1 second using Matlab:

main.m
% Define the variables
L = 1; % thickness of wall (m)
n = 50; % number of nodes
dx = L/(n-1); % distance between nodes
x = 0:dx:L; % location of nodes
k = 0.5; % thermal conductivity of wall (W/m*K)
h = 20; % convective heat transfer coefficient (W/m^2*K)
T_inf = 20; % temperature of cooling liquid (°C)
q = 5000; % heat flux on left side (W/m^2)
alpha = k/(rho*cp); % thermal diffusivity of wall
t_end = 5; % end time of simulation (s)
dt = 0.001; % time step
t = 0:dt:t_end; % time vector
T0 = 20; % initial temperature of wall (°C)
T = ones(n,length(t))*T0; % temperature matrix

% Define coefficients for Crank-Nicolson method
r = alpha*dt/(dx^2);
a = -r/2;
b = 1 + r;
c = -r/2;

% Calculate temperature distribution at each time step
for j = 2:length(t)
    % Apply heat flux on left side for 0.2 seconds every 1 second
    if mod(t(j),1) <= 0.2
        T(1,j) = T(2,j-1) + q*dx/(k*h);
    else
        T(1,j) = T(2,j-1);
    end
    
    % Apply boundary conditions
    T(n,j) = T_inf;
    
    % Calculate temperature at interior nodes using Crank-Nicolson method
    for i = 2:n-1
        T(i,j) = a*T(i-1,j-1) + b*T(i,j-1) + c*T(i+1,j-1);
    end
end

% Plot the temperature distribution
[X,T] = meshgrid(t,x);
pcolor(X,T,T.'), shading interp, colorbar
xlabel('Time (s)')
ylabel('Distance (m)')
title('Temperature Distribution for Plane Wall')
1354 chars
47 lines

This code uses the Crank-Nicolson method to solve the heat equation for the plane wall and a heat flux boundary condition on the left side for 0.2 seconds every 1 second. The temperature distribution is then plotted as a function of time and distance using the pcolor function.

related categories

gistlibby LogSnag