model temperature as a function of position in a plane wall undergoing transient heat conduction with cyclic heat flux applied to one side in matlab

One way to model temperature as a function of position in a plane wall undergoing transient heat conduction with cyclic heat flux applied to one side is to use the Heat Transfer Toolbox in Matlab. Specifically, we can use the pdepe function to solve the heat equation subject to initial and boundary conditions.

Here's an example code that demonstrates this approach:

main.m
function temperature_in_wall()

    % Define the parameters of the problem
    k = 1;      % Thermal conductivity
    rho = 1;    % Density
    c = 1;      % Specific heat
    L = 1;      % Thickness of the wall
    Q0 = 1;     % Magnitude of the heat flux
    T0 = 0;     % Initial temperature
    h = 0.05;   % Convective heat transfer coefficient
    Ta = 0;     % Ambient temperature
    tspan = [0 10];  % Time interval to solve over
    x = linspace(0,L,101);  % Spatial grid

    % Define the heat flux function
    function q = heat_flux(x,t)
        q = Q0 * (1 - 2*abs(mod(t,1)-0.5));
    end

    % Define the PDE system
    function [c,f,s] = heat_eqn(x,t,u,DuDx)
        c = rho*c;
        f = k*DuDx;
        s = heat_flux(x,t) + h*(Ta - u);
    end

    % Set the initial and boundary conditions
    function [pl,ql,pr,qr] = heat_bc(xl,ul,xr,ur,t)
        pl = ul - T0;
        ql = 0;
        pr = ur - T0;
        qr = k*(h/c)*ur - h*Ta;
    end

    % Solve the PDE
    sol = pdepe(0,@heat_eqn,@heat_bc,@initial_condition,x,tspan);

    % Plot the results
    surf(x,t,sol);
    title('Temperature distribution in the wall');
    xlabel('Location in wall');
    ylabel('Time');
    zlabel('Temperature')

    % Define the initial condition
    function u0 = initial_condition(x)
        u0 = T0 * ones(size(x));
    end
end
1342 chars
50 lines

This code defines a heat flux function that oscillates between positive and negative values with a period of 2 seconds, and applies it to one side of a 1-meter-thick wall. The other side is maintained at a constant temperature of 0 degrees Celsius. The code solves the heat equation subject to these conditions and plots the resulting temperature distribution in the wall over time.

Note that this is just one example of how to model this problem in Matlab, and there are many other approaches that could be used depending on the specific details of the problem.

related categories

gistlibby LogSnag