{
 "metadata": {
  "name": "",
  "signature": "sha256:ce47d914f54a1d45d40a3d6f4d1380a1b0ebd1de3c08f3c2df6139c5199b3710"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 13 : Equilibrium In Complex Chemical Reactions"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 13.1   Page: 349\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math \n",
      "\n",
      "T =273.15+25            #[K] given temperature\n",
      "R = 8.314               #[J/(mol*K)] universal gas consmath.tant\n",
      "\n",
      "\n",
      "g_0_H = 0               #[kJ/mol]\n",
      "g_0_OH = -157.29        #[kJ/mol]\n",
      "g_0_H2O = -237.1        #[kJ/mol]\n",
      "\n",
      "delta_g_0 = g_0_H + g_0_OH - g_0_H2O        #[kJ/mol]\n",
      "delta_g_1 = delta_g_0*1000                  #[J/mol]\n",
      "\n",
      "K = math.exp((-delta_g_1)/(R*T))\n",
      "\n",
      "K_w = K\n",
      "\n",
      "print \"At the equilibrium the product of the hydrogen ion and hydroxil ion is %0.1e\"%(K_w)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "At the equilibrium the product of the hydrogen ion and hydroxil ion is 1.0e-14\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 13.2   Page: 351\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "\n",
      "from scipy.optimize import fsolve \n",
      "import math \n",
      "\n",
      "n_H2SO4 = 1.                #[mol] mole of the sulphuric acid\n",
      "w_water = 1000.             #[g] weight of the water \n",
      "T =273.15+25                #[K] temperature\n",
      "R = 8.314                   #[J/(mol*K)]\n",
      "\n",
      "\n",
      "g_0_H = 0                   #[J/mol] free energy of the hydrogen ion\n",
      "g_0_HSO4 = -756.01*1000     #[J/mol] free energy of the bisulphate ion\n",
      "g_0_H2SO4 = -744.50*1000    #[J/mol] free enery of sulphuric acid\n",
      "\n",
      "delta_g_0 = g_0_H + g_0_HSO4 - g_0_H2SO4            #[J/mol]\n",
      "\n",
      "K_1 = math.exp((-delta_g_0)/(R*T))\n",
      "\n",
      "\n",
      "g_0_H = 0                   #[J/mol] free energy of the hydrogen ion\n",
      "g_0_SO4 = -744.62*1000      #[J/mol] free energy of sulphate ion\n",
      "g_0_HSO4 = -756.01*1000     #[J/mol] free energy of the bisulphate ion\n",
      "\n",
      "delta_g_1 = g_0_H + g_0_SO4 - g_0_HSO4      #[J/mol]\n",
      "\n",
      "K_2 = math.exp((-delta_g_1)/(R*T))\n",
      "\n",
      "\n",
      "\n",
      "def F(e):\n",
      "    f = [0,0]\n",
      "    f[0] = ((e[0]-e[1])*(e[0]+e[1]))/(1-e[0]) - K_1\n",
      "    f[1] = ((e[1])*(e[0]+e[1]))/(e[0]-e[1]) - K_2\n",
      "    return f\n",
      "\n",
      "e = [0.8,0.1]\n",
      "y = fsolve(F,e)\n",
      "e_1 = y[0]\n",
      "e_2 = y[1]\n",
      "\n",
      "m_H2SO4 = 1-e_1             # [molal]\n",
      "m_HSO4 = e_1 - e_2          #[molal]\n",
      "m_SO4 = e_2                 #[molal]\n",
      "m_H = e_1 + e_2             #[molal]\n",
      "\n",
      "print \" The equilibrium concentration of H2SO4 in terms of molality is %f molal\"%(m_H2SO4)\n",
      "print \" The equilibrium concentration of HSO4- in terms of molality is %f molal\"%(m_HSO4)\n",
      "print \" The equilibrium concentration of SO4-- in terms of molality is %f molal\"%(m_SO4)\n",
      "print \" The equilibrium concentration of H+ in terms of molality is    %f molal\"%(m_H)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The equilibrium concentration of H2SO4 in terms of molality is 0.009444 molal\n",
        " The equilibrium concentration of HSO4- in terms of molality is 0.980653 molal\n",
        " The equilibrium concentration of SO4-- in terms of molality is 0.009903 molal\n",
        " The equilibrium concentration of H+ in terms of molality is    1.000459 molal\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 13.3   Page: 352\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "from scipy.optimize import fsolve \n",
      "import math \n",
      "\n",
      "P = 10.             #[MPa] given pressure\n",
      "T = 250.            #[C] Temperature\n",
      "n_T_0 = 1.          #[mol]\n",
      "n_CO = 0.15         #[mol]\n",
      "n_CO2 = 0.08        #[mol]\n",
      "n_H2 = 0.74         #[mol]\n",
      "n_CH4 = 0.03        #[mol]\n",
      "\n",
      "\n",
      "\n",
      "V_1 = -2\n",
      "V_2 = 0\n",
      "K_1 = 49.9          # For the first reaction \n",
      "K_2 = 0.032         # For the second reaction\n",
      "\n",
      "v_CO_1 = -1\n",
      "v_H2_1 = -2\n",
      "v_CH3OH_1 = +1\n",
      "v_CO2_2 = -1\n",
      "v_H2_2 = -1\n",
      "v_CO_2 = +1\n",
      "v_H2O_2 = +1\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "def F(e):\n",
      "    f = [0,0]\n",
      "    f[0] = ((0 + e[0])/(1 - 2*e[0]))/(((0.15 - e[0] + e[1])/(1 - 2*e[0]))*((0.74 - 2*e[0] - e[1])/(1 - 2*e[0]))**(2)) - K_1\n",
      "    f[1] = (((0.15 - e[0] + e[1])/(1 - 2*e[0]))*((0 + e[1])/(1 - 2*e[0])))/(((0.08 - e[1])/(1 - 2*e[0]))*((0.74 - 2*e[0] - e[1])/(1 - 2*e[0]))) - K_2\n",
      "    return f\n",
      "\n",
      "\n",
      "e = [0.109, 0]\n",
      "y = fsolve(F,e)\n",
      "e_1 = y[0]\n",
      "e_2 = y[1]\n",
      "\n",
      "c_CO2 = e_2/(n_CO2)*100\n",
      "c_CO = e_1/(n_CO + 0.032)*100\n",
      "\n",
      "print \" Percent conversion of CO is %f%%\"%(c_CO)\n",
      "print \" Percent conversion of CO2 is %f%%\"%(c_CO2)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Percent conversion of CO is 96.815234%\n",
        " Percent conversion of CO2 is 47.930771%\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 13.4  Page: 354\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math \n",
      "\n",
      "T = 273.15+25           #[K] Temperature\n",
      "R = 8.314               #[J/(mol*K)] universal gas consmath.tant\n",
      "\n",
      "g_0_Ag = 77.12*1000         #[J/mol]\n",
      "g_0_Cl = -131.26*1000       #[J/mol]\n",
      "g_0_AgCl = -109.8*1000      #[J/mol]\n",
      "\n",
      "delta_g_0 = g_0_Ag + g_0_Cl - g_0_AgCl      #[J/mol]\n",
      "\n",
      "K = math.exp((-delta_g_0)/(R*T))\n",
      "\n",
      "\n",
      "a_AgCl = 1.00\n",
      "\n",
      "print \"The amount of solid dissolved in terms of solubility product is %0.2e\"%(K)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The amount of solid dissolved in terms of solubility product is 1.77e-10\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 13.5   Page: 357\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "import math \n",
      "\n",
      "T = 273.15+25           #[K] Given temperature of air\n",
      "P = 1.                  #[atm] Pressure of the air\n",
      "y_CO2 = 350.*10**(-6)   # Amount of CO2 present in air at the given condition \n",
      "R = 8.314               #[J/(mol*K)]\n",
      "\n",
      "g_0_H2CO3 = -623.1*1000         #[J/mol]\n",
      "g_0_H = 0.                      #[J/mol]\n",
      "g_0_HCO3 = -586.85*1000         #[J/mol]\n",
      "\n",
      "delta_g_0 = g_0_H + g_0_HCO3 - g_0_H2CO3            #[J/mol]\n",
      "K_1 = math.exp((-delta_g_0)/(R*T)) \n",
      "\n",
      "g_0_CO3 = -527.89*1000          #[J/mol]\n",
      "\n",
      "delta_g_1 = g_0_H + g_0_CO3 - g_0_HCO3          #[J/mol]\n",
      "K_2 = math.exp((-delta_g_1)/(R*T))\n",
      "\n",
      "\n",
      "H = 1480.               #[atm]\n",
      "\n",
      "x_CO2 = P*y_CO2/H\n",
      "\n",
      "n_water = 1000/18.                  #[mol]\n",
      "m_CO2 = x_CO2*n_water               #[molal]\n",
      "\n",
      "m_HCO3 = math.sqrt(K_1*m_CO2)       #[molal]\n",
      "m_H = m_HCO3                        #[molal]\n",
      "\n",
      "m_CO3 = K_2*(m_HCO3/m_H)            #[molal]\n",
      "\n",
      "print \" Amount of the CO2 dissolved in water in equilibrium with air is \\t\\t\\t%0.2e molal\"%(m_CO2)\n",
      "print \" Conentration of HCO3 ion and hydrogen ion H- in solution in equilibrium with air is    %0.2e molal\"%(m_HCO3)\n",
      "print \" And concentration of CO3 ion in the solution in equilibrium with air is\\t\\t%0.2e molal\"%(m_CO3)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Amount of the CO2 dissolved in water in equilibrium with air is \t\t\t1.31e-05 molal\n",
        " Conentration of HCO3 ion and hydrogen ion H- in solution in equilibrium with air is    2.42e-06 molal\n",
        " And concentration of CO3 ion in the solution in equilibrium with air is\t\t4.68e-11 molal\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 13.6   Page: 358\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "import math \n",
      "\n",
      "m_H = 10**(-10)         #[molal] molality of hydrogen ion\n",
      "K_1 = 4.5*10**(-7)\n",
      "K_2 = 4.7*10**(-11)\n",
      "\n",
      "m_CO2 = 1.32*10**(-5)           #[molal] from previous example\n",
      "m_HCO3 = K_1*(m_CO2/m_H)        #[molal]\n",
      "\n",
      "m_CO3 = K_2*(m_HCO3/m_H)        #[molal]\n",
      "\n",
      "print \" Amount of the CO2 dissolved in water in equilibrium with air is    \\t%0.2e molal\"%(m_CO2)\n",
      "print \" Conentration of HCO3 ion in solution in equilibrium with air is \\t %0.2e molal\"%(m_HCO3)\n",
      "print \" And concentration of CO3 ion in the solution in equilibrium with air is  %0.2e molal\"%(m_CO3)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Amount of the CO2 dissolved in water in equilibrium with air is    \t1.32e-05 molal\n",
        " Conentration of HCO3 ion in solution in equilibrium with air is \t 5.94e-02 molal\n",
        " And concentration of CO3 ion in the solution in equilibrium with air is  2.79e-02 molal\n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 13.7   Page: 362\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math \n",
      "\n",
      "T = 298.15          #[K] Temperature\n",
      "F = 96500.          #[(coulomb)/(mole*electrons)] faraday consmath.tant\n",
      "\n",
      "\n",
      "n_e = 6.            #[electron]\n",
      "g_0_CO2 = -394.4*1000           #[J/mol] \n",
      "g_0_Al = 0                      #[J/mol]\n",
      "g_0_C = 0                       #[J/mol]\n",
      "g_0_Al2O3 = -1582.3*1000        #[J/mol]\n",
      "\n",
      "delta_g_0 = 1.5*g_0_CO2 + 2*g_0_Al - 1.5*g_0_C - g_0_Al2O3          #[J/mol]\n",
      "\n",
      "E_0 = (-delta_g_0)/(n_e*F)      #[V]\n",
      "\n",
      "print \"Standard state cell voltage for the production of aluminium is %f Volt\"%(E_0)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Standard state cell voltage for the production of aluminium is -1.711054 Volt\n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 13.8  Page: 362\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "T = 298.15          #[K] Temperature\n",
      "F = 96500.          #[(coulomb)/(mole*electrons)] faraday consmath.tant\n",
      "\n",
      "delta_g_0 = -587.7*1000         #[J/mol]\n",
      "n_e = 1                         #[electron] no of electron transferred\n",
      "E_298_0 = (-delta_g_0)/(n_e*F)          #[V]\n",
      "\n",
      "print \"The reversible voltage for given electrochemical device is %f Volt\"%(E_298_0)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The reversible voltage for given electrochemical device is 6.090155 Volt\n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 13.9   Page: 363\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math \n",
      "\n",
      "T = 298.15      #[K] Temperature\n",
      "P_0 = 1.        #[atm]\n",
      "P = 100.        #[atm]\n",
      "E_0 = -1.229    #[V]\n",
      "F = 96500.      #[(coulomb)/(mole*electrons)] faraday consmath.tant\n",
      "R = 8.314       #[J/(mol*K)] universal gas consmath.tant \n",
      "\n",
      "n_e = 2.        #[(mole electrons)/mole]\n",
      "\n",
      "\n",
      "\n",
      "E = E_0 - 1.5*(R*T)*math.log(P/P_0)/(n_e*F)\n",
      "\n",
      "print \"The equilibrium cell voltage of electrolytic cell if feed and product are at the pressure 100 atm is %f Volt\"%(E)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The equilibrium cell voltage of electrolytic cell if feed and product are at the pressure 100 atm is -1.317721 Volt\n"
       ]
      }
     ],
     "prompt_number": 21
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 13.10  Page: 365 \n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math \n",
      "\n",
      "T = 273.15+25           #[K] Temperature\n",
      "P = 11.38/760           #[atm] Pressure\n",
      "R = 0.08206             #[(L*atm)/(mol*K)] Gas consmath.tant\n",
      "v = 0.6525/0.04346      #[L/g] Specific volume \n",
      "M = 60.05               #[g/mol] Molecular weight of HAc in the monomer form\n",
      "\n",
      "V = v*M                 #[L/mol]\n",
      "\n",
      "z = (P*V)/(R*T)\n",
      "\n",
      "print \"The value of the compressibility factor for HAc at given condition is %f\"%(z) \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of the compressibility factor for HAc at given condition is 0.551780\n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 13.11   Page: 366\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "from scipy.optimize import fsolve \n",
      "import math \n",
      "\n",
      "T = 273.15+25       #[K] Temperature\n",
      "P = 11.38           #[torr] Pressure\n",
      "\n",
      "\n",
      "K = 10**(-10.4184 + 3164/T)         #[1/torr]\n",
      "\n",
      "\n",
      "def f(y_HAc_2): \n",
      "\t return  K*(P*(1-y_HAc_2))**(2)/P-y_HAc_2\n",
      "y_HAc_2 = fsolve(f,0)\n",
      "y_HAc = 1-y_HAc_2\n",
      "\n",
      "print \"Mole fraction of the monomer in the vapour phase is %f\"%(y_HAc)\n",
      "print \"Mole fraction of the dimer in the vapour phase is   %f\"%(y_HAc_2)\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Mole fraction of the monomer in the vapour phase is 0.210713\n",
        "Mole fraction of the dimer in the vapour phase is   0.789287\n"
       ]
      }
     ],
     "prompt_number": 23
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 13.12  Page: 367\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math \n",
      "\n",
      "T = 273.15+25           #[K] Temperature\n",
      "P = 11.38/760           #[atm] Pressure\n",
      "R = 0.08206             #[(L*atm)/(mol*K)] Gas consmath.tant\n",
      "v = 0.6525/0.04346      #[L/g] Specific volume \n",
      "\n",
      "y_HAc = 0.211           # monomer \n",
      "y_HAc_2 = 0.789         # dimer\n",
      "\n",
      "M_HAc = 60.05           #[g/mol] monomer \n",
      "M_HAc_2 = 120.10        #[g/mol] dimer\n",
      "\n",
      "M_avg = M_HAc*y_HAc + M_HAc_2*y_HAc_2           #[g/mol]\n",
      "\n",
      "V = v*M_avg             #[L/mol]\n",
      "\n",
      "z = (P*V)/(R*T)\n",
      "\n",
      "print \"The compressibility factor z for the gaseous mixture is %f\"%(z)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The compressibility factor z for the gaseous mixture is 0.987135\n"
       ]
      }
     ],
     "prompt_number": 25
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}