function [S] = lng(x)

[S] = Helmholtz_anonymous_21985668(x);


function [S] = Helmholtz_anonymous_21985668(x)

[S] = StandardState_anonymous_21977700(x);


function [S] = StandardState_anonymous_21977700(x)

[S]      = EquationOfState_anonymous_21611580(x);
i        = [3,4,5];
[S_1]    = MuT_cp_poly3_21965832(x(1));
S.g(1)   = S.g(1) + S_1.dmudT'*x(i);
S.g(i)   = S.g(i) + S_1.mu;
S.H(1,1) = S.H(1,1) + S_1.d2mudTdT'*x(i);
S.H(i,1) = S.H(i,1) + S_1.dmudT;
S.H(1,i) = S.H(i,1)';


function [S] = EquationOfState_anonymous_21611580(x)

[S]   = EquationOfState_anonymous_21601848(x);
[S_1] = ModTVN_ideal_idealgas_21608604(x);
S.g   = S.g + S_1.g;
S.H   = S.H + S_1.H;


function [S] = EquationOfState_anonymous_21601848(x)

[S] = ModTVN_pr_21599040(x);


function [S] = ModTVN_pr_21599040(x)

R                          = 8.314511984;
d_1                        = 2.414213562;
d_2                        = 0.4142135624;
t_c                        = [190.4;305.4;369.8];
p_c                        = [4600000.0;4880000.0;4250000.0];
Omega_b                    = 0.0777960739;
T                          = x(1);
V                          = x(2);
i                          = [3,4,5];
n                          = x(i);
e                          = [1;1;1];
c                          = 1/(d_1 + d_2);
NR                         = sum(n)*R;
RT                         = R*T;
NRT                        = NR*T;
dBdn                       = Omega_b*R*(t_c./p_c);
B                          = n'*dBdn;
C_1circ                    = (1/(V + d_1*B) - 1/(V - d_2*B))/B;
C_2circ                    = (-d_1/(V + d_1*B)^2 - d_2/(V - d_2*B)^2 - C_1circ)/B;
C_lnd                      = log((V + d_1*B)/(V - d_2*B));
C_lnv                      = log(V/(V - B));
C_1                        = (d_1/(V + d_1*B) + d_2/(V - d_2*B) - C_lnd/B)/B;
C_2                        = (-(d_1/(V + d_1*B))^2 + (d_2/(V - d_2*B))^2 - 2*C_1)/B;
[d2AdTdT,d2AdndT,d2AdndnT] = ModTVN_pr_a_soave_21582048(T,n,R,t_c,p_c);
dAdT                       = d2AdndT'*n/2;
dAdn                       = d2AdndnT*n;
A                          = dAdn'*n/2;
g_1                        = NR*C_lnv - c*dAdT*C_lnd/B;
g_2                        = -NRT*B/(V*(V - B)) + A/((V + d_1*B)*(V - d_2*B));
g_i                        = RT*C_lnv*e + (NRT/(V - B) - c*A*C_1)*dBdn - c*C_lnd/B*dAdn;
H_11                       = -c*d2AdTdT*C_lnd/B;
H_21                       = -B*NR/(V*(V - B)) + dAdT/((V + d_1*B)*(V - d_2*B));
H_i1                       = R*C_lnv*e + (NR/(V - B) - c*dAdT*C_1)*dBdn - c*C_lnd/B*d2AdndT;
H_22                       = -NRT/V^2 + NRT/(V - B)^2 + c*A*(1/(V + d_1*B)^2 - 1/(V - d_2*B)^2)/B;
H_i2                       = -RT*B/(V*(V - B))*e - (NRT/(V - B)^2 + c*A*C_2circ)*dBdn - c*C_1circ*dAdn;
H_ii                       = RT/(V - B)*(e*dBdn' + dBdn*e') + (NRT/(V - B)^2 - c*A*C_2)*dBdn*dBdn' - c*C_1*(dAdn*dBdn' + dBdn*dAdn') - c*C_lnd/B*d2AdndnT;
S.g                        = [g_1;g_2;g_i];
S.H                        = [H_11,H_21',H_i1';H_21,H_22,H_i2';H_i1,H_i2,H_ii];


function [d2AdTdT,d2AdndT,d2AdndnT] = ModTVN_pr_a_soave_21582048(T,n,R,t_c,p_c)

e        = [1;1;1];
Omega_a  = 0.4572355289;
K        = [0,0,0;0,0,0;0,0,0];
r_c      = t_c./sqrt(p_c);
F        = 2*Omega_a*R^2*(r_c*r_c'.*(e*e' - K));
[m]      = ModTVN_pr_a_soave_m_pr_21579792;
k        = e + m.*(e - sqrt(T./t_c));
k_t      = -1/(2*T)*(m - k + e);
k_tt     = -1/(2*T)*k_t;
d2AdTdT  = (n.*k_tt)'*F*(k.*n) + (n.*k_t)'*F*(k_t.*n);
d2AdndT  = k_t.*(F*(k.*n)) + k.*(F*(k_t.*n));
d2AdndnT = F.*(k*k');


function [m] = ModTVN_pr_a_soave_m_pr_21579792

omega_az = [0.0115478;0.099493;0.152291];
e        = [1;1;1];
m        = 0.37464*e + 1.54226*omega_az + -0.2699*omega_az.^2;


function [S] = ModTVN_ideal_idealgas_21608604(x)

R     = 8.314511984;
pcirc = [101325.0;101325.0;101325.0];
xcirc = [1.0;1.0;1.0];
T     = x(1);
V     = x(2);
i     = [3,4,5];
n     = x(i);
NR    = sum(n)*R;
NRT   = NR*T;
e     = [1;1;1];
p     = R*log(R*T*(n./pcirc)/V);
g_1   = n'*p;
g_2   = -NRT/V;
g_i   = T*p;
H_11  = NR/T;
H_21  = -NR/V;
H_i1  = p + R*e;
H_22  = NRT/V^2;
H_i2  = -R*(T/V)*e;
H_ii  = R*T*diag(e./n);
S.g   = [g_1;g_2;g_i];
S.H   = [H_11,H_21',H_i1';H_21,H_22,H_i2';H_i1,H_i2,H_ii];


function [S] = MuT_cp_poly3_21965832(T)

tcirc      = [298.15;298.15;298.15];
t          = [T;T;T];
e          = [1;1;1];
t_1        = t - tcirc;
t_2        = (t.^2 - tcirc.^2)/2;
t_3        = (t.^3 - tcirc.^3)/3;
t_4        = (t.^4 - tcirc.^4)/4;
C          = [19.2451589,0.0521100975,1.1970673e-005,-1.131354165e-008;5.4077306,0.178053297,-6.93545635e-005,8.71012955e-009;-4.22321995,0.3061729825,-0.0001585904895,3.21366529e-008];
c_p        = sum(C.*[e,t,t.^2,t.^3],2);
s          = sum(C.*[log(t./tcirc),t_1,t_2,t_3],2);
h          = sum(C.*[t_1,t_2,t_3,t_4],2);
S.mu       = h - T*s;
S.dmudT    = -s;
S.d2mudTdT = -(c_p/T);
i          = [1,2,3];
[S_1]      = MuT_hs_h0_21957912(T);
S.mu(i)    = S.mu(i) + S_1.mu;
S.dmudT(i) = S.dmudT(i) + S_1.dmudT;


function [S] = MuT_hs_h0_21957912(T)

hcirc   = [-74900.0;-84740.0;-103900.0];
[S]     = MuT_hs_s0_21945552(T);
S.mu    = S.mu + hcirc;
S.dmudT = S.dmudT + [0;0;0];


function [S] = MuT_hs_s0_21945552(T)

scirc   = [186.27;229.12;270.2];
S.mu    = -(T*scirc);
S.dmudT = -scirc;
