find initial temperature as a function of position in a plane wall under transient heat conduction in matlab

To find the initial temperature as a function of position in a plane wall under transient heat conduction in MATLAB, you will need to solve the Heat Equation with the given boundary and initial conditions. Here's an approach to solve this problem using the Finite Difference Method:

  1. Discretize the wall into a grid of n x m nodes, with the distance between two adjacent nodes in x direction being dx and in y direction being dy.

  2. Define the time step size dt.

  3. Define the boundary conditions. For example, if the wall is exposed to an environment of constant temperature T_inf1 and T_inf2 on two opposite sides, the boundary conditions can be T(1,j,k) = T_inf1, T(n,j,k) = T_inf2 for j = 1:m and k = 1:Nt (number of time steps).

  4. Define the initial condition. For example, if the wall initially has a uniform temperature T0, the initial condition can be T(i,j,1) = T0 for i = 2:n-1 and j = 2:m-1.

  5. Use the Forward Time Centered Space (FTCS) scheme to update the temperature at each node at each time step. The FTCS scheme is given by:

T(i,j,k+1) = T(i,j,k) + alpha*(T(i+1,j,k) - 2T(i,j,k) + T(i-1,j,k) + T(i,j+1,k) - 2T(i,j,k) + T(i,j-1,k))

where alpha = k/(rho*Cp)*dt/dx^2 is the thermal diffusivity of the material.

  1. Repeat step 5 for k = 1:Nt-1, where Nt is the number of time steps.

  2. The final solution gives the temperature distribution in the wall as a function of position and time.

Here's a sample MATLAB code that implements the above steps for a wall of length L, height H and initial temperature T0:

main.m
% Define parameters
L = 1; % length of the wall
H = 1; % height of the wall
T0 = 20; % initial temperature of the wall
T_inf1 = 100; % temperature of left boundary
T_inf2 = 50; % temperature of right boundary
k = 1; % thermal conductivity of the material
rho = 1; % density of the material
Cp = 1; % specific heat capacity of the material
N = 100; % number of nodes in x direction
M = 100; % number of nodes in y direction
dx = L/(N-1); % distance between two nodes in x direction
dy = H/(M-1); % distance between two nodes in y direction
dt = 0.1; % time step size
Nt = 100; % number of time steps
alpha = k/(rho*Cp)*dt/(dx^2); % thermal diffusivity of the material

% Define initial condition
T = ones(N,M,Nt)*T0;
T(1,:,:) = T_inf1;
T(N,:,:) = T_inf2;

% Solve using FTCS scheme
for k = 1:Nt-1
    for i = 2:N-1
        for j = 2:M-1
            T(i,j,k+1) = T(i,j,k) + alpha*(T(i+1,j,k) - 2*T(i,j,k) + T(i-1,j,k) + T(i,j+1,k) - 2*T(i,j,k) + T(i,j-1,k));
        end
    end
end

% Plot temperature profile at final time
[X,Y] = meshgrid(0:dx:L,0:dy:H);
contourf(X,Y,T(:,:,Nt)');
colorbar
xlabel('x')
ylabel('y')
title('Temperature profile at final time')
1158 chars
39 lines

This code discretizes the wall into a 100 x 100 grid, uses a time step size of 0.1 and solves for 100 time steps. The resulting temperature distribution is plotted using the contourf function. You can adjust these parameters as per your requirements.

related categories

gistlibby LogSnag