% Heat Integration calculation
% Production of ammonia
% PARAMETERS
deltaTmin = 10;
shift = deltaTmin / 2;
% STREAM DATA
StreamName = {'C1'; 'C2'; 'H1'; 'H2'};
TypeStream = {'Cold'; 'Cold'; 'Hot'; 'Hot'};
Tin = [152.44; 77.98; 56.08; 220];
Tout = [200; 152.84; 40; 69];
Cp = [3.597; 9.245; 3.042; 3.12];
% APPLY TEMPERATURE SHIFTS
Tin_shifted = zeros(size(Tin));
Tout_shifted = zeros(size(Tout));
for i = 1:length(StreamName)
if strcmpi(TypeStream{i}, 'Cold')
Tin_shifted(i) = Tin(i) + shift;
Tout_shifted(i) = Tout(i) + shift;
elseif strcmpi(TypeStream{i}, 'Hot')
Tin_shifted(i) = Tin(i) - shift;
Tout_shifted(i) = Tout(i) - shift;
end
end
% CREATE AND DISPLAY STREAM TABLE
streamTable = table(StreamName, TypeStream, Tin, Tout, Cp, Tin_shifted,
Tout_shifted);
disp('Shifted Stream Temperature Table (ΔTmin = 10°C)');
disp(streamTable);
% HEAT CASCADE CALCULATION
allTemps = unique([Tin_shifted; Tout_shifted]);
allTemps = sort(allTemps, 'descend');
n_intervals = length(allTemps) - 1;
deltaT = diff(allTemps);
netCp = zeros(n_intervals, 1);
for i = 1:n_intervals
T_high = allTemps(i);
T_low = allTemps(i+1);
for j = 1:height(streamTable)
T_in = streamTable.Tin_shifted(j);
T_out = streamTable.Tout_shifted(j);
Cp_j = streamTable.Cp(j);
if strcmpi(streamTable.TypeStream{j}, 'Hot')
if T_in >= T_high && T_out <= T_low
netCp(i) = netCp(i) - Cp_j;
end
elseif strcmpi(streamTable.TypeStream{j}, 'Cold')
1
if T_in <= T_low && T_out >= T_high
netCp(i) = netCp(i) + Cp_j;
end
end
end
end
% HEAT FLOW AND ENTHALPY
heatFlow = netCp .* deltaT;
enthalpy = zeros(n_intervals + 1, 1);
for i = 2:length(enthalpy)
enthalpy(i) = enthalpy(i-1) + heatFlow(i-1);
end
% SHIFTED ENTHALPY AND UTILITIES
enthalpyShifted = enthalpy - min(enthalpy);
Q_hot_min = -min(enthalpy);
Q_cold_min = enthalpyShifted(end);
% CALCULATE TOTAL COLD STREAM DUTY
Q_heating_total = 0;
for i = 1:height(streamTable)
if strcmpi(streamTable.TypeStream{i}, 'Cold')
Q_heating_total = Q_heating_total + streamTable.Cp(i) *
(streamTable.Tout(i) - streamTable.Tin(i));
end
end
% COMPUTE MAXIMUM HEAT RECOVERY
MaxHeatRecovery = Q_heating_total - Q_hot_min;
% COMPUTE PINCH TEMP
pinchIdx = find(enthalpyShifted == 0, 1);
if isempty(pinchIdx)
[~, pinchIdx] = min(abs(enthalpyShifted));
end
T_pinch_shifted = allTemps(pinchIdx);
T_pinch_cold_real = T_pinch_shifted - shift;
T_pinch_hot_real = T_pinch_shifted + shift;
% DISPLAY HEAT CASCADE TABLE
fprintf('\nHeat Cascade Table (ΔTmin = %.1f°C):\n', deltaTmin);
fprintf('---------------------------------------------------------------\n');
fprintf('| Interval | T_high � T_low | ΔT (°C) | Net Cp | Q (kJ/kmol) |
Enthalpy |\n');
fprintf('---------------------------------------------------------------\n');
for i = 1:n_intervals
fprintf('| %2d | %6.1f � %6.1f | %7.1f | %6.1f | %10.1f | %8.1f
|\n', ...
i, allTemps(i), allTemps(i+1), deltaT(i), netCp(i), heatFlow(i),
enthalpyShifted(i));
end
fprintf('---------------------------------------------------------------\n');
fprintf('Minimum Hot Utility (Qh,min): %.1f kJ/kmol\n', Q_hot_min);
2
fprintf('Minimum Cold Utility (Qc,min): %.1f kJ/kmol\n\n', Q_cold_min);
% DISPLAY PINCH ANALYSIS SUMMARY
fprintf('\n----- Pinch Analysis Summary -----\n');
fprintf('Minimum External Heating (Qh,min): %.1f kJ/kmol\n', Q_hot_min);
fprintf('Minimum External Cooling (Qc,min): %.1f kJ/kmol\n', Q_cold_min);
fprintf('Maximum Heat Recovery: %.1f kJ/kmol\n', MaxHeatRecovery);
fprintf('Pinch Temperature (shifted): %.1f°C\n', T_pinch_shifted);
fprintf('Corresponding Cold Pinch (real temp): %.1f°C\n', T_pinch_cold_real);
fprintf('Corresponding Hot Pinch (real temp): %.1f°C\n', T_pinch_hot_real);
fprintf('-----------------------------------\n');
% PLOT: STREAM TEMPERATURE PROFILE
figure;
hold on;
grid on;
title('Stream Temperature Profile (Aligned with Pinch Temperature)');
ylabel('Shifted Temperature (°C)');
set(gca, 'XTick', []);
set(gca, 'YDir', 'reverse');
numLevels = length(allTemps);
yMap = containers.Map('KeyType', 'double', 'ValueType', 'double');
for k = 1:numLevels
yMap(allTemps(k)) = k;
end
yticks(1:numLevels);
yticklabels(allTemps);
ylim([0.5, numLevels + 0.5]);
x_offset = 1;
x = 1;
label_offset = 0.3;
for i = 1:length(StreamName)
color = strcmpi(TypeStream{i}, 'Hot') * [1 0 0] + strcmpi(TypeStream{i},
'Cold') * [0 0 1];
y1 = yMap(Tin_shifted(i));
y2 = yMap(Tout_shifted(i));
plot([x x], [y1, y2], '-', 'Color', color, 'LineWidth', 3);
upper_y = min(y1, y2);
text(x, upper_y - label_offset, StreamName{i}, ...
'HorizontalAlignment', 'center', ...
'FontSize', 10, 'FontWeight', 'bold', 'Color', color);
x = x + x_offset;
end
xlim([0, length(StreamName) + 1]);
% Add horizontal line at the pinch temperature (shifted)
pinch_y = yMap(T_pinch_shifted);
yline(pinch_y, '--r', ...
sprintf('Pinch = %.1f°C', T_pinch_shifted), ...
3
'LabelHorizontalAlignment', 'left', ...
'LabelVerticalAlignment', 'bottom', ...
'FontWeight', 'bold');
% PLOT: GRAND COMPOSITE CURVE (GCC)
figure;
hold on;
grid on;
title('Grand Composite Curve (GCC)');
xlabel('Enthalpy (kJ/kmol)');
ylabel('Shifted Temperature (°C)');
plot(enthalpyShifted, allTemps, 'LineWidth', 2, 'Color', [0 0.5 0.8]);
% Highlight pinch
xline(0, '--k', 'Q_{hot,min}', 'LabelVerticalAlignment','bottom', ...
'FontWeight', 'bold');
yline(T_pinch_shifted, '--r', ...
sprintf('Pinch = %.1f°C', T_pinch_shifted), ...
'LabelHorizontalAlignment', 'left', ...
'LabelVerticalAlignment', 'bottom', ...
'FontWeight', 'bold');
Shifted Stream Temperature Table (ΔTmin = 10°C)
StreamName TypeStream Tin Tout Cp Tin_shifted
Tout_shifted
__________ __________ ______ ______ _____ ___________
____________
{'C1'} {'Cold'} 152.44 200 3.597
157.44 205
{'C2'} {'Cold'} 77.98 152.84 9.245
82.98 157.84
{'H1'} {'Hot' } 56.08 40 3.042
51.08 35
{'H2'} {'Hot' } 220 69 3.12
215 64
Heat Cascade Table (ΔTmin = 10.0°C):
---------------------------------------------------------------
| Interval | T_high � T_low | ΔT (°C) | Net Cp | Q (kJ/kmol) | Enthalpy |
---------------------------------------------------------------
| 1 | 215.0 � 205.0 | -10.0 | -3.1 | 31.2 | 451.3 |
| 2 | 205.0 � 157.8 | -47.2 | 0.5 | -22.5 | 482.5 |
| 3 | 157.8 � 157.4 | -0.4 | 9.7 | -3.9 | 460.0 |
| 4 | 157.4 � 83.0 | -74.5 | 6.1 | -456.1 | 456.1 |
| 5 | 83.0 � 64.0 | -19.0 | -3.1 | 59.2 | 0.0 |
| 6 | 64.0 � 51.1 | -12.9 | 0.0 | -0.0 | 59.2 |
| 7 | 51.1 � 35.0 | -16.1 | -3.0 | 48.9 | 59.2 |
---------------------------------------------------------------
Minimum Hot Utility (Qh,min): 451.3 kJ/kmol
Minimum Cold Utility (Qc,min): 108.1 kJ/kmol
4
----- Pinch Analysis Summary -----
Minimum External Heating (Qh,min): 451.3 kJ/kmol
Minimum External Cooling (Qc,min): 108.1 kJ/kmol
Maximum Heat Recovery: 411.9 kJ/kmol
Pinch Temperature (shifted): 83.0°C
Corresponding Cold Pinch (real temp): 78.0°C
Corresponding Hot Pinch (real temp): 88.0°C
-----------------------------------
5
6
Published with MATLAB® R2025b