{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 5 : Properties of Real Gases"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.1 page no: 109"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# variables \n",
      "V = 0.6                         #m**3 vessel\n",
      "T = 473.                        #K temperature\n",
      "N = 1. * 10 ** 3                 #mol\n",
      "R = 8.314                       #Pa * m**3/molK\n",
      "\n",
      "# Calculation \n",
      "P = N * R * T / (V * 10**5) \n",
      "\n",
      "# Result\n",
      "print \"(a)Pressure calculated using ideal gas equation = %.2f bar\"%P\n",
      "a = 0.4233                      #N * m**4 / mol**2\n",
      "b = 3.73 * 10**-5               #m**3/mol\n",
      "P1 = (R*T/(V/N - b)-a/(V/N)**2)/10**5 \n",
      "print \"(a)Pressure calculated using van der waals equation = %.2f bar\"%P1\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)Pressure calculated using ideal gas equation = 65.54 bar\n",
        "(a)Pressure calculated using van der waals equation = 58.13 bar\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.2 pageno : 110"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# variables \n",
      "P = 10.**7                              #Pa \n",
      "T = 500.                                #K molar volume\n",
      "R = 8.314                               #Pa * L / mol K\n",
      "N = 1000.\n",
      "\n",
      "# Calculation \n",
      "V = N * R * T / ( P * 1000) \n",
      "\n",
      "# Result\n",
      "print \"(a)Volume of CO2 calculated using ideal gas equation = %.4e m**3\"%V\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)Volume of CO2 calculated using ideal gas equation = 4.1570e-04 m**3\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.3 pageno : 111"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# variables \n",
      "V = 0.6 * 10**-3                        #m**3\n",
      "T = 473.                                #K vellel of volume\n",
      "Tc = 405.5                              #K temperature\n",
      "Pc = 112.8 * 10 ** 5                    #Pa pressure\n",
      "R = 8.314 \n",
      "\n",
      "# Calculation \n",
      "a = 0.4278 * (R**2) * (Tc ** 2.5)/Pc \n",
      "b = 0.0867 * R * Tc / Pc \n",
      "P1 = (R*T/(V - b) - a/((T**0.5)*V*(V + b)))/10**5 \n",
      "\n",
      "# Result\n",
      "print \"Pressure developed by gas = %.2f bar\"%P1\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Pressure developed by gas = 57.87 bar\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.4 pageno : 112"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# variables \n",
      "P = 10.**6                              #Pa\n",
      "T = 373.                                #K molar volume\n",
      "Tc = 405.5                              #K temperature\n",
      "Pc = 112.8 * 10 ** 5                    #Pa pressure\n",
      "R = 8.314 \n",
      "\n",
      "# Calculation \n",
      "a = 0.4278 * (R**2) * (Tc ** 2.5)/Pc \n",
      "b = 0.0867 * R * Tc / Pc \n",
      "#P1 = (R*T/(V - b) - a/((T**0.5)*V*(V + b)))/10**5 \n",
      "#10**6=((8.314*373)/(V-2.59*10**-5))-8.68/((373**0.5)*V*(V+2.59*10**-5) \n",
      "#solving this we get,\n",
      "V = 3.0 * 10**-3                        #m**3/mol\n",
      "\n",
      "# Result\n",
      "print \"molar volume of gas = %.e m**3/mol\"%V\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "molar volume of gas = 3e-03 m**3/mol\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.5 pageno : 112"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# variables \n",
      "B = -2.19 * 10**-4                  #m**3/mol virial coefficients\n",
      "C = -1.73 * 10**-8                  #m**6/mol**2\n",
      "P = 10.                             #bar molar volume\n",
      "T = 500.                            #K\n",
      "\n",
      "# Calculation \n",
      "#virial equation is given as, Z = PV/RT = 1 + B/V + C/V**2\n",
      "#V = (RT/P)*(1 + B/V + C/V**2)\n",
      "# now by assuming different values for V on RHS and checking for corresponding V on LHS, we have to assume such value of V on RHS by which we get the same value for LHS V\n",
      "#by trial and error we get,\n",
      "V = 3.92 * 10**-3                   #m**3\n",
      "\n",
      "# Result\n",
      "print \"Molar volume of methanol = %.3e m**3\"%V\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Molar volume of methanol = 3.920e-03 m**3\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.6 pageno : 120"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# variables \n",
      "T = 510.                        #K molar volume\n",
      "P = 26.6                        #bar \n",
      "Tc = 425.2                      #K temperature\n",
      "Pc = 38.                        #bar pressure\n",
      "Zc = 0.274                      # compressibility factor\n",
      "R = 8.314 \n",
      "\n",
      "# Calculation \n",
      "Pr = P / Pc \n",
      "Tr = T / Tc \n",
      "\n",
      "# Result\n",
      "print \"Pr = \",Pr\n",
      "print \"Tr = %.2f\"%Tr\n",
      "\n",
      "#From fig. 5.4 and 5.5 from the text book\n",
      "Z = 0.865 \n",
      "D = 0.15 \n",
      "Z1 = Z + D * ( Zc - 0.27) \n",
      "V = R * T * Z1 / (P * 10**5) \n",
      "print \"Molar volume of n-butane = %.4e m**3/mol\"%V\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Pr =  0.7\n",
        "Tr = 1.20\n",
        "Molar volume of n-butane = 1.3798e-03 m**3/mol\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.7 pageno : 120"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# variables \n",
      "T = 510.                    #K molar volumes\n",
      "P = 26.6                    #bar\n",
      "Tc = 425.2                  #K temperature\n",
      "Pc = 38.                    #bar pressure\n",
      "w = 0.193                   # acentric factor\n",
      "R = 8.314 \n",
      "\n",
      "# Calculation \n",
      "Pr = P / Pc \n",
      "Tr = T / Tc \n",
      "\n",
      "# Result\n",
      "print \"Pr = \",Pr\n",
      "print \"Tr = %.2f\"%Tr\n",
      "\n",
      "#From fig. 5.6 and 5.7 from the text book\n",
      "Z0 = 0.855 \n",
      "Z1 = 0.042 \n",
      "Z = Z0 + w*Z1 \n",
      "print \"Z = %.4f\"%Z\n",
      "V = R * T * Z / (P * 10**5) \n",
      "\n",
      "print \"Molar volume of n-butane = %.4e m**3/mol\"%V\n",
      "\n",
      "# note : answer may vary because of rounding error."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Pr =  0.7\n",
        "Tr = 1.20\n",
        "Z = 0.8631\n",
        "Molar volume of n-butane = 1.3758e-03 m**3/mol\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.8 pageno : 122"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from numpy import *\n",
      "# variables \n",
      "P = 6000.                               #kPa ethane\n",
      "T = 325.                                #K ethane\n",
      "xn2 = 0.4                               # gas mixture\n",
      "xethane = 0.6 \n",
      "an2 = 0.1365                            #N m**4 / mol**2 nitrogen\n",
      "\n",
      "# Calculation \n",
      "bn2 = 3.86 * 10**-5                     #m**3/mol\n",
      "aethane = 0.557                         #N m**4 / mol**2\n",
      "bethane = 6.51 * 10**-5                 #m**3/mol\n",
      "Pcn2 = 3394.                            #kPa\n",
      "Tcn2 = 126.2                            #K\n",
      "Pcethane = 4880.                        #kPa\n",
      "Tcethane = 305.4                        #K\n",
      "R = 8.314 \n",
      "\n",
      "\n",
      "# Result\n",
      "V = R * T / (P*1000) \n",
      "print \"(a)Molar volume by ideal gas equation = %.3e m**3/mol\"%V\n",
      "\n",
      "\n",
      "a = (xn2 * (an2**0.5) + xethane * (aethane**0.5))**2 \n",
      "b = (xn2*bn2 + xethane*bethane) \n",
      "#substituting the above values in van der waals equation, and solving, we get\n",
      "#V^3 - 5.0484*10^-4V^2+5.9117*10^-8V-3.2214*10^-12=0\n",
      "#Using co-efficients from the above equation,\n",
      "coeff = [1, -5.0484e-4, 5.9117e-8, -3.2217e-12]\n",
      "x = roots(coeff)\n",
      "y = x[0]\n",
      "print \"(b)Molar volume by van der waals equation =\",round((y.real)/1e-4,3),\"*10^-4 m**3/mol\"\n",
      "\n",
      "\n",
      "Prin2 = P/Pcn2 \n",
      "Trin2 = T/Tcn2 \n",
      "Priethane = P/Pcethane \n",
      "Triethane = T/Tcethane \n",
      "# using compressibilty chart, \n",
      "Zn2 = 1 \n",
      "Zethane = 0.42 \n",
      "Z = xn2 * Zn2 + xethane * Zethane \n",
      "V2 = Z * R * T / P * (10**-3)\n",
      "print \"(c)Molar volume based on compressibilty factor = %.2e m**3/mol\"%V2\n",
      "\n",
      "\n",
      "Pri1n2 = xn2*P/Pcn2 \n",
      "Tri1n2 = T/Tcn2 \n",
      "Pri1ethane = xethane*P/Pcethane \n",
      "Tri1ethane = T/Tcethane \n",
      "# using compressibilty chart, \n",
      "Zn21 = 1. \n",
      "Zethane1 = 0.76 \n",
      "Z1 = xn2 * Zn21 + xethane * Zethane1 \n",
      "V3 = (Z1 * R * T / P ) * (10**-3)\n",
      "print \"(c)Molar volume based on daltons law = %.3e m**3/mol\"%V3\n",
      "\n",
      "\n",
      "Tc = xn2 * Tcn2 + xethane * Tcethane \n",
      "Pc = xn2 * Pcn2 + xethane * Pcethane \n",
      "Zc = 0.83 \n",
      "V4 = Zc * R *T / P * (10**-3)\n",
      "print \"(d)Molar volume by kays method = %.3e m**3/mol\"%V4\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)Molar volume by ideal gas equation = 4.503e-04 m**3/mol\n",
        "(b)Molar volume by van der waals equation = 3.68 *10^-4 m**3/mol\n",
        "(c)Molar volume based on compressibilty factor = 2.94e-04 m**3/mol\n",
        "(c)Molar volume based on daltons law = 3.855e-04 m**3/mol\n",
        "(d)Molar volume by kays method = 3.738e-04 m**3/mol\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.9 page no : 124"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# variables \n",
      "P1 = 40.                            #% ( nitrogen )\n",
      "P2 = 60.                            #% ( ethane )\n",
      "T = 325.                            #K ethane\n",
      "\n",
      "# Calculation \n",
      "V = 4.5 * 10**-4                    #m**3/mol\n",
      "a1 = 0.1365                         #N*m**4/mol**2\n",
      "b1 = 3.86 * 10 ** -5                #m**3/mol\n",
      "a2 = 0.557                          #N*m**4/mol**2\n",
      "b2 = 6.51 * 10 ** -5                #m**3/mol\n",
      "Pc1 = 3394.                         #kPa\n",
      "Tc1 = 126.1                         #K\n",
      "Pc2 = 4880.                         #kPa\n",
      "Tc2 = 305.4                         #K\n",
      "R = 8.314 \n",
      "Pideal = R * T / (V * 1000)         #kPa\n",
      "\n",
      "# Result\n",
      "print \"(a)Pressure of Gas by the ideal gas equation = %.f kPa\"%Pideal\n",
      "y1 = P1/100. \n",
      "y2 = P2/100. \n",
      "a = (y1 * (a1**(1./2)) + y2 * (a2**(1./2)))**2 \n",
      "b = y1 * b1 + y2 * b2 \n",
      "Pv = ((R * T / (V - b)) - a / (V**2))/1000 \n",
      "print \"(b)Pressure of Gas by Van der waals equation = %.f kPa\"%Pv\n",
      "Tc = y1*Tc1 + y2*Tc2 \n",
      "Pc = y1*Pc1 + y2*Pc2 \n",
      "Vc = R * Tc / Pc                    #Pseudo critical ideal volume\n",
      "Vr = V / Vc                         #Pseudo reduced ideal volume\n",
      "Tr = T / Tc                         #Pseudo reduced temperature\n",
      "\n",
      "#From fig 5.3, we get Pr = 1.2\n",
      "Pr = 1.2 \n",
      "Pk = Pr * Pc \n",
      "print \"(c)Pressure of Gas by the Kays method = %.f kPa\"%Pk\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)Pressure of Gas by the ideal gas equation = 6005 kPa\n",
        "(b)Pressure of Gas by Van der waals equation = 5080 kPa\n",
        "(c)Pressure of Gas by the Kays method = 5143 kPa\n"
       ]
      }
     ],
     "prompt_number": 22
    }
   ],
   "metadata": {}
  }
 ]
}