function RH = calculate_RH(Tdry, Twet, P)
% Tdry: dry bulb temperature in °C
% Twet: wet bulb temperature in °C
% P: atmospheric pressure in kPa

% Constants for water vapor pressure calculation
Tn = 273.15; % Triple point of water
a = 6.116441; % Constant a
b = 17.502; % Constant b
c = 240.97; % Constant c

% Calculate saturation vapor pressure
gamma = b * Tdry / (c + Tdry);
es_0 = a * 10^(gamma);

% Correct for atmospheric pressure
pws = es_0 * (1.0007 + 3.46e-6*P); % Saturation vapor pressure at given pressure

% Calculate vapor pressure from wet bulb temperature
ew = a * 10^(b * Twet /(c + Twet));

% Calculate relative humidity
RH = ew / pws * 100;

end

you didn't use Tn to calculate Relative humidity