function [p,cp,h,rho,s] = LiBr_properties_mass_fce(t, w) 

% disp("given parameters")
% t=300 %[C]
T=t+273.15;%[K]
 %w=0.65 %=Mass fraction of LiBr mixture
Mbr= 0.08685; %[kg/mol]
Mw= 0.018015268 ;%[kg/mol]
x=(w/Mbr)/((w/Mbr)+((1-w)/Mw)) ; %[molar fraction]
mtw= 1/(1000*((x*Mbr)+(1-x)*(Mw)));%J/mol to kJ/kg
mtwr=((x*Mbr)+(1-x)*(Mw));%used for conversion of density mol/m^3 to kg/m^3
% critical point prop
hc=37548.5; %[J/mol]
Tc=647.096;
T0=221;
rhoc=17873; %[mol*m^-3]%
sc= 79.3933; %[J mol^-1 K^-1]
cpt=76.0227; %[J mol^-1 K^-1]
Tt= 273.16;%[K]
pc= 2.2067e7; %[pa]


% function Enthalpy of pure saturated water

k1=[1 1/3 -4.37196e-1 
   2 2/3 3.03440e-1
   3 5/6 -1.29582
   4 21/6 -1.7641e-1];

i=length(k1);
su=0;
for n=1:i
    su=su+k1(n,3)*(1-(T/Tc))^(k1(n,2));
end

hT=hc*[1+su]; %[J/mol]
% 'KJ/mol pure saturated water';

% function Enthalpy of the LiBR water mixture

k2=[1 1 0 0 2.27431e0
2 1 1 0 -7.99511e0
3 2 6 0 3.85239e2
4 3 6 0 -1.63940e4
5 6 2 0 -4.22562e2
6 1 0 1 1.13314e-1
7 3 0 1 -8.33474e0
8 5 4 1 -1.73833e4
9 4 0 2 6.49763e0
10 5 4 2 3.24552e3
11 5 5 2 -1.34643e4
12 6 5 2 3.99322e4
13 6 6 2 -2.58877e5
14 1 0 3 -1.93046e-3
15 2 3 3 2.80616e0
16 2 5 3 -4.04479e1
17 2 7 3 1.45342e2
18 5 0 3 -2.74873e0
19 6 3 3 -4.49743e2
20 7 1 3 -1.21794e1
21 1 0 4 -5.83739e-3
22 1 4 4 2.33910e-1
23 2 2 4 3.41888e-1
24 2 6 4 8.85259e0
25 2 7 4 -1.78731e1
26 3 0 4 7.35179e-2
27 1 0 5 -1.79430e-4
28 1 1 5 1.84261e-3
29 1 2 5 -6.24282e-3
30 1 3 5 6.84765e-3];

i=length(k2);
hu=0;
for n=1:i
    hu=hu+k2(n,5)*(x^k2(n,2))*((0.4-x)^k2(n,3))*(Tc/(T-T0))^k2(n,4);
end

hm=(1-x)*hT+hc*hu;
h= hm*mtw;
% disp("specific enthalpy of LiBr mixture is [kJ kg^-1]")
% disp(h)

%function of density of pure water%

kr1=[1 1/3 1.99274064e0
    2 2/3 1.09965342e0
    3 5/3 -5.10839303e-1
    4 16/3 -1.75493479e0
    5 43/3 -4.55170352e1
    6 110/3 -6.7469445e5];

i=length(kr1);
skr1 = 0;
for n=1:i
    skr1 = skr1+(kr1(n,3))*((1-(T/Tc))^kr1(n,2));
end
rhoW=rhoc*(1+skr1);

%function of density of LiBr mixture%
kr2=[1 1 0 1.746e0
    2 1 6 4.709e0];
i=size(kr2,1);
skr2=0;
for n=1:i
    skr2=skr2+(kr2(n,4)*(x^kr2(n,2))*((T/Tc)^kr2(n,3)));
end
rhom=((1-x)*rhoW)+(rhoc*skr2);
rho=rhom*mtwr;
% disp("Density of Mixture of LiBr [kg m^-3]")
% disp(rho);

%function of entropy of pure water%

ks1=[1 1/3 -3.34112e-1
    2 1 -8.47987e-1
    3 8/3 -9.11980e-1
    4 8 -1.64046];
sks1=0;
i= length (ks1);
for n=1:i
    sks1= sks1+ ks1(n,3)*((1-(T/Tc))^ks1(n,2));
end
sW=sc*(1+sks1);

%function of entropy of LiBr Mixture%
ks2 =[1 1 0 0 1.53091e0
    2 1 1 0 -4.52564e0
    3 2 6 0 6.98302e2
    4 3 6 0 -2.16664e4
    5 6 2 0 -1.47533e3
    6 1 0 1 8.47012e-2
    7 3 0 1 -6.59523e0
    8 5 4 1 -2.95331e4
    9 1 0 2 9.56314e-3
    10 2 0 2 -1.88679e-1
    11 2 4 2 9.31752e0
    12 4 0 2 5.78104e0
    13 5 4 2 1.38931e4
    14 5 5 2 -1.71762e4
    15 6 2 2 4.15108e2
    16 6 5 2 -5.55647e4
    17 1 0 3 -4.23409e-3
    18 3 4 3 3.05242e1
    19 5 0 3 -1.67620e0
    20 7 1 3 1.48283e1
    21 1 0 4 3.03055e-3
    22 1 2 4 -4.01810e-2
    23 1 4 4 1.49252e-1
    24 2 7 4 2.59240e0
    25 3 1 4 -1.77421e-1
    26 1 0 5 -6.99650e-5
    27 1 1 5 6.05007e-4
    28 1 2 5 -1.65228e-3
    29 1 3 5 1.22966e-3];
i=length(ks2);
sks2=0;
for n=1:i
    sks2= sks2+ks2(n,5)*x^(ks2(n,2))*(0.4-x)^(ks2(n,3))*(Tc/(T-T0))^(ks2(n,4));
end
sm= (1-x)*sW+sc*sks2;
s=sm*mtw;
% disp("specific entropy of LiBr mixture is [kJ kg^-1 K^-1]")
% disp(s)

%function of cp for pure water%
kcp1=[1 0 0 1.38801e0
    2 2 2 -2.95318e0
    3 3 3 3.18721e0
    4 6 5 -6.45473e-1
    5 34 0 9.18946e5];
i=length(kcp1);
skcp1=0;
for n=1:i
    skcp1=skcp1+kcp1(n,4)*(1-(T/Tc))^(kcp1(n,2))*(T/Tt)^(kcp1(n,3));
end
cpW= cpt*skcp1;

%function of cp for LiBr Mixture%
kcp2=[1 2 0 0 -1.42094e1
    2 3 0 0 4.04943e1
    3 3 1 0 1.11135e2
    4 3 2 0 2.29980e2
    5 3 3 0 1.34526e3
    6 2 0 2 -1.41010e-2
    7 1 3 3 1.24977e-2
    8 1 2 4 -6.83209e-4];
i=length(kcp2);
skcp2=0;
for n=1:i
    skcp2=skcp2+kcp2(n,5)*x^(kcp2(n,2))*(0.4-x)^(kcp2(n,3))*(Tc/(T-T0))^(kcp2(n,4));
end
cpm=(1-x)*cpW+cpt*skcp2;
cp=cpm*mtw;
% disp("sprecific heat capacity cp of LiBr mixture is [kJ kg^-1 K^-1]")
% disp(cp)

%function of pressure theta%
ktheta=[1 3 0 0 -2.41303e2
    2 4 5 0 1.91750e7
    3 4 6 0 -1.75521e8
    4 8 3 0 3.25430e7
    5 1 0 1 3.92571e2
    6 1 2 1 -2.12626e3
    7 4 6 1 1.85127e8
    8 6 0 1 1.91216e3];
stheta=0;
i=length(ktheta);
for n=1:i
    stheta= stheta+ ktheta(n,5)*x^(ktheta(n,2))*(0.4-x)^(ktheta(n,3))*(T/Tc)^(ktheta(n,4));
end
theta= T- stheta;

%function pSIGMA(T)%
ktheta2=[1 1.0e0 -7.85951783e0
    2 1.5e0 1.84408259e0
    3 3.0e0 -1.17866497e1
    4 3.5e0 2.26807411e1
    5 4.0e0 -1.59618719e1
    6 7.5e0 1.80122502e0];
stheta2=0;
i=length(ktheta2);
for n=1:i
    stheta2=stheta2 + ktheta2(n,3)* (1-(theta/Tc))^(ktheta2(n,2));
end
psig= pc*exp((Tc/theta)*stheta2);
p=psig/1000;
% disp("Pressure of LiBr mixture is [kPa]:")
% disp(p)
end
