create a temperature distribution plot for different time intervals of a plane wall under transient heat conduction with heat flux applied to one side for 0.2 seconds every 1 second in matlab

To create a temperature distribution plot for different time intervals of a plane wall under transient heat conduction with heat flux applied to one side for 0.2 seconds every 1 second in Matlab, we can follow the steps given below:

  1. Define the problem geometry, boundary conditions, and material properties.
  2. Create a discretized mesh of the geometry.
  3. Set the time step and number of time steps to simulate the transient behavior.
  4. Define the heat flux function based on the problem statement.
  5. Solve the transient heat conduction equation at each time step using the finite difference method.
  6. Plot the temperature distribution at each time step.

Here is some sample code to get started:

main.m
% Define problem parameters
L = 1.0; % Length of wall (m)
Tf = 20.0; % Initial temperature (C)
q = 1000.0; % Heat flux (W/m2)
alpha = 1.2e-5; % Thermal diffusivity (m2/s)
t_final = 6.0; % Final simulation time (s)
delta_t = 0.01; % Time step size (s)
delta_x = 0.05; % Space step size (m)

% Set up grid
x = 0:delta_x:L;
t = 0:delta_t:t_final;
n_x = length(x);
n_t = length(t);

% Initialize temperature matrix
T = zeros(n_x, n_t);
T(:,1) = Tf;

% Define heat flux function
q_func = @(t) q*(mod(t,1)<0.2);

% Define finite difference coefficients
D = alpha*delta_t/delta_x^2;
E = -2*D;

% Time loop
for i = 2:n_t
    % Boundary condition at x=0
    T(1,i) = Tf;
    
    % Solve for temperature at each interior node
    for j = 2:n_x-1
        T(j,i) = T(j,i-1) + D*(T(j+1,i-1) - 2*T(j,i-1) + T(j-1,i-1)) + q_func(t(i))*delta_t;
    end
    
    % Boundary condition at x=L
    T(n_x,i) = T(n_x-1,i);
end

% Plot temperature distribution at specified times
plot(x, T(:,1), 'b-', x, T(:,101), 'r-', x, T(:,201), 'g-', x, T(:,301), 'k-');
xlabel('Distance (m)');
ylabel('Temperature (C)');
legend('t=0 s', 't=1 s', 't=2 s', 't=3 s');
1133 chars
46 lines

In this code, the problem parameters are defined at the beginning, including the size of the wall (L), the initial temperature (Tf), the heat flux (q), the thermal diffusivity (alpha), the final simulation time (t_final), and the time and space step sizes (delta_t and delta_x).

The grid is set up based on these parameters, the temperature matrix is initialized, and the heat flux function is defined as a scalar multiple of a step function that is 0.2 seconds long every 1 second.

The finite difference coefficients are also defined, and a time loop is used to solve the transient heat conduction equation at each time step.

Finally, the temperature distribution is plotted at four different times using the plot function.

gistlibby LogSnag