Borrar filtros
Borrar filtros

Plot Pressure- enthalpy (P-H) diagram

130 visualizaciones (últimos 30 días)
Hussein
Hussein el 13 de Ag. de 2023
Editada: Karan Singh el 23 de Ag. de 2023
Dear All,
How can I plot a PH (pressue- enthalpy) diagram using coolprop library through matlab for 'R134a'?
Regards

Respuestas (1)

Karan Singh
Karan Singh el 23 de Ag. de 2023
Editada: Karan Singh el 23 de Ag. de 2023
Hi Hussein, as you would have tried and seen the CoolProp library. First install this library.
So we can try via python in MATLAB. Here are the detailed steps for the same.
  1. Install python from Welcome to Python.org according to your os I have used the Python 3.9.1.
  2. Open MATLAB and add python by using the following commands:
pyversion C:\Users\<user>\AppData\Local\Programs\Python\Python39\python.exe
Check the Python version to ensure it's set up correctly.
pyversion
Now, Python is integrated into your MATLAB environment. Proceed to install "CoolProp."
  1. To install "CoolProp," execute the following MATLAB command:
[v,e]=pyversion; system([e, ' -m pip install --user -U CoolProp'])
2. Now that "CoolProp" is installed, you can set the parameter values and write the rest of the code.
% Define pressure and enthalpy ranges
pressure = linspace(0, 2e6, 100); % Pressure range in Pa
enthalpy = linspace(0, 3000e3, 100); % Enthalpy range in J/kg
% Calculate specific volume
v = zeros(length(pressure), length(enthalpy));
for i = 1:length(pressure)
for j = 1:length(enthalpy)
v(i, j) = CoolProp.PropsSI('D', 'P', pressure(i), 'H', enthalpy(j), 'R134a');
end
end
% Plot the PH diagram
figure;
contourf(enthalpy, pressure, v, 'LineStyle', 'none');
colorbar;
xlabel('Enthalpy (J/kg)');
ylabel('Pressure (Pa)');
title('R134a Pressure-Enthalpy (PH) Diagram');
This would plot the required result, please note that using "CoolProp" through the Python interface in MATLAB may have some performance implications due to the inter-language communication overhead.

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by