Clear Filters
Clear Filters

Two figures in to two plots. I need to plot (the density Vs pressure) and ( the density vs. Temperature) for the data itself and using Peng Robinson model.

2 views (last 30 days)
%% Data
%%% The first column is Temperature, the second is preesure, the third is
%%% density.
M = [280.148 0.8087 50.98
282.148 0.8176 50.98
303.139 0.9086 50.93
333.130 1.0324 50.86
343.127 1.0732 50.83
343.127 1.0732 50.83
353.125 1.1133 50.81
363.122 1.1517 50.78
373.118 1.1917 50.76
393.115 1.2687 50.71
413.111 1.3464 50.66
433.108 1.4198 50.61
453.105 1.4983 50.55
463.105 1.5352 50.53
473.104 1.5694 50.50
298.144 1.3543 88.74
313.136 1.4815 88.68
333.129 1.6423 88.60
353.125 1.7971 88.51
373.120 1.9469 88.42
393.115 2.0934 88.33
413.111 2.2368 88.25
433.108 2.3777 88.15
453.106 2.5158 88.06
463.105 2.5782 88.02
473.103 2.6462 87.97
323.133 2.4778 187.16
333.130 2.6918 187.07
343.128 2.8973 186.98
353.125 3.0955 186.90
363.123 3.2897 186.80
373.120 3.4793 186.71
383.117 3.6659 186.62
393.115 3.8500 186.52
403.113 4.0315 186.43
413.096 4.2113 186.33
423.110 4.3893 186.24
433.108 4.5653 186.14
453.106 4.9132 185.94
473.104 5.2557 185.75
328.136 2.7507 217.07
333.130 2.8804 217.02
343.128 3.1307 216.92
353.125 3.3720 216.81
363.122 3.6070 216.70
373.120 3.8369 216.60
383.117 4.0627 216.49
393.115 4.2851 216.38
403.113 4.5046 216.27
413.111 4.7215 216.16
423.110 4.9359 216.05
433.108 5.1482 215.93
443.107 5.3590 215.82
453.106 5.5681 215.71
473.104 5.9819 215.48
338.133 3.4746 346.47
343.128 3.7078 346.38
353.125 4.1544 346.21
363.122 4.5877 346.04
373.120 5.0116 345.87
383.117 5.4282 345.69
393.115 5.8368 345.52
403.113 6.2456 345.34
413.111 6.6476 345.16
423.110 7.0463 344.98
433.108 7.4415 344.80
443.107 7.8342 344.62
453.106 8.2232 344.43
473.104 8.9952 344.06
339.483 3.6320 449.66
343.128 3.8638 449.58
353.125 4.4800 449.35
363.122 5.0833 449.13
373.114 5.6791 448.90
383.117 6.2699 448.67
393.115 6.8559 448.44
403.110 7.4375 448.21
413.111 8.0157 447.98
423.110 8.5901 447.74
433.108 9.1613 447.51
453.106 10.2950 447.03
473.104 11.4172 446.54
339.283 3.6298 567.41
339.383 3.6364 567.41
340.252 3.7060 567.38
341.246 3.7847 567.35
342.253 3.8643 567.32
343.254 3.9436 567.30
343.254 3.9433 567.30
353.256 4.7442 567.01
363.255 5.5492 566.73
373.237 6.3547 566.44
383.258 7.1616 566.15
393.259 7.9540 565.85
413.261 9.5565 565.26
433.262 11.1515 564.66
453.263 12.7424 564.05
473.265 14.3170 563.43
333.145 3.1762 704.48
336.133 3.3908 704.38
338.133 3.5423 704.31
339.133 3.6316 704.28
340.128 3.7323 704.24
341.132 3.8353 704.21
342.132 3.9397 704.17
343.128 4.0445 704.13
353.115 5.1362 703.78
373.120 7.4227 703.05
393.115 9.7631 702.32
413.111 12.1260 701.57
433.108 14.4957 700.81
453.203 16.8750 700.03
339.133 3.6695 756.32
343.126 4.1431 756.16
353.125 5.3898 755.78
363.122 6.6820 755.39
373.120 7.9998 754.99
383.124 9.3353 754.60
393.115 10.6792 754.20
403.124 12.0331 753.79
413.111 13.3882 753.39
423.110 14.7467 752.98
433.108 16.1064 752.56
439.963 17.0384 752.28
335.140 3.3660 848.73
338.133 3.8158 848.60
343.128 4.5902 848.38
348.130 5.3874 848.16
353.133 6.1998 847.94
363.122 7.8533 847.50
373.120 9.5370 847.05
383.117 11.2391 846.60
393.133 12.9576 846.14
413.111 16.4039 845.22
416.116 16.9240 845.08
333.130 3.5409 924.19
338.133 4.4970 923.95
343.118 5.4717 923.71
348.130 6.4679 923.47
353.128 7.4740 923.23
358.128 8.4908 922.98
363.114 9.5120 922.73
368.125 10.5448 922.49
373.121 11.5796 922.24
378.123 12.6205 921.99
383.104 13.6591 921.74
393.115 15.7549 921.23
328.142 3.3843 988.22
333.130 4.5304 987.96
338.133 5.7026 987.70
343.128 6.8878 987.43
348.163 8.0951 987.17
353.125 9.2934 986.90
358.128 10.5115 986.64
363.122 11.7320 986.37
368.129 12.9609 986.10
373.120 14.1900 985.83
378.123 15.4247 985.56
383.117 16.6599 985.29
306.530 1.8664 1145.32
308.181 2.4621 1145.25
313.180 4.2649 1144.94
318.178 6.0758 1144.59
323.177 7.8960 1144.31
328.176 9.7266 1143.96
333.175 11.5449 1143.64
346.031 16.2723 1142.82];
%% Data extraction
T = M(:,1); % extract Temperature data
P = M(:,2); % extract Pressure data
rho = M(:,3); % extract Density data
[T, I] = sort(T); % sorted Temperature [K]
P = P(I); % sorted Pressure [MPa]
rho = rho(I); % sorted Density [kg/m³]
v = 1./rho; % specific volume [m³/kg]
%% Parameters
R = 8.314462618/(120.02e-3)*1e-6; % Gas constant [MJ/(kg*K)]
Tc = 339.45; % Critical Temperature [K]
Pc = 3642.77e-3; % Critical Pressure [MPa]
omega = 0.2986;
kappa = 0.37464 + 1.54266*omega - 0.26992*omega^2;
alpha = (1 + kappa*(1 - sqrt(T/Tc))).^2;
a = 0.45724*(R^2*Tc^2)/Pc; % parameter a in P–R EoS (Wiki)
% b = 0.07780*(R^2*Tc^2)/Pc; % parameter b (defined by OP)
b = 0.07780*(R*Tc)/Pc; % parameter b in P–R EoS (Wiki)
%% Peng–Robinson equation of state
pPR = (R*T)./(v - b) - (a*alpha)./(v.^2 + 2*b*v - b^2);
%% Graphing
%% ???

Accepted Answer

Mathieu NOE
Mathieu NOE on 20 Dec 2023
Edited: Mathieu NOE on 20 Dec 2023
hello
I finally plotted 3 figures as it was not clear to me is you wanted to use P or pPR as the pressure value . Anyway, I wanted to see the difference between the two =>see first plot
aslo I would suggest to put your data in a separate txt file so you get much more compact and nicer code
so in brief , a very simple suggestion below
your data are now in the attached txt file
%% Data
M = readmatrix('mydata.txt',"NumHeaderLines",1);
%% Data extraction
T = M(:,1); % extract Temperature data
P = M(:,2); % extract Pressure data
rho = M(:,3); % extract Density data
[T, I] = sort(T); % sorted Temperature [K]
P = P(I); % sorted Pressure [MPa]
rho = rho(I); % sorted Density [kg/m³]
v = 1./rho; % specific volume [m³/kg]
%% Parameters
R = 8.314462618/(120.02e-3)*1e-6; % Gas constant [MJ/(kg*K)]
Tc = 339.45; % Critical Temperature [K]
Pc = 3642.77e-3; % Critical Pressure [MPa]
omega = 0.2986;
kappa = 0.37464 + 1.54266*omega - 0.26992*omega^2;
alpha = (1 + kappa*(1 - sqrt(T/Tc))).^2;
a = 0.45724*(R^2*Tc^2)/Pc; % parameter a in P–R EoS (Wiki)
% b = 0.07780*(R^2*Tc^2)/Pc; % parameter b (defined by OP)
b = 0.07780*(R*Tc)/Pc; % parameter b in P–R EoS (Wiki)
%% Peng–Robinson equation of state
pPR = (R*T)./(v - b) - (a*alpha)./(v.^2 + 2*b*v - b^2);
%% Graphing
% Two figures in to two plots.
% I need to plot (the density Vs pressure) and ( the density vs. Temperature)
% for the data itself and using Peng Robinson model.
%plot (pPR Vs P)
figure(1)
plot(P,pPR,'*');
title('pPR Vs P');
xlabel('P [MPa]');
ylabel('pPR [MPa]');
%plot (density Vs pressure pPR)
figure(2)
plot(pPR,rho,'*');
title('Density Vs Pressure');
xlabel('pressure [MPa]');
ylabel('density [kg/m³]');
%plot (density Vs Temperature)
figure(3)
plot(T,rho,'*');
title('Density Vs Temperature');
xlabel('temperature [K]');
ylabel('density [kg/m³]');

More Answers (1)

Sam Chak
Sam Chak on 20 Dec 2023
Edited: Sam Chak on 20 Dec 2023
Previously, didn't @Torsten successfully demonstrate how to plot the Peng–Robinson equation here? Are you expecting the data points to be plotted as dots?
Update: I'm unsure whether the Peng–Robinson equation can be rearranged to plot tPR. Please check and confirm.
%% Data
% The first column is Temperature, the second is preesure, the third is density.
M = [280.148 0.8087 50.98
282.148 0.8176 50.98
303.139 0.9086 50.93
333.130 1.0324 50.86
343.127 1.0732 50.83
343.127 1.0732 50.83
353.125 1.1133 50.81
363.122 1.1517 50.78
373.118 1.1917 50.76
393.115 1.2687 50.71
413.111 1.3464 50.66
433.108 1.4198 50.61
453.105 1.4983 50.55
463.105 1.5352 50.53
473.104 1.5694 50.50
298.144 1.3543 88.74
313.136 1.4815 88.68
333.129 1.6423 88.60
353.125 1.7971 88.51
373.120 1.9469 88.42
393.115 2.0934 88.33
413.111 2.2368 88.25
433.108 2.3777 88.15
453.106 2.5158 88.06
463.105 2.5782 88.02
473.103 2.6462 87.97
323.133 2.4778 187.16
333.130 2.6918 187.07
343.128 2.8973 186.98
353.125 3.0955 186.90
363.123 3.2897 186.80
373.120 3.4793 186.71
383.117 3.6659 186.62
393.115 3.8500 186.52
403.113 4.0315 186.43
413.096 4.2113 186.33
423.110 4.3893 186.24
433.108 4.5653 186.14
453.106 4.9132 185.94
473.104 5.2557 185.75
328.136 2.7507 217.07
333.130 2.8804 217.02
343.128 3.1307 216.92
353.125 3.3720 216.81
363.122 3.6070 216.70
373.120 3.8369 216.60
383.117 4.0627 216.49
393.115 4.2851 216.38
403.113 4.5046 216.27
413.111 4.7215 216.16
423.110 4.9359 216.05
433.108 5.1482 215.93
443.107 5.3590 215.82
453.106 5.5681 215.71
473.104 5.9819 215.48
338.133 3.4746 346.47
343.128 3.7078 346.38
353.125 4.1544 346.21
363.122 4.5877 346.04
373.120 5.0116 345.87
383.117 5.4282 345.69
393.115 5.8368 345.52
403.113 6.2456 345.34
413.111 6.6476 345.16
423.110 7.0463 344.98
433.108 7.4415 344.80
443.107 7.8342 344.62
453.106 8.2232 344.43
473.104 8.9952 344.06
339.483 3.6320 449.66
343.128 3.8638 449.58
353.125 4.4800 449.35
363.122 5.0833 449.13
373.114 5.6791 448.90
383.117 6.2699 448.67
393.115 6.8559 448.44
403.110 7.4375 448.21
413.111 8.0157 447.98
423.110 8.5901 447.74
433.108 9.1613 447.51
453.106 10.2950 447.03
473.104 11.4172 446.54
339.283 3.6298 567.41
339.383 3.6364 567.41
340.252 3.7060 567.38
341.246 3.7847 567.35
342.253 3.8643 567.32
343.254 3.9436 567.30
343.254 3.9433 567.30
353.256 4.7442 567.01
363.255 5.5492 566.73
373.237 6.3547 566.44
383.258 7.1616 566.15
393.259 7.9540 565.85
413.261 9.5565 565.26
433.262 11.1515 564.66
453.263 12.7424 564.05
473.265 14.3170 563.43
333.145 3.1762 704.48
336.133 3.3908 704.38
338.133 3.5423 704.31
339.133 3.6316 704.28
340.128 3.7323 704.24
341.132 3.8353 704.21
342.132 3.9397 704.17
343.128 4.0445 704.13
353.115 5.1362 703.78
373.120 7.4227 703.05
393.115 9.7631 702.32
413.111 12.1260 701.57
433.108 14.4957 700.81
453.203 16.8750 700.03
339.133 3.6695 756.32
343.126 4.1431 756.16
353.125 5.3898 755.78
363.122 6.6820 755.39
373.120 7.9998 754.99
383.124 9.3353 754.60
393.115 10.6792 754.20
403.124 12.0331 753.79
413.111 13.3882 753.39
423.110 14.7467 752.98
433.108 16.1064 752.56
439.963 17.0384 752.28
335.140 3.3660 848.73
338.133 3.8158 848.60
343.128 4.5902 848.38
348.130 5.3874 848.16
353.133 6.1998 847.94
363.122 7.8533 847.50
373.120 9.5370 847.05
383.117 11.2391 846.60
393.133 12.9576 846.14
413.111 16.4039 845.22
416.116 16.9240 845.08
333.130 3.5409 924.19
338.133 4.4970 923.95
343.118 5.4717 923.71
348.130 6.4679 923.47
353.128 7.4740 923.23
358.128 8.4908 922.98
363.114 9.5120 922.73
368.125 10.5448 922.49
373.121 11.5796 922.24
378.123 12.6205 921.99
383.104 13.6591 921.74
393.115 15.7549 921.23
328.142 3.3843 988.22
333.130 4.5304 987.96
338.133 5.7026 987.70
343.128 6.8878 987.43
348.163 8.0951 987.17
353.125 9.2934 986.90
358.128 10.5115 986.64
363.122 11.7320 986.37
368.129 12.9609 986.10
373.120 14.1900 985.83
378.123 15.4247 985.56
383.117 16.6599 985.29
306.530 1.8664 1145.32
308.181 2.4621 1145.25
313.180 4.2649 1144.94
318.178 6.0758 1144.59
323.177 7.8960 1144.31
328.176 9.7266 1143.96
333.175 11.5449 1143.64
346.031 16.2723 1142.82];
%% Data extraction
T = M(:,1); % extract Temperature data
P = M(:,2); % extract Pressure data
rho = M(:,3); % extract Density data
[T, I] = sort(T); % sorted Temperature [K]
P = P(I); % sorted Pressure [MPa]
rho = rho(I); % sorted Density [kg/m³]
v = 1./rho; % specific volume [m³/kg]
%% Parameters
R = 8.314462618/(120.02e-3)*1e-6; % Gas constant [MJ/(kg*K)]
Tc = 339.45; % Critical Temperature [K]
Pc = 3642.77e-3; % Critical Pressure [MPa]
omega = 0.2986;
kappa = 0.37464 + 1.54266*omega - 0.26992*omega^2;
alpha = (1 + kappa*(1 - sqrt(T/Tc))).^2;
a = 0.45724*(R^2*Tc^2)/Pc; % parameter a in P–R EoS (Wiki)
b = 0.07780*(R*Tc)/Pc; % parameter b in P–R EoS (Wiki)
%% Peng–Robinson equation of state
pPR = (R*T)./(v - b) - (a*alpha)./(v.^2 + 2*b*v - b^2);
tPR = (P + (a*alpha)./(v.^2 + 2*b*v - b^2)).*(v - b)/R;
%% Graphing
figure(1)
hold on
plot(rho, P, '.'), grid on % <-- from data
plot(rho, pPR, 'o'), grid on % <-- computed from Peng–Robinson equation
hold off
title('Density vs. Pressure')
xlabel Density, ylabel Pressure
legend('Data', 'Peng–Robinson', 'location', 'NW')
figure(2)
hold on
plot(rho, T, '.'), grid on % <-- from data
plot(rho, tPR, 'o'), grid on % <-- computed from Peng–Robinson equation
hold off
title('Density vs. Temperature')
xlabel Density, ylabel Temperature
legend('Data', 'Peng–Robinson', 'location', 'NE')

Categories

Find more on Execution Speed in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!