lee-kessler equation in matlab

The Lee-Kesler equation is a thermodynamic equation commonly used to estimate the properties of saturated liquid and vapor, along with enthalpy and entropy values for pure substances. The equation can be expressed in terms of reduced variables as:

Z = 1 + B - Q/RT - (A / (RT * B)) * (ln(1 + B/RT) / (Z + B))

where: Z = Compressibility factor A = One of two adjustable parameters of the equation B = One of two adjustable parameters of the equation Q = Heat of vaporization T = Temperature in Kelvin

To apply this equation in Matlab, you must first define A and B constants for the substance of interest. You can then use the equation by creating a function that takes temperature as input and returns the corresponding compressibility factor value. Here's an example Matlab code that implements the Lee-Kesler equation:

main.m
function z = lee_kesler_eqn(Tr, A, B)
% Tr: Reduced temperature
% A, B: Constants dependent on the substance

% Calculate reduced variables
Pr = 1; % Assume saturation pressure at this point
Q = 0; % Assume ideal gas enthalpy

% Calculate compressibility factor
for i = 1:100 % Iterate until convergence
    z = 1 + B - Q/(Tr*z) - (A / (Tr * B)) * (log(1 + B/Tr) / (z + B));
end
379 chars
13 lines

Note that the last line is iterating the solution until convergence is reached, which is a common numerical solution approach for this equation. You can then call this function by passing the reduced temperature and constants for the substance:

main.m
A = 2.316; % Example constant values for methane
B = 0.1253; 
Tr = 0.8; % Example reduced temperature
z = lee_kesler_eqn(Tr, A, B)
131 chars
5 lines

This would return the compressibility factor value for methane at a temperature of 0.8 times its critical temperature.

related categories

gistlibby LogSnag