clc;
clear;
close all;
% Given boundary temperatures (°C)
T1 = 100;
T2 = 120;
T3 = 125;
T4 = 145;
% Wall thicknesses (m)
L_A = 0.02;
L_B = 0.03;
L_C = 0.05;
% Interface positions (m)
x1 = 0;
x2 = L_A;
x3 = L_A + L_B;
x4 = L_A + L_B + L_C;
% -----------------------------
% Region A: Linear (no generation)
xA = linspace(x1, x2, 50);
T_A = T1 + (T2 - T1) * (xA - x1) / (x2 - x1);
% Region B: Linear (no generation)
xB = linspace(x2, x3, 50);
T_B = T2 + (T3 - T2) * (xB - x2) / (x3 - x2);
% -----------------------------
% Region C: Parabolic (with heat generation)
xC = linspace(x3, x4, 50);
% Define mid-point temperature (higher due to heat generation)
T_mid = 140; % at x_midC = midpoint of C region
x_midC = (x3 + x4) / 2;
% Fit a parabola through (x3,T3), (x_midC,T_mid), (x4,T4)
M = [x3^2 x3 1;
x_midC^2 x_midC 1;
x4^2 x4 1];
Y = [T3; T_mid; T4];
abc = M\Y; % Solve for coefficients a, b, c
a = abc(1);
b = abc(2);
c = abc(3);
T_C = a*xC.^2 + b*xC + c;
1
% -----------------------------
% Combine all regions
x_total = [xA xB xC];
T_total = [T_A T_B T_C];
% -----------------------------
% Plot the temperature distribution
figure;
plot(x_total, T_total, 'r-', 'LineWidth', 2);
hold on;
plot([x2 x2], [min(T_total) max(T_total)], 'k--');
plot([x3 x3], [min(T_total) max(T_total)], 'k--');
hold off;
xlabel('x (m)', 'FontSize', 12);
ylabel('Temperature (°C)', 'FontSize', 12);
title('Temperature Distribution Across Composite Wall', 'FontSize', 13);
legend('T(x)', 'Interface 1-2', 'Interface 2-3', 'Location', 'best');
grid on;
text(0.01, 175, 'Region A', 'FontSize', 11);
text(0.035, 140, 'Region B', 'FontSize', 11);
text(0.07, 125, 'Region C', 'FontSize', 11);