summaryrefslogtreecommitdiff
path: root/Chemical_Engineering_Thermodynamics_by_P_Ahuja/2-Equations_of_state.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'Chemical_Engineering_Thermodynamics_by_P_Ahuja/2-Equations_of_state.ipynb')
-rw-r--r--Chemical_Engineering_Thermodynamics_by_P_Ahuja/2-Equations_of_state.ipynb1168
1 files changed, 1168 insertions, 0 deletions
diff --git a/Chemical_Engineering_Thermodynamics_by_P_Ahuja/2-Equations_of_state.ipynb b/Chemical_Engineering_Thermodynamics_by_P_Ahuja/2-Equations_of_state.ipynb
new file mode 100644
index 0000000..72a9295
--- /dev/null
+++ b/Chemical_Engineering_Thermodynamics_by_P_Ahuja/2-Equations_of_state.ipynb
@@ -0,0 +1,1168 @@
+{
+"cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 2: Equations of state"
+ ]
+ },
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.10: Estimation_of_molar_volume.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear;\n",
+"clc;\n",
+"\n",
+"//Example - 2.10\n",
+"//Page number - 52\n",
+"printf('Example - 2.10 and Page number - 52\n\n');\n",
+"\n",
+"//Given\n",
+"T = 71+273.15;//[K] - Temperature\n",
+"P = 69*10^(5);//[N/m^(2)] - Pressure\n",
+"y1 = 0.5;//[mol] - mole fraction of equimolar mixture\n",
+"y2 = 0.5;\n",
+"R = 8.314;//[J/mol*K] - Universal gas constant\n",
+"\n",
+"//For component 1 (methane)\n",
+"Tc_1 =190.6;//[K] - Critical temperature\n",
+"Pc_1 = 45.99*10^(5);//[N/m^(2)] - Critical pressure\n",
+"Vc_1 = 98.6;//[cm^(3)/mol] - Critical volume\n",
+"Zc_1 = 0.286;// Critical compressibility factor\n",
+"w_1 = 0.012;// acentric factor\n",
+"\n",
+"//For component 2 (hydrogen sulphide)\n",
+"Tc_2 = 373.5;//[K]\n",
+"Pc_2 = 89.63*10^(5);//[N/m^(2)]\n",
+"Vc_2 = 98.5;//[cm^(3)/mol]\n",
+"Zc_2 = 0.284;\n",
+"w_2 = 0.094;\n",
+"\n",
+"//For component 1\n",
+"Tr_1 = T/Tc_1;//Reduced temperature\n",
+"//At reduced temperature\n",
+"B1_0 = 0.083-(0.422/(Tr_1)^(1.6));\n",
+"B1_1 = 0.139-(0.172/(Tr_1)^(4.2));\n",
+"//We know,(B*Pc)/(R*Tc) = B_0+(w*B_1)\n",
+"B_11 = ((B1_0+(w_1*B1_1))*(R*Tc_1))/Pc_1;//[m^(3)/mol]\n",
+"\n",
+"//Similarly for component 2\n",
+"Tr_2 = T/Tc_2;//Reduced temperature\n",
+"//At reduced temperature Tr_2,\n",
+"B2_0 = 0.083 - (0.422/(Tr_2)^(1.6));\n",
+"B2_1 = 0.139 - (0.172/(Tr_2)^(4.2));\n",
+"B_22 = ((B2_0+(w_2*B2_1))*(R*Tc_2))/Pc_2;//[m^(3)/mol]\n",
+"\n",
+"//For cross coeffcient\n",
+"Tc_12 = (Tc_1*Tc_2)^(1/2);//[K]\n",
+"w_12 = (w_1 + w_2)/2;\n",
+"Zc_12 = (Zc_1 + Zc_2)/2;\n",
+"Vc_12 = (((Vc_1)^(1/3) + (Vc_2)^(1/3))/2)^(3);//[cm^(3)/mol]\n",
+"Vc_12 = Vc_12*10^(-6);//[m^(3)/mol]\n",
+"Pc_12 = (Zc_12*R*Tc_12)/Vc_12;//[N/m^(2)]\n",
+"\n",
+"//Now we have,(B_12*Pc_12)/(R*Tc_12) = B_0+(w_12*B_1)\n",
+"//where B_0 and B_1 are to be evaluated at Tr_12\n",
+"Tr_12 = T/Tc_12;\n",
+"//At reduced temperature Tr_12\n",
+"B_0 = 0.083 - (0.422/(Tr_12)^(1.6));\n",
+"B_1 = 0.139 - (0.172/(Tr_12)^(4.2));\n",
+"B_12=((B_0 + (w_12*B_1))*R*Tc_12)/Pc_12;//[m^(3)/mol]\n",
+"\n",
+"//For the mixture\n",
+"B = y1^(2)*B_11+2*y1*y2*B_12 + y2^(2)*B_22;//[m^(3)/mol]\n",
+"\n",
+"//Now given virial equation is, Z=1+(B*P)/(R*T)\n",
+"Z = 1 + (B*P)/(R*T);\n",
+"\n",
+"//Also Z = (P*V)/(R*T).Therefore,\n",
+"V = (Z*R*T)/P;//[m^(3)/mol]\n",
+"\n",
+"printf(' The molar volume of the mixture is %e m^(3)/mol',V);\n",
+"//The value obtained is near the experimental value of V_exp = 3.38*10^(-4) m^(3)/mol\n",
+""
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.11: Calculation_of_maximum_temperature.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear;\n",
+"clc;\n",
+"funcprot(0);\n",
+"// Example - 2.11\n",
+"// Page number - 53\n",
+"printf('Example - 2.11 and Page number - 53\n\n');\n",
+"// Given\n",
+"P = 6*10^(6);// [Pa] - Pressure\n",
+"P_max = 12*10^(6);// [Pa] - Max pressure to which cylinder may be exposed\n",
+"T = 280;//[K] - Temperature\n",
+"R = 8.314;//[J/mol*K] - Universal gas constant\n",
+"//(1).Assuming ideal gas behaviour,\n",
+"V_ideal = (R*T)/P;//[m^(3)/mol]\n",
+"//Now when temperature and pressure are increased,the molar volume remains same,as total volume and number of moles are same.\n",
+"//For max pressure of 12 MPa,temperature is\n",
+"T_max_ideal = (P_max*V_ideal)/R;\n",
+"printf(' (1).The maximum temperature assuming ideal behaviour is %f K\n',T_max_ideal);\n",
+"// (2).Assuming virial equation of state\n",
+"// For component 1 (methane),at 280 K\n",
+"Tc_1 = 190.6;//[K]\n",
+"Pc_1 = 45.99*10^(5);//[N/m^(2)]\n",
+"Vc_1 = 98.6;//[cm^(3)/mol]\n",
+"Zc_1 = 0.286;\n",
+"w_1 = 0.012;\n",
+"Tr_1 = T/Tc_1;//Reduced temperature\n",
+"B1_0 = 0.083 - (0.422/(Tr_1)^(1.6));\n",
+"B1_1 = 0.139 - (0.172/(Tr_1)^(4.2));\n",
+"//We know,(B*Pc)/(R*Tc) = B_0+(w*B_1)\n",
+"B_11 = ((B1_0 + (w_1*B1_1))*(R*Tc_1))/Pc_1;//[m^(3)/mol]\n",
+"//For component 2 (Propane)\n",
+"Tc_2 = 369.8;//[K]\n",
+"Pc_2 = 42.48*10^(5);//[N/m^(2)]\n",
+"Vc_2 = 200;//[cm^(3)/mol]\n",
+"Zc_2 = 0.276;\n",
+"w_2 = 0.152;\n",
+"Tr_2 = T/Tc_2;// Reduced temperature\n",
+"B2_0 = 0.083 - (0.422/(Tr_2)^(1.6));\n",
+"B2_1 = 0.139 - (0.172/(Tr_2)^(4.2));\n",
+"B_22 = ((B2_0 + (w_2*B2_1))*(R*Tc_2))/Pc_2;//[m^(3)/mol]\n",
+"//For cross coeffcient\n",
+"y1 = 0.8;//mole fraction of component 1\n",
+"y2 = 0.2;//mole fraction of component 2\n",
+"Tc_12 = (Tc_1*Tc_2)^(1/2);//[K]\n",
+"w_12 = (w_1 + w_2)/2;\n",
+"Zc_12 = (Zc_1 + Zc_2)/2;\n",
+"Vc_12 = (((Vc_1)^(1/3) + (Vc_2)^(1/3))/2)^(3);//[cm^(3)/mol]\n",
+"Vc_12 = Vc_12*10^(-6);//[m^(3)/mol]\n",
+"Pc_12 = (Zc_12*R*Tc_12)/Vc_12;//[N/m^(2)]\n",
+"Tr_12 = T/Tc_12;\n",
+"//At reduced temperature,Tr_12,\n",
+"B_0 = 0.083 - (0.422/(Tr_12)^(1.6));\n",
+"B_1 = 0.139 - (0.172/(Tr_12)^(4.2));\n",
+"B_12 = ((B_0 + (w_12*B_1))*R*Tc_12)/Pc_12;//[m^(3)/mol]\n",
+"//For the mixture\n",
+"B = y1^(2)*B_11+2*y1*y2*B_12 + y2^(2)*B_22;//[m^(3)/mol]\n",
+"//Now given virial equation is, Z=1+(B*P)/(R*T)\n",
+"Z = 1 + (B*P)/(R*T);\n",
+"//Also Z = (P*V)/(R*T).Therefore,\n",
+"V_real = (Z*R*T)/P;//[m^(3)/mol]\n",
+"// This molar volume remains the same as the volume and number of moles remains fixed.\n",
+"// Sice Z is a function of presure and temperature,we shall assume a temperature,calculate Z and again calculate temperature,till convergence is obtained.\n",
+"// We will use the concept of iteration to compute the convergent value of temperature\n",
+"// Let us start with the temperature at ideal conditions i.e T = 560 K,\n",
+"T_prime = 560;//[K]\n",
+"fault = 10;\n",
+"while(fault > 1)\n",
+"T_prime_r1 = T_prime/Tc_1;\n",
+"B_prime1_0 = 7.7674*10^(-3);\n",
+"B_prime1_1 = 0.13714;\n",
+"B_prime_11 = ((B_prime1_0 + (w_1*B_prime1_1))*(R*Tc_1))/Pc_1;//[m^(3)/mol]\n",
+"//Similarly for component 2,\n",
+"T_prime_r2 = T_prime/Tc_2;\n",
+"B_prime2_0 = -0.1343;\n",
+"B_prime2_1 = 0.10887;\n",
+"B_prime_22 = ((B_prime2_0 + (w_2*B_prime2_1))*(R*Tc_2))/Pc_2;//[m^(3)/mol]\n",
+"//For cross coefficient (assuming k12=0)\n",
+"//Tc_12 , w_12 , Zc_12 , Vc_12 and Pc_12 have already been calculated above,now\n",
+"T_prime_r12 = T_prime/Tc_12;//\n",
+"//At reduced temperature,T_prime_r12,\n",
+"B_prime_0 = 0.083 - (0.422/(T_prime_r12)^(1.6));\n",
+"B_prime_1 = 0.139 - (0.172/(T_prime_r12)^(4.2));\n",
+"B_prime_12 = ((B_prime_0+(w_12*B_prime_1))*R*Tc_12)/Pc_12;//[m^(3)/mol]\n",
+"//For the mixture\n",
+"B_prime = y1^(2)*B_prime_11 + 2*y1*y2*B_prime_12 + y2^(2)*B_prime_22;//[m^(3)/mol]\n",
+"Z_prime = 1 + (B_prime*P_max)/(R*T_prime);\n",
+"T_new = (P_max*V_real)/(Z_prime*R);\n",
+"fault = abs(T_prime - T_new);\n",
+"T_prime = T_new;\n",
+"end\n",
+"printf(' (2).The maximum temperature assuming the gas to follow virial equation of stste is %f K\n',T_new);"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.12: Calculation_of_pressure.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear;\n",
+"clc;\n",
+"\n",
+"// Example - 2.12\n",
+"// Page number - 64\n",
+"printf('Example - 2.12 and Page number - 64\n\n');\n",
+"\n",
+"//Given\n",
+"\n",
+"V_vessel = 0.1;//[m^(3)]// Volume of vessel\n",
+"T = 25 + 273.15;//[K] - Temperature\n",
+"R = 8.314;//[J/mol*K] - Universal gas constant\n",
+"m = 25*1000;//[g]// Mass of ethylene\n",
+"Tc = 282.3;//[K] - Critical temperature\n",
+"Pc = 50.40;//[bar] - Critical pressure\n",
+"Pc = Pc*10^(5);//[N/m^(2)]\n",
+"Zc = 0.281;// Critical compressibility factor\n",
+"Vc = 131;//[cm^(3)/mol] - Critical volume\n",
+"Vc = Vc*10^(-6);//[m^(3)/mol]\n",
+"w = 0.087;// Acentric factor\n",
+"M = 28.054;// Molecular weight of ethylene\n",
+"\n",
+"n = m/M;//[mole] - No. of moles of ethylene\n",
+"V = V_vessel/n;//[m^(3)/mol] - Molar volume\n",
+"\n",
+"//Under Redlich Kwong equation of state, we have\n",
+"a = (0.42748*(R^(2))*(Tc^(2.5)))/Pc;//[Pa*m^(6)*K^(1/2)/mol]\n",
+"b = (0.08664*R*Tc)/Pc;//[m^(3)/mol]\n",
+"P = ((R*T)/(V-b))-(a/(T^(1/2)*V*(V+b)));//[N/m^(2)]\n",
+"printf(' The required pressure using Redlich Kwong equation of state is %e N/m^(2)\n',P);\n",
+"\n",
+"//For ideal gas equation of state,\n",
+"P_ideal = (R*T)/V;//[N/m^(2)]\n",
+"printf(' For ideal gas equation of state,the required pressure is %e N/m^(2)\n',P_ideal);\n",
+""
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.13: Calculation_of_pressure.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear;\n",
+"clc;\n",
+"\n",
+"// Example - 2.13\n",
+"// Page number - 65\n",
+"printf('Example - 2.13 and Page number - 65\n\n');\n",
+"\n",
+"//Given\n",
+"\n",
+"V_vessel = 360*10^(-3);//[m^(3)] - volume of vessel\n",
+"T = 62+273.15;//[K] - Temperature\n",
+"R = 8.314;//[J/mol*K] - Universal gas constant\n",
+"m = 70*1000;//[g]/ - Mass of carbon dioxide\n",
+"\n",
+"//For carbon dioxide\n",
+"Tc = 304.2;//[K] - Cricitical temperature\n",
+"Pc = 73.83;//[bar] - Cricitical pressure\n",
+"Pc = Pc*10^(5);// [N/m^(2)]\n",
+"Zc = 0.274;// Critical compressibility factor\n",
+"Vc = 94.0;//[cm^(3)/mol]\n",
+"Vc = Vc*10^(-6);//[m^(3)/mol]\n",
+"w = 0.224;// Acentric factor\n",
+"M = 44.01;// Molecular weight of carbon dioxide\n",
+"\n",
+"n = m/M;//[mol] - No. of moles\n",
+"V = V_vessel/n;//[m^(3)/mol]//molar volume\n",
+"\n",
+"// (1)\n",
+"// Ideal gas behaviour\n",
+"P_1 = (R*T)/V;//[N/m^(2)]\n",
+"printf(' (1).The required pressure using ideal equation of state is %e N/m^(2)\n',P_1);\n",
+"\n",
+"// (2)\n",
+"// Virial equation of state, Z = 1 + (B*P)/(R*T)\n",
+"// (P*V)/(R*T) = 1 + (B*P)/(R*T), and thus P = (R*T)/(V - B). Now\n",
+"Tr = T/Tc;//Reduced temperature\n",
+"// At reduced temperature Tr,\n",
+"B_0 = 0.083 - (0.422/(Tr)^(1.6));\n",
+"B_1 = 0.139 - (0.172/(Tr)^(4.2));\n",
+"B = ((B_0 + (w*B_1))*(R*Tc))/Pc;//[m^(3)/mol]\n",
+"P_2 = (R*T)/(V - B);//[N/m^(2)]\n",
+"printf(' (2).The required pressure using given virial equation of state is %e N/m^(2)\n',P_2);\n",
+"\n",
+"// (3)\n",
+"// Virial equation of state, Z = 1 + (B/V)\n",
+"// (P*V)/(R*T) = 1 + (B/V)\n",
+"P_3 = ((R*T)/V) + (B*R*T)/(V^(2));//[N/m^(2)]\n",
+"printf(' (3).The required pressure using given virial equation of state is %e N/m^(2)\n',P_3);\n",
+"\n",
+"// (4)\n",
+"// Van der Walls equation of state,P = ((R*T)/(V-b)) - a/(V^(2))\n",
+"a = (27*(R^(2))*(Tc^(2)))/(64*Pc);//[Pa*m^(6)/mol^(2)]\n",
+"b = (R*Tc)/(8*Pc);//[m^(3)/mol]\n",
+"P_4 = ((R*T)/(V-b)) - a/(V^(2));//[N/m^(2)]\n",
+"printf(' (4).The required pressure using van der Walls equation of state is %e N/m^(2)\n',P_4);\n",
+"\n",
+"//(5)\n",
+"// Redlich Kwong equation of state,\n",
+"a_1 = (0.42748*(R^(2))*(Tc^(2.5)))/Pc;//[Pa*m^(6)*K^(1/2)/mol]\n",
+"b_1 = (0.08664*R*Tc)/Pc;//[m^(3)/mol]\n",
+"P_5 = ((R*T)/(V - b_1)) - (a_1/(T^(1/2)*V*(V + b_1)));//[N/m^(2)]\n",
+"printf(' (5).The required pressure using Redlich Kwong equation of state is %e N/m^(2)\n',P_5);\n",
+"\n",
+""
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.14: Determination_of_compressibility_factor.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear;\n",
+"clc;\n",
+"funcprot(0);\n",
+"// Example - 2.14\n",
+"// Page number - 66\n",
+"printf('Example - 2.14 and Page number - 66\n\n');\n",
+"//Given\n",
+"T = 500+273.15;//[K] - Temperature\n",
+"R = 8.314;//[J/mol*K] - Universal gas constant\n",
+"P = 325*1000;//[Pa] - Pressure\n",
+"Tc = 647.1;//[K] - Cricitical temperature\n",
+"Pc = 220.55;//[bar] - Cricitical pressure\n",
+"Pc = Pc*10^(5);//[N/m^(2)]\n",
+"//(1)\n",
+"// Van der Walls equation of state,\n",
+"a = (27*(R^(2))*(Tc^(2)))/(64*Pc);//[Pa*m^(6)/mol^(2)]\n",
+"b = (R*Tc)/(8*Pc);//[m^(3)/mol]\n",
+"// The cubic form of van der Walls equation of state is given by,\n",
+"// V^(3)-(b+(R*T)/P)*V^(2)+(a/P)*V-(a*b)/P=0\n",
+"// Solving the cubic equation\n",
+"deff('[y]=f(V)','y=V^(3)-(b+(R*T)/P)*V^(2)+(a/P)*V-(a*b)/P');\n",
+"V_1 = fsolve(1,f);\n",
+"V_2 = fsolve(10,f);\n",
+"V_3 = fsolve(100,f);\n",
+"// The above equation has 1 real and 2 imaginary roots. We consider only real root,\n",
+"Z_1 = (P*V_1)/(R*T);//compressibility factor\n",
+"printf(' (1).The compressibility factor of steam using van der Walls equation of state is %f\n',Z_1);\n",
+"//(2)\n",
+"//Redlich Kwong equation of state,\n",
+"a_1 = (0.42748*(R^(2))*(Tc^(2.5)))/Pc;//[Pa*m^(6)*K^(1/2)/mol]\n",
+"b_1 = (0.08664*R*Tc)/Pc;//[m^(3)/mol]\n",
+"// The cubic form of Redlich Kwong equation of state is given by,\n",
+"// V^(3)-((R*T)/P)*V^(2)-((b_1^(2))+((b_1*R*T)/P)-(a/(T^(1/2)*P))*V-(a*b)/(T^(1/2)*P)=0\n",
+"//Solving the cubic equation\n",
+"deff('[y]=f1(V)','y=V^(3)-((R*T)/P)*V^(2)-((b_1^(2))+((b_1*R*T)/P)-(a_1/(T^(1/2)*P)))*V-(a_1*b_1)/(T^(1/2)*P)');\n",
+"V_4=fsolve(1,f1);\n",
+"V_5=fsolve(10,f1);\n",
+"V_6=fsolve(100,f1);\n",
+"// The above equation has 1 real and 2 imaginary roots. We consider only real root,\n",
+"// Thus compressibility factor is\n",
+"Z_2 = (P*V_4)/(R*T);//compressibility factor\n",
+"printf(' (2).The compressibility factor of steam using Redlich Kwong equation of state is %f\n',Z_2);"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.15: Determination_of_molar_volume.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear;\n",
+"clc;\n",
+"\n",
+"// Example - 2.15\n",
+"// Page number - 67\n",
+"printf('Example - 2.15 and Page number - 67\n\n');\n",
+"\n",
+"//Given\n",
+"T = 250+273.15;//[K]\n",
+"R = 8.314;//[J/mol*K]\n",
+"P = 39.76;//[bar] Vapour pressure of water at T\n",
+"P = P*10^(5);//[N/m^(2)]\n",
+"Tc = 647.1;//[K] - Cricitical temperature\n",
+"Pc = 220.55*10^(5);//[N/m^(2)] - Cricitical pressure\n",
+"w = 0.345;//Acentric factor\n",
+"M = 18.015;// Molecular weight of water\n",
+"\n",
+"// Using peng-Robinson equation of stste \n",
+"m = 0.37464 + 1.54226*w - 0.26992*w^(2);\n",
+"Tr = T/Tc;\n",
+"alpha = (1 + m*(1 - Tr^(1/2)))^(2);\n",
+"a = ((0.45724*(R*Tc)^(2))/Pc)*alpha;//[Pa*m^(6)/mol^(2)]\n",
+"b = (0.07780*R*Tc)/Pc;//[m^(3)/mol]\n",
+"// Cubuc form of Peng-Robinson equation of stste is given by\n",
+"// V^(3) + (b-(R*T)/P)*V^(2) - ((3*b^(2)) + ((2*R*T*b)/P) - (a/P))*V+b^(3) + ((R*T*(b^(2))/P) - ((a*b)/P) = 0;\n",
+"// Solving the cubic equation\n",
+"deff('[y]=f(V)','y=V^(3)+(b-(R*T)/P)*V^(2)-((3*b^(2))+((2*R*T*b)/P)-(a/P))*V+b^(3)+((R*T*(b^(2)))/P)-((a*b)/P)');\n",
+"V_1 = fsolve(-1,f);\n",
+"V_2 = fsolve(0,f);\n",
+"V_3 = fsolve(1,f);\n",
+"//The largest root is for vapour phase,\n",
+"V_vap = V_3;//[m^(3)/mol] - Molar volume (saturated vapour)\n",
+"V_vap = V_vap*10^(6)/M;//[cm^(3)/g]\n",
+"\n",
+"printf(' The moar volume of saturated water in the vapour phase (V_vap) is %f cm^(3)/g\n',V_vap);\n",
+"\n",
+"//The smallest root is for liquid phase,\n",
+"V_liq = V_1;//[m^(3)/mol] - molar volume (saturated liquid)\n",
+"V_liq = V_liq*10^(6)/M;//[cm^(3)/g]\n",
+"printf(' The moar volume of saturated water in the liquid phase (V_liq) is %f cm^(3)/g\n',V_liq);\n",
+"\n",
+"//From steam table at 250 C, V_vap = 50.13 [cm^(3)/g] and V_liq = 1.251 [cm^(3)/g].\n",
+"printf(' From steam table at 250 C, V_vap = 50.13 [cm^(3)/g] and V_liq = 1.251 [cm^(3)/g]');\n",
+""
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.16: Calculation_of_volume.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear;\n",
+"clc;\n",
+"funcprot(0);\n",
+"\n",
+"// Example - 2.16\n",
+"// Page number - 68\n",
+"printf('Example - 2.16 and Page number - 68\n\n');\n",
+"\n",
+"//Given\n",
+"T = 500+273.15;//[K] - Temperature\n",
+"P = 15;//[atm] - Pressure\n",
+"P = P*101325;//[N/m^(2)]\n",
+"R = 8.314;//[J/mol*K] - Universal gas constant\n",
+"Tc = 190.6;//[K] - Cricitical temperature\n",
+"Pc = 45.99*10^(5);//[N/m^(2)] - Cricitical pressure\n",
+"Vc = 98.6;//[cm^(3)/mol] - Cricitical molar volume\n",
+"Zc = 0.286;// Critical compressibility factor\n",
+"w = 0.012;// Acentric factor\n",
+"\n",
+"//(1)\n",
+"//Virial equation of state,Z = 1 + (B*P)/(R*T)\n",
+"Tr_1 = T/Tc;//Reduced temperature\n",
+"B_0 = 0.083-(0.422/(Tr_1)^(1.6));\n",
+"B_1 = 0.139-(0.172/(Tr_1)^(4.2));\n",
+"// We know,(B*Pc)/(R*Tc) = B_0+(w*B_1)\n",
+"B = ((B_0+(w*B_1))*(R*Tc))/Pc;//[m^(3)/mol]//second virial coefficient\n",
+"Z = 1 + (B*P)/(R*T);//compressibility factor\n",
+"//(P*V)/(R*T)=1+(B*P)/(R*T),and thus,\n",
+"V_1 = (Z*R*T)/P;//[m^(3)/mol]\n",
+"printf(' (1).The molar volume of methane using given virial equation is %e m^(3)/mol\n',V_1);\n",
+"\n",
+"//(2).\n",
+"//Virial equation of state,Z = 1 + (B/V)\n",
+"//Also,Z = (P*V)/(R*T). Substituting the value of Z,we get\n",
+"// V^(2) - ((R*T)/P)*V - ((B*R*T)/P) = 0.Solving the quadratic equation\n",
+"deff('[y]=f(V)','y=V^(2)-((R*T)/P)*V-((B*R*T)/P)');\n",
+"V2_1=fsolve(0,f);\n",
+"V2_2=fsolve(1,f);\n",
+"// Out of two roots,we will consider only positive root\n",
+"printf(' (2).The molar volume of methane using given virial equation is %e m^(3)/mol\n',V2_2);\n",
+"\n",
+"// (3)\n",
+"// Van der Walls equation of state,\n",
+"// (P + (a/V^(2)))*(V - b) = R*T\n",
+"a_3 = (27*(R^(2))*(Tc^(2)))/(64*Pc);//[Pa*m^(6)/mol^(2)]\n",
+"b_3 = (R*Tc)/(8*Pc);//[m^(3)/mol]\n",
+"// The cubic form of van der Walls equation of state is given by,\n",
+"// V^(3) - (b + (R*T)/P)*V^(2) + (a/P)*V - (a*b)/P = 0\n",
+"// Solving the cubic equation\n",
+"deff('[y]=f1(V)','y=V^(3)-(b_3+(R*T)/P)*V^(2)+(a_3/P)*V-(a_3*b_3)/P');\n",
+"V3_1=fsolve(1,f1);\n",
+"V3_2=fsolve(10,f1);\n",
+"V3_3=fsolve(100,f1);\n",
+"// The above equation has 1 real and 2 imaginary roots. We consider only real root.\n",
+"printf(' (3).The molar volume of methane using van der Walls equation of state is %e m^(3)/mol\n',V3_1);\n",
+"\n",
+"// (4)\n",
+"// Redlich Kwong equation of state\n",
+"a_4 = (0.42748*(R^(2))*(Tc^(2.5)))/Pc;//[Pa*m^(6)*K^(1/2)/mol]\n",
+"b_4 = (0.08664*R*Tc)/Pc;//[m^(3)/mol]\n",
+"// The cubic form of Redlich Kwong equation of state is given by,\n",
+"// V^(3) - ((R*T)/P)*V^(2) - ((b_1^(2)) + ((b_1*R*T)/P) - (a/(T^(1/2)*P))*V - (a*b)/(T^(1/2)*P) = 0\n",
+"// Solving the cubic equation\n",
+"deff('[y]=f2(V)','y=V^(3)-((R*T)/P)*V^(2)-((b_4^(2))+((b_4*R*T)/P)-(a_4/(T^(1/2)*P)))*V-(a_4*b_4)/(T^(1/2)*P)');\n",
+"V4_1=fsolve(1,f2);\n",
+"V4_2=fsolve(10,f2);\n",
+"V4_3=fsolve(100,f2);\n",
+"//The above equation has 1 real and 2 imaginary roots. We consider only real root.\n",
+"printf(' (4).The molar volume of methane using Redlich Kwong equation of state is %e m^(3)/mol\n',V4_1);\n",
+"\n",
+"// (5)\n",
+"// Using Peng-Robinson equation of state \n",
+"m = 0.37464 + 1.54226*w - 0.26992*w^(2);\n",
+"Tr_5 = T/Tc;\n",
+"alpha = (1 + m*(1 - Tr_5^(1/2)))^(2);\n",
+"a = ((0.45724*(R*Tc)^(2))/Pc)*alpha;//[Pa*m^(6)/mol^(2)]\n",
+"b = (0.07780*R*Tc)/Pc;//[m^(3)/mol]\n",
+"// Cubic form of Peng-Robinson equation of stste is given by\n",
+"// V^(3)+(b-(R*T)/P)*V^(2)-((3*b^(2))+((2*R*T*b)/P)-(a/P))*V+b^(3)+((R*T*(b^(2))/P)-((a*b)/P)=0;\n",
+"// Solving the cubic equation\n",
+"deff('[y]=f3(V)','y=V^(3)+(b-(R*T)/P)*V^(2)-((3*b^(2))+((2*R*T*b)/P)-(a/P))*V+b^(3)+((R*T*(b^(2)))/P)-((a*b)/P)');\n",
+"V5_1=fsolve(-1,f3);\n",
+"V5_2=fsolve(0,f3);\n",
+"V5_3=fsolve(1,f3);\n",
+"//The largest root is for vapour phase,\n",
+"//The largest root is only considered as the systemis gas\n",
+"printf(' (5).The molar volume of methane using Peng-Robinson equation of state is %e m^(3)/mol\n',V5_3);"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.17: Estimation_of_compressibility_factor.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear;\n",
+"clc;\n",
+"funcprot(0);\n",
+"\n",
+"// Example - 2.17\n",
+"// Page number - 70\n",
+"printf('Example - 2.17 and Page number - 70\n\n');\n",
+"\n",
+"//Given\n",
+"T = 310.93;//[K] - Temperature\n",
+"P = 2.76*10^(6);//[N/m^(2)] - Pressure\n",
+"R = 8.314;//[J/mol*K] - Universal gas constant\n",
+"y1 = 0.8942;// Mole fraction of component 1 (methane)\n",
+"y2 = 1-y1;// Mole fraction of component 2 (n-butane)\n",
+"\n",
+"//For component 1 (methane)\n",
+"Tc_1 = 190.58;//[K] - Cricitical temperature\n",
+"Pc_1 = 46.05;//[bar] - Cricitical pressure\n",
+"Pc_1 = Pc_1*10^(5);//[N/m^(2)]\n",
+"Zc_1 = 0.288;// Critical compressibility factor\n",
+"Vc_1 = 99.1;//[cm^(3)/mol]\n",
+"Vc_1 = Vc_1*10^(-6);//[m^(3)/mol]\n",
+"w_1 = 0.011;// Acentric factor\n",
+"\n",
+"//For component 2 (n-butane)\n",
+"Tc_2 = 425.18;//[K] - Cricitical temperature\n",
+"Pc_2 = 37.97;//[bar] - Cricitical pressure\n",
+"Pc_2 = Pc_2*10^(5);// [N/m^(2)]\n",
+"Zc_2 = 0.274;// Critical compressibility factor\n",
+"Vc_2 = 255.1;// [cm^(3)/mol]\n",
+"Vc_2 = Vc_2*10^(-6);// [m^(3)/mol]\n",
+"w_2 = 0.193;// Acentric factor\n",
+"\n",
+"// (1)\n",
+"// Virial equation of state, Z = 1 + (B*P)/(R*T)\n",
+"// For component 1 (methane)\n",
+"Tr_1 = T/Tc_1;//Reduced temperature\n",
+"// At reduced temperature\n",
+"B1_0 = 0.083 - (0.422/(Tr_1)^(1.6));\n",
+"B1_1 = 0.139 - (0.172/(Tr_1)^(4.2));\n",
+"// We know,(B*Pc)/(R*Tc) = B_0+(w*B_1)\n",
+"B_11 = ((B1_0+(w_1*B1_1))*(R*Tc_1))/Pc_1;//[m^(3)/mol]\n",
+"\n",
+"//Similarly for component 2\n",
+"Tr_2 = T/Tc_2;//Reduced temperature\n",
+"//At reduced temperature Tr_2,\n",
+"B2_0 = 0.083 - (0.422/(Tr_2)^(1.6));\n",
+"B2_1 = 0.139 - (0.172/(Tr_2)^(4.2));\n",
+"B_22 = ((B2_0 + (w_2*B2_1))*(R*Tc_2))/Pc_2;//[m^(3)/mol]\n",
+"\n",
+"//For cross coeffcient\n",
+"Tc_12 = (Tc_1*Tc_2)^(1/2);//[K]\n",
+"w_12 = (w_1 + w_2)/2;\n",
+"Zc_12 = (Zc_1 + Zc_2)/2;\n",
+"Vc_12 = (((Vc_1)^(1/3)+(Vc_2)^(1/3))/2)^(3);//[m^(3)/mol]\n",
+"Pc_12 =(Zc_12*R*Tc_12)/Vc_12;//[N/m^(2)]\n",
+"\n",
+"//Now we have,(B_12*Pc_12)/(R*Tc_12) = B_0+(w_12*B_1)\n",
+"//where B_0 and B_1 are to be evaluated at Tr_12\n",
+"Tr_12 = T/Tc_12;\n",
+"//At reduced temperature Tr_12\n",
+"B_0 = 0.083 - (0.422/(Tr_12)^(1.6));\n",
+"B_1 = 0.139 - (0.172/(Tr_12)^(4.2));\n",
+"B_12 = ((B_0+(w_12*B_1))*R*Tc_12)/Pc_12;//[m^(3)/mol]\n",
+"\n",
+"//For the mixture\n",
+"B = y1^(2)*B_11+2*y1*y2*B_12+y2^(2)*B_22;//[m^(3)/mol]\n",
+"Z_1 = 1+(B*P)/(R*T);//compressibility factor\n",
+"printf(' (1).The compressibility factor of mixture using Virial equation of state is %f\n',Z_1);\n",
+"\n",
+"// (2)\n",
+"// Pseudo reduced method.\n",
+"T_pc = (y1*Tc_1)+(y2*Tc_2);//[K] - Cricitical temperature\n",
+"P_pc = (y1*Pc_1)+(y2*Pc_2);//[N/m^(2)] - Cricitical pressure\n",
+"w = (y1*w_1)+(y2*w_2);// Acentric factor\n",
+"T_pr = T/T_pc;// Reduced temperature\n",
+"P_pr = P/P_pc;// Reduced pressure\n",
+"//At this value of Tpr,\n",
+"B0 = 0.083 - (0.422/(T_pr)^(1.6));\n",
+"B1 = 0.139 - (0.172/(T_pr)^(4.2));\n",
+"Z0 = 1 + B0*(P_pr/T_pr);\n",
+"Z1 = B1*(P_pr/T_pr);\n",
+"Z = Z0 + w*Z1;\n",
+"printf(' (2).The compressibility factor of mixture using pseudo reduced method is %f\n',Z);\n",
+"\n",
+"// (3)\n",
+"// Redlich Kwong equation of state is given by\n",
+"// P = ((R*T)/(V-b)) - (a/(T^(1/2)*V*(V+b)))\n",
+"// For methane,component 1\n",
+"a_1 = (0.42748*(R^(2))*(Tc_1^(2.5)))/Pc_1;//[Pa*m^(6)*K^(1/2)/mol]\n",
+"b_1 = (0.08664*R*Tc_1)/Pc_1;//[m^(3)/mol]\n",
+"//For n-butane,component 2\n",
+"a_2 = (0.42748*(R^(2))*(Tc_2^(2.5)))/Pc_2;//[Pa*m^(6)*K^(1/2)/mol]\n",
+"b_2 = (0.08664*R*Tc_2)/Pc_2;//[m^(3)/mol]\n",
+"//For the mixture\n",
+"a_12 = (a_1*a_2)^(1/2);//[Pa*m^(6)*K^(1/2)/mol]\n",
+"a = y1^(2)*a_1 + 2*y1*y2*a_12 + y2^(2)*a_2;//[Pa*m^(6)*K^(1/2)/mol]\n",
+"b = (y1*b_1) + (y2*b_2);//[m^(3)/mol]\n",
+"// The cubic form of Redlich Kwong equation of state is given by,\n",
+"// V^(3) - ((R*T)/P)*V^(2) - ((b_1^(2)) + ((b_1*R*T)/P) - (a/(T^(1/2)*P))*V - (a*b)/(T^(1/2)*P) = 0\n",
+"// Solving the cubic equation\n",
+"deff('[y]=f(V)','y=V^(3)-((R*T)/P)*V^(2)-((b^(2))+((b*R*T)/P)-(a/(T^(1/2)*P)))*V-(a*b)/(T^(1/2)*P)');\n",
+"V_1=fsolve(1,f);\n",
+"V_2=fsolve(10,f);\n",
+"V_3=fsolve(100,f);\n",
+"// Thus compressibility factor is\n",
+"Z_3 = (P*V_1)/(R*T);//compressibility factor\n",
+"printf(' (3).The compressibility factor of mixture using Redlich Kwong equation of state is %f\n',Z_3);\n",
+""
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.1: Relations_in_virial_coefficients.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear;\n",
+"clc;\n",
+"\n",
+"//Example - 2.1\n",
+"//Page number - 40\n",
+"printf('Example - 2.1 and Page number - 40\n\n');\n",
+"\n",
+"//This problem involves proving a relation in which no numerical components are involved.\n",
+"//For prove refer to this example 2.1 on page number 40 of the book.\n",
+"printf(' This problem involves proving a relation in which no numerical components are involved.\n\n');\n",
+"printf(' For prove refer to this example 2.1 on page number 40 of the book.');\n",
+""
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.2: Determination_of_acentric_factor.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear;\n",
+"clc;\n",
+"\n",
+"//Example - 2.2\n",
+"//Page number - 42\n",
+"printf('Example - 2.2 and Page number - 42\n\n');\n",
+"\n",
+"//Given\n",
+"Tc = 647.1;//[K] - Critical temperature\n",
+"Pc = 220.55;//[bar] - Critical pressure\n",
+"Tr = 0.7;// Reduced temperature\n",
+"\n",
+"T = Tr*Tc;//[K]\n",
+"//From steam table,vapour pressure of H2O at T is 10.02 [bar], as reported in the book\n",
+"P = 10.02;//[bar]\n",
+"w = -1-log10((P/Pc));\n",
+"printf(' The acentric factor (w) of water at given condition is %f ',w);"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.3: Calculation_of_acentric_factor.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear;\n",
+"clc;\n",
+"\n",
+"//Example - 2.3\n",
+"//Page number - 42\n",
+"printf('Example - 2.3 and Page number - 42\n\n');\n",
+"\n",
+"//Given\n",
+"//log10(Psat)=8.1122-(1592.864/(t+226.184))// 'Psat' in [mm Hg] and 't' in [c]\n",
+"Tc = 513.9;//[K] - Critical temperature\n",
+"Pc = 61.48;//[bar] - Critical pressure\n",
+"Pc = Pc*10^(5);//[N/m^(2)]\n",
+"Tr = 0.7;// Reduced temperature\n",
+"\n",
+"T = Tr*Tc;//[K] - Temperature\n",
+"T = T - 273.15;//[C]\n",
+"P_sat = 10^(8.1122 - (1592.864/(T + 226.184)));//[mm Hg]\n",
+"P_sat = (P_sat/760)*101325;//[N/m^(2)]\n",
+"Pr_sat = P_sat/Pc;\n",
+"w = -1-log10(Pr_sat);// Acentric factor\n",
+"printf(' The acentric factor (w) for ethanol at given condition is %f',w);"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.4: Calculation_of_virial_coefficients.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear;\n",
+"clc;\n",
+"\n",
+"//Example - 2.4\n",
+"//Page number - 45\n",
+"printf('Example - 2.4 and Page number - 45\n\n');\n",
+"\n",
+"//Given\n",
+"T = 380;//[K] - Temperature\n",
+"Tc = 562.1;//[K] - Critical temperature\n",
+"P = 7;//[atm] - Pressure\n",
+"P = P*101325;//[N/m^(2)]\n",
+"Pc = 48.3;//[atm] - Critical pressure\n",
+"Pc = Pc*101325;//[N/m^(2)]\n",
+"R = 8.314;//[J/mol*K] - Universal gas constant\n",
+"w = 0.212;// acentric factor\n",
+"Tr = T/Tc;// Reduced temperature\n",
+"\n",
+"B_0 = 0.083-(0.422/(Tr)^(1.6));\n",
+"B_1 = 0.139-(0.172/(Tr)^(4.2));\n",
+"\n",
+"//We know,(B*Pc)/(R*Tc) = B_0+(w*B_1)\n",
+"B = ((B_0+(w*B_1))*(R*Tc))/Pc;//[m^(3)/mol]\n",
+"printf(' The second virial coefficient for benzene is %e m^(3)/mol\n',B);\n",
+"\n",
+"//Compressibility factor is given by\n",
+"Z = 1 + ((B*P)/(R*T));\n",
+"printf(' The compressibility factor at 380 K is %f\n',Z);\n",
+"\n",
+"//We know thar Z=(P*V)/(R/*T),therfore\n",
+"V = (Z*R*T)/P;//[m^(3)/mol]\n",
+"printf(' The molar volume is %e m^(3)/mol\n',V);\n",
+""
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.5: Calculation_of_mass_using_virial_equation_of_state.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear;\n",
+"clc;\n",
+"\n",
+"//Example - 2.5\n",
+"//Page number - 46\n",
+"printf('Example - 2.5 and Page number - 46\n\n');\n",
+"\n",
+"//Given\n",
+"V_1 = 0.3;//[m^(3)]//volume of cylinder\n",
+"T = 60+273.15;//[K] - Temperature\n",
+"P = 130*10^(5);//[N/m^(2)] - Pressure\n",
+"Tc = 305.3;//[K] - Critical temperature\n",
+"Pc = 48.72*10^(5);//[N/m^(2)] - Critical pressure\n",
+"w = 0.100;//acentric factor\n",
+"M = 30.07;//molecular weight of ethane\n",
+"Tr = T/Tc;// Reduced temperature\n",
+"R = 8.314;//[J/mol*K] - Universal gas constant\n",
+"\n",
+"B_0 = 0.083-(0.422/(Tr)^(1.6));\n",
+"B_1 = 0.139-(0.172/(Tr)^(4.2));\n",
+"\n",
+"//We know,(B*Pc)/(R*Tc) = B_0+(w*B_1)\n",
+"B = ((B_0 + (w*B_1))*(R*Tc))/Pc;//[m^(3)/mol] - Second virial coefficient\n",
+"Z = 1 + ((B*P)/(R*T));//Compressibility factor\n",
+"V = (Z*R*T)/P;//[m^(3)/mol] - Molar volume\n",
+"\n",
+"//No.of moles in 0.3 m^(3) cylinder is given by\n",
+"n1 = V_1/V;//[mol]\n",
+"\n",
+"//Mass of gas in cylinder is given by \n",
+"m1 = (n1*M)/1000;//[kg]\n",
+"printf(' Under actual conditions,the mass of ethane is, %f kg\n',m1);\n",
+"\n",
+"//Under ideal condition, taking Z = 1,\n",
+"V_ideal = (R*T)/P;//[m^(3)/mol]\n",
+"n2 = V_1/V_ideal;//[mol]\n",
+"m2 = (n2*M)/1000;//[kg]\n",
+"printf(' Under ideal conditions,the mass of ethane is, %f kg\n',m2);\n",
+"\n",
+""
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.6: Calculation_of_molar_volume.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear;\n",
+"clc;\n",
+"funcprot(0);\n",
+"\n",
+"//Example - 2.6\n",
+"//Page number - 47\n",
+"printf('Example - 2.6 and Page number - 47\n\n');\n",
+"\n",
+"//Given\n",
+"T = 373.15;//[K] - Temperature\n",
+"P = 101325;//[N/m^(2)] - Pressure\n",
+"Tc = 647.1;//[K] - Critical temperature\n",
+"Pc = 220.55*10^(5);//[N/m^(2)] - Critical pressure\n",
+"w = 0.345;//acentric factor\n",
+"Tr = T/Tc;// Reduced temperature\n",
+"R = 8.314;//[J/mol*K] - UNiversal gas constant\n",
+"\n",
+"B_0 = 0.083-(0.422/(Tr)^(1.6));\n",
+"B_1 = 0.139-(0.172/(Tr)^(4.2));\n",
+"\n",
+"//We know,(B*Pc)/(R*Tc) = B_0+(w*B_1)\n",
+"B = ((B_0+(w*B_1))*(R*Tc))/Pc;//[m^(3)/mol] - Second virial coefficient\n",
+"\n",
+"//We have, Z = 1+(B/V) and Z = (P*V)/(R*T). Substituting the value of Z,we get\n",
+"// V^(2)-((R*T)/P)*V-((B*R*T)/P)=0 .Solving the quadratic equation by shreedharcharya rule\n",
+"V1 = (((R*T)/P) + (((R*T)/P)^(2) + 4*1*((B*R*T)/P))^(1/2))/2*1;\n",
+"\n",
+"printf(' The molar volume of water vapour is %f m^(3)/mol',V1);\n",
+"\n",
+"//The roots are,V1 = 0.0003670 [m^(3)/mol] and V2 = 0.0302510 [m^(3)/mol].\n",
+"//As 'V2' is near to ideal volume (0.030618 [m^(3)/mol]),it is taken as the molar volume\n",
+"//The other root 'V1' hss no physical significance"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.7: Calculation_of_molar_volume_and_virial_coefficients.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear;\n",
+"clc;\n",
+"funcprot(0);\n",
+"//Example - 2.7\n",
+"// Page number - 47\n",
+"printf('Example - 2.7 and Page number - 47\n\n');\n",
+"// Given\n",
+"T = 50+273.15;//[K] - Temperature\n",
+"P = 15*10^(5);//[N/m^(2)] - Pressure\n",
+"Tc = 305.3;//[K] - Critical temperature\n",
+"Pc = 48.72*10^(5);//[N/m^(2)] - Critical pressure\n",
+"w = 0.100;// Acentric factor\n",
+"B = -157.31;//[cm^(3)/mol] - second virial coefficient\n",
+"B = B*10^(-6);//[m^(3)/mol]\n",
+"C = 9650;//[cm^(6)/mol^(2)] - third virial coefficient\n",
+"C = C*10^(-12);//[cm^(6)/mol^(2)]\n",
+"R = 8.314;//[J/mol*K] - Universal gas constant\n",
+"// (1)\n",
+"V_1 = (R*T)/P;//[m^(3)/mol] - Molar volume\n",
+"printf(' (1).The molar volume for ideal equation of state is %e m^(3)/mol\n',V_1);\n",
+"// (2)\n",
+"Tr = T/Tc;// Reduced temperature\n",
+"// At this temperature\n",
+"B_0 = 0.083-(0.422/(Tr)^(1.6));\n",
+"B_1 = 0.139-(0.172/(Tr)^(4.2));\n",
+"// We know,(B*Pc)/(R*Tc) = B_0+(w*B_1)\n",
+"B_2 = ((B_0 + (w*B_1))*(R*Tc))/Pc;//[m^(3)/mol]//second virial coefficient\n",
+"printf(' (2).The second virial coefficent using Pitzer correlation is found to be %e m^(3)/mol which is same as given value\n',B_2);\n",
+"// (3)\n",
+"// Given (virial equation),Z=1+(B/V)\n",
+"V_3 = B + (R*T)/P;//[m^(3)/mol] - Molar volume\n",
+"printf(' (3).The molar volume using virial equation of state is %e m^(3)/mol\n',V_3);\n",
+"// (4)\n",
+"// Given (virial equation),Z = 1 + ((B*P)/(R*T)) + ((C - B^(2))/(R*T)^(2))*P^(2)\n",
+"V_4 = B + (R*T)/P + ((C - B^(2))/(R*T))*P;// [m^(3)/mol]\n",
+"printf(' (4).The molar volume using given virial equation of state is %e m^(3)/mol\n',V_4);\n",
+"// (5)\n",
+"// Given,Z = 1 + (B/V)\n",
+"// Also,Z = (P*V)/(R*T). Substituting the value of Z,we get\n",
+"// V^(2)-((R*T)/P)*V-((B*R*T)/P)=0.Solving the quadratic equation\n",
+"deff('[y]=f(V)','y=V^(2)-((R*T)/P)*V-((B*R*T)/P)');\n",
+"V_5_1 = fsolve(0,f);\n",
+"V_5_2 = fsolve(1,f);\n",
+"printf(' (5).The molar volume using given virial equation of state is %e m^(3)/mol\n',V_5_2);\n",
+"// The roots are,V_5_1=0.0001743 [m^(3)/mol] and V_5_2=0.0016168 [m^(3)/mol].\n",
+"// As 'V_2' is near to ideal volume (0.0017911 [m^(3)/mol]),it is taken as the molar volume\n",
+"// (6)\n",
+"// Given,Z = 1 + (B/V) + (C/V^(2))\n",
+"// Also,Z = (P*V)/(R*T). Substituting the value of Z,we get\n",
+"// V^(3)-((R*T)/P)*V^(2)-((B*R*T)/P)*V-((C*R*T)/P)=0. Solving the cubic equation\n",
+"deff('[y]=f1(V)','y=V^(3)-((R*T)/P)*V^(2)-((B*R*T)/P)*V-((C*R*T)/P)');\n",
+"V_6_3=fsolve(-1,f1);\n",
+"V_6_4=fsolve(0,f1);\n",
+"V_6_5=fsolve(1,f1);\n",
+"//The above equation has 1 real and 2 imaginary roots. We consider only real root.\n",
+"printf(' (6).The molar volume using given virial equation of state is %e m^(3)/mol\n',V_6_5);"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.8: Determination_of_second_and_third_virial_coefficients.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear;\n",
+"clc;\n",
+"funcprot(0);\n",
+"\n",
+"//Example - 2.8\n",
+"// Page number - 49\n",
+"printf('Example - 2.8 and Page number - 49\n\n');\n",
+"\n",
+"//Given\n",
+"T = 0 + 273.15;//[K] - Temperature\n",
+"R = 8.314;//[J/mol*K] - Universal gas constant\n",
+"\n",
+"//Virial equation of state, Z=1+(B/V)+(C/V^(2))\n",
+"//From above equation we get (Z-1)*V=B+(C/V)\n",
+"\n",
+"P=[50,100,200,400,600,1000];\n",
+"Z=[0.9846,1.0000,1.0365,1.2557,1.7559,2.0645];\n",
+"V=zeros(6);\n",
+"k=zeros(6);\n",
+"t=zeros(6);\n",
+"for i=1:6;\n",
+" V(i)=(Z(i)*R*T)/(P(i)*101325);//[m^(3)/mol]\n",
+" k(i)=(Z(i)-1)*V(i);\n",
+" t(i)=1/V(i);\n",
+"end\n",
+"[C,B,sig]=reglin(t',k');\n",
+"\n",
+"//From the regression, we get intercept=B and slope=C,and thus,\n",
+"printf(' The value of second virial coefficient (B) is %e m^(3)/mol\n',B);\n",
+"printf(' The value of third virial coefficient (C) is %e m^(6)/mol^(2)',C);\n",
+""
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.9: Estimation_of_second_virial_coefficient.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear;\n",
+"clc;\n",
+"\n",
+"//Example - 2.9\n",
+"//Page number - 51\n",
+"printf('Example - 2.9 and Page number - 51\n\n');\n",
+"\n",
+"//Given\n",
+"T = 444.3;//[K] - Temperature\n",
+"R = 8.314;//[J/mol*K] - Universal gas constant\n",
+"B_11 = -8.1;//[cm^(3)/mol]\n",
+"B_11 = -8.1*10^(-6);//[m^(3)/mol]\n",
+"B_22 = -293.4*10^(-6);//[m^(3)/mol]\n",
+"y1 = 0.5;// mole fraction // equimolar mixture\n",
+"y2 = 0.5;\n",
+"\n",
+"// For component 1 (methane)\n",
+"Tc_1 = 190.6;//[K] - cricitical temperature\n",
+"Vc_1 = 99.2;//[cm^(3)/mol] - cricitical molar volume\n",
+"Zc_1 = 0.288;// critical compressibility factor\n",
+"w_1 = 0.012;// acentric factor\n",
+"\n",
+"// For component 2 (n-butane)\n",
+"Tc_2 = 425.2;//[K]\n",
+"Vc_2 = 255.0;//[cm^(3)/mol]\n",
+"Zc_2 = 0.274;\n",
+"w_2 = 0.199;\n",
+"\n",
+"//Using virial mixing rule,we get\n",
+"Tc_12 = (Tc_1*Tc_2)^(1/2);//[K]\n",
+"w_12 = (w_1 + w_2)/2;\n",
+"Zc_12 = (Zc_1+Zc_2)/2;\n",
+"Vc_12 = (((Vc_1)^(1/3) + (Vc_2)^(1/3))/2)^(3);//[cm^(3)/mol]\n",
+"Vc_12 = Vc_12*10^(-6);//[cm^(3)/mol]\n",
+"Pc_12 = (Zc_12*R*Tc_12)/Vc_12;//[N/m^(2)]\n",
+"Tr_12 = T/Tc_12;//Reduced temperature\n",
+"B_0 = 0.083 - (0.422/(Tr_12)^(1.6));\n",
+"B_1 = 0.139 - (0.172/(Tr_12)^(4.2));\n",
+"\n",
+"//We know,(B_12*Pc_12)/(R*Tc_12) = B_0 + (w_12*B_1)\n",
+"B_12 = ((B_0+(w_12*B_1))*(R*Tc_12))/Pc_12;//[m^(3)/mol] - Cross coefficient\n",
+"B = y1^(2)*B_11+2*y1*y2*B_12+y2^(2)*B_22;//[m^(3)/mol] - Second virial coefficient for mixture\n",
+"B = B*10^(6);//[cm^(3)/mol]\n",
+"printf(' The second virial coefficient,(B) for the mixture of gas is %f cm^(3)/mol',B);\n",
+"\n",
+"\n",
+""
+ ]
+ }
+],
+"metadata": {
+ "kernelspec": {
+ "display_name": "Scilab",
+ "language": "scilab",
+ "name": "scilab"
+ },
+ "language_info": {
+ "file_extension": ".sce",
+ "help_links": [
+ {
+ "text": "MetaKernel Magics",
+ "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md"
+ }
+ ],
+ "mimetype": "text/x-octave",
+ "name": "scilab",
+ "version": "0.7.1"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}