Antoine's equation - K values

13 views (last 30 days)
David Vujic
David Vujic on 5 Dec 2020
Commented: David Vujic on 2 Feb 2021
I need to write code for this problem in Octave, this is MathCad file.
I don't know how to code this part with Kvalues.
s = [0.3; 0.5; 0.2];
P = 10;
fi = 0.7;
n = 3;
A = [9.1058; 9.0580; 9.2131];
B = [1872.46; 2154.9; 2477.07];
C = [-25.16; -34.42; -39.94];
Tmin = [164; 195; 220];
Tmax = [249; 290; 330];
Pn = 10.^(A-B./(T+C));
K = Pn./P
f = @(T) (sum(s/(1+fi*(Kvrednost)-1)))-1 ;
Tguess = 50 ;
Temperatura = fzero(f, Tguess)

Accepted Answer

Alan Stevens
Alan Stevens on 5 Dec 2020
Like this perhaps:
s = [0.3; 0.5; 0.2];
P = 10;
fi = 0.7;
n = 3;
A = [9.1058; 9.0580; 9.2131];
B = [1872.46; 2154.9; 2477.07];
C = [-25.16; -34.42; -39.94];
Tmin = [164; 195; 220];
Tmax = [249; 290; 330];
f = @(T) sum(s./(1+fi*(Kfn(n,P,T,A,B,C)-1)))-1 ;
Tguess = 50 ;
Temperatura = fzero(f, Tguess);
disp(Temperatura)
function K = Kfn(n,P,T,A,B,C)
T = T + 273.15;
K = zeros(n,1);
for i = 1:n
Pn = A(i) - B(i)/(T + C(i));
Pn = exp(Pn);
K(i) = Pn/P;
end
end

More Answers (3)

David Vujic
David Vujic on 7 Dec 2020
I have one more question. I can't get temp = 78.225, I always get 119.23. What is the problem ?
n = 3;
s = [0.3; 0.5; 0.2];
P = 10;
fi = 0.7;
Tnk = [231.1; 272.7; 309.2];
Tc = [369.8; 425.2; 469.7];
pc = [42.5; 38; 33.7];
function K = Kfn(n,P,T,Tnk,Tc,pc)
T = T + 273.15;
K = zeros(n,1);
for i = 1:n
Tr = T/Tc(i);
Tmk = Tnk(i)/Tc(i);
A = (Tmk/(1-Tmk))*log(pc(i)/1.01325);
lgPrsat = A*(1-(1/Tr));
Prsat = 10^lgPrsat;
Pn = Prsat*pc(i);
K(i) = Pn/P;
end
end
f = @(T) sum(s./(1+fi*(Kfn(n,P,T,Tnk,Tc,pc)-1)))-1 ;
Tguess = 90 ;
Temperatura = fzero(f, Tguess);
disp(Temperatura)
  2 Comments
Alan Stevens
Alan Stevens on 7 Dec 2020
In Mathcad log is log to the base 10; in MATLAB it is log to the base e. Change
A = (Tmk/(1-Tmk))*log(pc(i)/1.01325);
to
A = (Tmk/(1-Tmk))*log10(pc(i)/1.01325);
David Vujic
David Vujic on 7 Dec 2020
It works, thanks!

Sign in to comment.


David Vujic
David Vujic on 21 Dec 2020
How to code this in Matlab ?
I tried it, but errors occur always.
xF = [0.015;0.025;0.59;0.37];
F = 179;
f1 = @(D,B,xD,xB) D*xD+B*xB-F*xF;
Dguess = 100;
Bguess = 79;
xDguess = [0;0;0;0];
xBguess = [0;0;0;0];
((D*xD(2))/(F*xF(2))) = 0.89;
((B*xB(3))/(F*xF(3))) = 0.9995;
xD(4) = 0;
xB(1) = 0;
sum(xD) = 1;
sum(xB) = 1;
rez = fzero(f1,Dguess,Bguess,xDguess,xBguess)
  2 Comments
Alan Stevens
Alan Stevens on 21 Dec 2020
fzero only allows you to find a single value.
The Mathcad calculation you have here is very heavy-handed! The parameters can be calculated in the following straightforward manner:
Fxf = 179*[0.015; 0.025; 0.59; 0.37];
DxD1 = Fxf(1);
DxD2 = 0.89*Fxf(2);
BxB2 = -DxD2 + Fxf(2) ;
BxB4 = Fxf(4);
BxB3 = 0.9995*Fxf(3);
DxD3 = -BxB3 + Fxf(3);
D = DxD1 + DxD2 + DxD3;
B = BxB2 + BxB3 + BxB4;
xD = [DxD1; DxD2; DxD3; 0]/D;
xB = [0; BxB2; BxB3; BxB4]/B;
disp(['D = ', num2str(D)])
disp(['B = ', num2str(B)])
disp('xD = '), disp(xD)
disp('xB = '), disp(xB)

Sign in to comment.


David Vujic
David Vujic on 1 Feb 2021
New and last problem for this project.
I got Tvrh = 47.8817 and Tdno = 97.2349, I need this highlighted results. What is the problem ?
A = [9.2806; 9.3935; 9.3993; 9.3991];
B = [2788.51; 3096.52; 3272.47; 3328.57];
C = [-52.36; -53.67; -59.95; -63.72];
Pkljuc = @(s,T) sum(s.*exp(A.-B./((T+273.15)+C)));
Pkljuc(xD,45)
P = 0.17790;
Pvrha = 0.2;
Pdno = 0.28;
function K = Kfn(n,P,T,A,B,C)
T = T + 273.15;
K = zeros(n,1);
for i = 1:n
Pn = A(i) - B(i)/(T + C(i));
Pn = exp(Pn);
K(i) = Pn/P;
end
end
s = xD;
f1 = @(T) sum(s.*(Kfn(n,Pvrha,T,A,B,C)))-1;
T1guess = 50 ;
Tkljucanja = fzero(f1, T1guess);
T1 = Tkljucanja+273.15;
disp (["Temperatura kljucanja = ", num2str(Tkljucanja) , " deg C "]);
s = xB;
f2 = @(T) sum(s./(Kfn(n,Pdno,T,A,B,C)))-1 ;
T2guess = 50 ;
Trose = fzero(f2, T2guess);
T2 = Trose+273.15;
disp (["Temperatura rose = ", num2str(Trose) , " deg C "]);
  4 Comments
Alan Stevens
Alan Stevens on 1 Feb 2021
I think you have your functions f1 and f2 defined with the wrong operator.
Instead of
f1 = @(T) sum(s.*(Kfn(n,Pvrha,T,A,B,C)))-1;
use
f1 = @(T) sum(s./(Kfn(n,Pvrha,T,A,B,C)))-1;
and instead of
f2 = @(T) sum(s./(Kfn(n,Pdno,T,A,B,C)))-1 ;
use
f2 = @(T) sum(s.*(Kfn(n,Pdno,T,A,B,C)))-1 ;
David Vujic
David Vujic on 2 Feb 2021
Yes, that's it. Works perfect. Thanks.

Sign in to comment.

Categories

Find more on ThingSpeak in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!