# Variables
V = 0.35; #m**3
import math
m_CO = 0.4; #kg
m_air = 1; #kg
m_O2 = 0.233; #kg
m_N2 = 0.767; #kg
T = 293.; #K
R0 = 8.314; #kJ/kg K
M_O2 = 32.; #Molecular mass of O2
M_N2 = 28.; #Molecular mass of N2
M_CO = 28.; #Molecular mass of CO
# Calculations and Results
p_O2 = m_O2*R0*10**3*T/M_O2/V/10**5; #bar
print ("partial pressure for p_O2 %.3f")% (p_O2), ("bar")
p_N2 = m_N2*R0*10**3*T/M_N2/V/10**5; #bar
print ("partial pressure for p_N2 %.3f")% (p_N2), ("bar")
p_CO = m_CO*R0*10**3*T/M_CO/V/10**5; #bar
print ("partial pressure for p_CO %.3f")%(p_CO), ("bar")
print ("(ii) Total pressure in the vessel")
p = p_O2+p_N2+p_CO;
print ("p = %.3f")% (p), ("bar")
# Variables
R0 = 8.314;
M_O2 = 32.;
M_N2 = 28.;
M_Ar = 40.;
M_CO2 = 44.;
# Calculations
R_O2 = R0/M_O2; #kJ/kg K
R_N2 = R0/M_N2; #kJ/kg K
R_Ar = R0/M_Ar; #kJ/kg K
R_CO2 = R0/M_CO2; #kJ/kg K
O2 = 0.2314;
N2 = 0.7553;
Ar = 0.0128;
CO2 = 0.0005;
# Results
print ("(i) Gas constant for air")
R = O2*R_O2 + N2*R_N2 + Ar*R_Ar + CO2*R_CO2;
print ("R = %.3f")%(R), ("kJ/kg K")
print ("(ii) Apparent molecular weight.")
M = R0/R;
print ("M = %.3f")%(M)
# Variables
p = 1.; #bar
#For oxygen
m_O2 = 0.2314;
M_O2 = 32;
n_O2 = m_O2/M_O2;
#For Nitrogen
m_N2 = 0.7553;
M_N2 = 28.;
n_N2 = m_N2/M_N2;
#For Argon
m_Ar = 0.0128;
M_Ar = 40;
n_Ar = m_Ar/M_Ar;
#For CO2
m_CO2 = 0.0005;
M_CO2 = 44;
n_CO2 = m_CO2/M_CO2;
# Calculations and Results
n = n_O2 + n_N2 + n_Ar + n_CO2;
#Let Vi/V be A
A_O2 = n_O2/n * 100;
print ("Vi/V of O2 = %.3f")%(A_O2),("%")
A_N2 = n_N2/n * 100;
print ("Vi/V of N2 = %.3f")%(A_N2), ("%")
A_Ar = n_Ar/n *100;
print ("Vi/V of Ar %.3f")% (A_Ar), ("%")
A_CO2 = n_CO2/n * 100;
print ("Vi/V of CO2 = %.3f")% (A_CO2), ("%")
P_O2 = n_O2/n*p;
print ("Partial pressure of O2 = %.3f")% (P_O2), ("bar")
P_N2 = n_N2/n*p;
print ("Partial pressure of N2 = %.3f")% (P_N2), ("bar")
P_Ar = n_Ar/n*p;
print ("Partial pressure of Ar = %.3f")% (P_Ar), ("bar")
P_CO2 = n_CO2/n*p;
print ("Partial pressure of CO2 = %.4f")% (P_CO2), ("bar")
# Variables
p = 1.*10**5; #Pa
T = 293.; #K
n_CO2 = 1.; #moles of CO2
n = 4.; #moles of air
M_CO2 = 44.;
M_N2 = 28.;
M_O2 = 32.;
#Let A be the volumeetric analysis
A_O2 = 0.21;
A_N2 = 0.79;
# Calculations and Results
n_O2 = A_O2*n;
n_N2 = A_N2*n;
print ("(i) The masses of CO2, O2 and N2, and the total mass")
m_CO2 = n_CO2*M_CO2;
print ("Mass of CO2 = %.3f")%(m_CO2),("kg")
m_O2 = n_O2*M_O2;
print ("Mass of O2 = %.3f")%(m_O2),("kg")
m_N2 = n_N2*M_N2;
print ("Mass of N2 = %.3f")%(m_N2),("kg")
m = m_CO2 + m_O2 + m_N2;
print ("Total mass = %.3f")% (m), ("kg")
print ("(ii) The percentage carbon content by mass")
#Since the molecular weight of carbon is 12, therefore, there are 12 kg of carbon present for every mole of CO2
m_C = 12; #kg
C = m_C/m*100;
print ("Percentage carbon in mixture %.3f")%(C),("%")
print ("(iii) The apparent molecular weight and the gas consmath.tant for the mixture")
n = n_CO2 + n_O2 + n_N2;
M = n_CO2/n*M_CO2 + n_O2/n*M_O2 + n_N2/n*M_N2;
print ("Apparent Molecular weight %.3f")%(M)
R0 = 8.314;
R = R0/M;
print ("Gas constant for the mixture = %.3f")%(R),("kJ/kg K")
print ("(iv) The specific volume of the mixture")
v = R*10**3*T/p;
print ("specific volume = %.3f")%(v),("m**3/kg")
# Variables
p = 1.*10**5; #Pa
T = 298.; #K
M_H2 = 2.;
M_O2 = 32.;
R0 = 8314.;
# ratio = V_H2/V_O2 = 2;
ratio = 2;
# Calculations and Results
print ("(i) The mass of O2 required")
#Let the mass of O2 per kg of H2 = x kg
m_H2 = 1; #kg
n_H2 = m_H2/M_H2;
# n_O2 = x/M_O2
x = M_O2*n_H2/ratio;
print ("Mass of O2 per kg of H2 = %.3f")%(x), ("kg")
print ("(ii) The volume of the container")
n_O2 = x/M_O2;
n = n_H2 + n_O2;
V = n*R0*T/p;
print ("V = %.3f")%(V), ("m**3")
#Let composition of mixture by volume be denoted by c1
#Let Final composition desired be denoted by c2
# Variables
c1_H2 = 0.78;
c1_CO = 0.22;
c2_H2 = 0.52;
c2_CO = 0.48;
M_H2 = 2.;
M_CO = 28.;
# Calculations
M = c1_H2*M_H2 + c1_CO*M_CO;
# Let x kg of mixture be removed and y kg of CO be added.
x = (c1_H2 - c2_H2)/c1_H2*M;
# Results
print ("Mass of mixture removed = %.3f")%(x), ("kg")
y = M_CO/M*x;
print ("Mass of CO added = %.3f")%(y),("kg")
import math
# Variables
ratio = 1./8; #volume ratio; v1/v2
T1 = 1223.; #K
cp_CO2 = 1.235; #kJ/kg K
cp_O2 = 1.088; #kJ/kg K
cp_N2 = 1.172; #kJ/kg K
n_CO2 = 0.13;
n_O2 = 0.125;
n_N2 = 0.745;
M_CO2 = 44.;
M_O2 = 32.;
M_N2 = 28.;
# Calculations
m_CO2 = M_CO2*n_CO2;
m_O2 = M_O2*n_O2;
m_N2 = M_N2*n_N2;
m = m_CO2 + m_O2 + m_N2;
# Let Fraction by mass be denoted by F
F_CO2 = m_CO2/m;
F_O2 = m_O2/m;
F_N2 = m_N2/m;
cp = F_CO2*cp_CO2 + F_O2*cp_O2 + F_N2*cp_N2;
R0 = 8.314;
R = F_CO2*R0/M_CO2 + F_O2*R0/M_O2 + F_N2*R0/M_N2;
cv = cp - R;
n = 1.2;
print ("(i) The workdone")
T2 = T1*(ratio)**(n-1);
W = R*(T1-T2)/(n-1);
print ("W = %.3f")%(W), ("kJ/kg")
print ("(ii) The heat flow")
du = cv*(T2-T1);
Q = du + W;
print ("Q = %.3f")%(Q), ("kJ/kg")
print ("(iii) Change of entropy per kg of mixture")
ds_1A = R*math.log(1/ratio); #isothermal process
ds_2A = cv*math.log(T1/T2);
ds_12 = ds_1A - ds_2A;
print ("change of entropy = %.3f")% (ds_12), ("kJ/kg K")
import math
# Variables
M_CO2 = 44.;
M_H2 = 2.;
M_N2 = 28.;
M_CH4 = 16.;
M_CO = 28.;
# Let volumetric analysis be denoted by V
V_CO = 0.28;
V_H2 = 0.13;
V_CH4 = 0.04;
V_CO2 = 0.04;
V_N2 = 0.51;
Cp_CO = 29.27; #kJ/mole K
Cp_H2 = 28.89; #kJ/mole K
Cp_CH4 = 35.8; #kJ/mole K
Cp_CO2 = 37.22; #kJ/mole K
Cp_N2 = 29.14; #kJ/mole K
R0 = 8.314;
# Calculations and Results
Cp = V_CO*Cp_CO + V_H2*Cp_H2 + V_CO2*Cp_CO2 + V_CH4*Cp_CH4 + V_N2*Cp_N2;
print ("Cp = %.3f")%(Cp), ("kJ/mole K")
Cv = Cp-R0;
print ("Cv = %.3f")% (Cv), ("kJ/mole K")
M = V_CO*M_CO + V_H2*M_H2 + V_CO2*M_CO2 + V_CH4*M_CH4 + V_N2*M_N2;
cp = Cp/M;
print ("cp = %.3f")%(cp), ("kJ/kg K")
cv = Cv/M;
print ("cv %.3f")% (cv), ("kJ/kg K")
import math
# Variables
p = 1.3 #bar
R0 = 8.314;
M_CO2 = 44.;
M_O2 = 32.;
M_N2 = 28.;
M_CO = 28.;
m_O2 = 0.1;
m_N2 = 0.7;
m_CO2 = 0.15;
m_CO = 0.05;
#Considering 1 kg of mixture
m = 1; #kg
# Calculations
#let moles be denoted by n
n_O2 = m_O2/M_O2;
n_N2 = m_N2/M_N2;
n_CO2 = m_CO2/M_CO2;
n_CO = m_CO/M_CO;
M = 1/(m_O2/M_O2 + m_N2/M_N2 + m_CO2/M_CO2 + m_CO/M_CO);
n = m/M;
x_O2 = n_O2/n;
x_N2 = n_N2/n;
x_CO2 = n_CO2/n;
x_CO = n_CO/n;
# Results
print ("(i) Partial pressures of the constituents")
P_O2 = x_O2*p;
print ("Partial pressure of O2 = %.3f")% (P_O2), ("bar")
P_N2 = x_N2*p;
print ("Partial pressure of N2 = %.3f")% (P_N2), ("bar")
P_CO2 = x_CO2*p;
print ("Partial pressure of CO2 = %.3f")% (P_CO2), ("bar")
P_CO = x_CO*p;
print ("Partial pressure of CO = %.3f")% (P_CO), ("bar")
R_mix = R0/M;
print ("Gas constant of mixture = %.3f")%(R_mix), ("kJ/kg K")
# Variables
p = 4.*10**5; #Pa
import math
T = 293.; #K
R0 = 8.314;
m_N2 = 4.; #kg
m_CO2 = 6.; #kg
M_N2 = 28.; #Molecular mass
M_CO2 = 44.; #Molecular mass
n_N2 = m_N2/M_N2; #moles of N2
n_CO2 = m_CO2/M_CO2; #moles of CO2
x_N2 = n_N2/(n_N2+n_CO2);
print ("x_N2 = %.3f")% (x_N2)
x_CO2 = n_CO2/(n_CO2+n_N2);
print ("x_CO2 = %.3f")% (x_CO2)
print ("(ii) The equivalent molecular weight of the mixture")
M = x_N2*M_N2 + x_CO2*M_CO2;
print ("M = %.3f")%(M), ("kg/kg-mole")
print ("(iii) The equivalent gas consmath.tant of the mixture")
m = m_N2+m_CO2;
Rmix = (m_N2*(R0/M_N2) + m_CO2*(R0/M_CO2))/m;
print ("Rmix = %.3f")% (Rmix), ("kJ/kg K")
print ("(iv) The partial pressures and partial volumes")
P_N2 = x_N2*p/10**5;
print ("P_N2 = %.3f")% (P_N2), ("bar")
P_CO2 = x_CO2*p/10**5;
print ("P_CO2 = %.3f")% (P_CO2), ("bar")
V_N2 = m_N2*R0/M_N2*T/p*10**3;
print ("V_N2 %.3f")% (V_N2), ("m**3")
V_CO2 = m_CO2*R0/M_CO2*T/p*10**3;
print ("V_CO2 %.3f")% (V_CO2), ("m**3")
print ("(v) The volume and density of the mixture")
V = m*Rmix*10**3*T/p;
print ("V = %.3f")% (V), ("m**3")
rho_mix = m/V;
print ("Density of mixture = %.3f")% (rho_mix), ("kg/m**3")
print ("(vi) cp and cv of the mixture")
y_N2 = 1.4;
cv_N2 = (R0/M_N2)/(y_N2 - 1);
cp_N2 = cv_N2*y_N2;
y_CO2 = 1.286;
cv_CO2 = (R0/M_CO2)/(y_CO2 - 1);
cp_CO2 = cv_CO2*y_CO2;
cp = (m_N2*cp_N2 + m_CO2*cp_CO2)/(m_N2+m_CO2);
print ("cp = %.3f")%(cp),("kJ/kg K")
cv = (m_N2*cv_N2 + m_CO2*cv_CO2)/(m_N2+m_CO2);
print ("cv = %.3f")%(cv),("kJ/kg K")
T1 = 293.; #K
T2 = 323.; #K
dU = m*cv*(T2-T1);
print ("Change in internal energy = %.3f")% (dU), ("kJ")
dH = m*cp*(T2-T1);
print ("Change in enthalpy = %.3f")% (dH), ("kJ")
dS = m*cv*math.log(T2/T1); #Consmath.tant volume process
print ("Change in entropy = %.3f")% (dS), ("kJ/kg K")
print ("When the mixture is heated at constant pressure")
print ("If the mixture is heated at constant pressure ΔU and ΔH will remain the same")
dS = m*cp*math.log(T2/T1);
print ("Change in entropy = %.3f")% (dS), ("kJ/kg K")
# Note : Answers are slightly different because of rounding error.
# Variables
Cv_O2 = 21.07; #kJ/mole K
Cv_CO = 20.86; #kJ/mole K
p_O2 = 8*10**5; #Pa
p_CO = 1*10**5; #Pa
V_O2 = 1.8; #m**3
V_CO = 3.6; #m**3
T_O2 = 323.; #K
T_CO = 293.; #K
R0 = 8314.;
# Calculations and Results
n_O2 = p_O2*V_O2/R0/T_O2;
n_CO = p_CO*V_CO/R0/T_CO;
n = (n_O2+n_CO);
V = (V_O2+V_CO);
print ("(i) Final temperature (T) and pressure (p) of the mixture")
#Before mixing
U1 = n_O2*Cv_O2*T_O2 + n_CO*Cv_CO*T_CO;
T = U1/(n_O2*Cv_O2 + n_CO*Cv_CO);
t = T-273;
print ("Final temperature = %.3f")% (t), ("°C")
p = n*R0*T/V/10**5;
print ("Final pressure = %.3f")% (p), ("bar")
#For oxygen
dS_O1A = n_O2*R0*math.log(V/V_O2); #isothermal process
dS_O2A = n_O2*Cv_O2*math.log(T_O2/T); #consmath.tant volume process
dS_O12 = dS_O1A - dS_O2A; # Change of entropy of O2
#For CO
dS_CO12 = n_CO*R0*math.log(V/V_CO) + n_CO*Cv_CO*math.log(T/T_CO); #Change of entropy of CO
dS = (dS_O12 + dS_CO12)/10**3;
print ("(ii)Change of entropy of system = %.3f")% (dS), ("kJ/K")
import math
# Variables
p_A = 16.*10**5; #Pa
p_B = 6.4*10**5; #Pa
T_A = 328.; #K
T_B = 298.; #K
n_A = 0.6 #kg-mole
m_B = 3; #kg
R0 = 8314.;
M_A = 28.;
y = 1.4;
V_A = n_A*R0*T_A/p_A;
m_A = n_A*M_A;
R = R0/M_A;
V_B = m_B*R*T_B/p_B;
V = V_A+V_B;
m = m_A+m_B;
T = 303.; #K
print ("(a) (i) Final equilibrium pressure, p")
p = m*R*T/V/10**5;
print ("p = %.3f")% (p), ("bar")
cv = R/10**3/(y-1);
print ("(ii) Amount of heat transferred, Q :")
U1 = cv*(m_A*T_A + m_B*T_B);
U2 = m*cv*T;
Q = U2-U1;
print ("Q = %.3f")% (Q),("kJ")
print ("(b) If the vessel were insulated :")
print ("(i) Final temperature,")
T = cv*(m_A*T_A + m_B*T_B)/(m*cv);
t = T-273;
print ("T = %.3f")% (t), ("°C")
print ("(ii) Final pressure")
p = m*R*T/V/10**5;
print ("p = %.3f")% (p), ("bar")
import math
# Variables
m_O2 = 3.; #kg
M_O2 = 32.;
m_N2 = 9.; #kg
M_N2 = 28.;
R0 = 8.314;
# Calculations
R_O2 = R0/M_O2;
R_N2 = R0/M_N2;
x_O2 = (m_O2/M_O2)/((m_O2/M_O2) + (m_N2/M_N2));
x_N2 = (m_N2/M_N2)/((m_O2/M_O2) + (m_N2/M_N2));
dS = -m_O2*R_O2*math.log(x_O2) -m_N2*R_N2*math.log(x_N2);
# Results
print ("Change in entropy = %.3f")% (dS),("kJ/kg K")
# Variables
m_N2 = 2.5; #kg
M_N2 = 28.;
p_N2 = 15.; #bar
p_total = 20.; #bar
# Calculations
n_N2 = m_N2/M_N2;
p_O2 = p_total-p_N2;
n_O2 = p_O2/p_N2*n_N2;
M_O2 = 32;
m_O2 = n_O2*M_O2;
# Results
print ("Mass of O2 added = %.3f")% (m_O2), ("kg")
# Variables
n_O2 = 1.;
M_N2 = 28.;
M_O2 = 32.;
# Calculations and Results
print ("(i) Moles of N2 per mole of O2 :")
n_N2 = n_O2*0.79/0.21;
print ("n_N2 = %.3f")%(n_N2),("moles")
n = n_O2+n_N2;
print ("(ii)")
p = 1; #atm
p_O2 = n_O2/n*p;
print ("p_O2 = %.3f")% (p_O2), ("atm")
p_N2 = n_N2/n*p;
print ("p_N2 = %.3f")% (p_N2), ("atm")
x = n_N2*M_N2/(n_N2*M_N2+n_O2*M_O2);
print ("(iii) The kg of nitrogen per kg of mixture = %.3f")% (x), ("kg N2/kg mix")
import math
# Variables
V = 0.6; #m**3
p1 = 12.*10**5; #Pa
p2 = 18.*10**5; #Pa
T = 298.; #K
R0 = 8.314;
x_O2 = 0.23;
x_N2 = 0.77;
n = p1*V/R0/10**3/T;
#Considering 100 kg of air
m_O2 = 23.; #kg
m_N2 = 77.; #kg
M_O2 = 32.;
M_N2 = 28.;
m = 100.; #kg
# Calculations and Results
R = (m_O2/M_O2 + m_N2/M_N2)*R0/m; #for air
M = R0/R #for air
m = p1*V/R/T/10**3;
m_O2 = x_O2*m;
print ("Mass of O2 = %.3f")% (m_O2), ("kg")
m_N2 = x_N2*m;
print ("Mass of N2 = %.3f")% (m_N2), ("kg")
#After adding CO2 in the vessel
p2 = 18.*10**5; #Pa;
p_CO2 = 6.*10**5; #Pa
M_CO2 = 44.;
R_CO2 = R0/M_CO2;
m_CO2 = p_CO2*V/(R_CO2*10**3*T);
print ("Mass of CO2 = %.3f")% (m_CO2), ("kg")
# Variables
V = 6; #m**3
A = 0.45;
B = 0.55;
R_A = 0.288; #kJ/kg K
R_B = 0.295; #kJ/kg K
m = 2. #kg
T = 303. #K
# Calculations
print ("(i) The partial pressures")
m_A = A*m;
m_B = B*m;
p_A = m_A*R_A*10**3*T/V/10**5; #bar
print ("p_A = %.3f")% (p_A), ("bar")
p_B = m_B*R_B*10**3*T/V/10**5; #bar
print ("p_B = %.3f")% (p_B), ("bar")
print ("(ii) The total pressure")
p = p_A+p_B;
print ("p = %.3f")% (p), ("bar")
print ("(iii) The mean value of R for the mixture")
Rm = (m_A*R_A + m_B*R_B)/(m_A + m_B);
print ("Rm = %.3f")% (Rm), ("kJ/kg K")
# Variables
m_O2 = 4.; #kg
m_N2 = 6.; #kg
p = 4.*10**5; #Pa
T = 300.; #K
M_O2 = 32.;
M_N2 = 28.;
m = 10.; #kg
# Calculations and Results
print ("(i) The mole fraction of each component")
n_O2 = m_O2/M_O2;
n_N2 = m_N2/M_N2;
x_O2 = n_O2/(n_O2+n_N2);
print ("x_O2 = %.3f")% (x_O2)
x_N2 = n_N2/(n_N2+n_O2);
print ("x_N2 = %.3f")% (x_N2)
print ("(ii) The average molecular weight")
M = (n_O2*M_O2 + n_N2*M_N2)/(n_O2 + n_N2);
print ("M = %.3f")%(M)
print ("(iii) The specific gas consmath.tant")
R0 = 8.314;
R = R0/M;
print ("R = %.3f")% (R), ("kJ/kg K")
print ("(iv) The volume and density")
V = m*R*T*10**3/p;
print ("V = %.3f")%(V), ("m**3")
rho = (m_O2/V) + (m_N2/V);
print ("density = %.3f")% (rho), ("kg/m**3")
print ("(v) The partial pressures and partial volumes")
p_O2 = n_O2*R0*10**3*T/V/10**5; #bar
print ("p_O2 = %.3f")%(p_O2), ("bar")
p_N2 = n_N2*R0*10**3*T/V/10**5; #bar
print ("p_N2 = %.3f")% (p_N2), ("bar")
V_O2 = x_O2*V;
print ("V_O2 = %.3f")% (V_O2), ("m**3")
V_N2 = x_N2*V;
print ("V_N2 = %.3f")% (V_N2), ("m**3")
import math
# Variables
cp_CO2 = 0.85; #kJ/kg K
cp_N2 = 1.04; #kJ/kg K
m_CO2 = 4.; #kg
T1_CO2 = 313.; #K
m_N2 = 8.; #kg
T1_N2 = 433.; #K
p2 = 0.7; #bar
p1_CO2 = 1.4; #bar
p1_N2 = 1.;
R = 8.314;
M_CO2 = 44.;
M_N2 = 28.;
R_CO2 = R/M_CO2;
R_N2 = R/M_N2;
# Calculations and Results
print ("(i) Final temperature, T2")
T2 = (m_CO2*cp_CO2*T1_CO2 + m_N2*cp_N2*T1_N2)/(m_CO2*cp_CO2 + m_N2*cp_N2);
print ("T2 = %.3f")%(T2),("K")
print ("(ii) Change in entropy")
n_CO2 = 0.0909;
n_N2 = 0.2857;
n = n_CO2 + n_N2;
x_CO2 = n_CO2/n;
x_N2 = n_N2/n;
p2_CO2 = x_CO2*p2;
p2_N2 = x_N2*p2;
dS = m_CO2*cp_CO2*math.log(T2/T1_CO2) - m_CO2*R_CO2*math.log(p2_CO2/p1_CO2) + m_N2*cp_N2*math.log(T2/T1_N2) - m_N2*R_N2*math.log(p2_N2/p1_N2);
print ("dS = %.3f")%(dS), ("kJ/K")
import math
# Variables
cv_O2 = 0.39; #kJ/kg K
cv_N2 = 0.446; #kJ/kg K
n_O2 = 1.;
n_N2 = 2.;
M_O2 = 32.;
M_N2 = 28.;
m_O2 = 32.; #kg
m_N2 = 2*28.; #kg
T_O2 = 293.; #K
T_N2 = 301.; #K
R0 = 8.314;
# Calculations
p_O2 = 2.5*10**5; #Pa
p_N2 = 1.5*10**5; #Pa
T2 = (m_O2*cv_O2*T_O2 + m_N2*cv_N2*T_N2)/(m_O2*cv_O2 + m_N2*cv_N2);
V_O2 = n_O2*R0*10**5*T_O2/p_O2;
V_N2 = n_N2*R0*10**5*T_N2/p_N2;
V = V_O2+V_N2;
dS = m_O2*(cv_O2*math.log(T2/T_O2) + R0/M_O2*math.log(V/V_O2)) + m_N2*(cv_N2*math.log(T2/T_N2) + R0/M_N2*math.log(V/V_N2));
# Results
print ("Entropy change in the mixing process = %.3f")%(dS),("kJ")
import math
# Variables
cv_N2 = 0.744; #kJ/kg K
cv_H2 = 10.352; #kJ/kg K
cp_N2 = 1.041; #kJ/kg K
cp_H2 = 14.476; #kJ/kg K
V = 0.45; #m**3
V_H2 = 0.3; #m**3
V_N2 = 0.15; #m**3
p_H2 = 3.*10**5; #Pa
p_N2 = 6.*10**5; #Pa
T_H2 = 403.; #K
T_N2 = 303.; #K
# Calculations and Results
R_H2 = 8.314/2;
R_N2 = 8.314/28;
print ("(i) Temperature of equilibrium mixture")
m_H2 = p_H2*V_H2/(R_H2*10**3)/T_H2;
m_N2 = p_N2*V_N2/(R_N2*10**3)/T_N2;
T2 = (m_H2*cv_H2*T_H2 + m_N2*cv_N2*T_N2)/(m_H2*cv_H2 + m_N2*cv_N2);
print ("T2 = %.3f")%(T2),("K")
print ("(ii) Pressure of the mixture")
p2_H2 = m_H2*R_H2*10**3*T2/V;
p2_N2 = m_N2*R_N2*10**3*T2/V;
p2 = p2_H2+p2_N2;
print ("p2 = %.3f")%(p2/10**5),("bar")
print ("(iii) Change in entropy :")
dS_H2 = m_H2*(cp_H2*math.log(T2/T_H2) - R_H2*math.log(p2_H2/p_H2));
print ("Change in entropy of H2 = %.3f")%(dS_H2),("kJ/K")
dS_N2 = m_N2*(cp_N2*math.log(T2/T_N2) - R_N2*math.log(p2_N2/p_N2));
print ("Change in entropy of N2 = %.3f")%(dS_N2),("kJ/K")
dS = dS_H2+dS_N2;
print ("Total change in entropy = %.3f")%(dS),("kJ/K")
import math
# Variables
cv_N2 = 0.745; #kJ/kg K
cv_CO2 = 0.653; #kJ/kg K
cp_N2 = 1.041; #kJ/kg K
cp_CO2 = 0.842; #kJ/kg K
m_N2 = 4.; #kg
m_CO2 = 6.; #kg
pmix = 4.; #bar
m = m_N2+m_CO2;
T1 = 298.; #K
T2 = 323.; #K
# Calculations and Results
cv_mix = (m_N2*cv_N2 + m_CO2*cv_CO2)/(m_N2+m_CO2);
print ("cv_mix = %.3f")% (cv_mix), ("kJ/kg K")
cp_mix = (m_N2*cp_N2 + m_CO2*cp_CO2)/(m_N2+m_CO2);
print ("cp_mix = %.3f")% (cp_mix), ("kJ/kg K")
dU = m*cv_mix*(T2-T1);
print ("Change in internal energy = %.3f")% (dU), ("kJ")
dH = m*cp_mix*(T2-T1);
print ("Change in enthalpy = %.3f")% (dH), ("kJ")
dS = m_N2*cv_N2*math.log(T2/T1) + m_CO2*cv_CO2*math.log(T2/T1);
print ("Change in entropy = %.3f")% (dS), ("kJ/K")