bwrs状态方程matlab
时间: 2023-12-06 16:37:34 浏览: 167
以下是使用MATLAB实现BWRS状态方程的示例代码:
```matlab
function [P, V, Z, F] = BWRS(T, C, P0, V0, tol)
% BWRS - Calculate the pressure, volume, compressibility factor, and fugacity
% coefficient using the BWRS equation of state.
%
% Syntax: [P, V, Z, F] = BWRS(T, C, P0, V0, tol)
%
% Inputs:
% - T: Temperature (K)
% - C: Composition (mole fraction)
% - P0: Initial pressure guess (Pa)
% - V0: Initial volume guess (m^3/mol)
% - tol: Tolerance for convergence
%
% Outputs:
% - P: Pressure (Pa)
% - V: Volume (m^3/mol)
% - Z: Compressibility factor
% - F: Fugacity coefficient
%
% Example:
% T = 300; % K
% C = [0.2 0.3 0.5]; % Composition
% P0 = 1e5; % Pa
% V0 = 0.024; % m^3/mol
% tol = 1e-6;
% [P, V, Z, F] = BWRS(T, C, P0, V0, tol);
% Constants
R = 8.314; % J/(mol*K)
kappa = 0.37464 + 1.54226 .* C - 0.26992 .* C.^2; % Binary interaction parameters
alpha = (1 + kappa .* (1 - sqrt(T ./ 647.3))).^2; % Temperature-dependent parameter
a = 0.45724 .* R.^2 .* (T ./ 647.3).^2 .* alpha; % Attraction parameter
b = 0.07780 .* R .* T ./ P0; % Repulsion parameter
% Initialization
P = P0;
V = V0;
Z = P .* V ./ (R .* T);
F = exp((Z - 1) - log(Z - b) - a ./ (2 .* sqrt(2) .* b) .* log((Z + (1 + sqrt(2)) .* b) ./ (Z + (1 - sqrt(2)) .* b)));
% Iteration
err = inf;
while err > tol
dZdP = (V - b) ./ (R .* T) - a ./ (R .* T .* sqrt(2) .* b .* (Z + (1 + sqrt(2)) .* b).^2) .* (Z + (1 + sqrt(2)) .* b - Z.^2 .* (2 .* Z + (1 + sqrt(2)) .* b));
dFdP = F .* (dZdP ./ Z - 1 ./ (Z - b) + a ./ (R .* T .* sqrt(2) .* b .* (Z + (1 + sqrt(2)) .* b).^2) .* (2 .* Z + (1 + sqrt(2)) .* b - Z.^2 .* (2 .* Z + 2 .* (1 + sqrt(2)) .* b)));
P_new = P - F .* (Z - 1) .* V ./ dFdP;
V_new = R .* T ./ P_new .* Z;
Z_new = P_new .* V_new ./ (R .* T);
F_new = exp((Z_new - 1) - log(Z_new - b) - a ./ (2 .* sqrt(2) .* b) .* log((Z_new + (1 + sqrt(2)) .* b) ./ (Z_new + (1 - sqrt(2)) .* b)));
err = abs(P_new - P);
P = P_new;
V = V_new;
Z = Z_new;
F = F_new;
end
end
```
阅读全文