{
 "metadata": {
  "name": "ch15_1",
  "signature": "sha256:aa6f699613cdf9bcba2dda4617212630ca1760d21939d5cd99d17e7e03b7e885"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 15 : Vapour Liquid Equilibrium"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.1  Page Number : 503"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Variables\n",
      "T = 90+ 273.15;\t\t\t#[K] - Temperature\n",
      "P = 1;\t\t\t#[atm] - Pressure\n",
      "x_1 = 0.5748;\t\t\t# Equilibrium composition of liquid phase\n",
      "y_1 = 0.7725;\t\t\t# Equilibrium composition of vapour phase\n",
      "\n",
      "\t\t\t# We start with 1 mol of mixture of composition z_1 = 0.6, from marterial balance we get\n",
      "\t\t\t# (L + V)*z_1 = L*x_1 + V*y_1\n",
      "\t\t\t# Since total number of moles is 1, we get\n",
      "\t\t\t# z_1 = L*x_1 + (1-L)*y_1\n",
      "\n",
      "# Calculations and Results\n",
      "z_1_1 = 0.6;\t\t\t# - Mole fraction of benzene\n",
      "L_1 = (z_1_1 - y_1)/(x_1 - y_1);\n",
      "V_1 = 1 - L_1;\n",
      "\n",
      "print \" For z_1 = 0.6\";\n",
      "print \" The moles in the liquid phase is %f mol\"%(L_1);\n",
      "print \" The moles in the vapour phase is %f mol\"%(V_1);\n",
      "\n",
      "z_1_2 = 0.7;\t\t\t# - Mole fraction of benzene\n",
      "L_2 = (z_1_2 - y_1)/(x_1 - y_1);\n",
      "V_2 = 1 - L_2;\n",
      "\n",
      "print \" For z_1 = 0.7\";\n",
      "print \" The moles in the liquid phase is %f mol\"%(L_2);\n",
      "print \" The moles in the vapour phase is %f mol\"%(V_2);\n",
      "\n",
      "\n",
      "\t\t\t# For z = 0.8\n",
      "\t\t\t# The feed remains vapour and the liquid is not formed at all as it is outside the two-phase region (x_1 = 0.5748 and y_1 = 0.7725).\n",
      "print \" For z_1 = 0.8\";\n",
      "\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " For z_1 = 0.6\n",
        " The moles in the liquid phase is 0.872534 mol\n",
        " The moles in the vapour phase is 0.127466 mol\n",
        " For z_1 = 0.7\n",
        " The moles in the liquid phase is 0.366717 mol\n",
        " The moles in the vapour phase is 0.633283 mol\n",
        " For z_1 = 0.8\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.2  Page Number : 515"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "import math\n",
      "\n",
      "# Variables\n",
      "\t\t\t# math.log(P_1_sat) = 14.39155 - 2795.817/(t + 230.002)\n",
      "\t\t\t# math.log(P_2_sat) = 16.26205 - 3799.887/(t + 226.346)\n",
      "\n",
      "\t\t\t#(a)\n",
      "x_1_a =0.43;\t\t\t# Equilibrium composition of liquid phase\n",
      "t_a = 76;\t\t\t#[C] - Temperature\n",
      "x_2_a = 1 - x_1_a;\n",
      "\n",
      "# Calculations and Results\n",
      "\t\t\t# Since liquid phase composition is given we use the relation \n",
      "\t\t\t# P = x_1*P_1_sat + x_2*P_2_sat\n",
      "\t\t\t# At t = 76 C\n",
      "P_1_sat_a = math.exp(14.39155 - 2795.817/(t_a + 230.002));\n",
      "P_2_sat_a = math.exp(16.26205 - 3799.887/(t_a + 226.346));\n",
      "\t\t\t# Therefore total pressure is\n",
      "P_a = x_1_a*P_1_sat_a + x_2_a*P_2_sat_a;\t\t\t#[kPa]\n",
      "y_1_a = (x_1_a*P_1_sat_a)/(P_a);\n",
      "y_2_a = (x_2_a*P_2_sat_a)/(P_a);\n",
      "\n",
      "print \"a).The system pressure is = %f kPa\"%(P_a);\n",
      "print \"    The vapour phase composition is y_1 = %f\"%(y_1_a);\n",
      "\n",
      "\t\t\t#(b)\n",
      "y_1_b = 0.43;\t\t\t# Equilibrium composition of vapour phase\n",
      "y_2_b = 1 - y_1_b;\n",
      "t_b = 76;\t\t\t#[C] - Temperature\n",
      "\n",
      "P_1_sat_b = math.exp(14.39155 - 2795.817/(t_b + 230.002));\n",
      "P_2_sat_b = math.exp(16.26205 - 3799.887/(t_b + 226.346));\n",
      "\n",
      "\t\t\t# Since vapour phase composition is given ,the system pressure is given by\n",
      "\t\t\t# 1/P = y_1/P_1_sat + y_2/P_2_sat\n",
      "P_b = 1/(y_1_b/P_1_sat_b + y_2_b/P_2_sat_b);\n",
      "\n",
      "x_1_b = (y_1_b*P_b)/P_1_sat_b;\n",
      "x_2_b = (y_2_b*P_b)/P_2_sat_b;\n",
      "\n",
      "print \"b).The system pressure is P = %f kPa\"%(P_b);\n",
      "print \"    The liquid phase composition is x_1 = %f\"%(x_1_b);\n",
      "\n",
      "\t\t\t#(c)\n",
      "x_1_c = 0.32;\t\t\t# Equilibrium composition of liquid phase\n",
      "x_2_c = 1 - x_1_c;\n",
      "P_c = 101.33;\t\t\t#[kPa] - Pressure of the system\n",
      "\n",
      "\t\t\t# We have,  P = x_1*P_1_sat + x_2*P_2_sat\n",
      "t_1_sat = 2795.817/(14.39155 - math.log(P_c)) - 230.002;\n",
      "t_2_sat = 3799.887/(16.26205 - math.log(P_c)) - 226.346;\n",
      "t = x_1_c*t_1_sat + x_2_c*t_2_sat;\n",
      "\n",
      "error = 10;\n",
      "while(error>0.1):\n",
      "    P_1_sat = math.exp(14.39155 - 2795.817/(t + 230.002));\n",
      "    P_2_sat = math.exp(16.26205 - 3799.887/(t + 226.346));\n",
      "    P = x_1_c*P_1_sat + x_2_c*P_2_sat;\n",
      "    error=abs(P - P_c);\n",
      "    t = t - 0.1;\n",
      "\n",
      "P_1_sat_c = math.exp(14.39155 - 2795.817/(t + 230.002));\n",
      "P_2_sat_c = math.exp(16.26205 - 3799.887/(t + 226.346));\n",
      "\n",
      "y_1_c = (x_1_c*P_1_sat_c)/(P_c);\n",
      "y_2_c = 1 - y_1_c;\n",
      "\n",
      "print \"c).The system temperature is t = %f C\"%(t);\n",
      "print \"    The vapour phase composition is y_1 = %f\"%(y_1_c);\n",
      "\n",
      "\t\t\t#(d)\n",
      "y_1_d = 0.57;\t\t\t# Vapour phase composition\n",
      "y_2_d = 1 - y_1_d;\n",
      "P_d = 101.33;\t\t\t#[kPa] - Pressure of the system\n",
      "\n",
      "\t\t\t# Since vapour phase composition is given, we can use the relation\n",
      "\t\t\t# 1/P = y_1/P_1_sat + y_2/P_2_sat\n",
      "t_1_sat_d = 2795.817/(14.39155 - math.log(P_d)) - 230.002;\n",
      "t_2_sat_d = 3799.887/(16.26205 - math.log(P_d)) - 226.346;\n",
      "t_d = y_1_d*t_1_sat_d + y_2_d*t_2_sat_d;\n",
      "\n",
      "fault = 10;\n",
      "while(fault>0.1):\n",
      "    P_1_sat_prime = math.exp(14.39155 - 2795.817/(t_d + 230.002));\n",
      "    P_2_sat_prime = math.exp(16.26205 - 3799.887/(t_d + 226.346));\n",
      "    P_prime = 1/(y_1_d/P_1_sat_prime + y_2_d/P_2_sat_prime);\n",
      "    fault=abs(P_prime - P_d);\n",
      "    t_d = t_d + 0.01;\n",
      "\n",
      "P_1_sat_d = math.exp(14.39155 - 2795.817/(t_d + 230.002));\n",
      "P_2_sat_d = math.exp(16.26205 - 3799.887/(t_d + 226.346));\n",
      "\n",
      "x_1_d = (y_1_d*P_d)/(P_1_sat_d);\n",
      "x_2_d = 1 - x_1_d;\n",
      "\n",
      "print \"d).The system temperature is t = %f C\"%(t_d);\n",
      "print \"    The liquid phase composition is x_1 = %f\"%(x_1_d);\n",
      "\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "a).The system pressure is = 105.268363 kPa\n",
        "    The vapour phase composition is y_1 = 0.782290\n",
        "b).The system pressure is P = 60.894254 kPa\n",
        "    The liquid phase composition is x_1 = 0.136725\n",
        "c).The system temperature is t = 79.943314 C\n",
        "    The vapour phase composition is y_1 = 0.679347\n",
        "d).The system temperature is t = 84.600005 C\n",
        "    The liquid phase composition is x_1 = 0.234934\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.3  Page Number : 516"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "x_1_a = 0.25;\t\t\t# Equilibrium composition of liquid phase\n",
      "x_2_a = 0.35;\n",
      "x_3_a = 1 - x_1_a - x_2_a;\n",
      "t_a = 80;\t\t\t#[C] - Temperature\n",
      "\n",
      "# Calculations and Results\n",
      "\t\t\t# At t = 80 C\n",
      "P_1_sat_a = math.exp(14.3916 - 2795.82/(t_a + 230.00));\n",
      "P_2_sat_a = math.exp(14.2724 - 2945.47/(t_a + 224.00));\n",
      "P_3_sat_a = math.exp(14.2043 - 2972.64/(t_a + 209.00));\n",
      "\n",
      "\t\t\t# Since liquid phase composition is given we use the relation \n",
      "P_a = x_1_a*P_1_sat_a + x_2_a*P_2_sat_a + x_3_a*P_3_sat_a;\t\t\t#[kPa]\n",
      "\n",
      "y_1_a = (x_1_a*P_1_sat_a)/(P_a);\n",
      "y_2_a = (x_2_a*P_2_sat_a)/(P_a);\n",
      "y_3_a = (x_3_a*P_3_sat_a)/(P_a);\n",
      "\n",
      "print \"a).The system pressure is P = %f kPa\"%(P_a);\n",
      "print \"    The vapour phase composition is given by y_1 = %f  y_2 = %f and y_3 = %f \"%(y_1_a,y_2_a,y_3_a);\n",
      "\n",
      "\t\t\t#(2)\n",
      "y_1_b = 0.50;\t\t\t# Equilibrium composition of liquid phase\n",
      "y_2_b = 0.30;\n",
      "y_3_b = 1 - y_1_a - y_2_a;\n",
      "t_b = 85;\t\t\t#[C] - Temperature\n",
      "\n",
      "\t\t\t# At t = 80 C\n",
      "P_1_sat_b = math.exp(14.3916 - 2795.82/(t_b + 230.00));\n",
      "P_2_sat_b = math.exp(14.2724 - 2945.47/(t_b + 224.00));\n",
      "P_3_sat_b = math.exp(14.2043 - 2972.64/(t_b + 209.00));\n",
      "\n",
      "\t\t\t# Since vapour phase composition is given we use the relation \n",
      "P_b = 1/(y_1_b/P_1_sat_b + y_2_b/P_2_sat_b + y_3_b/P_3_sat_b);\t\t\t#[kPa]\n",
      "\n",
      "\t\t\t# Therefore we have\n",
      "x_1_b = (y_1_b*P_b)/P_1_sat_b;\n",
      "x_2_b = (y_2_b*P_b)/P_2_sat_b;\n",
      "x_3_b = (y_3_b*P_b)/P_3_sat_b;\n",
      "\n",
      "print \"b).The system pressure is P = %f kPa\"%(P_b);\n",
      "print \"    The liquid phase composition is given by x_1 = %f x_2 = %f and x_3 = %f \"%(x_1_b,x_2_b,x_3_b);\n",
      "\n",
      "\t\t\t#(c)\n",
      "x_1_c = 0.30;\t\t\t# Equilibrium composition of liquid phase\n",
      "x_2_c = 0.45;\n",
      "x_3_c = 1 - x_1_c - x_2_c;\n",
      "P_c = 80;\t\t\t#[kPa] - Pressure of the system\n",
      "\n",
      "\t\t\t# We have,  P = x_1*P_1_sat + x_2*P_2_sat + x_3*P_3_sat\n",
      "t_1_sat = 2795.82/(14.3916 - math.log(P_c)) - 230.00;\t\t\t#[C]\n",
      "t_2_sat = 2945.47/(14.2724 - math.log(P_c)) - 224.00;\t\t\t#[C]\n",
      "t_3_sat = 2972.64/(14.2043 - math.log(P_c)) - 209.00;\t\t\t#[C]\n",
      "t = x_1_c*t_1_sat + x_2_c*t_2_sat + x_3_c*t_3_sat;\n",
      "\n",
      "error = 10;\n",
      "while(error>0.5):\n",
      "    P_1_sat = math.exp(14.3916 - 2795.82/(t + 230.00));\n",
      "    P_2_sat = math.exp(14.2724 - 2945.47/(t + 224.00));\n",
      "    P_3_sat = math.exp(14.2043 - 2972.64/(t + 209.00));\n",
      "    P = x_1_c*P_1_sat + x_2_c*P_2_sat + x_3_c*P_3_sat;\n",
      "    error=abs(P - P_c);\n",
      "    t = t - 0.2;\n",
      "\n",
      "P_1_sat_c = math.exp(14.3916 - 2795.82/(t + 230.00));\n",
      "P_2_sat_c = math.exp(14.2724 - 2945.47/(t + 224.00));\n",
      "P_3_sat_c = math.exp(14.2043 - 2972.64/(t + 209.00));\n",
      "\n",
      "y_1_c = (x_1_c*P_1_sat_c)/(P_c);\n",
      "y_2_c = (x_2_c*P_2_sat_c)/(P_c);\n",
      "y_3_c = 1 - y_1_c - y_2_c;\n",
      "\n",
      "print \"c).The system temperature is t = %f C\"%(t);\n",
      "print \"    The vapour phase composition is y_1 = %f y_2 %f and y_3 = %f\"%(y_1_c,y_2_c,y_3_c);\n",
      "\n",
      "\t\t\t#(d)\n",
      "y_1_d = 0.6;\t\t\t# Vapour phase composition\n",
      "y_2_d = 0.2;\n",
      "y_3_d = 1 - y_1_d - y_2_d;\n",
      "P_d = 90;\t\t\t#[kPa] - Pressure of the system\n",
      "\n",
      "\t\t\t# Since vapour phase composition is given, we can use the relation\n",
      "\t\t\t# 1/P = y_1/P_1_sat + y_2/P_2_sat + y_3/P_3_sat\n",
      "t_1_sat_d = 2795.82/(14.3916 - math.log(P_d)) - 230.00;\n",
      "t_2_sat_d = 2945.47/(14.2724 - math.log(P_d)) - 224.00;\n",
      "t_3_sat_d = 2972.64/(14.2043 - math.log(P_d)) - 209.00;\n",
      "t_d = y_1_d*t_1_sat_d + y_2_d*t_2_sat_d + y_3_d*t_3_sat_d;\n",
      "\n",
      "fault = 10;\n",
      "while(fault>0.5):\n",
      "    P_1_sat_prime = math.exp(14.3916 - 2795.82/(t_d + 230.00));\n",
      "    P_2_sat_prime = math.exp(14.2724 - 2945.47/(t_d + 224.00));\n",
      "    P_3_sat_prime = math.exp(14.2043 - 2972.64/(t_d + 209.00));\n",
      "    P_prime = 1/(y_1_d/P_1_sat_prime + y_2_d/P_2_sat_prime + y_3_d/P_3_sat_prime);\n",
      "    fault=abs(P_prime - P_d);\n",
      "    t_d = t_d + 0.2;\n",
      "\n",
      "P_1_sat_d = math.exp(14.3916 - 2795.82/(t_d + 230.00));\n",
      "P_2_sat_d = math.exp(14.2724 - 2945.47/(t_d + 224.00));\n",
      "P_3_sat_d = math.exp(14.2043 - 2972.64/(t_d + 209.00));\n",
      "\n",
      "x_1_d = (y_1_d*P_d)/(P_1_sat_d);\n",
      "x_2_d = (y_2_d*P_d)/(P_2_sat_d);\n",
      "x_3_d = 1 - x_1_d - x_2_d;\n",
      "\n",
      "print \"d).The system temperature is t = %f C\"%(t_d);\n",
      "print \"    The liquid phase composition is x_1 = %f x_2 = %f and x_3 = %f\"%(x_1_d,x_2_d,x_3_d);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "a).The system pressure is P = 108.239332 kPa\n",
        "    The vapour phase composition is given by y_1 = 0.497672  y_2 = 0.316379 and y_3 = 0.185948 \n",
        "b).The system pressure is P = 129.287998 kPa\n",
        "    The liquid phase composition is given by x_1 = 0.259997 x_2 = 0.338895 and x_3 = 0.401108 \n",
        "c).The system temperature is t = 67.020387 C\n",
        "    The vapour phase composition is y_1 = 0.544826 y_2 0.357251 and y_3 = 0.097922\n",
        "d).The system temperature is t = 73.127683 C\n",
        "    The liquid phase composition is x_1 = 0.307471 x_2 = 0.230183 and x_3 = 0.462346\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.4  Page Number : 519"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "import math\n",
      "\n",
      "# Variables\n",
      "T = 120;\t\t\t#[C] - Temperature\n",
      "P_1 = 1;\t\t\t#[atm] - Initial pressure\n",
      "P_1 = P_1*101.325;\t\t\t#[kPa]\n",
      "R = 8.314;\t\t\t#[J/mol*K] - Universal gas constant\n",
      "\n",
      "y_1 = 0.3;\t\t\t# Mole fraction of propane\n",
      "y_2 = 0.5;\t\t\t# Mole fraction of butane\n",
      "y_3 = 0.2;\t\t\t# Mole fraction of hexane\n",
      "\n",
      "\t\t\t# math.log(P_1_sat) = 13.7713 - 1892.47/(t + 248.82)\n",
      "\t\t\t# math.log(P_2_sat) = 13.7224 - 2151.63/(t + 236.91)\n",
      "\t\t\t# math.log(P_3_sat) = 13.8216 - 2697.55/(t + 224.37)\n",
      "\n",
      "# Calculations and Results\n",
      "\t\t\t#(a)\n",
      "P_1_sat = math.exp(13.7713 - 1892.47/(T + 248.82));\n",
      "P_2_sat = math.exp(13.7224 - 2151.63/(T + 236.91));\n",
      "P_3_sat = math.exp(13.8216 - 2697.55/(T + 224.37));\n",
      "\n",
      "\t\t\t# Since vapour phase composition is given we can use the relation,\n",
      "P_2 = 1/(y_1/P_1_sat + y_2/P_2_sat + y_3/P_3_sat);\t\t\t#[kPa]\n",
      "\n",
      "print \" a).The pressure of the mixture when first drop condenses is given by P = %f kPa\"%(P_2);\n",
      "\n",
      "\t\t\t#(b)\n",
      "x_1 = (y_1*P_2)/P_1_sat;\n",
      "x_2 = (y_2*P_2)/P_2_sat;\n",
      "x_3 = (y_3*P_2)/P_3_sat;\n",
      "\n",
      "print \" b).The liquid phase composition is given by x_1 propane = %f x_2 butane = %f and x_3 hexane = %f \"%(x_1,x_2,x_3);\n",
      "\n",
      "\t\t\t# (c)\n",
      "\t\t\t# Work transfer per mol is given by\n",
      "\t\t\t# W = integral(P*dV) = integral((R*T/V)*dV) = R*T*math.log(V_2/V_1) = R*T*math.log(P_1/P_2)\n",
      "w = R*(T+273.15)*math.log(P_1/P_2);\t\t\t#[J/mol]\n",
      "\t\t\t# For 100 mol\n",
      "W = w*100;\t\t\t#[J]\n",
      "W = W*10**(-3);\t\t\t#[kJ]\n",
      "print \" c).The work required for 100 mol of mixture handeled is %f kJ\"%(W);\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " a).The pressure of the mixture when first drop condenses is given by P = 1278.060855 kPa\n",
        " b).The liquid phase composition is given by x_1 propane = 0.067811 x_2 butane = 0.291139 and x_3 hexane = 0.641049 \n",
        " c).The work required for 100 mol of mixture handeled is -828.526086 kJ\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.5  Page Number : 520"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "import math\n",
      "# Variables\n",
      "T = 27;\t\t\t#[C] - Temperature\n",
      "\n",
      "\t\t\t# math.log(P_1_sat) = 13.8216 - 2697.55/(t + 224.37)\n",
      "\t\t\t# math.log(P_2_sat) = 13.8587 - 2911.32/(t + 216.64)\n",
      "\n",
      "\t\t\t#(a)\n",
      "x_1_a = 0.2;\n",
      "x_2_a = 1 - x_1_a;\n",
      "\n",
      "# Calculations and Results\n",
      "\t\t\t# At t = 27 C\n",
      "P_1_sat = math.exp(13.8216 - 2697.55/(T + 224.37));\t\t\t#[kPa]\n",
      "P_2_sat = math.exp(13.8587 - 2911.32/(T + 216.64));\t\t\t#[kPa]\n",
      "P_a = x_1_a*P_1_sat + x_2_a*P_2_sat;\t\t\t#[kPa]\n",
      "\n",
      "y_1_a = x_1_a*P_1_sat/P_a;\n",
      "y_2_a = x_2_a*P_2_sat/P_a;\n",
      "\n",
      "print \"a).The total pressure is P = %f kPa\"%(P_a);\n",
      "print \"    The vapour phase composition is given by y_1 = %f and y_2 = %f\"%(y_1_a,y_2_a);\n",
      "\n",
      "\t\t\t#(b)\n",
      "y_1_b = 0.2;\n",
      "y_2_b = 1 - y_1_b;\n",
      "\t\t\t# Since vapour phase composition is given we can use the relation \n",
      "P_b = 1/(y_1_b/P_1_sat + y_2_b/P_2_sat);\t\t\t#[kPa]\n",
      "\n",
      "\t\t\t# Therefore we have\n",
      "x_1_b = (y_1_b*P_b)/P_1_sat;\n",
      "x_2_b = (y_2_b*P_b)/P_2_sat;\n",
      "\n",
      "print \"b).The total pressure is, P = %f kPa\"%(P_b);\n",
      "print \"    The liquid phase composition is given by x_1 = %f and x_2 = %f\"%(x_1_b,x_2_b);\n",
      "\n",
      "\t\t\t#(c)\n",
      "P_c = 30;\t\t\t#[kPa] - Total pressure\n",
      "x_1_c = 0.2;\n",
      "x_2_c = 1 - x_1_c;\n",
      "\n",
      "\t\t\t# We have,  P = x_1*P_1_sat + x_2*P_2_sat\n",
      "t_1_sat = 2697.55/(13.8216 - math.log(P_c)) - 224.37;\n",
      "t_2_sat = 2911.32/(13.8587 - math.log(P_c)) - 216.64;\n",
      "t = x_1_c*t_1_sat + x_2_c*t_2_sat;\n",
      "\n",
      "fault = 10;\n",
      "while(fault>0.3):\n",
      "    P_1_sat = math.exp(13.8216 - 2697.55/(t + 224.37));\n",
      "    P_2_sat = math.exp(13.8587 - 2911.32/(t + 216.64));\n",
      "    P = x_1_c*P_1_sat + x_2_c*P_2_sat;\n",
      "    fault = abs(P - P_c);\n",
      "    t = t - 0.1;\n",
      "\n",
      "P_1_sat_c = math.exp(13.8216 - 2697.55/(t + 224.37));\n",
      "P_2_sat_c = math.exp(13.8587 - 2911.32/(t + 216.64));\n",
      "\n",
      "y_1_c = (x_1_c*P_1_sat_c)/(P_c);\n",
      "y_2_c = 1 - y_1_c;\n",
      "\n",
      "print \"c).The system temperature is t = %f C\"%(t);\n",
      "print \"    The vapour phase composition is y_1 = %f and y_2 = %f \"%(y_1_c,y_2_c);\n",
      "\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "a).The total pressure is P = 9.795726 kPa\n",
        "    The vapour phase composition is given by y_1 = 0.448801 and y_2 = 0.551199\n",
        "b).The total pressure is, P = 7.835131 kPa\n",
        "    The liquid phase composition is given by x_1 = 0.071288 and x_2 = 0.928712\n",
        "c).The system temperature is t = 53.904663 C\n",
        "    The vapour phase composition is y_1 = 0.413592 and y_2 = 0.586408 \n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.6  Page Number : 521"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Variables\n",
      "P = 90;\t\t\t#[kPa] - Pressure\n",
      "R = 8.314;\t\t\t#[J/mol*K] - Universal gas constant\n",
      "\n",
      "\t\t\t# math.log(P_sat) = A - B/(t + C)\n",
      "\n",
      "\t\t\t# For benzene\n",
      "A_1 = 13.8594;\n",
      "B_1 = 2773.78;\n",
      "C_1 = 220.07;\n",
      "\t\t\t# For ethyl benzene\n",
      "A_2 = 14.0045;\n",
      "B_2 = 3279.47;\n",
      "C_2 = 213.20;\n",
      "\n",
      "x_1 = 0.5;\t\t\t# Equimolar mixture\n",
      "x_2 = 0.5;\n",
      "\n",
      "\t\t\t# The bubble point temperature equation is\n",
      "\t\t\t# P = x_1*P_1_sat + x_2*P_2_sat\n",
      "\n",
      "# Calculations and Results\n",
      "t_1_sat = B_1/(A_1 - math.log(P)) - C_1;\n",
      "t_2_sat = B_2/(A_2 - math.log(P)) - C_2;\n",
      "t = x_1*t_1_sat + x_2*t_2_sat;\n",
      "\n",
      "fault = 10;\n",
      "while(fault>0.3):\n",
      "    P_1_sat = math.exp(A_1 - B_1/(t + C_1));\n",
      "    P_2_sat = math.exp(A_2 - B_2/(t + C_2));\n",
      "    P_net = x_1*P_1_sat + x_2*P_2_sat;\n",
      "    fault=abs(P_net - P);\n",
      "    t = t - 0.1;\n",
      "\n",
      "print \" The bubble point temperature is %f C\"%(t);\n",
      "\n",
      "\t\t\t# Now let us determine dew point temperature for y_1 = 0.5, and P = 90 kPa\n",
      "y_1 = 0.5;\t\t\t# Equimolar mixture\n",
      "y_2 = 0.5;\n",
      "\n",
      "\t\t\t# 1/P = y_1/P_1_sat + y_2/P_2_sat\n",
      "\t\t\t# Let us statrt with t = 104.07\n",
      "t_old = 104.07;\n",
      "error = 10;\n",
      "while(error>0.3):\n",
      "    P_1_sat_prime = math.exp(A_1 - B_1/(t_old + C_1));\n",
      "    P_2_sat_prime = math.exp(A_2 - B_2/(t_old + C_2));\n",
      "    P_net_prime = 1/(y_1/P_1_sat_prime + y_2/P_2_sat_prime);\n",
      "    error=abs(P_net_prime - P);\n",
      "    t_old = t_old + 0.1;\n",
      "\n",
      "print \" The dew point temperature is %f C\"%(t_old);\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The bubble point temperature is 93.862003 C\n",
        " The dew point temperature is 114.470000 C\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.7  Page Number : 522"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Variables\n",
      "P = 1;\t\t\t#[bar] - Pressure\n",
      "P = P*10**(2);\t\t\t#[kPa]\n",
      "\n",
      "\t\t\t# math.log(P_1_sat) = 13.8594 - 2773.78/(t + 220.07)\n",
      "\t\t\t# math.log(P_2_sat) = 14.0098 - 3103.01/(t + 219.79)\n",
      "\n",
      "\t\t\t# The bubble point equation is\n",
      "\t\t\t# P = x_1*P_1_sat + x_2*P_2_sat;\n",
      "\n",
      "t_1_sat = 2773.78/(13.8594 - math.log(P)) - 220.07;\n",
      "t_2_sat = 3103.01/(14.0098 - math.log(P)) - 219.79;\n",
      "\n",
      "\t\t\t# For x_1 = 0.1\n",
      "\t\t\t# t = x_1_1*t_1_sat + x_2_1*t_2_sat;\n",
      "x_1 = [0.1,0.5,0.9];\n",
      "x_2 = [0,0,0]\n",
      "\n",
      "# Calculations and Results\n",
      "for i in range(3):\n",
      "    x_2[i] = 1 - x_1[i];\n",
      "    t = x_1[i]*t_1_sat + x_2[i]*t_2_sat;\n",
      "    fault = 10;\n",
      "    while(fault>0.3):\n",
      "        P_1_sat = math.exp(13.8594 - 2773.78/(t + 220.07));\n",
      "        P_2_sat = math.exp(14.0098 - 3103.01/(t + 219.79));\n",
      "        P_net = x_1[i]*P_1_sat + x_2[i]*P_2_sat;\n",
      "        fault=abs(P_net - P);\n",
      "        t = t - 0.1;\n",
      "    print \" The bubble point temperature for x_1 = %f) is %f C\"%(x_1[i],t);\n",
      "\n",
      "\n",
      "\n",
      "\t\t\t# Now let us determine dew point temperature\n",
      "\t\t\t# 1/P = y_1/P_1_sat + y_2/P_2_sat\n",
      "\n",
      "y_1 = [0.1,0.5,0.9];\n",
      "y_2 = [0,0,0]\n",
      "for j in range(3):\n",
      "    y_2[j] = 1 - y_1[j];\n",
      "    t_prime = y_1[j]*t_1_sat + y_2[j]*t_2_sat;\n",
      "    error = 10;\n",
      "    while(error>0.3):\n",
      "        P_1_sat = math.exp(13.8594 - 2773.78/(t_prime + 220.07));\n",
      "        P_2_sat = math.exp(14.0098 - 3103.01/(t_prime + 219.79));\n",
      "        P_net = 1/(y_1[j]/P_1_sat + y_2[j]/P_2_sat);\n",
      "        error=abs(P_net - P);\n",
      "        t_prime = t_prime + 0.1;\n",
      "    \n",
      "    print \" The dew point temperature for y_1 = %f is %f C\"%(y_1[j],t_prime);\n",
      "\n",
      "\n",
      "\t\t\t#Therefore\n",
      "print \" The temperature range for z_1 = 0.1 which two phase exist is 105.61 C to 108.11 C\";\n",
      "print \" The temperature range for z_1 = 0.5 which two phase exist is 91.61 C to 98.40 C\";\n",
      "print \" The temperature range for z_1 = 0.9 which two phase exist is 81.71 C to 84.51 C\";\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The bubble point temperature for x_1 = 0.100000) is 105.605549 C\n",
        " The bubble point temperature for x_1 = 0.500000) is 91.607993 C\n",
        " The bubble point temperature for x_1 = 0.900000) is 81.710437 C\n",
        " The dew point temperature for y_1 = 0.100000 is 108.105549 C\n",
        " The dew point temperature for y_1 = 0.500000 is 98.407993 C\n",
        " The dew point temperature for y_1 = 0.900000 is 84.510437 C\n",
        " The temperature range for z_1 = 0.1 which two phase exist is 105.61 C to 108.11 C\n",
        " The temperature range for z_1 = 0.5 which two phase exist is 91.61 C to 98.40 C\n",
        " The temperature range for z_1 = 0.9 which two phase exist is 81.71 C to 84.51 C\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.8  Page Number : 524"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "from scipy.optimize import fsolve \n",
      "import math \n",
      "\n",
      "# Variables\n",
      "x_1 = 0.20;\n",
      "x_2 = 0.45;\n",
      "x_3 = 0.35;\n",
      "P = 10;\t\t\t#[atm]\n",
      "P = P*101325*10**(-3);\t\t\t#[kPa]\n",
      "\n",
      "\t\t\t# math.log(P_1_sat) = 13.7713 - 1892.47/(t + 248.82)\n",
      "\t\t\t# math.log(P_2_sat) = 13.7224 - 2151.63/(t + 236.91)\n",
      "\t\t\t# math.log(P_3_sat) = 13.8183 - 2477.07/(t + 233.21)\n",
      "\n",
      "\t\t\t#(a)\n",
      "\t\t\t# The bubble point equation is\n",
      "\t\t\t# P = x_1*P_1_sat + x_2*P_2_sat + x_3*P_3_sat\n",
      "\n",
      "# Calculations and Results\n",
      "t_1_sat = 1892.47/(13.7713 - math.log(P)) - 248.82;\n",
      "t_2_sat = 2151.63/(13.7224 - math.log(P)) - 236.91;\n",
      "t_3_sat = 2477.07/(13.8183 - math.log(P)) - 233.21;\n",
      "t = x_1*t_1_sat + x_2*t_2_sat + x_3*t_3_sat;\n",
      "\n",
      "fault = 10;\n",
      "while(fault>0.1):\n",
      "    P_1_sat = math.exp(13.7713 - 1892.47/(t + 248.82));\n",
      "    P_2_sat = math.exp(13.7224 - 2151.63/(t + 236.91));\n",
      "    P_3_sat = math.exp(13.8183 - 2477.07/(t + 233.21));\n",
      "    P_net = x_1*P_1_sat + x_2*P_2_sat + x_3*P_3_sat;\n",
      "    fault=abs(P_net - P);\n",
      "    t = t - 0.003;\n",
      "\n",
      "BPT = t;\n",
      "print \" a).The bubble point temperature is %f C\"%(BPT);\n",
      "\n",
      "\t\t\t# (b)\n",
      "\t\t\t# Now let us determine dew point temperature for y_1 = 0.5, and P = 90 kPa\n",
      "y_1 = 0.20;\n",
      "y_2 = 0.45;\n",
      "y_3 = 0.35;\n",
      "\n",
      "\t\t\t# 1/P = y_1/P_1_sat + y_2/P_2_sat + y_3/P_3_sat\n",
      "\n",
      "t_old = 90;\t\t\t#[C]\n",
      "error = 10;\n",
      "while(error>0.1):\n",
      "    P_1_sat_prime = math.exp(13.7713 - 1892.47/(t_old + 248.82));\n",
      "    P_2_sat_prime = math.exp(13.7224 - 2151.63/(t_old + 236.91));\n",
      "    P_3_sat_prime = math.exp(13.8183 - 2477.07/(t_old + 233.21));\n",
      "    P_net_prime = 1/(y_1/P_1_sat_prime + y_2/P_2_sat_prime + y_3/P_3_sat_prime);\n",
      "    error=abs(P_net_prime - P);\n",
      "    t_old = t_old + 0.003;\n",
      "\n",
      "DPT = t_old;\n",
      "print \" b).The dew point temperature is %f C\"%(DPT);\n",
      "\n",
      "\t\t\t# (c)\n",
      "\t\t\t# Therefore at 82 C two phase exists\n",
      "\t\t\t# At 82 C and P = 1013.25 kPa pressure\n",
      "T_c = 82;\t\t\t#[C]\n",
      "P_c = 1013.25;\t\t\t#[kPa]\n",
      "z_1 = 0.20;\n",
      "z_2 = 0.45;\n",
      "z_3 = 0.35;\n",
      "\n",
      "P_1_sat_c = math.exp(13.7713 - 1892.47/(T_c + 248.82));\n",
      "P_2_sat_c = math.exp(13.7224 - 2151.63/(T_c + 236.91));\n",
      "P_3_sat_c = math.exp(13.8183 - 2477.07/(T_c + 233.21));\n",
      "\n",
      "K_1 = P_1_sat_c/P_c;\n",
      "K_2 = P_2_sat_c/P_c;\n",
      "K_3 = P_3_sat_c/P_c;\n",
      "\n",
      "\t\t\t# We have to find such a V that the following equation is satisfied.\n",
      "\t\t\t# summation(y_i) = K_i*z_i/(1-V+V*K_i) = 1\n",
      "\t\t\t# K_1*z_1/(1-V+V*K_1) + K_2*z_2/(1-V+V*K_2) + K_3*z_3/(1-V+V*K_3) = 1\n",
      "\n",
      "def f1(V): \n",
      "\t return  K_1*z_1/(1-V+V*K_1) + K_2*z_2/(1-V+V*K_2) + K_3*z_3/(1-V+V*K_3)-1\n",
      "V = fsolve(f1,0.4)\n",
      "\n",
      "\t\t\t# Therefore now we have\n",
      "y_1_c = K_1*z_1/(1-V+V*K_1);\n",
      "y_2_c = K_2*z_2/(1-V+V*K_2);\n",
      "y_3_c = K_3*z_3/(1-V+V*K_3);\n",
      "x_1_c = y_1_c/K_1;\n",
      "x_2_c = y_2_c/K_2;\n",
      "x_3_c = y_3_c/K_3;\n",
      "\n",
      "print \" c).The proportion of vapour is given by V = %f\"%(V);\n",
      "print \"     The composition of vapour foemed is given by y_1 = %f y_2 = %f and y_3 = %f \"%(y_1_c,y_2_c,y_3_c);\n",
      "print \"     The composition of liquid formed is given by x_1 = %f x_2 = %f and x_3 = %f \"%(x_1_c,x_2_c,x_3_c);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " a).The bubble point temperature is 71.833954 C\n",
        " b).The dew point temperature is 97.254000 C\n",
        " c).The proportion of vapour is given by V = 0.332143\n",
        "     The composition of vapour foemed is given by y_1 = 0.365018 y_2 = 0.466574 and y_3 = 0.168408 \n",
        "     The composition of liquid formed is given by x_1 = 0.117932 x_2 = 0.441757 and x_3 = 0.440311 \n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.9  Page Number : 526"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "from scipy.optimize import fsolve \n",
      "import math \n",
      "\n",
      "# Variables\n",
      "T = 27;\t\t\t#[C] - Temperature\n",
      "z_1 = 0.4;\n",
      "z_2 = 0.3;\n",
      "z_3 = 0.3;\n",
      "\n",
      "\t\t\t# math.log(P_sat) = A - B/(t + C)\n",
      "\n",
      "\t\t\t# For propane\n",
      "A_1 = 13.7713;\n",
      "B_1 = 1892.47;\n",
      "C_1 = 248.82;\n",
      "\t\t\t# For i-butane\n",
      "A_2 = 13.4331;\n",
      "B_2 = 1989.35;\n",
      "C_2 = 236.84;\n",
      "\t\t\t# For n-butane\n",
      "A_3 = 13.7224;\n",
      "B_3 = 2151.63;\n",
      "C_3 = 236.91;\n",
      "\n",
      "\t\t\t#(a)\n",
      "\t\t\t\n",
      "y_1 = z_1;\n",
      "y_2 = z_2;\n",
      "y_3 = z_3;\n",
      "\n",
      "# Calculations and Results\n",
      "\t\t\t# At 27 C,\n",
      "P_1_sat = math.exp(A_1 - B_1/(T + C_1));\n",
      "P_2_sat = math.exp(A_2 - B_2/(T + C_2));\n",
      "P_3_sat = math.exp(A_3 - B_3/(T + C_3));\n",
      "\n",
      "\t\t\t# The dew point pressure is given by\n",
      "P_1 = 1/(y_1/P_1_sat + y_2/P_2_sat + y_3/P_3_sat); \n",
      "\n",
      "\n",
      "x_1 = z_1;\n",
      "x_2 = z_2;\n",
      "x_3 = z_3;\n",
      "\n",
      "\t\t\t# The bubble point pressure is given by\n",
      "P_2 = x_1*P_1_sat + x_2*P_2_sat + x_3*P_3_sat;\n",
      "\n",
      "print \" a).The two phase region exists between %f and %f kPa\"%(P_1,P_2);\n",
      "\n",
      "\t\t\t#(b)\n",
      "\t\t\t# The mean of the two-phase pressure range is given by\n",
      "P_mean = (P_1 + P_2)/2;\n",
      "\n",
      "\t\t\t# Now let us calculate the K values of the components\n",
      "K_1 = P_1_sat/P_mean;\n",
      "K_2 = P_2_sat/P_mean;\n",
      "K_3 = P_3_sat/P_mean;\n",
      "\n",
      "\t\t\t# summation of y_i = 1, gives\n",
      "\t\t\t# (K_1*z_1)/(1-V-K_1*V) + (K_2*z_2)/(1-V-K_2*V) + (K_3*z_3)/(1-V-K_3*V) = 1\n",
      "\t\t\t# Solving we get\n",
      "def f(V): \n",
      "\t return (K_1*z_1)/(1-V+K_1*V) + (K_2*z_2)/(1-V+K_2*V) + (K_3*z_3)/(1-V+K_3*V)-1\n",
      "V = fsolve(f,0.1)\n",
      "\n",
      "y_1_prime = (z_1*K_1)/(1-V+K_1*V);\n",
      "\n",
      "print \" b).The mole fraction of propane in vapour phase is %f whereas in the feed is %f and fraction of vapour in the system is %f\"%(y_1_prime,z_1,V);\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " a).The two phase region exists between 421.886904 and 588.370027 kPa\n",
        " b).The mole fraction of propane in vapour phase is 0.559489 whereas in the feed is 0.400000 and fraction of vapour in the system is 0.425313\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.10  Page Number : 527"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Variables\n",
      "T = 50;\t\t\t#[C] - Temperature\n",
      "P = 64;\t\t\t#[kPa] - Pressure\n",
      "z_1 = 0.7;\n",
      "z_2 = 0.3;\n",
      "\n",
      "# math.log(P_sat) = A - B/(t + C)\n",
      "\n",
      "# For acetone\n",
      "A_1 = 14.37824;\n",
      "B_1 = 2787.498;\n",
      "C_1 = 229.664;\n",
      "# For acetonitrile\n",
      "A_2 = 14.88567;\n",
      "B_2 = 3413.099;\n",
      "C_2 = 250.523;\n",
      "\n",
      "# Calculations\n",
      "# At 50 C,\n",
      "P_1_sat = math.exp(A_1 - B_1/(T + C_1));\t\t\t#[kPa]\n",
      "P_2_sat = math.exp(A_2 - B_2/(T + C_2));\t\t\t#[kPa]\n",
      "\n",
      "# Now let us calculate the K values of the components\n",
      "K_1 = P_1_sat/P;\n",
      "K_2 = P_2_sat/P;\n",
      "\n",
      "# summation of y_i = 1, gives\n",
      "# (K_1*z_1)/(1-V-K_1*V) + (K_2*z_2)/(1-V-K_2*V) = 1\n",
      "# Solving we get\n",
      "def f(V): \n",
      "    return (K_1*z_1)/(1-V+K_1*V) + (K_2*z_2)/(1-V+K_2*V) -1\n",
      "V = fsolve(f,0.1)\n",
      "L = 1 - V;\n",
      "# Therefore\n",
      "y_1 = (K_1*z_1)/(1-V+K_1*V);\n",
      "y_2 = (K_2*z_2)/(1-V+K_2*V);\n",
      "\n",
      "x_1 = y_1/K_1;\n",
      "x_2 = y_2/K_2;\n",
      "\n",
      "# Results\n",
      "print \" The value of V = %f\"%(V);\n",
      "print \" The value of L = %f\"%(L);\n",
      "print \" The liquid phase composition is x_1 = %f and x_2 = %f\"%(x_1,x_2);\n",
      "print \" The vapour phase composition is y_1 = %f and y_2 = %f\"%(y_1,y_2);\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The value of V = 0.450368\n",
        " The value of L = 0.549632\n",
        " The liquid phase composition is x_1 = 0.619963 and x_2 = 0.380037\n",
        " The vapour phase composition is y_1 = 0.797678 and y_2 = 0.202322\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.11  Page Number : 528"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Variables\n",
      "P = 12.25*101325*10**(-3);\t\t\t#[kPa]\n",
      "z_1 = 0.8;\n",
      "z_2 = 1 - z_1;\n",
      "V = 0.4;\n",
      "# math.log(P_1_sat) = 13.7713 - 2892.47/(T + 248.82)\n",
      "# math.log(P_2_sat) = 13.7224 - 2151.63/(T + 236.91)\n",
      "\n",
      "# P_1_sat = math.exp(13.7713 - 21892.47/(T + 248.82));\n",
      "# P_2_sat = math.exp(13.7224 - 2151.63/(T + 236.91));\n",
      "\n",
      "# Let the total mixture be 1 mol\n",
      "# We have to assume a temperature such that,\n",
      "# y_1 + y_2 = (K_1*z_1)/(1-V-K_1*V) + (K_2*z_2)/(1-V-K_2*V) = 1\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "x_1 = z_1;\n",
      "x_2 = z_2;\n",
      "\n",
      "# The bubble point pressure is given by\n",
      "# P = x_1*(math.exp(13.7713 - 21892.47/(T + 248.82))) + x_2*(math.exp(13.7224 - 2151.63/(T + 236.91)));\n",
      "\n",
      "# Calculations\n",
      "def f(T): \n",
      "\t return x_1*(math.exp(13.7713 - 1892.47/(T + 248.82))) + x_2*(math.exp(13.7224 - 2151.63/(T + 236.91))) - P\n",
      "T_1 = fsolve(f,0.1)\n",
      "BPT = T_1;\n",
      "\n",
      "\n",
      "y_1 = z_1;\n",
      "y_2 = z_2;\n",
      "\n",
      "# The dew point equation is given by\n",
      "# 1/P = y_1/P_1_sat + y_2/P_2_sat\n",
      "def f1(T): \n",
      "\t return 1/(y_1/(math.exp(13.7713 - 1892.47/(T + 248.82))) + y_2/(math.exp(13.7224 - 2151.63/(T + 236.91)))) - P\n",
      "T_2 = fsolve(f1,0.1)\n",
      "DPT = T_2;\n",
      "\n",
      "T = 47;\t\t\t#[C]\n",
      "error = 10;\n",
      "while(error>0.001):\n",
      "    P_1_sat = math.exp(13.7713 - 1892.47/(T + 248.82));\n",
      "    P_2_sat = math.exp(13.7224 - 2151.63/(T + 236.91));\n",
      "    K_1 = P_1_sat/P;\n",
      "    K_2 = P_2_sat/P;\n",
      "    y1 = (K_1*z_1)/(1-V+K_1*V);\n",
      "    y2 = (K_2*z_2)/(1-V+K_2*V);\n",
      "    y = y1 + y2;\n",
      "    error=abs(y - 1);\n",
      "    T = T - 0.0001;\n",
      "\n",
      "# Results\n",
      "print \" The temperature when 40 mol  of mixture is in the vapour is %f C\"%(T);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The temperature when 40 mol  of mixture is in the vapour is 45.333000 C\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.12  Page Number : 529"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Variables\n",
      "T = 105;\t\t\t#[C]\n",
      "P = 1.5;\t\t\t#[atm]\n",
      "P = P*101325*10**(-3);\t\t\t#[kPa]\n",
      "z = [0.4,0.3667,0.2333];\t\t\t# Feed composition\n",
      "x = [0.3,0.3,0.4];\t\t\t# Equilibrium liquid phase composition\n",
      "y = [0.45,0.40,0.15];\t\t\t# Equilibrium vapour phase composition\n",
      "\n",
      "# From the material balance equation of component 1, we get\n",
      "# (L + V)*z_1 = L*x_1 + V*y_1\n",
      "\n",
      "# Since total moles are one, therefore  L + V = 1 and thus\n",
      "# z_1 = L*x_1 + (1-L)*y_1\n",
      "# Calculations and Results\n",
      "for i in range(3):\n",
      "    L = (z[i] - y[i])/(x[i] - y[i]);\n",
      "    V = 1 - L;\n",
      "    print \" The number of moles in liquid phase z = %f is given by L = %f\"%(z[i],L);\n",
      "    print \" The number of moles in vapour phase z = %f is given by V = %f\"%(z[i],V);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The number of moles in liquid phase z = 0.400000 is given by L = 0.333333\n",
        " The number of moles in vapour phase z = 0.400000 is given by V = 0.666667\n",
        " The number of moles in liquid phase z = 0.366700 is given by L = 0.333000\n",
        " The number of moles in vapour phase z = 0.366700 is given by V = 0.667000\n",
        " The number of moles in liquid phase z = 0.233300 is given by L = 0.333200\n",
        " The number of moles in vapour phase z = 0.233300 is given by V = 0.666800\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.13  Page Number : 530"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Variables\n",
      "T = 90;\t\t\t#[C]\n",
      "P = 1;\t\t\t#[atm]\n",
      "P = P*101325*10**(-3);\t\t\t#[kPa]\n",
      "z_1 = [0.1,0.5,0.8];\n",
      "\n",
      "# Calculations\n",
      "# math.log(P_1_sat) = 13.8594 - 2773.78/(t + 220.07)\n",
      "# math.log(P_2_sat) = 14.0098 - 3103.01/(t + 219.79)\n",
      "\n",
      "#At T = 90 C\n",
      "P_1_sat = math.exp(13.8594 - 2773.78/(T + 220.07));\n",
      "P_2_sat = math.exp(14.0098 - 3103.01/(T + 219.79));\n",
      "K_1 = P_1_sat/P;\n",
      "K_2 = P_2_sat/P;\n",
      "\n",
      "# For z_1 = 0.1\n",
      "# y1 = (K_1*z_1(i))/(1-V+K_1*V);\n",
      "# y2 = (K_2*z_2)/(1-V+K_2*V);\n",
      "\n",
      "x_1 = (P - P_2_sat)/(P_1_sat - P_2_sat);\n",
      "y_1 = (x_1*P_1_sat)/(P);\n",
      "\n",
      "# For two phase region to exist at 90 C and 101.325 kPa,z_1 sholud lie between x_1 and y_1\n",
      "\n",
      "# Results\n",
      "print \" For two phase region to exist at 90 C and 101.325 kPa, z_1 sholud lie between %f and %f\"%(x_1,y_1);\n",
      "print \" For z_1 = 0.1 and z_1 = 0.5 only liquid phase exists V = 0.\"\n",
      "print \" For z_1 = 0.8 only vapour exists V = 1.\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " For two phase region to exist at 90 C and 101.325 kPa, z_1 sholud lie between 0.574884 and 0.772458\n",
        " For z_1 = 0.1 and z_1 = 0.5 only liquid phase exists V = 0.\n",
        " For z_1 = 0.8 only vapour exists V = 1.\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.14  Page Number : 531"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "from numpy import zeros\n",
      "\n",
      "# Variables\n",
      "T = 90;\t\t\t#[C]\n",
      "P = 1;\t\t\t#[atm]\n",
      "P = P*101325*10**(-3);\t\t\t#[kPa]\n",
      "z_1 = [0.1,0.5,0.8];\n",
      "\n",
      "# math.log(P_1_sat) = 13.8594 - 2773.78/(t + 220.07)\n",
      "# math.log(P_2_sat) = 14.0098 - 3103.01/(t + 219.79)\n",
      "\n",
      "# Calculations and Results\n",
      "#(a)\n",
      "#At T = 90 C\n",
      "P_1_sat = math.exp(13.8594 - 2773.78/(T + 220.07));\n",
      "P_2_sat = math.exp(14.0098 - 3103.01/(T + 219.79));\n",
      "K_1 = P_1_sat/P;\n",
      "\n",
      "x_1 = [0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0];\n",
      "P_prime = zeros(11);\n",
      "x_2 = zeros(11);\n",
      "y_1 = zeros(11);\n",
      "\n",
      "print \" a.\";\n",
      "print \" x_1    \\t\\t  P   \\t\\t   y_1      \";\n",
      "\n",
      "for i in range(11):\n",
      "    x_2[i] = 1 - x_1[i];\n",
      "    P_prime[i] = x_1[i]*P_1_sat + x_2[i]*P_2_sat;\n",
      "    y_1[i] = (x_1[i]*P_1_sat)/P_prime[i];\n",
      "    print \" %f \\t  %f  \\t   %f  \"%(x_1[i],P_prime[i],y_1[i]);\n",
      "\n",
      "\t\t\t#(b)\n",
      "T_1_sat = 2773.78/(13.8594-math.log(P)) - 220.07;\t\t\t#[C]\n",
      "T_2_sat = 3103.01/(14.0098-math.log(P)) - 219.79;\t\t\t#[C]\n",
      "\n",
      "T_prime = [110.62,107,104,101,98,95,92,89,86,83,80.09];\n",
      "\n",
      "P1_sat = zeros(11);\n",
      "P2_sat = zeros(11);\n",
      "x_1 = zeros(11);\n",
      "y_1 = zeros(11);\n",
      "\n",
      "print \"  b.\";\n",
      "print \" TC  \\t\\t  P_1_sat kPa  \\t\\t P_2_sat kPa \\t\\t  x_1  \\t\\t  y_1 \";\n",
      "\n",
      "for j in range(11):\n",
      "    P1_sat[j] = math.exp(13.8594 - 2773.78/(T_prime[j] + 220.07));\n",
      "    P2_sat[j] = math.exp(14.0098 - 3103.01/(T_prime[j] + 219.79));\n",
      "    x_1[j] = (P-P2_sat[j])/(P1_sat[j]-P2_sat[j]);\n",
      "    y_1[j] = (x_1[j]*P1_sat[j])/P;\n",
      "    print \" %f \\t    %f    \\t   %f    \\t      %f  \\t       %f \"%(T_prime[j],P1_sat[j],P2_sat[j],x_1[j],y_1[j]);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " a.\n",
        " x_1    \t\t  P   \t\t   y_1      \n",
        " 0.000000 \t  54.233834  \t   0.000000  \n",
        " 0.100000 \t  62.425251  \t   0.218098  \n",
        " 0.200000 \t  70.616668  \t   0.385597  \n",
        " 0.300000 \t  78.808085  \t   0.518277  \n",
        " 0.400000 \t  86.999502  \t   0.625971  \n",
        " 0.500000 \t  95.190920  \t   0.715131  \n",
        " 0.600000 \t  103.382337  \t   0.790162  \n",
        " 0.700000 \t  111.573754  \t   0.854176  \n",
        " 0.800000 \t  119.765171  \t   0.909433  \n",
        " 0.900000 \t  127.956588  \t   0.957615  \n",
        " 1.000000 \t  136.148005  \t   1.000000  \n",
        "  b.\n",
        " TC  \t\t  P_1_sat kPa  \t\t P_2_sat kPa \t\t  x_1  \t\t  y_1 \n",
        " 110.620000 \t    237.827187    \t   101.332530    \t      -0.000055  \t       -0.000129 \n",
        " 107.000000 \t    216.742019    \t   91.320455    \t      0.079767  \t       0.170629 \n",
        " 104.000000 \t    200.376847    \t   83.629571    \t      0.151570  \t       0.299740 \n",
        " 101.000000 \t    184.975751    \t   76.460482    \t      0.229134  \t       0.418300 \n",
        " 98.000000 \t    170.500977    \t   69.787769    \t      0.313139  \t       0.526923 \n",
        " 95.000000 \t    156.915208    \t   63.586616    \t      0.404360  \t       0.626206 \n",
        " 92.000000 \t    144.181607    \t   57.832824    \t      0.503680  \t       0.716718 \n",
        " 89.000000 \t    132.263848    \t   52.502830    \t      0.612106  \t       0.799008 \n",
        " 86.000000 \t    121.126156    \t   47.573718    \t      0.730789  \t       0.873601 \n",
        " 83.000000 \t    110.733338    \t   43.023234    \t      0.861050  \t       0.941001 \n",
        " 80.090000 \t    101.331285    \t   38.950606    \t      0.999899  \t       0.999961 \n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.15  Page Number : 533"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Variables\n",
      "P_1_sat = 79.80;\t\t\t#[kPa]\n",
      "P_2_sat = 40.45;\t\t\t#[kPa]\n",
      "\n",
      "#(1)\n",
      "T = 373.15;\t\t\t#[K]\n",
      "x_1 = 0.05;\n",
      "x_2 = 1 - x_1;\n",
      "Y1 = math.exp(0.95*x_2**(2));\n",
      "Y2 = math.exp(0.95*x_1**(2));\n",
      "\n",
      "# Calculations and Results\n",
      "# The total pressure of the system is given by\n",
      "P = x_1*Y1*P_1_sat + x_2*Y2*P_2_sat;\t\t\t#[kPa]\n",
      "y_1 = x_1*Y1*P_1_sat/P;\n",
      "y_2 = x_2*Y2*P_2_sat/P;\n",
      "\n",
      "print \" 1).The first bubble is formed at %f kPa and the composition y_1 = %f\"%(P,y_1);\n",
      "\n",
      "#(2)\n",
      "T = 373.15;\t\t\t#[K]\n",
      "y_1_prime = 0.05;\n",
      "y_2_prime = 1 - y_1_prime;\n",
      "\n",
      "# Let us assume a value of x_1,\n",
      "x_1_prime = 0.0001;\n",
      "\n",
      "error = 10;\n",
      "while(error>0.001):\n",
      "    x_2_prime = 1 - x_1_prime;\n",
      "    Y1_prime = math.exp(0.95*x_2_prime**(2));\n",
      "    Y2_prime = math.exp(0.95*x_1_prime**(2));\n",
      "    P_prime = x_1_prime*Y1_prime*P_1_sat + x_2_prime*Y2_prime*P_2_sat;\n",
      "    x_1 = (y_1_prime*P_prime)/(Y1_prime*P_1_sat);\n",
      "    error=abs(x_1_prime - x_1);\n",
      "    x_1_prime = x_1_prime + 0.00001;\n",
      "\n",
      "P_2 = x_1_prime*Y1_prime*P_1_sat + x_2_prime*Y2_prime*P_2_sat;\n",
      "\n",
      "print \" 2).The first drop is formed at %f kPa and has the composition x_1 = %f\"%(P_2,x_1_prime);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " 1).The first bubble is formed at 47.923166 kPa and the composition y_1 = 0.196237\n",
        " 2).The first drop is formed at 41.974204 kPa and has the composition x_1 = 0.009370\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.16  Page Number : 534"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "# Variables\n",
      "T = 78.15;\t\t\t#[C]\n",
      "P_1_sat = 755;\t\t\t#[mm Hg]\n",
      "P_2_sat = 329;\t\t\t#[mm Hg]\n",
      "\n",
      "z_1 = 0.3;\n",
      "V = 0.5;\n",
      "\n",
      "# math.log(Y1) = 0.845/(1 + 0.845*(x_1/x_2))**(2)\n",
      "# math.log(Y2) = 1/(1 + 1.183*(x_2/x_1))**(2)\n",
      "\n",
      "# A value of x_1 is to determined for which  V = 0.5\n",
      "# Let us assume a value of x_1, say x_1 = 0.150\n",
      "x_1 = 0.150;\n",
      "\n",
      "# Calculations\n",
      "error = 10;\n",
      "while(error>0.001):\n",
      "    x_2 = 1 - x_1;\n",
      "    Y1 = math.exp(0.845/(1 + 0.845*(x_1/x_2))**(2));\n",
      "    Y2 = math.exp(1/(1 + 1.183*(x_2/x_1))**(2));\n",
      "    P = x_1*Y1*P_1_sat + x_2*Y2*P_2_sat;\n",
      "    y_1 = (x_1*Y1*P_1_sat)/P;\n",
      "    V_prime = (z_1 - x_1)/(y_1 - x_1);\n",
      "    error=abs(V_prime - V);\n",
      "    x_1 = x_1 + 0.00001;\n",
      "\n",
      "P_prime = x_1*Y1*P_1_sat + x_2*Y2*P_2_sat;\t\t\t#[mm hg]\n",
      "\n",
      "# At x_1 ,  V = 0.5, \n",
      "# Therefore when the mixture is 50 % vaporized at 78.15 C the mole fraction of component 1 in the liquid phase is x_1 and the system pressure is P_prime\n",
      "\n",
      "# Results\n",
      "print \" The required pressure is %f mm Hg\"%(P_prime);\n",
      "print \" and the mole fraction of component 1 in the liquid phase for this pressure is x_1 = %f\"%(x_1);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The required pressure is 505.838606 mm Hg\n",
        " and the mole fraction of component 1 in the liquid phase for this pressure is x_1 = 0.157650\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.17  Page Number : 536"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "from scipy.stats import linregress\n",
      "\n",
      "# Variables\n",
      "T = 25;\t\t\t#[C] - Temperature\n",
      "P = [118.05,124.95,137.90,145.00,172.90,207.70,227.70,237.85,253.90,259.40,261.10,262.00,258.70,252.00,243.80];\t\t\t#[mm Hg]\n",
      "x_1 = [0.0115,0.0160,0.0250,0.0300,0.0575,0.1125,0.1775,0.2330,0.4235,0.5760,0.6605,0.7390,0.8605,0.9250,0.9625];\n",
      "y_1 = [0.1810,0.2250,0.3040,0.3450,0.4580,0.5670,0.6110,0.6325,0.6800,0.7050,0.7170,0.7390,0.8030,0.8580,0.9160];\n",
      "\n",
      "# Pressure value for which x_1 = y_1 = 0, corresponds to P_2_sat,therefore\n",
      "P_2_sat = 97.45;\t\t\t#[mm Hg]\n",
      "# Pressure value for which x_1 = y_1 = 1, corresponds to P_1_sat,therefore\n",
      "P_1_sat = 230.40;\t\t\t#[mm Hg]\n",
      "\n",
      "x_2 = zeros(15);\n",
      "y_2 = zeros(15);\n",
      "Y1 = zeros(15);\n",
      "Y2 = zeros(15);\n",
      "GE_RT = zeros(15);\n",
      "x1x2_GE_RT = zeros(15);\n",
      "\n",
      "# Calculations\n",
      "for i in range(15):\n",
      "    x_2[i] = 1 - x_1[i];\n",
      "    y_2[i] = 1 - y_1[i];\n",
      "    Y1[i] = (y_1[i]*P[i])/(x_1[i]*P_1_sat);\n",
      "    Y2[i] = (y_2[i]*P[i])/(x_2[i]*P_2_sat);\n",
      "    GE_RT[i] = x_1[i]*math.log(Y1[i]) + x_2[i]*math.log(Y2[i]);\t\t\t# G_E/(R*T)\n",
      "    x1x2_GE_RT[i] = (x_1[i]*x_2[i])/GE_RT[i];\n",
      "\n",
      "\n",
      "#[M,N,sig]=reglin(x_1,x1x2_GE_RT);\n",
      "M,N,sig,d,e = linregress(x_1,x1x2_GE_RT);\n",
      "\n",
      "# Linear regression between x_1 and x_1*x_2/(G_E/R*T) gives intercept = N and slope = M\n",
      "\n",
      "# van Laar equation is x_1*x_2/(G_E/R*T) = 1/A + (1/B - 1/A)\n",
      "# 1/A = N\n",
      "A = 1/N;\n",
      "B = 1/(M + 1/A);\n",
      "\n",
      "# Results\n",
      "print \" The value of Van Laar coefficient A =  %f\"%(A);\n",
      "print \" The value of Van Laar coefficient B =  %f\"%(B);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The value of Van Laar coefficient A =  2.270624\n",
        " The value of Van Laar coefficient B =  1.781821\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.18  Page Number : 541"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "from scipy.optimize import fsolve \n",
      "import math \n",
      "\n",
      "# Variables\n",
      "T = 343.15;\t\t\t#[K] - Temperature\n",
      "# At 343.15 K\n",
      "# math.log(Y1) = 0.95*x_2**(2)\n",
      "# math.log(Y2) = 0.95*x_1**(2)\n",
      "P_1_sat = 79.80;\t\t\t#[kPa]\n",
      "P_2_sat = 40.50;\t\t\t#[kPa]\n",
      "\n",
      "# Calculations\n",
      "# At x_1 = 0,\n",
      "Y1_infinity = math.exp(0.95);\n",
      "alpha_12_x0 = (Y1_infinity*P_1_sat)/(P_2_sat);\n",
      "# At x_1 = 1,\n",
      "Y2_infinity = math.exp(0.95);\n",
      "alpha_12_x1 = (P_1_sat)/(Y2_infinity*P_2_sat);\n",
      "\n",
      "\n",
      "# At azeotrope, Y1*P1_sat = Y2*P2_sat\n",
      "# Y2/Y1 = P_1_sat/P_2_sat\n",
      "# Taking math.logarithm of both sides we get\n",
      "# math.log(Y2) - math.log(Y1) = math.log(P_1_sat/P_2_sat)\n",
      "# 0.95*x_1**(2) - 0.95*x_2**(2) = math.log(P_1_sat/P_2_sat)\n",
      "# Solving the above equation\n",
      "def f(x_1): \n",
      "\t return 0.95*x_1**(2) - 0.95*(1-x_1)**(2) - math.log(P_1_sat/P_2_sat)\n",
      "x_1 = fsolve(f,0.1)\n",
      "\n",
      "# At x_1\n",
      "x_2 = 1 - x_1;\n",
      "Y1 = math.exp(0.95*x_2**(2));\n",
      "Y2 = math.exp(0.95*x_1**(2));\n",
      "P = x_1*Y1*P_1_sat + x_2*Y2*P_2_sat;\t\t\t#[kPa] - Azeotrope pressure\n",
      "y_1 = (x_1*Y1*P_1_sat)/P;\n",
      "\n",
      "# Since x_1 = y_1, (almost equal) ,the above condition is of azeotrope formation\n",
      "\n",
      "\n",
      "\n",
      "# Results\n",
      "print \" Since alpha_12_x=0 = %f and alpha_12_x=1 = %f \"%(alpha_12_x0,alpha_12_x1);\n",
      "print \" and since alpha_12 is a continuous curve and in between a value of alpha_12 = 1, shall come and at this composition the azeotrope shall get formed.\"\n",
      "print \" The azeotrope composition is x_1 = y_1 = %f\"%(x_1);\n",
      "print \" The azeotrope presssure is %f kPa\"%(P);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Since alpha_12_x=0 = 5.094806 and alpha_12_x=1 = 0.762023 \n",
        " and since alpha_12 is a continuous curve and in between a value of alpha_12 = 1, shall come and at this composition the azeotrope shall get formed.\n",
        " The azeotrope composition is x_1 = y_1 = 0.856959\n",
        " The azeotrope presssure is 81.366308 kPa\n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.19  Page Number : 541"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Variables\n",
      "T = 45;\t\t\t#[C] - Temperature\n",
      "\n",
      "x_1 = [0.0455,0.0940,0.1829,0.2909,0.3980,0.5069,0.5458,0.5946,0.7206,0.8145,0.8972,0.9573];\n",
      "y_1 = [0.1056,0.1818,0.2783,0.3607,0.4274,0.4885,0.5098,0.5375,0.6157,0.6913,0.7869,0.8916];\n",
      "P = [31.957,33.553,35.285,36.457,36.996,37.068,36.978,36.778,35.792,34.372,32.331,30.038];\n",
      "\n",
      "\t\t\t# Pressure value for which x_1 = y_1 = 0, corresponds to P_2_sat,therefore\n",
      "P_2_sat = 29.819;\t\t\t#[kPa]\n",
      "\t\t\t# Pressure value for which x_1 = y_1 = 1, corresponds to P_1_sat,therefore\n",
      "P_1_sat = 27.778;\t\t\t#[kPa]\n",
      "\n",
      "x_2 = zeros(12);\n",
      "y_2 = zeros(12);\n",
      "Y1 = zeros(12);\n",
      "Y2 = zeros(12);\n",
      "alpha_12 = zeros(12);\n",
      "GE_RT = zeros(12);\n",
      "x1x2_GE_RT = zeros(12);\n",
      "# Calculations and Results\n",
      "print \" x_1  \\t\\t  y_1    \\t   P   \\t\\t    Y1   \\t\\tY2  \\t    alpha_12    \\t  G_E/RT \\t  x1*x2/G_E/RT\";\n",
      "\n",
      "for i in range(12):\n",
      "    x_2[i] = 1 - x_1[i];\n",
      "    y_2[i] = 1 - y_1[i];\n",
      "    Y1[i] = (y_1[i]*P[i])/(x_1[i]*P_1_sat);\n",
      "    Y2[i] = (y_2[i]*P[i])/(x_2[i]*P_2_sat);\n",
      "    alpha_12[i] = (y_1[i]/x_1[i])/(y_2[i]/x_2[i]);\n",
      "    GE_RT[i] = x_1[i]*math.log(Y1[i]) + x_2[i]*math.log(Y2[i]);\t\t\t# G_E/(R*T)\n",
      "    x1x2_GE_RT[i] = (x_1[i]*x_2[i])/GE_RT[i];\n",
      "    print \" %f\\t  %f\\t  %f \\t     %f  \\t   %f \\t     %f\\t   %f  \\t%f\"%(x_1[i],y_1[i],P[i],Y1[i],Y2[i],alpha_12[i],GE_RT[i],x1x2_GE_RT[i]);\n",
      "\n",
      "\t\t\t#[M,N,sig]=reglin(x_1,x1x2_GE_RT);\n",
      "M,N,sig,d,e=linregress(x_1,x1x2_GE_RT);\n",
      "\n",
      "\t\t\t# Linear regression between x_1 and x_1*x_2/(G_E/R*T) gives intercept = N and slope = M\n",
      "\n",
      "\t\t\t# Now let us assume the system to follow van Laar  activity coefficient model. \n",
      "\t\t\t# x_1*x_2/(G_E/(R*T)) = x_1/B + x_2/A =  x_1/B + (1 - x_1)/A  =  1/A + (1/B - 1/A)*x_1 = N + M*x_1\n",
      "\n",
      "\t\t\t# 1/A = N\n",
      "A = 1/N;\n",
      "\t\t\t# (1/B - 1/A) = M\n",
      "B = 1/(M + 1/A);\n",
      "\n",
      "print \"\"\n",
      "print \" The value of van Laar parameters are, A = %f and B = %f \"%(A,B);\n",
      "\n",
      "Y1_infinity = math.exp(A);\n",
      "Y2_infinity = math.exp(B);\n",
      "\n",
      "\n",
      "\t\t\t\n",
      "\t\t\t# Now let us calculate the azeotrope composition.\n",
      "\t\t\t# At azeotrope, Y1*P1_sat = Y2*P2_sat\n",
      "\t\t\t# math.log(Y1/Y2) = math.log(P_2_sat/P_1_sat)\n",
      "\t\t\t# From van Laar model we get\n",
      "\t\t\t# math.log(P_2_sat/P_1_sat) = (A*B**(2)*2*x_2**(2))/(A*x_1 + B*x_2)**(2) + (B*A**(2)*2*x_1**(2))/(A*x_1 + B*x_2)**(2)\n",
      "\t\t\t# Solving the above equation\n",
      "def f(x_1): \n",
      "\t return  math.log(P_2_sat/P_1_sat) - (A*B**(2)*(1-x_1)**(2))/(A*x_1 + B*(1-x_1))**(2) + (B*A**(2)*x_1**(2))/(A*x_1 + B*(1-x_1))**(2)\n",
      "x_1 = fsolve(f,0.1)\n",
      "\n",
      "print \" The azeotrope composition is given by x_1 = y_1 = %f\"%(x_1);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " x_1  \t\t  y_1    \t   P   \t\t    Y1   \t\tY2  \t    alpha_12    \t  G_E/RT \t  x1*x2/G_E/RT\n",
        " 0.045500\t  0.105600\t  31.957000 \t     2.670039  \t   1.004220 \t     2.476833\t   0.048705  \t0.891698\n",
        " 0.094000\t  0.181800\t  33.553000 \t     2.336127  \t   1.016177 \t     2.141582\t   0.094298  \t0.903137\n",
        " 0.182900\t  0.278300\t  35.285000 \t     1.932808  \t   1.045150 \t     1.722733\t   0.156610  \t0.954268\n",
        " 0.290900\t  0.360700\t  36.457000 \t     1.627355  \t   1.102263 \t     1.375325\t   0.210697  \t0.979023\n",
        " 0.398000\t  0.427400\t  36.996000 \t     1.430228  \t   1.180094 \t     1.129007\t   0.242105  \t0.989635\n",
        " 0.506900\t  0.488500\t  37.068000 \t     1.285998  \t   1.289486 \t     0.929034\t   0.252871  \t0.988458\n",
        " 0.545800\t  0.509800\t  36.978000 \t     1.243394  \t   1.338371 \t     0.865446\t   0.251278  \t0.986567\n",
        " 0.594600\t  0.537500\t  36.778000 \t     1.196853  \t   1.407094 \t     0.792366\t   0.245302  \t0.982671\n",
        " 0.720600\t  0.615700\t  35.792000 \t     1.100930  \t   1.650961 \t     0.621199\t   0.209369  \t0.961630\n",
        " 0.814500\t  0.691300\t  34.372000 \t     1.050218  \t   1.918247 \t     0.510015\t   0.160745  \t0.939933\n",
        " 0.897200\t  0.786900\t  32.331000 \t     1.020818  \t   2.247586 \t     0.423097\t   0.101740  \t0.906550\n",
        " 0.957300\t  0.891600\t  30.038000 \t     1.007145  \t   2.557286 \t     0.366877\t   0.046909  \t0.871410\n",
        "\n",
        " The value of van Laar parameters are, A = 1.049085 and B = 1.064514 \n",
        " The azeotrope composition is given by x_1 = y_1 = 0.468254\n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.20  Page Number : 541"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Variables\n",
      "T = 25;\t\t\t#[C] - Temperature\n",
      "P_1_sat = 230.4;\t\t\t#[mm Hg]\n",
      "P_2_sat = 97.45;\t\t\t#[mm Hg]\n",
      "Y1_infinity = 8.6;\n",
      "Y2_infinity = 6.6;\n",
      "\n",
      "\t\t\t# Assuming ideal vpour behaviour means that phi = 1 and since system pressure is low, therefore\n",
      "\t\t\t# f_i = P_i_sat \n",
      "\t\t\t# Assuming the activity coefficients to follow van Laar model we get\n",
      "A = math.log(Y1_infinity);\n",
      "B = math.log(Y2_infinity);\n",
      "\n",
      "\t\t\t#math.log(Y1) = A/(1+ (A*x_1)/(B*x_2))**(2)\n",
      "\t\t\t# math.log(Y2) = B/(1+ (B*x_2)/(A*x_1))**(2)\n",
      "\n",
      "x_1 = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9];\n",
      "\n",
      "x_2 = zeros(9);\n",
      "Y1 = zeros(9);\n",
      "Y2 = zeros(9);\n",
      "y1_P = zeros(9);\n",
      "y2_P = zeros(9);\n",
      "P = zeros(9);\n",
      "y_1 = zeros(9);\n",
      "\n",
      "print \" a.\";\n",
      "print \" x_1      \\t\\t    Y1    \\t\\t    Y2    \\t\\t    y1*P    \\t\\t    y2*P   \\t\\t   P    \\t\\t   y_1 \";\n",
      "# Calculations and Results\n",
      "for i in range(9):\n",
      "    x_2[i] = 1 - x_1[i];\n",
      "    Y1[i] = math.exp(A/(1+ (A*x_1[i])/(B*x_2[i]))**(2));\n",
      "    Y2[i] = math.exp(B/(1+ (B*x_2[i])/(A*x_1[i]))**(2));\n",
      "    y1_P[i] = x_1[i]*Y1[i]*P_1_sat;\n",
      "    y2_P[i] = x_2[i]*Y2[i]*P_2_sat;\n",
      "    P[i] = x_1[i]*Y1[i]*P_1_sat + x_2[i]*Y2[i]*P_2_sat;\n",
      "    y_1[i] = (x_1[i]*Y1[i]*P_1_sat)/P[i];\n",
      "    print \" %f\\t\\t %f\\t\\t %f \\t\\t %f \\t\\t %f \\t\\t %f \\t   %f\"%(x_1[i],Y1[i],Y2[i],y1_P[i],y2_P[i],P[i],y_1[i]);\n",
      "\n",
      "\t\t\t#(b)\n",
      "\t\t\t# The total system pressure versus x_1 shows a maxima and thus azeotrope is formed by the VLE system\n",
      "\t\t\t# The maxima occurs in the range of x_1 = 0.6 to 0.8, so an  azeotrope is formed in this composition range\n",
      "\n",
      "\t\t\t# At the azeotrope  point, Y1*P1_sat = Y2*P2_sat\n",
      "\t\t\t# math.log(Y1) - math.log(Y2) = math.log(P_2_sat/P_1_sat)\n",
      "\t\t\t# On putting the values and then solving the above equation we get\n",
      "def f(x_1): \n",
      "\t return  A/(1+1.14*x_1/(1-x_1))**(2)- B/(1+0.877*(1-x_1)/x_1)**(2) - math.log(P_2_sat/P_1_sat)\n",
      "x_1_prime = fsolve(f,0.1)\n",
      "\n",
      "\t\t\t# At x_1\n",
      "x_2_prime = 1 - x_1_prime;\n",
      "Y1_prime = math.exp(A/(1+ (A*x_1_prime)/(B*x_2_prime))**(2));\n",
      "Y2_prime = math.exp(B/(1+ (B*x_2_prime)/(A*x_1_prime))**(2));\n",
      "P_prime = x_1_prime*Y1_prime*P_1_sat + x_2_prime*Y2_prime*P_2_sat;\t\t\t#[kPa] - Azeotrope pressure\n",
      "y_1_prime = (x_1_prime*Y1_prime*P_1_sat)/P_prime;\n",
      "\n",
      "\t\t\t# Since x_1 = y_1,azeotrope formation will take place\n",
      "print \" b\";\n",
      "print \" The total system pressure versus x_1 shows a maxima and thus azeotrope is formed by the VLE system\";\n",
      "print \" The azeotrope composition is x_1 = y_1 = %f\"%(x_1_prime);\n",
      "print \" The azeotrope presssure is %f mm Hg\"%(P_prime);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " a.\n",
        " x_1      \t\t    Y1    \t\t    Y2    \t\t    y1*P    \t\t    y2*P   \t\t   P    \t\t   y_1 \n",
        " 0.100000\t\t 5.446877\t\t 1.024149 \t\t 125.496041 \t\t 89.822961 \t\t 215.319002 \t   0.582838\n",
        " 0.200000\t\t 3.680305\t\t 1.097308 \t\t 169.588473 \t\t 85.546152 \t\t 255.134625 \t   0.664702\n",
        " 0.300000\t\t 2.640401\t\t 1.225500 \t\t 182.504521 \t\t 83.597451 \t\t 266.101972 \t   0.685844\n",
        " 0.400000\t\t 2.002736\t\t 1.421865 \t\t 184.572186 \t\t 83.136461 \t\t 267.708646 \t   0.689452\n",
        " 0.500000\t\t 1.599580\t\t 1.708524 \t\t 184.271623 \t\t 83.247849 \t\t 267.519472 \t   0.688816\n",
        " 0.600000\t\t 1.340316\t\t 2.120132 \t\t 185.285311 \t\t 82.642744 \t\t 267.928055 \t   0.691549\n",
        " 0.700000\t\t 1.174189\t\t 2.709824 \t\t 189.373156 \t\t 79.221704 \t\t 268.594861 \t   0.705051\n",
        " 0.800000\t\t 1.072057\t\t 3.558780 \t\t 197.601501 \t\t 69.360613 \t\t 266.962114 \t   0.740186\n",
        " 0.900000\t\t 1.017109\t\t 4.791470 \t\t 210.907696 \t\t 46.692876 \t\t 257.600573 \t   0.818739\n",
        " b\n",
        " The total system pressure versus x_1 shows a maxima and thus azeotrope is formed by the VLE system\n",
        " The azeotrope composition is x_1 = y_1 = 0.706548\n",
        " The azeotrope presssure is 268.599631 mm Hg\n"
       ]
      }
     ],
     "prompt_number": 21
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.21  Page Number : 544"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "T = 50;\t\t\t#[C]\n",
      "\t\t\t# At 50 C\n",
      "P_1_sat = 0.67;\t\t\t#[atm]\n",
      "P_2_sat = 0.18;\t\t\t#[atm]\n",
      "Y1_infinity = 2.5;\n",
      "Y2_infinity = 7.2;\n",
      "\n",
      "# Calculations and Results\n",
      "\t\t\t#(1)\n",
      "\t\t\t# alpha_12 = (y_1/x_1)/(y_2/x_2) = (Y1*P_1_sat)/((Y2*P_2_sat))\n",
      "\t\t\t# At  x_1 tending to zero,\n",
      "alpha_12_x0 = (Y1_infinity*P_1_sat)/(P_2_sat);\n",
      "\t\t\t# At  x_1 tending to 1,\n",
      "alpha_12_x1 = (P_1_sat)/((Y2_infinity*P_2_sat));\n",
      "\n",
      "\n",
      "print \" 1).Since alpha_12_x=0) = %f and alpha_12_x=1) = %f \"%(alpha_12_x0,alpha_12_x1);\n",
      "print \"     and since alpha_12 is a continuous curve and in between a value of alpha_12 = 1 shall come and at this composition azeotrope shall get formed.\"\n",
      "\n",
      "\t\t\t\n",
      "print \" 2).Since the activity coefficient values are greater than 1 therefore the deviations from Roults law is positive\"\n",
      "print \"     and the azeotrope is maximum pressure or minimum boiling\";\n",
      "\n",
      "\t\t\t#(3)\n",
      "\t\t\t# Let us assume the system to follow van Laar activity coefficient model\n",
      "A = math.log(Y1_infinity);\n",
      "B = math.log(Y2_infinity);\n",
      "\n",
      "\t\t\t# math.log(Y1) = A/(1+ (A*x_1)/(B*x_2))**(2)\n",
      "\t\t\t# math.log(Y2) = B/(1+ (B*x_2)/(A*x_1))**(2)\n",
      "\n",
      "\t\t\t# At the azeotrope  point, Y1*P1_sat = Y2*P2_sat\n",
      "\t\t\t# math.log(Y1) - math.log(Y2) = math.log(P_2_sat/P_2_sat)\n",
      "\t\t\t# On putting the values and then solving the above equation\n",
      "def f(x_1): \n",
      "\t return  A/(1+ (A*x_1)/(B*(1-x_1)))**(2)- B/(1+ (B*(1-x_1))/(A*x_1))**(2) - math.log(P_2_sat/P_1_sat)\n",
      "x_1 = fsolve(f,0.1)\n",
      "\n",
      "\t\t\t# At x_1\n",
      "x_2 = 1 - x_1;\n",
      "Y1 = math.exp(A/(1+ (A*x_1)/(B*x_2))**(2));\n",
      "Y2 = math.exp(B/(1+ (B*x_2)/(A*x_1))**(2));\n",
      "P = x_1*Y1*P_1_sat + x_2*Y2*P_2_sat;\t\t\t#[kPa] - Azeotrope pressure\n",
      "y_1 = (x_1*Y1*P_1_sat)/P;\n",
      "\n",
      "\t\t\t# Since x_1 = y_1,the azeotrope formation will take place\n",
      "\n",
      "print \" 3).The azeotrope composition is x_1 = y_1 = %f\"%(x_1);\n",
      "print \"     The azeotrope presssure is %f atm\"%(P);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " 1).Since alpha_12_x=0) = 9.305556 and alpha_12_x=1) = 0.516975 \n",
        "     and since alpha_12 is a continuous curve and in between a value of alpha_12 = 1 shall come and at this composition azeotrope shall get formed.\n",
        " 2).Since the activity coefficient values are greater than 1 therefore the deviations from Roults law is positive\n",
        "     and the azeotrope is maximum pressure or minimum boiling\n",
        " 3).The azeotrope composition is x_1 = y_1 = 0.910173\n",
        "     The azeotrope presssure is 0.689143 atm\n"
       ]
      }
     ],
     "prompt_number": 21
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.22  Page Number : 545"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Variables\n",
      "T = 25;\t\t\t#[C]\n",
      "\t\t\t# At 50 C\n",
      "P_1_sat = 7.866;\t\t\t#[kPa]\n",
      "P_2_sat = 3.140;\t\t\t#[kPa]\n",
      "\n",
      "\t\t\t# G_E/(R*T) = 1.4938*x_1*x_2/(1.54*x_1 + 0.97*x_2)\n",
      "\n",
      "\t\t\t# The excess Gibbs free energy math.expression can be written as\n",
      "\t\t\t# x_1*x_2/(G_E/(R*T)) = 1.54*x_1/1.4938 + 0.97*x_2/1.4938 = x_1/0.97 + x_2/1.54\n",
      "\n",
      "\t\t\t# Comparing with the van Laar math.expression\n",
      "\t\t\t# x_1*x_2/(G_E/(R*T)) = x_1/B + x_2/A,  we get\n",
      "A = 1.54;\n",
      "B = 0.97;\n",
      "\n",
      "\t\t\t# The activity coefficients are thus given by\n",
      "\t\t\t# math.log(Y1) = A/(1+ (A*x_1)/(B*x_2))**(2)\n",
      "\t\t\t# math.log(Y2) = B/(1+ (B*x_2)/(A*x_1))**(2)\n",
      "\n",
      "x_1 = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.95];\n",
      "\n",
      "x_2 = zeros(10);\n",
      "Y1 = zeros(10);\n",
      "Y2 = zeros(10);\n",
      "P = zeros(10);\n",
      "y_1 = zeros(10);\n",
      "\n",
      "print \" x_1      \\t\\t    Y1    \\t\\t    Y2    \\t\\t P kPa    \\t\\t  y_1 \";\n",
      "\n",
      "# Calculations and Results\n",
      "for i in range(10):\n",
      "    x_2[i] = 1 - x_1[i];\n",
      "    Y1[i] = math.exp(A/(1+ (A*x_1[i])/(B*x_2[i]))**(2));\n",
      "    Y2[i] = math.exp(B/(1+ (B*x_2[i])/(A*x_1[i]))**(2));\n",
      "    P[i] = x_1[i]*Y1[i]*P_1_sat + x_2[i]*Y2[i]*P_2_sat;\n",
      "    y_1[i] = (x_1[i]*Y1[i]*P_1_sat)/P[i];\n",
      "    print \" %f\\t\\t %f\\t\\t %f \\t\\t %f \\t\\t  %f \"%(x_1[i],Y1[i],Y2[i],P[i],y_1[i]);\n",
      "\n",
      "\n",
      "\t\t\t# The azeotrope is formed near x_1 = 0.95 as in this region a maxima in pressure is obtained.\n",
      "\n",
      "\t\t\t# At the azeotrope  point, Y1*P1_sat = Y2*P2_sat\n",
      "\t\t\t# math.log(Y1) - math.log(Y2) = math.log(P_2_sat/P_2_sat)\n",
      "\t\t\t# On putting the values and then solving the above equation\n",
      "def f(x_1): \n",
      "\t return  A/(1+ (A*x_1)/(B*(1-x_1)))**(2)- B/(1+ (B*(1-x_1))/(A*x_1))**(2) - math.log(P_2_sat/P_1_sat)\n",
      "x_1_prime = fsolve(f,0.1)\n",
      "\n",
      "\t\t\t# At x_1\n",
      "x_2_prime = 1 - x_1_prime;\n",
      "Y1_prime = math.exp(A/(1+ (A*x_1_prime)/(B*x_2_prime))**(2));\n",
      "Y2_prime = math.exp(B/(1+ (B*x_2_prime)/(A*x_1_prime))**(2));\n",
      "P_prime = x_1_prime*Y1_prime*P_1_sat + x_2_prime*Y2_prime*P_2_sat;\t\t\t#[kPa] - Azeotrope pressure\n",
      "y_1_prime = (x_1_prime*Y1_prime*P_1_sat)/P_prime;\n",
      "\n",
      "\t\t\t# Since x_1_prime = y_1_prime,the azeotrope formation will take place\n",
      "\n",
      "print \" Part II \";\n",
      "print \" The azeotrope composition is x_1 = y_1 = %f\"%(x_1_prime);\n",
      "print \" The azeotrope presssure is %f kPa \"%(P_prime);\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " x_1      \t\t    Y1    \t\t    Y2    \t\t P kPa    \t\t  y_1 \n",
        " 0.100000\t\t 3.042798\t\t 1.022050 \t\t 5.281779 \t\t  0.453155 \n",
        " 0.200000\t\t 2.201629\t\t 1.081457 \t\t 6.180223 \t\t  0.560433 \n",
        " 0.300000\t\t 1.725242\t\t 1.172375 \t\t 6.648107 \t\t  0.612389 \n",
        " 0.400000\t\t 1.438293\t\t 1.292347 \t\t 6.960227 \t\t  0.650186 \n",
        " 0.500000\t\t 1.258593\t\t 1.440723 \t\t 7.211980 \t\t  0.686364 \n",
        " 0.600000\t\t 1.144175\t\t 1.617876 \t\t 7.432102 \t\t  0.726584 \n",
        " 0.700000\t\t 1.072060\t\t 1.824770 \t\t 7.621913 \t\t  0.774475 \n",
        " 0.800000\t\t 1.028913\t\t 2.062721 \t\t 7.770131 \t\t  0.833286 \n",
        " 0.900000\t\t 1.006610\t\t 2.333241 \t\t 7.858834 \t\t  0.906775 \n",
        " 0.950000\t\t 1.001587\t\t 2.481217 \t\t 7.874109 \t\t  0.950528 \n",
        " Part II \n",
        " The azeotrope composition is x_1 = y_1 = 0.958680\n",
        " The azeotrope presssure is 7.874467 kPa \n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 15.23  Page Number : 547"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Variables\n",
      "T = 58.7;\t\t\t#[C]\n",
      "P = 1;\t\t\t#[atm]\n",
      "P = P*101325*10**(-3);\t\t\t#[kPa]\n",
      "\n",
      "\t\t\t# math.log(P_sat) = 16.6758 - 3674.49/(t + 226.45) - For ethyl alcohol\n",
      "\t\t\t# math.log(P_sat) = 13.8216 - 2697.55/(t + 224.37) - For hexane\n",
      "\n",
      "\t\t\t# Let us take hexane as (1) and ethanol as (2)\n",
      "\t\t\t# At 58.7 C\n",
      "P_1_sat = math.exp(13.8216 - 2697.55/(T + 224.37));\t\t\t#[kPa]\n",
      "P_2_sat = math.exp(16.6758 - 3674.49/(T + 226.45));\t\t\t#[kPa]\n",
      "\n",
      "# Calculations and Results\n",
      "Y1 = P/P_1_sat;\n",
      "Y2 = P/P_2_sat;\n",
      "\n",
      "x_2 = 0.332;\t\t\t# Mol % of ethanol (given)\n",
      "x_1 = 1 - x_2;\t\t\t# Mol % of hehane\n",
      "\n",
      "\t\t\t# The van Laar parameters are given by\n",
      "A = ((1 + (x_2*math.log(Y2))/(x_1*math.log(Y1)))**(2))*math.log(Y1);\n",
      "B = ((1 + (x_1*math.log(Y1))/(x_2*math.log(Y2)))**(2))*math.log(Y2);\n",
      "\n",
      "print \" The value of van Laar parameters are A = %f and B = %f \"%(A,B);\n",
      "\n",
      "\t\t\t# Now let us calvulate the distribution coefficient K\n",
      "x_1_prime = 0.5;\t\t\t#[given]\n",
      "x_2_prime = 1 - x_1_prime;\n",
      "\n",
      "\t\t\t# The activity coefficients are thus given by\n",
      "\t\t\t# math.log(Y1) = A/(1+ (A*x_1)/(B*x_2))**(2)\n",
      "\t\t\t# math.log(Y2) = B/(1+ (B*x_2)/(A*x_1))**(2)\n",
      "\n",
      "Y1_prime = math.exp(A/(1+ (A*x_1_prime)/(B*x_2_prime))**(2));\n",
      "Y2_prime = math.exp(B/(1+ (B*x_2_prime)/(A*x_1_prime))**(2));\n",
      "P_prime = x_1_prime*Y1_prime*P_1_sat + x_2_prime*Y2_prime*P_2_sat;\n",
      "\n",
      "\t\t\t# We have,  K_1 = y_1/x_1 = Y1*P_1_sat/P\n",
      "K_1 = Y1_prime*P_1_sat/P_prime;\n",
      "\n",
      "print \" The distribution coefficient is given by  K_1  =  %f\"%(K_1)\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The value of van Laar parameters are A = 1.669879 and B = 2.662289 \n",
        " The distribution coefficient is given by  K_1  =  1.352866\n"
       ]
      }
     ],
     "prompt_number": 23
    }
   ],
   "metadata": {}
  }
 ]
}