create a for loop that incorporates cyclic transient heat conduction in a plane wall in matlab

Assuming that the temperature distribution across the wall is cyclic and the temperature at one end of the wall is fixed at a constant value, the following code can be used to simulate cyclic transient heat conduction in a plane wall using MATLAB:

main.m
% Input parameters
L = 0.1; % Thickness of wall (m)
k = 10; % Thermal conductivity of wall (W/m.K)
rho = 2000; % Density of wall (kg/m^3)
c = 1000; % Specific heat capacity of wall (J/kg.K)
T0 = 293; % Initial temperature of wall (K)
Tinf = 373; % Temperature at other end of wall (K)
h = 100; % Convective heat transfer coefficient (W/m^2.K)
alpha = k/(rho*c); % Thermal diffusivity
t = 0:0.1:3600; % Time vector (s)

% Calculate Fourier number
Fo = alpha.*(t(2)-t(1))./(L^2);

% Initialize temperature matrix
T = zeros(length(Fo),3);

% Set initial and boundary conditions
T(:,1) = T0;
T(1:10,2) = Tinf;
T(11:end,2) = T0;
T(:,3) = T0;

% Iterate using forward time central space method
for i = 2:length(Fo)
    T(i,3) = 2*T(i-1,2) - T(i-1,1) + Fo(i)*(T(i-1,2) - 2*T(i-1,1) + T(i-1,3));
    T(i,1) = T(i,3) + (2*h*L/k)*(Tinf - T(i,3));
    T(i,2) = T(i,3);
end

% Plot results
plot(t,T(:,1),'r',t,T(:,2),'g',t,T(:,3),'b')
legend('x = 0','x = L/2','x = L')
xlabel('Time (s)')
ylabel('Temperature (K)')
1002 chars
36 lines

This code uses the forward time central space numerical discretization method with a for loop to solve the heat conduction equation at each time step. The temperature at the two ends of the wall are assumed to be fixed at constant values, while the temperature distribution across the wall is cyclic.

Note that the code assumes constant thermophysical properties such as thermal conductivity, density and specific heat capacity. If these properties vary with temperature, the code will need to be modified to include these variations. Additionally, the code assumes one-dimensional heat transfer and does not account for any thermal resistance at the wall surfaces.

gistlibby LogSnag