{
 "metadata": {
  "name": "",
  "signature": "sha256:bcb2b5536fdc9000213789c2755747f3e4bd3724ffe95c35320fbc2314325dca"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 11 :\n",
      "Chemical Thermodynamics and\n",
      "Equilibrium"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 11.1 pg : 287"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "x = 1.5\n",
      "P = 14.696 \t    \t\t#psia\n",
      "m = 28.96\n",
      "\t\t\t\n",
      "# Calculations\n",
      "mf = 114.    \t\t\t# lbm/mol fuel\n",
      "ma = x*12.5*(1+3.76)*m\n",
      "AF = ma/mf\n",
      "n1 = 8.\n",
      "n2 = 9.\n",
      "n3 = (x-1)*12.5 \n",
      "n4 =  x*3.76*12.5\n",
      "np = n1+n2+n3+n4\n",
      "x1 = n1/np\n",
      "x2 = n2/np\n",
      "x3 = n3/np\n",
      "x4 = n4/np\n",
      "ph = x2*P\n",
      "Td = 113.5 \t\t\t#F\n",
      "\t\t\t\n",
      "# Results\n",
      "print \"Air fuel ratio  =  %.1f lbm air/lbm fuel\"%(AF)\n",
      "print \" Mole fraction of CO2  =  %.2f percent\"%(x1*100)\n",
      "print \" Mole fraction of H2O  =  %.2f percent\"%(x2*100)\n",
      "print \" Mole fraction of O2  =  %.2f percent\"%(x3*100)\n",
      "print \" Mole fraction of N2  =  %.2f percent\"%(x4*100)\n",
      "print (\"From tables of saturation pressure\")\n",
      "print \"Dew point   =  %.1f F\"%(Td)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Air fuel ratio  =  22.7 lbm air/lbm fuel\n",
        " Mole fraction of CO2  =  8.53 percent\n",
        " Mole fraction of H2O  =  9.60 percent\n",
        " Mole fraction of O2  =  6.67 percent\n",
        " Mole fraction of N2  =  75.20 percent\n",
        "From tables of saturation pressure\n",
        "Dew point   =  113.5 F\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 11.2 pg : 290"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "x1 = 9.\n",
      "x2 = 1.2\n",
      "x3 = 1.5\n",
      "x4 = 88.3\n",
      "\t\t\t\n",
      "# Calculations\n",
      "a = x1+x2\n",
      "b = 2*a\n",
      "xO = (2*x1 + x2+ 2*x3 + b)/2\n",
      "xN = x4/3.76\n",
      "ratio = xO/a\n",
      "percent = ratio/2 *100\n",
      "\t\t\t\n",
      "# Results\n",
      "print \"Percent theoretical air  =  %.1f percent\"%(percent)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Percent theoretical air  =  104.4 percent\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 11.3 pg : 291"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "T = 440. \t\t\t#F\n",
      "\t\t\t\n",
      "# Calculations\n",
      "h1 = -169290\n",
      "h2 = 7597.6\n",
      "h3 = 4030.2\n",
      "ht = h1+h2-h3\n",
      "\t\t\t\n",
      "# Results\n",
      "print \"Molal enthalpy of CO2  =  %d Btu/lbm mole\"%(ht)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Molal enthalpy of CO2  =  -165722 Btu/lbm mole\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 11.4 pg : 291"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "T = 77. \t    \t\t#F\n",
      "\t\t\t\n",
      "# Calculations\n",
      "Hr = -36420. \t\t\t#B\n",
      "hc = -169290. \t\t\t#B/lb mol\n",
      "hh = -122970. \t\t\t#B/lb mol\n",
      "Hp = 2*hc+3*hh\n",
      "Q = Hp-Hr\n",
      "\t\t\t\n",
      "# Results\n",
      "print \"Heat transfer  =  %d B/mol fuel\"%(Q)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Heat transfer  =  -671070 B/mol fuel\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 11.5 pg : 294"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "T2 = 440. \t\t\t#F\n",
      "T1 = 77. \t\t\t#F\n",
      "Mch4 = 16.\n",
      "Mw = 18.\n",
      "\t\t\t\n",
      "# Calculations\n",
      "h77 = 3725.1\n",
      "ht = 6337.9\n",
      "ht2 = 7597.6\n",
      "h772 = 4030.2\n",
      "hwt = 1260.3\n",
      "h77w = 45.02\n",
      "hr77 = -383040. \t\t\t#B/lbm mol\n",
      "dHR = 1*Mch4*0.532*(T1-T2) + 2*(h77-ht)\n",
      "dHp = 1*(ht2-h772) + 2*Mw*(hwt - h77w)\n",
      "hrp = dHp+hr77+dHR\n",
      "\t\t\t\n",
      "# Results\n",
      "print \"Enthalpy of combustion of gaseous methane  =  %d B/lbm mol fuel\"%(hrp)\n",
      "\n",
      "#The calculation in textbook is wrong Please check it using a calculator.\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enthalpy of combustion of gaseous methane  =  -344037 B/lbm mol fuel\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 11.6 pg : 295"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "Hr = -107530. \t\t\t#B/mol fuel\n",
      "print (\"By iteration of temperatures, T = 2700 R\")\n",
      "T = 2700. \t\t\t#R\n",
      "\t\t\t\n",
      "# Results\n",
      "print \"Adiabatic flame temperature  =  %d R\"%(T)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "By iteration of temperatures, T = 2700 R\n",
        "Adiabatic flame temperature  =  2700 R\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 11.7 pg : 306"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from numpy import poly1d,roots\n",
      "\n",
      "# Variables\n",
      "import math \n",
      "Kp = 0.668\n",
      "y = Kp**2\n",
      "\t\t\t\n",
      "# Calculations\n",
      "x = poly1d(0)\n",
      "vec = roots([y,2,-y,-2,0])        #x**3 + y*x**3 + 2*y*x**2 -y*x -2*y)\n",
      "\n",
      "eps = vec[0]\n",
      "x1 = (1-eps)/(1+ eps/2)\n",
      "x2 = eps/(1+eps/2)\n",
      "x3 = eps/2/(1+ eps/2)\n",
      "\t\t\t\n",
      "# Results\n",
      "print \"degree of reaction  =  %.3f \"%(eps)\n",
      "print \" Equilibrium concentration of CO2  =  %.3f \"%(x1)\n",
      "print \" Equilibrium concentration of CO  =  %.3f \"%(x2)\n",
      "print \" Equilibrium concentration of O2  =  %.3f \"%(x3)\n",
      "\n",
      "#the answers are different due to approximation in textbook\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "degree of reaction  =  -4.482 \n",
        " Equilibrium concentration of CO2  =  -4.417 \n",
        " Equilibrium concentration of CO  =  3.612 \n",
        " Equilibrium concentration of O2  =  1.806 \n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 11.8 pg : 307"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from numpy import roots\n",
      "\n",
      "# Variables\n",
      "Kp = 15.63\n",
      "y = Kp\n",
      "\t\t\t\n",
      "# Calculations\n",
      "vec = roots([y+1,0,-y])#x**2 + y*x**2 - y)\n",
      "eps = vec[0]\n",
      "x1 = (1-eps)/(1+eps)\n",
      "x2 = eps/(1+eps)\n",
      "x3 = eps/(1+eps)\n",
      "\t\t\t\n",
      "# Results\n",
      "print \" Equilibrium concentration of Cs  =  %.4f \"%(x1)\n",
      "print \" Equilibrium concentration of Cs+  =  %.4f \"%(x2)\n",
      "print \" Equilibrium concentration of e-  =  %.4f \"%(x3)\n",
      "\n",
      "#the answers are a bit different due to approximation in textbook\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Equilibrium concentration of Cs  =  0.0155 \n",
        " Equilibrium concentration of Cs+  =  0.4922 \n",
        " Equilibrium concentration of e-  =  0.4922 \n"
       ]
      }
     ],
     "prompt_number": 2
    }
   ],
   "metadata": {}
  }
 ]
}