Plot Pressure- enthalpy (P-H) diagram

Dear All,
How can I plot a PH (pressue- enthalpy) diagram using coolprop library through matlab for 'R134a'?
Regards

답변 (1개)

Karan Singh
Karan Singh 2023년 8월 23일
편집: Karan Singh 2023년 8월 23일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품

릴리스

R2022b

질문:

2023년 8월 13일

편집:

2023년 8월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by