MATLAB Heat Transfer Simulation: Conduction, Convection & Radiation
MATLAB heat transfer simulation is a useful way for engineering students to move from equations on paper to a numerical model they can inspect, modify and validate. In this tutorial, we build a practical steady-state thermal model covering conduction, convection and radiation. The complete MATLAB script calculates the three modes, solves a combined wall problem, produces seven engineering plots and checks the final energy balance.
The example is deliberately small enough to understand without a large CFD package, but it still introduces professional numerical habits: clear inputs, SI-unit consistency, a nonlinear energy balance, numerical root solving, parameter sensitivity and validation. You can run the supplied .m file first and then change the inputs to turn the article into a hands-on laboratory exercise.
Conduction + Convection + Radiation in One MATLAB Model
The model represents a hot fluid, an inner convection boundary, a solid wall and an outer surface that loses heat through both convection and thermal radiation. Seven MATLAB figures are generated automatically.
- Introduction to Heat Transfer
- Learning Objectives
- Three Modes of Heat Transfer
- Governing Equations
- MATLAB Problem Definition
- Complete MATLAB Code
- Explanation of the MATLAB Code
- Temperature Distribution Result
- Effect of Convection Coefficient
- Effect of Emissivity
- Conduction vs Convection vs Radiation
- Wall Thickness Sensitivity
- Energy-Balance Validation
- Student Exercises
- Engineering Applications
- Conclusion
- Frequently Asked Questions
1. Introduction to Heat Transfer
Heat transfer is the movement of thermal energy caused by a temperature difference. Mechanical, chemical, aerospace, energy and HVAC systems repeatedly use the same three mechanisms: conduction through matter, convection between a surface and a fluid, and thermal radiation between surfaces or surroundings.
Real systems often involve more than one mechanism at the same time. A wall separating a hot space from a colder environment may receive heat from the indoor air by convection, conduct it through the solid and then reject it outdoors by both convection and radiation. A calculation that considers only one mechanism can therefore miss part of the physical heat balance.
MATLAB is useful because it turns these relationships into a repeatable numerical experiment. Once the base case works, a few input changes can show how wall thickness, thermal conductivity, convection coefficient and emissivity affect the result.
2. Learning Objectives
After completing this tutorial, students should be able to:
- distinguish conduction, convection and radiation in a thermal system;
- apply Fourier law, Newton's law of cooling and the Stefan-Boltzmann relation;
- build a simple thermal-resistance model in MATLAB;
- solve a nonlinear surface-temperature balance using
fzero; - generate engineering plots from calculated variables;
- study the effects of convection coefficient, emissivity and wall thickness;
- check whether a numerical solution satisfies an energy balance.
3. Three Modes of Heat Transfer
| Mode | Main relationship | Physical meaning | Important parameters |
|---|---|---|---|
| Conduction | Q = kA(T1 - T2)/L | Energy transfer through a material because of a temperature gradient. | k, A, L, temperature difference |
| Convection | Q = hA(Ts - T∞) | Heat exchange between a surface and a surrounding fluid. | h, A, surface temperature, fluid temperature |
| Radiation | Q = εσA(Ts4 - Tsur4) | Thermal energy exchanged through electromagnetic radiation. | ε, σ, A, absolute temperatures |
Conduction is controlled by material conductivity and the temperature gradient. Convection introduces the heat-transfer coefficient h. Radiation is different because temperature appears to the fourth power and the equation requires absolute temperature.
4. Governing Equations
Fourier law for conduction
For the plane wall, k is thermal conductivity, A is area and L is wall thickness. Increasing k increases heat transfer, while increasing L increases conduction resistance.
Newton's law of cooling
The coefficient h depends on fluid and flow conditions. In a detailed study it may come from Reynolds, Prandtl and Nusselt correlations. Here it is an input so students can focus on the thermal model.
Stefan-Boltzmann radiation
The emissivity ε is dimensionless and σ is the Stefan-Boltzmann constant. Both temperatures in the fourth-power expression are absolute temperatures in Kelvin.
Combined steady-state balance
At steady state, heat reaching the outer surface equals heat leaving it. Radiation makes the equation nonlinear, so the unknown outer surface temperature is solved numerically.
5. MATLAB Problem Definition
The base case represents a one-square-metre wall with thickness 0.10 m and thermal conductivity 1.50 W/(m·K). The hot fluid is at 80°C, outdoor air is at 25°C, surroundings are at 15°C, the inner and outer convection coefficients are 12 and 10 W/(m²·K), and emissivity is 0.85.
| Parameter | Symbol | Base value | Unit |
|---|---|---|---|
| Wall thickness | L | 0.10 | m |
| Area | A | 1.00 | m² |
| Thermal conductivity | k | 1.50 | W/(m·K) |
| Hot fluid temperature | Thot | 80 | °C |
| Inner h | hin | 12 | W/(m²·K) |
| Outdoor fluid temperature | T∞ | 25 | °C |
| Outer h | hout | 10 | W/(m²·K) |
| Surroundings temperature | Tsur | 15 | °C |
| Emissivity | ε | 0.85 | - |
All calculations use SI units. That choice matters: mixed units can produce values that look reasonable while being physically wrong.
6. Complete MATLAB Code
Save the following as MATLAB_Heat_Transfer_Conduction_Convection_Radiation.m. The script calculates the base case, prints the results and creates seven MATLAB figures.
%% MATLAB Heat Transfer Simulation: Conduction, Convection & Radiation
% Educational script for engineering students.
% Demonstrates conduction, convection, radiation and a combined steady
% state wall model. Uses SI units throughout.
%
% Figures generated:
% 1. Standalone conduction/convection/radiation comparison
% 2. Temperature distribution through the wall
% 3. Effect of convection coefficient h
% 4. Effect of emissivity
% 5. Radiation contribution vs emissivity
% 6. Convection vs radiation heat rejection
% 7. Effect of wall thickness
clear; clc; close all;
%% 1. INPUT PARAMETERS
L = 0.10; % Wall thickness [m]
A = 1.00; % Area [m^2]
k = 1.50; % Wall thermal conductivity [W/(m*K)]
T_hot = 80; % Hot fluid temperature [deg C]
h_in = 12; % Inner convection coefficient [W/(m^2*K)]
T_inf = 25; % Outdoor fluid temperature [deg C]
h_out = 10; % Outer convection coefficient [W/(m^2*K)]
T_sur = 15; % Radiation surroundings temperature [deg C]
epsilon = 0.85; % Surface emissivity [-]
sigma = 5.670374419e-8; % Stefan-Boltzmann constant [W/(m^2*K^4)]
%% 2. STANDALONE CONDUCTION EXAMPLE
% Fourier law: Q = k*A*(T1-T2)/L
T1 = 80; T2 = 25;
Q_conduction = k*A*(T1-T2)/L;
%% 3. STANDALONE CONVECTION EXAMPLE
% Newton cooling: Q = h*A*(Ts-T_inf)
Ts_conv = 60;
Q_convection = h_out*A*(Ts_conv-T_inf);
%% 4. STANDALONE RADIATION EXAMPLE
% Stefan-Boltzmann: Q = eps*sigma*A*(Ts^4-Tsur^4)
Ts_rad = 60 + 273.15;
Tsur_K = T_sur + 273.15;
Q_radiation = epsilon*sigma*A*(Ts_rad^4-Tsur_K^4);
%% 5. COMBINED STEADY-STATE MODEL
% Hot fluid -> inner convection -> wall conduction -> outer surface
% Outer surface rejects heat by BOTH convection and radiation.
%
% At steady state:
% Q_cond = Q_conv,out + Q_rad
%
% Inner convection + wall conduction are represented by resistances.
R_in = 1/(h_in*A); % [K/W]
R_cond = L/(k*A); % [K/W]
% Heat arriving at outer surface for an assumed outer surface temperature.
Q_to_surface = @(Ts_C) (T_hot-Ts_C)/(R_in+R_cond);
% Heat leaving outer surface by convection + radiation.
Q_from_surface = @(Ts_C) h_out*A*(Ts_C-T_inf) + ...
epsilon*sigma*A*((Ts_C+273.15)^4-(T_sur+273.15)^4);
% Solve nonlinear surface energy balance.
balance = @(Ts_C) Q_to_surface(Ts_C)-Q_from_surface(Ts_C);
Ts_out = fzero(balance,35);
% Final combined-model results.
Q_total = Q_to_surface(Ts_out);
Q_conv_out = h_out*A*(Ts_out-T_inf);
Q_rad_out = epsilon*sigma*A*((Ts_out+273.15)^4-(T_sur+273.15)^4);
Ts_in = T_hot-Q_total*R_in;
q_total = Q_total/A;
balance_error = Q_total-(Q_conv_out+Q_rad_out);
conv_fraction = 100*Q_conv_out/Q_total;
rad_fraction = 100*Q_rad_out/Q_total;
%% 6. PRINT RESULTS
fprintf('\n============================================================\n');
fprintf(' MATLAB HEAT TRANSFER SIMULATION\n');
fprintf(' Conduction + Convection + Radiation\n');
fprintf('============================================================\n');
fprintf('\nINPUTS\n');
fprintf('Wall thickness = %.4f m\n',L);
fprintf('Thermal conductivity = %.3f W/(m K)\n',k);
fprintf('Area = %.3f m^2\n',A);
fprintf('Hot fluid temperature = %.2f deg C\n',T_hot);
fprintf('Outdoor fluid temperature = %.2f deg C\n',T_inf);
fprintf('Surroundings temperature = %.2f deg C\n',T_sur);
fprintf('Inner h = %.2f W/(m^2 K)\n',h_in);
fprintf('Outer h = %.2f W/(m^2 K)\n',h_out);
fprintf('Emissivity = %.3f\n',epsilon);
fprintf('\nCOMBINED MODEL RESULTS\n');
fprintf('Inner wall surface temp = %.3f deg C\n',Ts_in);
fprintf('Outer wall surface temp = %.3f deg C\n',Ts_out);
fprintf('Total heat transfer = %.3f W\n',Q_total);
fprintf('Heat flux = %.3f W/m^2\n',q_total);
fprintf('Outer convection = %.3f W (%.2f%%)\n',Q_conv_out,conv_fraction);
fprintf('Outer radiation = %.3f W (%.2f%%)\n',Q_rad_out,rad_fraction);
fprintf('Energy balance error = %.3e W\n',balance_error);
fprintf('\nSTANDALONE EXAMPLES\n');
fprintf('Conduction example = %.3f W\n',Q_conduction);
fprintf('Convection example = %.3f W\n',Q_convection);
fprintf('Radiation example = %.3f W\n',Q_radiation);
%% 7. FIGURE 1 - THREE HEAT-TRANSFER MODES
figure('Name','Heat Transfer Modes','Color','w');
bar([Q_conduction,Q_convection,Q_radiation]);
grid on;
xticks(1:3); xticklabels({'Conduction','Convection','Radiation'});
ylabel('Heat-transfer rate, Q [W]');
title('Standalone Heat-Transfer Mode Comparison');
set(gca,'FontSize',11);
%% 8. FIGURE 2 - TEMPERATURE DISTRIBUTION THROUGH WALL
x = linspace(0,L,200);
T_wall = Ts_in-(Ts_in-Ts_out)*(x/L);
figure('Name','Temperature Distribution','Color','w');
plot(x,T_wall,'LineWidth',2); hold on;
plot(0,Ts_in,'o','MarkerSize',8,'LineWidth',1.5);
plot(L,Ts_out,'o','MarkerSize',8,'LineWidth',1.5);
yline(T_hot,'--','Hot fluid','LineWidth',1.2);
yline(T_inf,'--','Outdoor fluid','LineWidth',1.2);
grid on;
xlabel('Distance through wall [m]');
ylabel('Temperature [deg C]');
title('Temperature Distribution Through the Solid Wall');
legend('Wall temperature','Inner surface','Outer surface','Hot fluid','Outdoor fluid','Location','best');
set(gca,'FontSize',11);
%% 9. FIGURE 3 - CONVECTION COEFFICIENT SENSITIVITY
h_values = linspace(2,40,100);
Q_h = zeros(size(h_values));
for i = 1:numel(h_values)
h_test = h_values(i);
balance_h = @(Ts) Q_to_surface(Ts) - ...
(h_test*A*(Ts-T_inf)+epsilon*sigma*A*((Ts+273.15)^4-Tsur_K^4));
Ts_test = fzero(balance_h,35);
Q_h(i) = Q_to_surface(Ts_test);
end
figure('Name','Convection Sensitivity','Color','w');
plot(h_values,Q_h,'LineWidth',2); grid on;
xlabel('Outer convection coefficient, h [W/(m^2 K)]');
ylabel('Total heat-transfer rate, Q [W]');
title('Effect of Convection Coefficient on Heat Transfer');
set(gca,'FontSize',11);
%% 10. FIGURE 4 - EMISSIVITY SENSITIVITY
epsilon_values = linspace(0.05,1.0,100);
Q_epsilon = zeros(size(epsilon_values));
for i = 1:numel(epsilon_values)
eps_test = epsilon_values(i);
balance_eps = @(Ts) Q_to_surface(Ts) - ...
(h_out*A*(Ts-T_inf)+eps_test*sigma*A*((Ts+273.15)^4-Tsur_K^4));
Ts_test = fzero(balance_eps,35);
Q_epsilon(i) = Q_to_surface(Ts_test);
end
figure('Name','Radiation Sensitivity','Color','w');
plot(epsilon_values,Q_epsilon,'LineWidth',2); grid on;
xlabel('Surface emissivity, epsilon [-]');
ylabel('Total heat-transfer rate, Q [W]');
title('Effect of Surface Emissivity on Total Heat Transfer');
set(gca,'FontSize',11);
%% 11. FIGURE 5 - RADIATION CONTRIBUTION VS EMISSIVITY
radiation_fraction = zeros(size(epsilon_values));
for i = 1:numel(epsilon_values)
eps_test = epsilon_values(i);
balance_eps = @(Ts) Q_to_surface(Ts) - ...
(h_out*A*(Ts-T_inf)+eps_test*sigma*A*((Ts+273.15)^4-Tsur_K^4));
Ts_test = fzero(balance_eps,35);
Q_test = Q_to_surface(Ts_test);
Q_rad_test = eps_test*sigma*A*((Ts_test+273.15)^4-Tsur_K^4);
radiation_fraction(i) = 100*Q_rad_test/Q_test;
end
figure('Name','Radiation Contribution','Color','w');
plot(epsilon_values,radiation_fraction,'LineWidth',2); grid on;
xlabel('Surface emissivity, epsilon [-]');
ylabel('Radiation contribution [%]');
title('Radiation Contribution to Total Heat Rejection');
set(gca,'FontSize',11);
%% 12. FIGURE 6 - OUTER-SURFACE HEAT REJECTION
figure('Name','Heat Rejection Contribution','Color','w');
bar([Q_conv_out,Q_rad_out]); grid on;
xticks(1:2); xticklabels({'Convection','Radiation'});
ylabel('Heat-transfer rate [W]');
title('Outer-Surface Heat Rejection Mechanisms');
set(gca,'FontSize',11);
%% 13. FIGURE 7 - WALL THICKNESS SENSITIVITY
L_values = linspace(0.01,0.30,100);
Q_L = zeros(size(L_values));
for i = 1:numel(L_values)
L_test = L_values(i);
R_cond_test = L_test/(k*A);
Q_surface_test = @(Ts) (T_hot-Ts)/(R_in+R_cond_test);
balance_L = @(Ts) Q_surface_test(Ts) - ...
(h_out*A*(Ts-T_inf)+epsilon*sigma*A*((Ts+273.15)^4-Tsur_K^4));
Ts_test = fzero(balance_L,35);
Q_L(i) = Q_surface_test(Ts_test);
end
figure('Name','Wall Thickness Sensitivity','Color','w');
plot(L_values,Q_L,'LineWidth',2); grid on;
xlabel('Wall thickness, L [m]');
ylabel('Total heat-transfer rate, Q [W]');
title('Effect of Wall Thickness on Heat Transfer');
set(gca,'FontSize',11);
%% 14. EDUCATIONAL SUMMARY
fprintf('\n============================================================\n');
fprintf('KEY ENGINEERING OBSERVATIONS\n');
fprintf('============================================================\n');
fprintf('1. Increasing wall thickness increases conduction resistance.\n');
fprintf('2. Increasing h generally increases surface heat transfer.\n');
fprintf('3. Increasing emissivity increases radiative heat transfer.\n');
fprintf('4. Radiation uses absolute temperature and depends on T^4.\n');
fprintf('5. At steady state, heat entering equals heat leaving.\n');
%% 15. OPTIONAL REUSABLE RADIATION FUNCTION
% Example use after the script has been run:
% Q = radiationHeatTransfer(60,15,0.85,1.0)
function Q = radiationHeatTransfer(Ts_C,Tsur_C,epsilon,A)
% radiationHeatTransfer - net radiation heat transfer [W]
% Inputs: Ts_C, Tsur_C [deg C], epsilon [-], A [m^2]
sigma = 5.670374419e-8;
Ts_K = Ts_C + 273.15;
Tsur_K = Tsur_C + 273.15;
Q = epsilon*sigma*A*(Ts_K^4-Tsur_K^4);
end
Set wall thickness, area, thermal conductivity, fluid temperatures, convection coefficients, emissivity and surroundings temperature.
Use Fourier law for conduction, Newton's law of cooling for convection and the Stefan-Boltzmann relation for radiation.
Represent inner convection and wall conduction as thermal resistances and write the outer-surface balance as conduction heat in equals convection plus radiation heat out.
Use MATLAB fzero to find the outer wall temperature that satisfies the combined steady-state energy balance.
Plot the temperature profile and sensitivity to convection coefficient, emissivity and wall thickness, then check that the energy-balance error is close to zero.
7. Explanation of the MATLAB Code
The script first clears the workspace and defines the thermal inputs. Keeping the inputs together makes the model easy to audit and modify. The next three sections calculate conduction, convection and radiation independently so students can see the individual mechanisms before studying the coupled problem.
The combined model defines R_in = 1/(h_in*A) and R_cond = L/(k*A). For an assumed outer surface temperature, MATLAB calculates the heat arriving at that surface. It separately calculates heat leaving by outdoor convection and radiation. The residual between these two quantities is passed to fzero.
When the residual reaches zero, the outer surface satisfies the steady-state energy balance. The script then calculates heat flux, convection and radiation contributions, and the balance error. The plotting sections reuse these variables for sensitivity studies rather than performing disconnected calculations.
8. Temperature Distribution Result
The wall temperature is linear in this example because the model assumes one-dimensional steady conduction, constant thermal conductivity and no internal heat generation. The plot also shows that fluid temperatures and wall-surface temperatures are not automatically the same; the difference across each fluid boundary is associated with convection.
Figure 2. Temperature profile through the wall, including the calculated inner and outer surface temperatures.
Use the full-size link beneath the figure when preparing a report or lecture note. The link points to the same Blogger-hosted image URL used by the displayed result.
9. Effect of Convection Coefficient
The third plot varies the outer convection coefficient from 2 to 40 W/(m²·K). For every value, MATLAB solves the surface-temperature equation again. This matters because changing h can change both the surface temperature and the final heat-transfer rate.
10. Effect of Emissivity
The fourth plot varies emissivity from 0.05 to 1.0. Increasing emissivity generally increases the ability of the surface to exchange thermal radiation, although the final result also depends on surface temperature and surroundings temperature.
11. Conduction vs Convection vs Radiation
The first plot compares the three standalone calculations. It is a teaching comparison, not a claim that the three values are independent heat losses from one identical boundary. The coupled wall model provides the physically consistent steady-state result.
The sixth plot focuses on the actual outer-surface heat rejection in the combined model. At that surface, the incoming conduction heat is divided between convection to the outdoor fluid and radiation to the surroundings.
12. Wall Thickness Sensitivity
Conduction resistance is proportional to wall thickness:
The seventh plot changes wall thickness from 0.01 to 0.30 m and resolves the coupled model at each value.
A thicker wall generally reduces the heat-transfer rate because it increases conduction resistance. The curve is coupled to the convection and radiation boundaries, so it represents the complete model rather than conduction alone.
13. Energy-Balance Validation
A numerical result should not be accepted simply because MATLAB returns a number. The script checks:
For a converged steady-state solution, this error should be very small relative to the heat-transfer rate. The Command Window prints the error in watts using scientific notation. The script also prints inner and outer surface temperatures, total heat transfer, heat flux and the convection/radiation contributions.
14. Student Exercises
| Exercise | Change | Question |
|---|---|---|
| 1 | Set k = 0.50 W/(m·K) | How does lower conductivity change total heat transfer? |
| 2 | Double wall thickness | How much does heat transfer decrease? |
| 3 | Set emissivity to 0.20 | How does the radiation contribution change? |
| 4 | Increase hout | What happens to the outer-surface temperature? |
| 5 | Set Tsur = 25°C | How does reducing the radiation temperature difference affect Qrad? |
| 6 | Change the area | Which quantities scale with area and which temperatures are controlled by resistances? |
| 7 | Compare low and high emissivity | When does radiation become a larger share of heat rejection? |
| 8 | Change spatial resolution | Compare wall-temperature profiles using 10, 20, 50 and 100 points. |
A strong student assignment is to submit the input table, governing equations, MATLAB code, three selected plots, an energy-balance check and a short engineering interpretation.
15. Engineering Applications
The same ideas appear in building envelopes, heat exchangers, electronics cooling, furnaces, boilers, thermal insulation and energy systems. Building walls combine conduction through layers with convection and long-wave radiation at surfaces. Heat exchangers involve convection on fluid sides and conduction through the separating wall. Electronics cooling can involve conduction through the package and heat sink followed by convection and radiation.
For students moving toward CFD, this model is a useful stepping stone. Before solving a full 2D temperature field, it helps to understand boundary conditions, thermal resistance, heat flux, sensitivity analysis and energy conservation.
The Thermal Diffusivity Calculator is useful when moving from steady conduction to transient analysis. The Stefan-Boltzmann Radiation Calculator isolates the radiation equation, while the U-value / R-value Calculator extends thermal resistance to multi-layer envelopes. For HVAC air-side work, the Psychrometric Calculator provides moist-air properties.
16. Conclusion
This MATLAB heat transfer simulation connects three fundamental mechanisms with a practical numerical workflow. The script calculates conduction, convection and radiation, solves the coupled steady-state wall problem with fzero, produces seven plots and checks the energy balance.
The real learning value is the workflow: define the physics, keep units consistent, formulate the equations, solve the unknown boundary condition, visualize the result, vary important parameters and validate the solution. Once this pattern is understood, it can be extended to transient conduction, fins, heat exchangers, thermal-resistance networks and 2D numerical heat-transfer solvers.
Frequently Asked Questions About MATLAB Heat Transfer Simulation
What does this MATLAB heat transfer simulation calculate?
The script demonstrates conduction, convection and radiation separately and then combines them in a steady-state wall model where heat reaches the outer surface by conduction and leaves through convection and radiation.
Which equations are used in the MATLAB heat transfer model?
The tutorial uses Fourier law for conduction, Newton's law of cooling for convection, and the Stefan-Boltzmann equation for radiation. The combined model is solved from a steady-state energy balance.
Why is fzero used in the MATLAB heat transfer simulation?
The radiation term contains absolute temperature raised to the fourth power, so the outer-surface energy balance is nonlinear. MATLAB fzero finds the surface temperature that makes heat entering equal heat leaving.
Why must radiation temperature be converted to Kelvin?
The Stefan-Boltzmann equation uses absolute temperature. Celsius values must therefore be converted to Kelvin before evaluating the fourth-power temperature terms.
Can I change the wall thickness and material in the MATLAB code?
Yes. Change L for wall thickness and k for thermal conductivity in the input section, then rerun the script. The wall-thickness plot updates automatically.
Can this model be used for a real engineering design?
It is suitable for learning, preliminary analysis and sensitivity studies. Detailed design may require temperature-dependent properties, contact resistance, view factors, transient effects, multidimensional conduction and validated standards.
Author and Technical Note
Authoritative External References
- MathWorks MATLAB Documentation - official MATLAB language and numerical-computing documentation.
- MathWorks fzero Documentation - official reference for scalar nonlinear equation solving.
- NIST Fundamental Physical Constants - reference values for physical constants.
- ASHRAE Handbook - established HVAC and thermal-engineering reference material.
- NIST REFPROP - high-accuracy thermodynamic and transport-property reference data.

Comments
Post a Comment