a plane wall is subjected to convective cooling on the right side and a heat flux that varies with time on the left side, create a temperature distribution for this in matlab

To create a temperature distribution for a plane wall subjected to convective cooling on the right side and a heat flux that varies with time on the left side in MATLAB, we can use the finite difference method to solve the one-dimensional heat conduction equation for a transient state:

heat equation

where T is the temperature, alpha is the thermal diffusivity, Q is the heat flux, and h is the convective heat transfer coefficient. We can discretize the equation using the forward difference in time and the central difference in space as follows:

discretized heat equation

To implement this in MATLAB, we need to define the parameters of the problem, including the material properties, dimensions, boundary conditions, and time step. We then create a matrix T to store the temperature values at each point in space and time, and use a loop to calculate the temperature distribution at each time step, based on the temperature values at the previous time step and the boundary conditions. Here's an example code:

main.m
% Define problem parameters
L = 1;   % length of the wall [m]
k = 1;   % thermal conductivity of the wall [W/m*K]
rho = 1; % density of the wall [kg/m^3]
c = 1;   % specific heat of the wall [J/kg*K]
alpha = k / (rho * c); % thermal diffusivity [m^2/s]
h = 10;  % convective heat transfer coefficient [W/m^2*K]
T_left = 100;           % temperature on the left side [C]
q_right = 1000;         % heat flux on the right side [W/m^2]
t_end = 100;            % end time [s]
dt = 0.1;               % time step [s]
dx = 0.01;              % space step [m]

% Initialize temperature matrix
nx = L / dx + 1;
nt = t_end / dt + 1;
T = zeros(nx, nt);
T(:, 1) = 20; % initial temperature [C]

% Apply boundary conditions
T(1, :) = T_left;
for i = 2:nt
    T(nx, i) = T(nx-1, i) - dx*q_right/k;
    T(2:nx-1, i) = T(2:nx-1, i-1) + alpha*dt/dx^2 * (T(3:nx, i-1) - 2*T(2:nx-1, i-1) + T(1:nx-2, i-1)) - h * dx/k * (T(2:nx-1, i-1) - T(nx, i));
end

% Plot temperature distribution
figure;
x = linspace(0, L, nx);
t = linspace(0, t_end, nt);
[X, Y] = meshgrid(t, x);
surf(X, Y, T');
xlabel('time [s]');
ylabel('position [m]');
zlabel('temperature [C]');
1138 chars
36 lines

This code calculates the temperature distribution for a wall of length L=1 m, thermal conductivity k=1 W/mK, density rho=1 kg/m^3, specific heat c=1 J/kgK, and convective heat transfer coefficient h=10 W/m^2*K, subjected to a heat flux of q_right=1000 W/m^2 on the right side and a temperature of T_left=100 C on the left side. The temperature distribution is calculated for a total time of t_end=100 s, using a time step of dt=0.1 s and a space step of dx=0.01 m. The temperature values are stored in a matrix T of size (nx, nt), where nx and nt are the number of grid points in space and time, respectively. The initial temperature is set to 20 C, and the boundary conditions are applied to the first and last rows of T. Finally, the temperature distribution is plotted using the surf function, with time on the x-axis, position on the y-axis, and temperature on the z-axis.

related categories

gistlibby LogSnag