summaryrefslogtreecommitdiff
path: root/Physical_And_Chemical_Equilibrium_For_Chemical_Engineers/ch12.ipynb
diff options
context:
space:
mode:
authorJovina Dsouza2014-06-18 12:43:07 +0530
committerJovina Dsouza2014-06-18 12:43:07 +0530
commit206d0358703aa05d5d7315900fe1d054c2817ddc (patch)
treef2403e29f3aded0caf7a2434ea50dd507f6545e2 /Physical_And_Chemical_Equilibrium_For_Chemical_Engineers/ch12.ipynb
parentc6f0d6aeb95beaf41e4b679e78bb42c4ffe45a40 (diff)
downloadPython-Textbook-Companions-206d0358703aa05d5d7315900fe1d054c2817ddc.tar.gz
Python-Textbook-Companions-206d0358703aa05d5d7315900fe1d054c2817ddc.tar.bz2
Python-Textbook-Companions-206d0358703aa05d5d7315900fe1d054c2817ddc.zip
adding book
Diffstat (limited to 'Physical_And_Chemical_Equilibrium_For_Chemical_Engineers/ch12.ipynb')
-rw-r--r--Physical_And_Chemical_Equilibrium_For_Chemical_Engineers/ch12.ipynb916
1 files changed, 916 insertions, 0 deletions
diff --git a/Physical_And_Chemical_Equilibrium_For_Chemical_Engineers/ch12.ipynb b/Physical_And_Chemical_Equilibrium_For_Chemical_Engineers/ch12.ipynb
new file mode 100644
index 00000000..1f171743
--- /dev/null
+++ b/Physical_And_Chemical_Equilibrium_For_Chemical_Engineers/ch12.ipynb
@@ -0,0 +1,916 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 12 : Chemical Equilibrium"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ " Example 12.1 Page: 311\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# find The chemical equilibrium composition of the gaseous mixture contains\n",
+ "\n",
+ "import math \n",
+ "\n",
+ "# Variables\n",
+ "T = 298.15 #[K] temperature\n",
+ "P = 1. #[atm] pressure \n",
+ "R = 8.314*10**(-3) #[kJ/(mol*K)]\n",
+ "\n",
+ "# Calculations\n",
+ "# For an ideal binary solution the Gi# Calculationss free energy is given by\n",
+ "# g_mix = summation(x_i*g_i_0) + R*T*summation(x_i*math.log(x_i))\n",
+ "# Differentiating the above equation with respect to x_a , remembering that for a binary mixture dx_b = dx_a, finding\n",
+ "\n",
+ "# dg_mix/dx_a = g_a_0-g_b_0+R*T*[math.log(x_a)+1-(math.log(x_b)+1)]\n",
+ "# and x_a+x_b = 1\n",
+ "# so\n",
+ "# dg_mix/dx_a = g_a_0-g_b_0+R*T*[math.log(x_a/(1-x_a))]\n",
+ "\n",
+ "# setting up this equal to zero ( to find the minimum on the g-x curve ) and solving gives\n",
+ "# x_a/(1-x_a) = exp((g_b_0-g_a_0)/(R*T))\n",
+ "\n",
+ "# From the table A.8 (page 427) reported in the book, pure component Gibbs free energies for isobumath.tane,a,and n-bumath.tane,b, we find\n",
+ "g_a_0 = -20.9 #[kJ/mol]\n",
+ "g_b_0 = -17.2 #[kJ/mol]\n",
+ "\n",
+ "# Now solving the above equation for x_a, we have\n",
+ "x_a = math.exp((g_b_0-g_a_0)/(R*T))/(1+math.exp((g_b_0-g_a_0)/(R*T)))\n",
+ "x_b = 1-x_a\n",
+ "\n",
+ "# Results\n",
+ "print \" The chemical equilibrium composition of the gaseous mixture contains %f mol fraction isobutane \\t\\t\\t\\t\\t\\t\\t\\tan %f mol fraction n-bumath.tane\"%(x_a,x_b)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The chemical equilibrium composition of the gaseous mixture contains 0.816475 mol fraction isobutane \t\t\t\t\t\t\t\tan 0.183525 mol fraction n-bumath.tane\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ " Example 12.2 Page: 319\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''\n",
+ "find\n",
+ "The equilibrium consmath.tant for the reaction\n",
+ "The concentration of NO at equilibrium\n",
+ "The equilibrium constant\n",
+ "The concentration of NO \n",
+ "'''\n",
+ "import math \n",
+ "\n",
+ "# Variables\n",
+ "T = 298.15 #[K] temperature\n",
+ "P = 0.987 #[atm] pressure\n",
+ "g_0_NO = 86.6 #[kJ/mol] Free energy of formation the NO from elements\n",
+ "R = 8.314 #[J/(mol*K)]\n",
+ "\n",
+ "# And the corresponding values for the elements N2 and O2 are\n",
+ "g_0_O2 = 0.00\n",
+ "g_0_N2 = 0.00\n",
+ "\n",
+ "# The reaction of the nitrogen and oxygen to form nitric oxide at 298.15 K is\n",
+ "# N2 + O2 = NO\n",
+ "\n",
+ "# Calculations\n",
+ "# Here \n",
+ "delta_g_0 = 2*g_0_NO - g_0_O2 - g_0_N2 #[kJ/mol]\n",
+ "# Changing in the J/mol \n",
+ "delta_g_01 = delta_g_0*1000 #[J/mol]\n",
+ "\n",
+ "# hence \n",
+ "K_298 = math.exp((-delta_g_01)/(R*T))\n",
+ "\n",
+ "# The activities are all \n",
+ "# a_i = f_i/f_i_0\n",
+ "# f_i_0 correspond to the smath.radians(numpy.arcmath.tan(ard state, which for gas at idael gas state are \n",
+ "f_0_N2 = 1. #[bar]\n",
+ "f_0_O2 = 1. #[bar]\n",
+ "f_0_NO = 1. #[bar]\n",
+ "\n",
+ "# If we make the most general statement of the activities (for gases ) we would have\n",
+ "# a_i = y_i*v_i*Y_i*P/f_i_0 = y_i*phi*P/f_i_0\n",
+ "\n",
+ "# At this low pressure we may safely asssume that the NO,O2 and N2 behave as ideal gases for which v_i*Y_i = phi = 1.00 and substituting these we find\n",
+ "# K_298 = [a_NO]**(2)/([a_N2]*[a_O2]) = [y_NO]**(2)/([y_N2]*[y_O2])\n",
+ "\n",
+ "# Now umath.sing this equilibrium consmath.tant we can calculare he equilibrium concentratin of NO in the air sample in which \n",
+ "#oxygen = 21%, nitrogen = 78% and argon = 1% ,so\n",
+ "y_N2 = 0.78\n",
+ "y_O2 = 0.21\n",
+ "\n",
+ "# Hence From above expression, we have\n",
+ "y_NO_298 = math.sqrt(K_298*y_N2*y_O2)\n",
+ "\n",
+ "# Making the similar calculations for the temperature 2000 K, we have\n",
+ "T_1 = 2000 #[K]\n",
+ "K_2000 = 4.0*10**-4\n",
+ "\n",
+ "# So,\n",
+ "y_NO_2000 = math.sqrt(K_2000*y_N2*y_O2)*10**(6) #[ppm]\n",
+ "\n",
+ "# Results\n",
+ "print \" The equilibrium constant for the reaction at 298.15 K is \\t\\t\\t %.1e\"%(K_298)\n",
+ "print \" The concentration of NO at equilibrium at temperature 298.15 K is \\t\\t %.1e\"%(y_NO_298)\n",
+ "print \" The equilibrium consmath.tant for the reaction at 2000 K is \\t\\t\\t %.1e\"%(K_2000)\n",
+ "print \" The concentration of NO at equilibrium at temperature 2000 K is \\t\\t %.0f ppm\"%(round(y_NO_2000,-2))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The equilibrium constant for the reaction at 298.15 K is \t\t\t 4.5e-31\n",
+ " The concentration of NO at equilibrium at temperature 298.15 K is \t\t 2.7e-16\n",
+ " The equilibrium consmath.tant for the reaction at 2000 K is \t\t\t 4.0e-04\n",
+ " The concentration of NO at equilibrium at temperature 2000 K is \t\t 8100 ppm\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ " Example 12.3 Page: 321\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# find The calculated NO cocentration\n",
+ "\n",
+ "from scipy.optimize import fsolve \n",
+ "import math \n",
+ "\n",
+ "# Variables\n",
+ "Temp = 2000. #[K]\n",
+ "n_air = 1. #[mol] no of moles of the air\n",
+ "\n",
+ "# Let the moless of the NO formed be 2*x\n",
+ "# Then at equilibrium the unreacted moles of the N2 and O2 will be (0.78-x) and (0.21-x) respectively\n",
+ "\n",
+ "# Calculations\n",
+ "# from the previous example, we have \n",
+ "# [y_NO]**(2) = K_298*[y_N2]*[y_O2]\n",
+ "# here \n",
+ "K_2000 = 4*10**(-4)\n",
+ "# Substituting all the values, we have \n",
+ "# (2*x)**(2) = K_2000*(0.78-x)*(0.21-x)\n",
+ "\n",
+ "#Now \n",
+ "def f(x): \n",
+ "\t return (2*x)**(2) - K_2000*(0.78-x)*(0.21-x)\n",
+ "#def f(x): \n",
+ "\t #return (K_2000-2)*x**(2)-K_2000*(0.78+0.21)*x+K_2000*0.78*0.21\n",
+ "x = fsolve(f,0)\n",
+ "# Here negative root is meaningless,so\n",
+ "# concentration of NO\n",
+ "c_NO = 2*x*10**(6) #[ppm]\n",
+ "# now\n",
+ "p = c_NO/8100.*100\n",
+ "\n",
+ "# Results\n",
+ "print \" The calculated NO cocentration is %f ppm, which %f%% of the value computed in example 12.1\"%(c_NO,p)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The calculated NO cocentration is 7996.442873 ppm, which 98.721517% of the value computed in example 12.1\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ " Example 12.5 Page: 324\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''\n",
+ "find\n",
+ "Concentration of the ethylene \n",
+ "Concentration of the water \n",
+ "Concentration of the ethanol\n",
+ "'''\n",
+ "\n",
+ "from scipy.optimize import fsolve \n",
+ "import math \n",
+ "\n",
+ "# Variables\n",
+ "Temp = 298. #[K]\n",
+ "K = 29.6 # equilibrium consmath.tant at 298 K \n",
+ "P = 1. #[bar]\n",
+ "n_water_0 = 0.833 #[mol]\n",
+ "n_ethylene_0 = 1. #[mol]\n",
+ "n_ethanol_0 = 0. #[mol]\n",
+ "\n",
+ "# Calculations\n",
+ "n_T_0 = (n_water_0+n_ethylene_0+n_ethanol_0) #[mol]\n",
+ "\n",
+ "# From the previous example, we have \n",
+ "# [(0+e)/(1.833-e)]/([(1-e)/(1.833-e)]*[(0.833-e)/(1.833-e)]) = K*P/(1 bar)\n",
+ "# let y = [(0+e)/(1.833-e)]/([(1-e)/(1.833-e)]*[(0.833-e)/(1.833-e)])- K*P/(1 bar)\n",
+ "def f(e): \n",
+ "\t return ((0+e)/(1.833-e))/(((1-e)/(1.833-e))*((0.833-e)/(1.833-e)))-K*P/(1)\n",
+ "e_1 = fsolve(f,0)\n",
+ "e_2 = fsolve(f,0.5)\n",
+ "\n",
+ "# Here the root 'e_2' is meaningless, Then \n",
+ "y_ethanol = ((0+e_2)/(1.833-e_2))\n",
+ "y_ethylene = ((1-e_2)/(1.833-e_2))\n",
+ "y_water = ((0.833-e_2)/(1.833-e_2))\n",
+ "\n",
+ "# Results\n",
+ "print \"Concentration of the ethylene at the equilibrium is %f\"%(y_ethylene)\n",
+ "print \" Concentration of the water at the equilibrium is %f\"%(y_water)\n",
+ "print \" Concentration of the ethanol at the equilibrium is %f\"%(y_ethanol)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Concentration of the ethylene at the equilibrium is 0.243702\n",
+ " Concentration of the water at the equilibrium is 0.092079\n",
+ " Concentration of the ethanol at the equilibrium is 0.664219\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ " Example 12.6 Page: 324\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''\n",
+ "find\n",
+ "The equilibrium mol fraction of the hydrogen \n",
+ "And the equilibrium mol fraction of the oxygen\n",
+ "'''\n",
+ "\n",
+ "from scipy.optimize import fsolve \n",
+ "import math \n",
+ "\n",
+ "# Variables\n",
+ "Temp = 273.15+25 #[C]\n",
+ "P = 1. #[bar]\n",
+ "R = 8.314 #[J/(mol*K)]\n",
+ "\n",
+ "# We have the reaction as \n",
+ "# H2 + 0.5O2 = H2O\n",
+ "# Using values of the Gibbs free energies of formation in the Table A.8(page 427) we have\n",
+ "g_H2O_0 = -237.1 #[kJ/mol]\n",
+ "g_O2_0 = 0 #[kJ/mol]\n",
+ "g_H2_0 = 0 #[kJ/mol]\n",
+ "\n",
+ "# Calculations\n",
+ "# now\n",
+ "delta_g_0 = g_H2O_0 - 0.5*g_O2_0-g_H2_0 #[kJ/mol]\n",
+ "# expresmath.sing delta_g_0 in [J/mol] \n",
+ "delta_g_1 = delta_g_0*1000 #[J/mol]\n",
+ "\n",
+ "# and \n",
+ "K = math.exp((-delta_g_1)/(R*Temp))\n",
+ "# And we have \n",
+ "# K = [a_H2O]/([a_H2]*[a_O2]**(0.5))\n",
+ "# Here we will again assume as in the previous example that we have an ideal solution of the ideal gases for which in equation 12.18 (page 320),we have \n",
+ "# v_i*Y_i = phi = 1.00 , and that for each reacmath.tant or product f_i_0 = 1 bar, putting all the values and simplifying \n",
+ "\n",
+ "# K = [y_H2O]/([y_H2]*[y_O2]**(0.5))*((1 bar)/P)**(0.5)\n",
+ "# Choomath.sing oxygen as the selected reacmath.tant, and assuming that we begin with 0.5 mol of oxygen and 1 mol of hydrogen,\n",
+ "# we have the stoichiometric coefficients of -1, -0.5 and +1 \n",
+ "# and \n",
+ "n_T_0 = 1.5#[mol]\n",
+ "# Also summation(v_i) = -0.5\n",
+ "\n",
+ "# Thus \n",
+ "# K = [e/(1.5-0.5*e)]/([(1-e)/(1.5-0.5*e)]*[(0.5-0.5*e)/(1.5-0.5*e)]**(0.5))\n",
+ "\n",
+ "# Now \n",
+ "def f(e): \n",
+ "\t return (e/(1.5-0.5*e))/(((1-e)/(1.5-0.5*e))*((0.5-0.5*e)/(1.5-0.5*e))**(0.5))\n",
+ "# e = fsolve(f,.99999)\n",
+ "# e = (1-2.4e-28)\n",
+ "\n",
+ "# So the equilibrium concentration of the hydrogen and oxygen are as\n",
+ "# y_H2 = [(1-e)/(1.5-0.5*e)]\n",
+ "# y_O2 = [(0.5-0.5*e)/(1.5-0.5*e)]\n",
+ "# These values are so less that scilab consol is print laying them zero, however we get\n",
+ "y_H2 = 2.4e-28\n",
+ "y_O2 = 0.5*y_H2\n",
+ "\n",
+ "# Results\n",
+ "print \" The equilibrium mol fraction of the hydrogen is %0.3e\"%(y_H2)\n",
+ "print \" And the equilibrium mol fraction of the oxygen is %e \"%(y_O2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The equilibrium mol fraction of the hydrogen is 2.400e-28\n",
+ " And the equilibrium mol fraction of the oxygen is 1.200000e-28 \n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ " Example 12.7 Page: 327\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''\n",
+ "find\n",
+ "Total change in the free energy of water going under given conditions \n",
+ "and the free energy change\n",
+ "'''\n",
+ "import math \n",
+ "from scipy.integrate import quad \n",
+ "\n",
+ "# Variables\n",
+ "Temp = 298.15 #[K]\n",
+ "Press = 1*10**(5) #[Pa]\n",
+ "R = 8.314 #[J/(mol*K)]\n",
+ "\n",
+ "# Calculations\n",
+ "# We will calculate the free energy change from liquid to hypothetical gas in three steps\n",
+ "# 1) The liquid is reduced in pressure from the smath.radians(numpy.arcmath.tan(ard pressure of 1 bar to its vapour pressure at 298.15K and for this cange in the state we have \n",
+ "v_liquid = 1.805*10**(-5) #[m**(3)/mol] this liquid specific volume and we will treat is as a consmath.tant\n",
+ "\n",
+ "# The vapour preesure of the water 25C is given as\n",
+ "P_vapour_25 = 0.0317*10**(5) #[Pa]\n",
+ "\n",
+ "# thus change in the Gibbs free energy is \n",
+ "\n",
+ "def f0(P): \n",
+ "\t return v_liquid*P**(0)\n",
+ "\n",
+ "delta_g_0_1 = quad(f0,Press,P_vapour_25)[0]\n",
+ "\n",
+ "\n",
+ "# 2) In the second step the liquid is vaporized at that pressure, for which\n",
+ "delta_g_0_2 = 0 #[J/mol]\n",
+ "# because this is an equilibrium vaporization.\n",
+ "\n",
+ "# 3) And in this last step the vapour is replaced by an ideal gas, which will not condence, and compressed from the vapour pressure at 298.15K to 1 bar\n",
+ "# In this case the specific volume v_ideal of the ideal gas is replaced by the ideal gas law viz. (R*T)/P\n",
+ "\n",
+ "def f1(P): \n",
+ "\t return 1./P\n",
+ "\n",
+ "delta_g_0_3 = (R*Temp)* quad(f1,P_vapour_25,Press)[0]\n",
+ "\n",
+ "\n",
+ "# Thus total change in free energy is \n",
+ "delta_g_0 = delta_g_0_1+delta_g_0_2+delta_g_0_3 #[J/mol]\n",
+ "#expresmath.sing the result in kJ/mol\n",
+ "delta_g_1 = delta_g_0/1000 #[kJ/mol]\n",
+ "\n",
+ "# Results\n",
+ "print \" Total change in the free energy of water going under given conditions is %0.2f kJ/mol\"%(delta_g_1)\n",
+ "\n",
+ "# From Table A.8 we find \n",
+ "delta_g_0_ideal_gas = -228.6 #[kJ/mol]\n",
+ "delta_g_0_liquid = -237.1 #[kJ/mol]\n",
+ "# So \n",
+ "delta_g_o = delta_g_0_ideal_gas-delta_g_0_liquid #[kJ/mol]\n",
+ "\n",
+ "print \" From the values of Table A.8 given in the book the free energy change is %0.2f kJ/mol\"%(delta_g_o)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Total change in the free energy of water going under given conditions is 8.55 kJ/mol\n",
+ " From the values of Table A.8 given in the book the free energy change is 8.50 kJ/mol\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ " Example 12.8 Page: 330\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# find Equilibrium constants for the formation of ammonia from hydrogen and nitrogen are\n",
+ "import math \n",
+ "from scipy.integrate import quad \n",
+ "\n",
+ "# Variables\n",
+ "T1 = 273.15+25 #[K]\n",
+ "T2 = 273.15+400 #[K]\n",
+ "R = 8.314 #[J/(mol*K)]\n",
+ "\n",
+ "# Umath.sing the table A.8, we have\n",
+ "# Gibb's free energy of the various species at 298.15 K are\n",
+ "g0_NH3 = -16.5 #[kJ/mol]\n",
+ "g0_N2 = 0 #[kJ/mol]\n",
+ "g0_H2 = 0 #[kJ/mol]\n",
+ "\n",
+ "# We have the reaction as \n",
+ "# 0.5N2 + 1.5H2 = NH3\n",
+ "\n",
+ "# Calculations\n",
+ "# So, Gibb's free energy change in the reaction is given as \n",
+ "delta_g_0 = g0_NH3 - 0.5*g0_N2 - 1.5*g0_H2 #[kJ/mol]\n",
+ "\n",
+ "# and\n",
+ "K_1 = math.exp(-delta_g_0*1000/(R*T1)) # Equilibrium consmath.tant of the reaction at temperature 298.15 K\n",
+ "\n",
+ "# Similarly enthalpy of the various species are \n",
+ "h0_NH3 = -46.1 #[kJ/mol]\n",
+ "h0_N2 = 0 #[kJ/mol]\n",
+ "h0_H2 = 0 #[kJ/mol]\n",
+ "\n",
+ "# So, enthalpy change of the reaction is given as \n",
+ "del_h_1 = h0_NH3 - 0.5*h0_N2 - 1.5*h0_H2 #[kJ/mol]\n",
+ "\n",
+ "# Now, from Table 12.3( page 332 )\n",
+ "a_NH3 = 3.578\n",
+ "a_H2 = 3.249\n",
+ "a_N2 = 3.280\n",
+ "b_NH3 = 3.020*10**(-3) #[1/K]\n",
+ "b_H2 = 0.422*10**(-3)\n",
+ "b_N2 = 0.593*10**(-3)\n",
+ "c_NH3 = 0 #[1/K**(2)]\n",
+ "c_H2 = 0 #[1/K**(2)]\n",
+ "c_N2 = 0 #[1/K**(2)]\n",
+ "d_NH3 = -0.186*10**(5) #[K**(2)]\n",
+ "d_H2 = 0.083*10**(5) #[K**(2)]\n",
+ "d_N2 = 0.040*10**(5) #[K**(2)]\n",
+ "\n",
+ "# So,\n",
+ "del_a = a_NH3 - 0.5*a_N2 - 1.5*a_H2\n",
+ "del_b = b_NH3 - 0.5*b_N2 - 1.5*b_H2\n",
+ "del_c = c_NH3 - 0.5*c_N2 - 1.5*c_H2\n",
+ "del_d = d_NH3 - 0.5*d_N2 - 1.5*d_H2\n",
+ "\n",
+ "# Now, enthalpy change of the reaction at any other temparature is given by\n",
+ "# Integrating and putting the limits, we have\n",
+ "# del_h = del_h_1 + R*( del_a*T + del_b*T**(2)/2 + del_c*T**(3)/3 - del_d/T) - R*( del_a*T_1 + del_b*T_1**(2)/2 + del_c*T_1**(3)/3 - del_d/T_1)\n",
+ "# let\n",
+ "I = R*( del_a*T1 + del_b*T1**(2)/2 + del_c*T1**(3)/3 - del_d/T1) #[J/mol]\n",
+ "\n",
+ "# From equation 12.28 and above relations we have\n",
+ "# Let math.log(K_2/K_1) = X, So,\n",
+ "\n",
+ "def f5(T): \n",
+ "\t return (del_h_1*1000 - I + R*(del_a*T + del_b*T**(2)/2 + del_c*T**(3)/3 - del_d/T))/T**(2)\n",
+ "\n",
+ "X = (1/R)* quad(f5,T1,T2)[0]\n",
+ "\n",
+ "\n",
+ "# So, \n",
+ "K_2 = K_1*math.exp(X)\n",
+ "\n",
+ "# Results\n",
+ "print \" Equilibrium consmath.tants for the formation of ammonia from hydrogen and nitrogen are \"\n",
+ "print \" K = %0.0f at temperature 25 deg C\"%(K_1)\n",
+ "print \" K = %f at temperature 400 deg C\"%(K_2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Equilibrium consmath.tants for the formation of ammonia from hydrogen and nitrogen are \n",
+ " K = 778 at temperature 25 deg C\n",
+ " K = 0.013588 at temperature 400 deg C\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ " Example 12.9 Page: 335\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''\n",
+ "find\n",
+ "The mole fraction of NH3 in the equilibrium\n",
+ "The mole fraction of NH3 in the equilibrium\n",
+ "'''\n",
+ "\n",
+ "from scipy.optimize import fsolve \n",
+ "import math \n",
+ "\n",
+ "# Variables\n",
+ "# Initial moles of the gases are \n",
+ "n_H2_0 = 1.5 #[mol]\n",
+ "n_N2_0 = 0.5 #[mol]\n",
+ "n_NH3_0 = 0 #[mol]\n",
+ "T_1 = 298.15 #[K]\n",
+ "T_2 = 673.15 #[K]\n",
+ "P = 1. #[bar]\n",
+ "\n",
+ "# We start with the equation as \n",
+ "# [f_NH3/f_0_NH3]/([f_N2/f_0_N2]**(0.5)*[f_H2/f_0_H2]**(1.5)) = K\n",
+ "\n",
+ "# For a pressure of 1 bar with the assumption of ideal solution of ideal gases and smath.radians(numpy.arcmath.tan(ard state fugacities of 1 bar,\n",
+ "# a_i = [f_i/f_0_i] = [P*y_i/(1 bar)] = y_i \n",
+ "# The equilibrium relation is given by \n",
+ "# K = [y_NH3]/([y_N2]**(0.5)*[y_H2]**(1.5))\n",
+ "\n",
+ "# We have the stoichiometric coefficient of N2, H2 and NH3 as -0.5, -1.5 and +1 respectively, so summation(v_i) = -1\n",
+ "# Now umath.sing the equilibrium relations which are Equations 12.W, 12.X and 12.Y ( page 322 ), we have \n",
+ "\n",
+ "# K = ((0+e)/(2-e))/(((0.5-0.5*e)/(2-e))**(0.5)*((1.5-1.5*e)/(2-e))**(1.5))\n",
+ "# Form the example 12.8 of this book we know that \n",
+ "K_298 = 778. # at temperature 298.15K\n",
+ "K_673 = 0.013 # at temperature 673.15K\n",
+ "\n",
+ "# Calculations\n",
+ "# Solving for temperature 298.15\n",
+ "def g(e_1): \n",
+ "\t return ((0+e_1)/(2-e_1))/(((0.5-0.5*e_1)/(2-e_1))**(0.5)*((1.5-1.5*e_1)/(2-e_1))**(1.5))-K_298\n",
+ " \n",
+ "e_1 = fsolve(g,0.97)\n",
+ "y_NH3_298 = e_1/(2-e_1)\n",
+ "\n",
+ "# Similarily solving for temperature 673.15K\n",
+ "def h(e_2): \n",
+ "\t return ((0+e_2)/(2-e_2))/(((0.5-0.5*e_2)/(2-e_2))**(0.5)*((1.5-1.5*e_2)/(2-e_2))**(1.5))-K_673\n",
+ "\n",
+ "e_2 = fsolve(h,0)\n",
+ "y_NH3_673 = e_2/(2-e_2)\n",
+ "\n",
+ "# Results\n",
+ "print \" The mole fraction of NH3 in the equilibrium at the temperature 298.15K and 1 bar is %f\"%(y_NH3_298)\n",
+ "print \" The mole fraction of NH3 in the equilibrium at the temperature 673.15K and 1 bar is %f\"%(y_NH3_673)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The mole fraction of NH3 in the equilibrium at the temperature 298.15K and 1 bar is 0.939036\n",
+ " The mole fraction of NH3 in the equilibrium at the temperature 673.15K and 1 bar is 0.004187\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ " Example 12.10 Page: 337\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# find The mole fraction of the ammonia in the equilibrium\n",
+ "\n",
+ "from scipy.optimize import fsolve \n",
+ "import math \n",
+ "\n",
+ "# Variables\n",
+ "Temp = 273.15+400 #[K]\n",
+ "P = 150*1.01325 #[bar]\n",
+ "\n",
+ "# Comparing this with the example 12.9, we see that we can use the same equation , but K_673 is replaced by K_673*(P/(1bar))**(1.5+0.5-1)\n",
+ "K_673 = 0.013\n",
+ "\n",
+ "# So \n",
+ "K = K_673*(P/1)**(1.5+0.5-1)\n",
+ "\n",
+ "# Calculations\n",
+ "# We have \n",
+ "# K = ((0+e)/(2-e))/(((0.5-0.5*e)/(2-e))**(0.5)*((1.5-1.5*e)/(2-e))**(1.5))\n",
+ "def f(e): \n",
+ "\t return ((0+e)/(2-e))/(((0.5-0.5*e)/(2-e))**(0.5)*((1.5-1.5*e)/(2-e))**(1.5))-K\n",
+ "e=fsolve(f,0.5)\n",
+ "\n",
+ "# Thus mole fraction of the ammonia in the gas is given by \n",
+ "y_NH3 = (0+e)/(2-e)\n",
+ "\n",
+ "# Results\n",
+ "print \"The mole fraction of the ammonia in the equilibrium is %0.2f\"%(y_NH3)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The mole fraction of the ammonia in the equilibrium is 0.31\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ " Example 12.11 Page: 338\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# find The mole fraction of the ammonia in the equilibrium\n",
+ "\n",
+ "from scipy.optimize import fsolve \n",
+ "import math \n",
+ "\n",
+ "# Variables\n",
+ "# The data used in this example will e same as in the example 12.10\n",
+ "T = 273.15+400 #[K] given temperature\n",
+ "P = 150*1.01325 #[bar] given pressure\n",
+ "\n",
+ "# Here again the equation will be same as in the example 12.9 like we used in the example 12.10 only K_673 is replaced by (K/K_v)*[P/(1 bar)]**(1.5+0.5-1)\n",
+ "K_673 = 0.013\n",
+ "# The value of 'K_v' is calculated by the equation 12.BN, which is \n",
+ "# log10(1/K_v) = (0.1191849/T + 91.87212/T**(2) + 25122730/T**(4))*P\n",
+ "\n",
+ "# Calculations\n",
+ "# So \n",
+ "K_v = (10**((0.1191849/T + 91.87212/T**(2) + 25122730/T**(4))*P))**(-1)\n",
+ "\n",
+ "# Thus \n",
+ "K = (K_673/K_v)*(P/1)**(1.5+0.5-1)\n",
+ "\n",
+ "# Now from the previous example we have\n",
+ "# K = ((0+e)/(2-e))/(((0.5-0.5*e)/(2-e))**(0.5)*((1.5-1.5*e)/(2-e))**(1.5))\n",
+ "\n",
+ "def f(e): \n",
+ "\t return ((0+e)/(2-e))/(((0.5-0.5*e)/(2-e))**(0.5)*((1.5-1.5*e)/(2-e))**(1.5))-K\n",
+ "e = fsolve(f,0.2)\n",
+ "\n",
+ "# Mol fraction of the ammonia in the gas phase in the equilibrium is given by\n",
+ "y_NH3 = (0+e)/(2-e)\n",
+ "\n",
+ "# Results\n",
+ "print \" The mole fraction of the ammonia in the equilibrium is %0.2f\"%(y_NH3)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The mole fraction of the ammonia in the equilibrium is 0.34\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ " Example 12.12 Page: 340\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''\n",
+ "find\n",
+ "On increasing the pressure from 1 atm to 150 atm the reacted amount of the equimolar\n",
+ "reactants at equilibrium becomes times of initial\n",
+ "'''\n",
+ "\n",
+ "from scipy.optimize import fsolve \n",
+ "import math \n",
+ "\n",
+ "# Variables\n",
+ "p_i = 1. #[atm] initial pressure \n",
+ "P = 150. #[atm] final pressure\n",
+ "T = 273+25. #[K] Given temperature\n",
+ "R = 8.314 #[J/(mol*K)]\n",
+ "\n",
+ "# Now ignoring the difference between 25C and 20C, we use the values given in the table A.8 (page 427) to get \n",
+ "delta_g_0 = 10.54*1000 #[J/mol]\n",
+ "# And thus \n",
+ "\n",
+ "# Calculations\n",
+ "K = math.exp((-delta_g_0)/(R*T))\n",
+ "\n",
+ "# Now the chemical reaction is given by\n",
+ "# C2H5OH + CH3COOH = C2H5OOC2H5 + H2O\n",
+ "\n",
+ "# Let we start with 1 mol each of ethanol and acetic acid, and at equilibrium 'e' moles each of the reacmath.tants reacted, then\n",
+ "# remaining amount of each of the two reacmath.tants will be (1-e) and that products formation will be 'e' mol each\n",
+ "\n",
+ "# We have \n",
+ "# K = (a_C2H5OOC2H5*a_H2O)/(a_C2H5OH*a_CH3COOH) = (x_C2H5OOC2H5*x_H2O)/(x_C2H5OH*x_CH3COOH) = (e*e)/((1-e)*(1-e))\n",
+ "# Now solving for 'e'\n",
+ "def f(e): \n",
+ "\t return (e*e)/((1-e)*(1-e))-K\n",
+ "e = fsolve(f,0)\n",
+ "\n",
+ "# To see the effect of changing the pressure we first compute the volume increase of the reaction \n",
+ "# delta_v = v_C2H5OOC2H5 + v_H2O - v_C2H5OH - v_CH3COOH, where v_i is the molar volume of the ith component\n",
+ "# From the Table 12.4(page 340), we have\n",
+ "v_C2H5OOC2H5 = 97.67 #[ml/mol]\n",
+ "v_H2O = 18.03 #[ml/mol]\n",
+ "v_C2H5OH = 58.30 #[ml/mol]\n",
+ "v_CH3COOH = 57.20 #[ml/mol]\n",
+ "\n",
+ "# Thus volume increase of the reaction is\n",
+ "delta_v = v_C2H5OOC2H5 + v_H2O - v_C2H5OH - v_CH3COOH #[ml/mol]\n",
+ "\n",
+ "# So, from Le Chatelier's principal, on increamath.sing the pressure , the reaction is forced in the direction of the reacmath.tant or away from the product \n",
+ "# To calculate the extent of shifting we will take the help of the activity of each of the four component \n",
+ "# a_i = (f_i/f_i_0) = (x_i*Y_i*p_i)/p_i*exp(v/(R*T)*(P-p_i))\n",
+ "# we will assume that this is an ideal solution so that Y_i = 1.00, for every component\n",
+ "\n",
+ "# Now substituting the activity of each component in the expression of the equilibrium consmath.tant given above, we have\n",
+ "# K = (x_C2H5OOC2H5*x_H2O)/(x_C2H5OH*x_CH3COOH)*exp[(delta_v)/(R*T)*(P-p_i)]\n",
+ "# or\n",
+ "# K = (e_1*e_1)/((1-e_1)*(1-e_1))*exp[(delta_v)/(R*T)*(P-p_i)]\n",
+ "\n",
+ "# Solving for 'e_1'\n",
+ "def g(e_1): \n",
+ "\t return (e_1*e_1)/((1-e_1)*(1-e_1))*math.exp((delta_v)/(R*T)*(P-p_i))-K\n",
+ "e_1 = fsolve(g,0.2)\n",
+ "\n",
+ "# Now if we carry out the calculation to enough significant figures then\n",
+ "a = e_1/e\n",
+ "\n",
+ "# It indicates that e_1 is 'a' times of that of the e\n",
+ "\n",
+ "# Results\n",
+ "print \"On increamath.sing the pressure from 1 atm to 150 atm the reacted amount of the equimolar \\\n",
+ "reacmath.tants at equilibrium becomes %f times of initial\"%(a)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On increamath.sing the pressure from 1 atm to 150 atm the reacted amount of the equimolar reacmath.tants at equilibrium becomes 0.994639 times of initial\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ " Example 12.13 Page: 342\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# find Value of the K_p at the given condition\n",
+ "\n",
+ "import math \n",
+ "\n",
+ "# Variables\n",
+ "P = 150. #[atm] given pressure\n",
+ "T = 400. #[C] temperature\n",
+ "# Umath.sing the values from the example 12.11, we know that\n",
+ "K = 0.013\n",
+ "K_v = 0.84\n",
+ "delta_v = 1.5+0.5-1\n",
+ "\n",
+ "# Calculations\n",
+ "# so \n",
+ "# K_p = (K/K_v)*[1/bar]**(-summation(v_i)) = (K/K_v)*[1/bar]**(delta_v)\n",
+ "\n",
+ "K_p = (K/K_v)*(1/1)**(delta_v) #[1/bar]\n",
+ "\n",
+ "# Results\n",
+ "print \" Value of the K_p at the given condition is %f 1/bar)\"%(K_p)\n",
+ "print \" The basic K is dimensionless%( but K_p has the dimensions of pressure to the power.\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Value of the K_p at the given condition is 0.015476 1/bar)\n",
+ " The basic K is dimensionless%( but K_p has the dimensions of pressure to the power.\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file