{
 "metadata": {
  "name": "",
  "signature": "sha256:9f0f51ee792551db4a5ae3ded00fa549611bdd66fece52d68af61c7a164f38e5"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 10 : Material Balances for Processes Involving Reaction"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 10.1 Page no. 264\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "F = 100             # feed to the reactor-[g mol]\n",
      "CH4 = 0.4*F         # [g mol]\n",
      "Cl2 = 0.5*F ;       # [g mol]\n",
      "N2= 0.1*F ;         #[g mol]\n",
      "\n",
      "nio_CH4 = CH4       #[g mol CH4]\n",
      "vi_CH4 = -1         # coefficint of CH4\n",
      "\n",
      "\n",
      "# Calculation and Result\n",
      "ex_CH4 = -(nio_CH4)/vi_CH4        # Max. extent of reaction based on CH4\n",
      "\n",
      "nio_Cl2 = Cl2 ;                   #[g mol Cl2]\n",
      "vi_Cl2 = -1 ;                     # coefficint of Cl2\n",
      "ex_Cl2 = -(nio_Cl2)/vi_Cl2 ;      # Max. extent of reaction based on Cl2\n",
      "\n",
      "if (ex_Cl2 > ex_CH4 ):\n",
      "    print '  CH4 is limiting reactant  '\n",
      "else:\n",
      "    print '  (b) Cl2 is limiting reactant  '\n",
      "\n",
      "cn_CH4 = 67/100.0 ;               # percentage conversion of CH4\n",
      "ex_r = (-cn_CH4)*CH4/vi_CH4 ;     # extent of reaction\n",
      "\n",
      "print ' extent of reaction is %.1f g moles reacting '%ex_r\n",
      "\n",
      "n_un = 11 ;                      # Number of unknowns in the given problem\n",
      "n_ie = 11 ;                      # Number of independent equations\n",
      "d_o_f = n_un-n_ie ;              # Number of degree of freedom\n",
      "print ' Number of degree of freedom for the given system is  %i '%d_o_f\n",
      "\n",
      "vi_CH3Cl = 1;\n",
      "vi_HCl = 1;\n",
      "vi_N2 = 0;\n",
      "p_CH4 = CH4+(vi_CH4*ex_r);       # [g mol]\n",
      "p_Cl2 = Cl2+(vi_Cl2*ex_r);       # [g mol]\n",
      "p_CH3Cl = 0+(vi_CH3Cl*ex_r);     # [g mol]\n",
      "p_HCl = 0+(vi_HCl*ex_r);         # [g mol]\n",
      "p_N2 =  N2+(vi_N2*ex_r);         # [g mol]\n",
      "\n",
      "print 'Composition of product stream in %% g mol of products'\n",
      "print 'Product            Percentage g mol'\n",
      "print 'CH4                %.1f%% g mol'%p_CH4\n",
      "print 'Cl2                %.1f%% g mol'%p_Cl2\n",
      "print 'CH3Cl              %.1f%% g mol'%p_CH3Cl\n",
      "print 'HCl                %.1f%% g mol'%p_HCl\n",
      "print 'N2                 %.1f%% g mol'%p_N2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "  CH4 is limiting reactant  \n",
        " extent of reaction is 26.8 g moles reacting \n",
        " Number of degree of freedom for the given system is  0 \n",
        "Composition of product stream in %% g mol of products\n",
        "Product            Percentage g mol\n",
        "CH4                13.2% g mol\n",
        "Cl2                23.2% g mol\n",
        "CH3Cl              26.8% g mol\n",
        "HCl                26.8% g mol\n",
        "N2                 10.0% g mol\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 10.2  Page no. 266\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "# Variables \n",
      "S = 5000. ;              # Sulphur [lb]\n",
      "CH4 =  80. ;             # [%]\n",
      "H2S =  20.;              # [%]\n",
      "\n",
      "n_un = 11. ;\n",
      "n_ie  = 11. ;\n",
      "\n",
      "# Calculation and Result\n",
      "d_o_f =  n_un-n_ie ;\n",
      "print 'Number of degree of freedom for the given system is  %i '%d_o_f\n",
      "\n",
      "m_S = 32.0              #molecular wt. of S -[lb]\n",
      "mol_S = S/32.0;\n",
      "nio_S = 0               #[g mol S]\n",
      "ni_S = mol_S ;          #[g mol S]\n",
      "vi_S = 3.               # coefficint of S -from given reaction\n",
      "ex_r = (ni_S-nio_S)/vi_S ;     #  Extent of reaction based on S\n",
      "print ' Extent of reaction is %.1f g moles reacting '%ex_r\n",
      "\n",
      "vi_H2O = 2. ;             # coefficint of H2O\n",
      "vi_H2S = -2. ;            # coefficint of H2S\n",
      "vi_SO2 = -1. ;            #coefficint of SO2\n",
      "vi_CH4 = 0 ;              #coefficint of CH4\n",
      "P_H2O = 0+(vi_H2O*ex_r);  # [lb mol]\n",
      "P_H2S = P_H2O/10 ;        #[lb mol]\n",
      "P_SO2 = 3.*P_H2S ;        #[lb mol]\n",
      "\n",
      "F = (P_H2S-vi_H2S*ex_r)/(H2S/100) ;          # total feed-[lb mol]\n",
      "F_SO2 = P_SO2-(vi_SO2*ex_r);                 # feed rate of SO2- [lb mol]\n",
      "F_CH4 = (CH4/100.)*F+vi_CH4*ex_r ;           #feed rate of CH4- [lb mol]\n",
      "F_H2S = ((H2S/100.)*F) ;                     # feed rate of H2S-[lb mol]\n",
      "\n",
      "f_cn = -(vi_H2S*ex_r)/((H2S/100.)*F)         # Fractional conversion of limiting reagent\n",
      "\n",
      "print '(1)Feed rate of H2S-  %.1f lb mol'%F_H2S\n",
      "print '(2)Feed rate of SO2-  %.1f lb mol'%F_SO2\n",
      "print '(3)Fractional conversion of limiting reagent-  %.2f '%f_cn"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Number of degree of freedom for the given system is  0 \n",
        " Extent of reaction is 52.1 g moles reacting \n",
        "(1)Feed rate of H2S-  114.6 lb mol\n",
        "(2)Feed rate of SO2-  83.3 lb mol\n",
        "(3)Fractional conversion of limiting reagent-  0.91 \n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 10.3  Page no. 270\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables \n",
      "F = 1                      #CH3OH -[gmol]\n",
      "f_cn = 90.                 #[%]\n",
      "vi_CH3OH = -1.             #coefficint of CH3OH\n",
      "\n",
      "# Calculation and Result\n",
      "ex_r1 = (-90./100)/vi_CH3OH       #  Extent of reaction based on CH3OH \n",
      "print ' Extent of reaction 1 is %.2f g moles reacting '%ex_r1\n",
      "\n",
      "yld = 75.                         #[%]\n",
      "ex_r2 = ex_r1-(F*(yld/100.0));\n",
      "print '  Extent of reaction 2 is %.2f g moles reacting '%ex_r2\n",
      "\n",
      "f_O2 = 0.21                      # mol. fraction of O2\n",
      "f_N2 = 0.79                      # mol. fraction of N2\n",
      "n_O2 = 2*((1/2.0)*F)             # entering oxygen -[g mol]\n",
      "air =  n_O2/f_O2                 # Amount of air entering\n",
      "n_N2 = air-n_O2                  # entering nitrogen -[g mol]\n",
      "\n",
      "n_un = 11.                       # Number of unknowns in the given problem\n",
      "n_ie  = 11.                      # Number of independent equations\n",
      "d_o_f =  n_un-n_ie               # Number of degree of freedom\n",
      "print '  Number of degree of freedom for the given system is  %i '%d_o_f\n",
      "\n",
      "v1_CH3OH = -1                    #coefficint of CH3OH\n",
      "v1_O2 = -1./2                    #coefficint of O2\n",
      "v1_CH2O = 1 ;                    #coefficint of CH2O\n",
      "v1_H2O = 1 ;                     #coefficint of H2O\n",
      "v1_CO = 0  ;                     #coefficient of CO\n",
      "\n",
      "#Reaction 2\n",
      "v2_O2 = -1./2                    #coefficint of O2\n",
      "v2_CH2O = -1                     #coefficint of CH2O\n",
      "v2_H2O = 1 ;                     #coefficint of H2O\n",
      "v2_CO = 1 ;                      #coefficient of CO\n",
      "P = F+air +(v1_CH3OH+v1_O2+v1_CH2O+v1_H2O)*ex_r1 +(v2_O2+v2_CH2O+v2_H2O+v2_CO)*ex_r2 ;# Product -[g mol]\n",
      "\n",
      "no_CH3OH = F+(v1_CH3OH*ex_r1)+0 ;             # [g mol]\n",
      "no_O2 = n_O2+(v1_O2*ex_r1)+v2_O2*ex_r2 ;      # [g mol]\n",
      "no_CH2O = 0 + v1_CH2O*ex_r1 +v2_CH2O*ex_r2 ;  #[g mol]\n",
      "no_CO =  0+v1_CO*ex_r1 +v2_CO*ex_r2 ;         #[g mol]\n",
      "no_H2O = 0+v1_H2O*ex_r1+v2_H2O*ex_r2 ;        # [g mol]\n",
      "no_N2 =  n_N2-0-0 ;                           # [g mol]\n",
      "\n",
      "\n",
      "y_CH3OH = (no_CH3OH/P )*100 ;                 # mole %\n",
      "y_O2 = (no_O2/P)*100 ;                        # mole %\n",
      "y_CH2O = (no_CH2O/P)*100 ;                    # mole %\n",
      "y_CO = (no_CO/P)*100 ;                        # mole %\n",
      "y_H2O = (no_H2O/P)*100 ;                      # mole % \n",
      "y_N2 = (no_N2/P )*100;                        # mole %\n",
      "\n",
      "print 'Composition of product'\n",
      "print 'Component        mole percent'\n",
      "print ' CH3OH           %.1f %%'%y_CH3OH\n",
      "print ' O2              %.1f %%'%y_O2\n",
      "print ' CH2O            %.1f %%'%y_CH2O\n",
      "print ' CO              %.1f %%'%y_CO\n",
      "print ' H2O             %.1f %%'%y_H2O\n",
      "print ' N2              %.1f %%'%y_N2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Extent of reaction 1 is 0.90 g moles reacting \n",
        "  Extent of reaction 2 is 0.15 g moles reacting \n",
        "  Number of degree of freedom for the given system is  0 \n",
        "Composition of product\n",
        "Component        mole percent\n",
        " CH3OH           1.6 %\n",
        " O2              7.6 %\n",
        " CH2O            11.9 %\n",
        " CO              2.4 %\n",
        " H2O             16.7 %\n",
        " N2              59.8 %\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 10.4  Page no. 273\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from numpy import matrix\n",
      "\n",
      "# Variables \n",
      "F = 4000. ;                  #[kg]\n",
      "m_H2O = 18.02 ;              # molecular masss of water\n",
      "m_C6H12O6 = 180.1 ;          # molecular mass of glucose\n",
      "m_CO2 = 44. ;                #molecular mass of CO2\n",
      "m_C2H3CO2H = 72.03 ;         # molecular mass of C2H3CO2H\n",
      "m_C2H5OH = 46.05 ;           # molecular mass of ethanol\n",
      "\n",
      "p_H2O = 88. ;                # [%]\n",
      "p_C6H12O6 = 12.;             # [%] \n",
      "\n",
      "# Calculation & Result\n",
      "ni_H2O = (F*p_H2O/100.)/m_H2O ;                    # initial moles of water\n",
      "ni_C6H12O6 = (F*(p_C6H12O6/100.))/m_C6H12O6 ;      # initial moles of glucose\n",
      "\n",
      "n_un = 9. \n",
      "n_ie  = 9. \n",
      "d_o_f =  n_un-n_ie\n",
      "print 'Number of degree of freedom for the given system is  %i '%d_o_f\n",
      "\n",
      "ur_C6H12O6 =  90. ;                        #[kg]\n",
      "pr_CO2 = 120. ;                            #[kg]\n",
      "nf_C6H12O6 = ur_C6H12O6/m_C6H12O6 ;        # [kmoles]\n",
      "nf_CO2 = pr_CO2/m_CO2 ;                    # [kmoles]\n",
      "\n",
      "\n",
      "a = matrix([[-1,-1],[2,0]]);               # matrix formed by coefficients of unknowns \n",
      "b = matrix([[(nf_C6H12O6-ni_C6H12O6)],[nf_CO2]]);      #matrix formed by constant\n",
      "x = a**(-1)*b;                             #matrix formed by solution\n",
      " \n",
      "print ' Extent of reaction 1 is %.3f kg moles reacting '%x[0]\n",
      "print ' Extent of reaction 2 is %.3f kg moles reacting '%x[1]\n",
      "\n",
      "nf_H2O = ni_H2O+0*x[0] +2*x[1];              \n",
      "nf_C2H5OH = 0+2*x[0]+0*x[1];\n",
      "nf_C2H3CO2H = 0+0*x[0]+2*x[1]\n",
      "total_wt = m_H2O*nf_H2O + m_C6H12O6*nf_C6H12O6 + m_CO2*nf_CO2 + \\\n",
      "m_C2H3CO2H*nf_C2H3CO2H + m_C2H5OH*nf_C2H5OH;\n",
      "mp_C2H5OH = (m_C2H5OH*nf_C2H5OH*100)/total_wt \n",
      "mp_C2H3CO2H = (m_C2H3CO2H*nf_C2H3CO2H*100)/total_wt\n",
      "\n",
      "print '  Mass percent of ethanol in broth at end of fermentation process is  %.1f %%'%mp_C2H5OH\n",
      "print ' Mass percent of propenoic acid  in broth at end of fermentation process is  %.1f %%'%mp_C2H3CO2H"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Number of degree of freedom for the given system is  0 \n",
        " Extent of reaction 1 is 1.364 kg moles reacting \n",
        " Extent of reaction 2 is 0.802 kg moles reacting \n",
        "  Mass percent of ethanol in broth at end of fermentation process is  3.1 %\n",
        " Mass percent of propenoic acid  in broth at end of fermentation process is  2.9 %\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 10.5  Page no. 279\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from numpy import matrix\n",
      "\n",
      "# Variables \n",
      "\n",
      "print '(a)Solution of Example 10.1 using element balance'\n",
      "F = 100                   # feed to the reactor-[g mol]\n",
      "\n",
      "CH4 =  0.4*F ;             # [g mol]\n",
      "Cl2 =  0.5*F ;             # [g mol]\n",
      "N2 =  0.1*F                #[g mol]\n",
      "\n",
      "n_un = 10                  # Number of unknowns in the given problem(excluding extent of reaction)\n",
      "n_ie  = 10 ;               # Number of independent equations\n",
      "d_o_f =  n_un-n_ie         # Number of degree of freedom\n",
      "print '    Number of degree of freedom for the given system is  %i '%d_o_f\n",
      "\n",
      "nio_CH4 = CH4 ;            #[g mol CH4]\n",
      "vi_CH4 = -1;               # coefficint of CH4\n",
      "\n",
      "# Calculation and  Result\n",
      "ex_CH4 = -(nio_CH4)/vi_CH4 ;      # Max. extent of reaction based on CH4\n",
      "\n",
      "\n",
      "nio_Cl2 =  Cl2             #[g mol Cl2]\n",
      "vi_Cl2 = -1                # coefficint of Cl2\n",
      "ex_Cl2 = -(nio_Cl2)/vi_Cl2       # Max. extent of reaction based on Cl2\n",
      "\n",
      "if (ex_Cl2 > ex_CH4 ):    \n",
      "    print '    CH4 is limiting reactant  '\n",
      "else:\n",
      "    print '  (b) Cl2 is limiting reactant  '\n",
      "\n",
      "cn_CH4 =  67.0/100          # percentage conversion of CH4(limiting reagent)\n",
      "no_CH4 = CH4-(cn_CH4*CH4) ; #CH4 in product -[g mol]\n",
      "\n",
      "no_N2 = N2                  #N2 in product -[g mol]\n",
      "\n",
      "C = CH4 ;                   #moles of CH4  =  moles of C (by molecular formula)\n",
      "H = 4*CH4 ;                 # moles of H  =  4*moles of CH4 (by molecular formula)\n",
      "Cl = 2*Cl2 ;                # moles of Cl = 2* moles of Cl2 (by molecular formula)\n",
      "\n",
      "a = matrix([[0,0,1],[0,1,3],[2,1,1]])            # matrix formed by coefficients of unknowns \n",
      "b = matrix([[C-no_CH4*1],[H-4*no_CH4],[Cl]]) ;   #matrix formed by constant\n",
      "x = a**(-1)*b ;                                  # matrix of solution\n",
      "\n",
      "print 'Composition of product stream in %% g mol of products'\n",
      "print 'Product            Percentage g mol'\n",
      "print 'CH4                %.1f%% g mol'%no_CH4\n",
      "print 'Cl2                %.1f%% g mol'%x[0]\n",
      "print 'CH3Cl              %.1f%% g mol'%x[2]\n",
      "print 'HCl                %.1f%% g mol'%x[1]\n",
      "print 'N2                 %.1f%% g mol'%no_N2\n",
      "\n",
      "#(b)Solution of Example 10.3 using element balance\n",
      "print '______________________________________________________________________________'\n",
      "print '(b)Solution of Example 10.3 using element balance'\n",
      "\n",
      "F = 1              #CH3OH -[gmol]\n",
      "yld = 75           #[%]\n",
      "cnv = 90 ;         #conversion of methanol-[%]\n",
      "\n",
      "f_O2 = 0.21 ;      # mol. fraction of O2\n",
      "f_N2 = 0.79 ;      # mol. fraction of N2\n",
      "n_O2 = 2*((1/2.0)*F)           # entering oxygen -[g mol]\n",
      "air =  n_O2/f_O2 ;             # Amount of air entering\n",
      "n_N2 = air-n_O2                # entering nitrogen -[g mol]\n",
      "\n",
      "n_un = 9           # Number of unknowns in the given problem(excluding extent of reactions)\n",
      "n_ie  = 9 ;        # Number of independent equations\n",
      "d_o_f =  n_un-n_ie      # Number of degree of freedom\n",
      "\n",
      "print '  Number of degree of freedom for the given system is  %i '%d_o_f\n",
      "\n",
      "no_N2 = n_N2        # inert ,terefore input  =  output\n",
      "C = 1*F             #moles of C  =  moles of CH3OH (by molecular formula)\n",
      "H = 4*F ;           #moles of H  =  4*moles of CH3OH (by molecular formula)\n",
      "O =  1*F +2*n_O2;   # moles of O =  1*moles of CH3OH + O in air\n",
      "no_CH2O = yld/100.0 #[g mol]\n",
      "no_CH3OH = F-((cnv/100.0)*F)      # [g mol]\n",
      "\n",
      "a = matrix([[0,0,1],[0,2,0],[2,1,1]])            # matrix formed by coefficients of unknowns \n",
      "b = matrix([[(C-(no_CH3OH*1+no_CH2O*1))],[(H-(4*no_CH3OH+2*no_CH2O))],[(O-(no_CH3OH*1+no_CH2O*1))]]);\n",
      "a = a.I\n",
      "x = a * b ;                                      # matrix of solution\n",
      "\n",
      "P = no_CH2O+no_CH3OH+no_N2+x[0]+x[1]+x[2];\n",
      "\n",
      "# Composition of product\n",
      "y_CH3OH = (no_CH3OH/P )*100;        # mole %\n",
      "y_O2 = ((x[0])/P)*100;              # mole %\n",
      "y_CH2O = (no_CH2O/P)*100 ;          # mole %\n",
      "y_CO = (x[2]/P)*100 ;               # mole %\n",
      "y_H2O = (x[1]/P)*100 ;              # mole % \n",
      "y_N2 = (no_N2/P )*100;              # mole %\n",
      "\n",
      "\n",
      "print 'Composition of product'\n",
      "print 'Component        mole percent'\n",
      "print ' CH3OH           %.1f %%'%y_CH3OH\n",
      "print ' O2              %.1f %%'%y_O2\n",
      "print ' CH2O            %.1f %%'%y_CH2O\n",
      "print ' CO              %.1f %%'%y_CO\n",
      "print ' H2O             %.1f %%'%y_H2O\n",
      "print ' N2              %.1f %%'%y_N2\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)Solution of Example 10.1 using element balance\n",
        "    Number of degree of freedom for the given system is  0 \n",
        "    CH4 is limiting reactant  \n",
        "Composition of product stream in %% g mol of products\n",
        "Product            Percentage g mol\n",
        "CH4                13.2% g mol\n",
        "Cl2                23.2% g mol\n",
        "CH3Cl              26.8% g mol\n",
        "HCl                26.8% g mol\n",
        "N2                 10.0% g mol\n",
        "______________________________________________________________________________\n",
        "(b)Solution of Example 10.3 using element balance\n",
        "  Number of degree of freedom for the given system is  0 \n",
        "Composition of product\n",
        "Component        mole percent\n",
        " CH3OH           1.6 %\n",
        " O2              7.6 %\n",
        " CH2O            11.9 %\n",
        " CO              2.4 %\n",
        " H2O             16.7 %\n",
        " N2              59.8 %\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 10.6  Page no. 281\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from numpy import matrix\n",
      "\n",
      "# Variables \n",
      "P=100. ;                   #Product from the reactor-[g mol]\n",
      "C3H8 = 0.195*P ;           # [g mol]\n",
      "C4H10 = 0.594*P ;          # [g mol]\n",
      "C5H12 = 0.211*P;           # [g mol]\n",
      "\n",
      "n_un = 3 ;                 # Number of unknowns in the given problem(excluding extent of reaction)\n",
      "n_ie  = 3 ;                # Number of independent equations\n",
      "\n",
      "# Calculation and Result\n",
      "d_o_f =  n_un-n_ie ;       # Number of degree of freedom\n",
      "print 'Number of degree of freedom for the given system is  %i '%d_o_f\n",
      "\n",
      "C = C3H8*3+C4H10*4+C5H12*5        # moles of C on product side\n",
      "H = C3H8*8+C4H10*10+C5H12*12 ;    # moles of H on product side\n",
      "\n",
      "a = matrix([[8,0],[18,2]])        # matrix formed by coefficients of unknowns \n",
      "b = matrix([[C],[H]]) ;           #matrix formed by constant\n",
      "a = a.I\n",
      "x = a*b ;                         # matrix of solution\n",
      "\n",
      "R = x[1]/x[0] ;                   # Ratio of H2 consumed to C8H18 reacted  = G/F\n",
      "print ' Molar ratio of H2 consumed to C8H18 reacted is %.3f  '%R"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Number of degree of freedom for the given system is  0 \n",
        " Molar ratio of H2 consumed to C8H18 reacted is 0.992  \n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 10.7   Page no. 286\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables \n",
      "C3H8 = 20                #C3H8 burned in a test-[kg]\n",
      "m_C3H8 = 44.09           # mol. wt . of 1 kmol C3H8\n",
      "cf_O2 = 5                # coefficient of O2 in given reaction\n",
      "air = 400                # Air given -[kg]\n",
      "m_air = 29.0             # molecular wt. of  1kmol air-[kg]\n",
      "O2p = 21                 # percentage of O2 in air-[%]\n",
      "p_CO2 =  44              # CO2 produced -[kg]\n",
      "p_CO = 12                # CO produced -[kg]\n",
      "\n",
      "# Calculation \n",
      "O2 = (air*O2p/100.0)/(m_air)      # amount of entering O2-[k mol]\n",
      "rqO2 = (C3H8*cf_O2)/(m_C3H8)      # Required O2 for given reaction\n",
      "ex_air = ((O2-rqO2)*100.0)/rqO2 ;  # Excess air percent-[%]\n",
      "\n",
      "# Result\n",
      "print 'Excess air percent is %.0f %%.'%ex_air"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Excess air percent is 28 %.\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 10.8  Page no. 287\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "# Variables\n",
      "F = 16.               # feed of CH4 -[kg]\n",
      "CH4p = 100.           #[%]\n",
      "m_CH4 = 16. ;         # mass of kmol of CH4-[kg]\n",
      "mol_CH4 = (F*CH4p/100)/m_CH4         #k moles of CH4 in feed-[kmol]\n",
      "air = 300. ;                         # Air given -[kg]\n",
      "m_air = 29.                          # molecular wt. of  1kmol air-[kg]\n",
      "mol_air = air/m_air ;                # kmoles of air-[kmol]\n",
      "O2p = 21.                            # percentage of O2 in air-[%]\n",
      "O2 = (mol_air*O2p/100)               # amount of entering O2-[k mol]\n",
      "N2 = mol_air-O2 ;                    # amount of entering N2-[k mol]\n",
      "\n",
      "n_un = 8.                   # Number of unknowns in the given problem(excluding extent of reactions)\n",
      "n_ie  = 8.                  # Number of independent equations\n",
      "d_o_f =  n_un-n_ie          # Number of degree of freedom\n",
      "print 'Number of degree of freedom for the given system is  %i '%d_o_f\n",
      "\n",
      "# Product composition analysis using element balance of C,H,O and N\n",
      "p_N2 = N2                   # inert \n",
      "C_in = 1*mol_CH4 ;          # kmoles of carbon in input-[kmol]\n",
      "H_in = 4*mol_CH4            # kmoles of hydrogen in input-[kmol]\n",
      "O_in = 2*O2 ;               # kmoles of oxygen in input-[kmol]\n",
      "p_CO2 = C_in/1 ;            #kmoles of  CO2 in product obtained  by carbon balance-[kmol]\n",
      "p_H2O = H_in/2 ;            #kmoles of  H2O in product obtained  by hydrogen balance-[kmol]\n",
      "p_O2 = (O_in-(2*p_CO2+p_H2O))/2         #kmoles of  O2 in product obtained  by oxygen balance-[kmol]\n",
      "p_CH4 = 0                   # Complete reaction occurs\n",
      "P = p_CH4 + p_N2+  p_CO2 + p_H2O + p_O2;\n",
      "\n",
      "y_N2 = p_N2*100/P ;         #[mol %]\n",
      "y_CO2 = p_CO2*100/P ;       #[mol %]\n",
      "y_H2O = p_H2O*100/P ;       #[mol %]\n",
      "y_O2 = p_O2*100/P ;         #[mol %]\n",
      "y_CH4 = p_CH4*100/P ;       #[mol %]\n",
      "\n",
      "# Results\n",
      "print 'Composition of product'\n",
      "print 'Component        mole percent'\n",
      "print ' CH4             %.1f %%'%y_CH4\n",
      "print ' O2              %.1f %%'%y_O2\n",
      "print ' CO2             %.1f %%'%y_CO2\n",
      "print ' H2O             %.1f %%'%y_H2O\n",
      "print ' N2              %.1f %%'%y_N2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Number of degree of freedom for the given system is  0 \n",
        "Composition of product\n",
        "Component        mole percent\n",
        " CH4             0.0 %\n",
        " O2              1.5 %\n",
        " CO2             8.8 %\n",
        " H2O             17.6 %\n",
        " N2              72.0 %\n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 10.9  Page no. 290\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "F = 100.                 # feed of coal -[lb]\n",
      "C = 83.05                #[%]\n",
      "H = 4.45                 #[%]\n",
      "O = 3.36 ;               # [%]\n",
      "N = 1.08                 # [%]\n",
      "S = 0.70                 #[%]\n",
      "ash = 7.36               #[%]\n",
      "H2O = 3.9 ;              #[%]\n",
      "w_C = 12. ;              # mol. wt. of C\n",
      "w_H =  1.008;            #mol. wt. of H\n",
      "w_O = 16. ;              # mol. wt. of O\n",
      "w_N = 14. ;              # mol. wt. of N\n",
      "w_S = 32.  ;             #mol. wt. of S\n",
      "\n",
      "CO2 =  15.4              #[%]\n",
      "CO = 0.0                 #[%]\n",
      "O2 = 4.0 ;               # [%]\n",
      "N2 = 80.6                #[%]\n",
      "ash_R = 86               #[%]\n",
      "odr = 14                 #[%]\n",
      "\n",
      "H2O_air =  .0048         # [lb H2O/lb dry air]\n",
      "m_air = 29.              # mol. wt. of air\n",
      "mf_O2 = 0.21             # mole fraction of  O2 in air\n",
      "mf_N2 = 0.79             #mole fraction of  N2 in air\n",
      "m_H2O =  18.             # mol. wt. of H2O\n",
      "\n",
      "#Calculations\n",
      "H_cl = (H2O*2)/m_H2O ;   # lb mol of H in coal moisture\n",
      "O_cl = H_cl/2. ;         # lb mol of O in coal moisture\n",
      "\n",
      "H_air = (H2O_air*m_air )/m_H2O      # lb mol of H per lb mol air\n",
      "O_air = H_air/2.                    # lb mol of O per lb mol  air \n",
      "\n",
      "# Ash balance to get refuse(R)\n",
      "R = ash/(ash_R/100.)              # Refuse-[lb]\n",
      "\n",
      "pub_cl = 14.                      # percentage of unburned coal in refuse-[%]\n",
      "ub_cl =  (14/100.)*R              # amount of unburned coal in refuse\n",
      "C_p = (C/(100-ash))*ub_cl         #  C in unburned coal-[lb]\n",
      "H_p = (H/(100-ash))*ub_cl ;       #  H in unburned coal-[lb]\n",
      "O_p =  (O/(100-ash))*ub_cl ;      #  O in unburned coal-[lb]\n",
      "N_p =  (N/(100-ash))*ub_cl ;      #  N in unburned coal-[lb]\n",
      "S_p =  (S/(100-ash))*ub_cl ;      #  S in unburned coal-[lb]\n",
      "mol_C =  C_p/w_C;                 # lb mol of C\n",
      "mol_H = H_p/w_H ;                 # lb mol of H\n",
      "mol_N = N_p/w_N ;                 # lb mol of N\n",
      "mol_O = O_p/w_O ;                 # lb mol of O\n",
      "mol_S = S_p/w_S ;                 # lb mol of S \n",
      "\n",
      "\n",
      "n_un = 4.                         # Number of unknowns in the given problem(excluding extent of reactions)\n",
      "n_ie  = 4.                        # Number of independent equations\n",
      "d_o_f =  n_un-n_ie                # Number of degree of freedom\n",
      "print 'Number of degree of freedom for the given system is  %i '%d_o_f\n",
      "\n",
      "#Using element balance of C+S, N& H\n",
      "P = (C/w_C + S/w_S - (mol_C+mol_S ))/.154        # mol of stack gas-[lb mol]\n",
      "A = (2*P*.806 +2*mol_N-N/w_N)/(2*mf_N2)          # mol of air -[lb mol]\n",
      "W = (H/w_H +H_cl+H_air*A-mol_H)/2                # moles of exit water-[lb mol]\n",
      "print ' Moles of stack gas(P)   -      %.1f  lb mol'%P\n",
      "print ' Moles of air (A)        -      %.1f lb mol '%A\n",
      "print ' Moles of exit water(W)  -      %.1f lb mol '%W\n",
      "\n",
      "C_req =  (C/w_C)/1\n",
      "H_req = (H/w_H)/4 \n",
      "N_req = 0                   # inert\n",
      "O_req = (O/w_O)/2 \n",
      "S_req = (S/w_S)/1 \n",
      "total_O2_req =  C_req+H_req+N_req+O_req +S_req \n",
      "O2_in = A*mf_O2             # O2 entering in air\n",
      "ex_air = 100*((O2_in-total_O2_req)/total_O2_req)\n",
      "\n",
      "# Results\n",
      "print ' Excess air is %.1f %%.'%ex_air"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Number of degree of freedom for the given system is  0 \n",
        " Moles of stack gas(P)   -      44.5  lb mol\n",
        " Moles of air (A)        -      45.4 lb mol \n",
        " Moles of exit water(W)  -      2.6 lb mol \n",
        " Excess air is 16.8 %.\n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "code",
     "collapsed": true,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}