summaryrefslogtreecommitdiff
path: root/Physical_And_Chemical_Equilibrium_For_Chemical_Engineers/ch12.ipynb
blob: 210f4e9f053129dc4cc22ade1cbb06593c4f7915 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
{
 "metadata": {
  "name": "",
  "signature": "sha256:0a1da29e7840a18bf7735e26f0a43477053969d9c5f5a2bfceee638c83ec8906"
 },
 "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": [
      "\n",
      "import math \n",
      "\n",
      "T = 298.15      #[K] temperature\n",
      "P = 1.          #[atm] pressure \n",
      "R = 8.314*10**(-3)      #[kJ/(mol*K)]\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "g_a_0 = -20.9       #[kJ/mol]\n",
      "g_b_0 = -17.2       #[kJ/mol]\n",
      "\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",
      "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",
      "import math \n",
      "\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",
      "g_0_O2 = 0.00\n",
      "g_0_N2 = 0.00\n",
      "\n",
      "\n",
      "delta_g_0 = 2*g_0_NO - g_0_O2 - g_0_N2          #[kJ/mol]\n",
      "delta_g_01 = delta_g_0*1000                     #[J/mol]\n",
      "\n",
      "K_298 = math.exp((-delta_g_01)/(R*T))\n",
      "\n",
      "f_0_N2 = 1.             #[bar]\n",
      "f_0_O2 = 1.             #[bar]\n",
      "f_0_NO = 1.             #[bar]\n",
      "\n",
      "\n",
      "\n",
      "y_N2 = 0.78\n",
      "y_O2 = 0.21\n",
      "\n",
      "y_NO_298 = math.sqrt(K_298*y_N2*y_O2)\n",
      "\n",
      "T_1 = 2000                  #[K]\n",
      "K_2000 = 4.0*10**-4\n",
      "\n",
      "y_NO_2000 = math.sqrt(K_2000*y_N2*y_O2)*10**(6)         #[ppm]\n",
      "\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": [
      "\n",
      "from scipy.optimize import fsolve \n",
      "import math \n",
      "\n",
      "Temp = 2000.                #[K]\n",
      "n_air = 1.                  #[mol] no of moles of the air\n",
      "\n",
      "\n",
      "K_2000 = 4*10**(-4)\n",
      "\n",
      "def f(x): \n",
      "\t return  (2*x)**(2) - K_2000*(0.78-x)*(0.21-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",
      "c_NO = 2*x*10**(6)              #[ppm]\n",
      "p = c_NO/8100.*100\n",
      "\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",
      "\n",
      "from scipy.optimize import fsolve \n",
      "import math \n",
      "\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",
      "n_T_0 = (n_water_0+n_ethylene_0+n_ethanol_0)        #[mol]\n",
      "\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",
      "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",
      "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",
      "\n",
      "from scipy.optimize import fsolve \n",
      "import math \n",
      "\n",
      "Temp = 273.15+25            #[C]\n",
      "P = 1.                      #[bar]\n",
      "R = 8.314                   #[J/(mol*K)]\n",
      "\n",
      "g_H2O_0 = -237.1            #[kJ/mol]\n",
      "g_O2_0 = 0                  #[kJ/mol]\n",
      "g_H2_0 = 0                  #[kJ/mol]\n",
      "\n",
      "delta_g_0 = g_H2O_0 - 0.5*g_O2_0-g_H2_0         #[kJ/mol]\n",
      "delta_g_1 = delta_g_0*1000                      #[J/mol]\n",
      "\n",
      "K = math.exp((-delta_g_1)/(R*Temp))\n",
      "\n",
      "n_T_0 = 1.5#[mol]\n",
      "\n",
      "\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",
      "\n",
      "y_H2 = 2.4e-28\n",
      "y_O2 = 0.5*y_H2\n",
      "\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",
      "import math \n",
      "from scipy.integrate import quad \n",
      "\n",
      "Temp = 298.15           #[K]\n",
      "Press = 1*10**(5)       #[Pa]\n",
      "R = 8.314               #[J/(mol*K)]\n",
      "\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",
      "P_vapour_25 = 0.0317*10**(5)            #[Pa]\n",
      "\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",
      "delta_g_0_2 = 0             #[J/mol]\n",
      "\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",
      "delta_g_0 = delta_g_0_1+delta_g_0_2+delta_g_0_3         #[J/mol]\n",
      "delta_g_1 = delta_g_0/1000                              #[kJ/mol]\n",
      "\n",
      "print \" Total change in the free energy of water going under given conditions is %0.2f kJ/mol\"%(delta_g_1)\n",
      "\n",
      "delta_g_0_ideal_gas = -228.6                            #[kJ/mol]\n",
      "delta_g_0_liquid = -237.1                               #[kJ/mol]\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": [
      "import math \n",
      "from scipy.integrate import quad \n",
      "\n",
      "T1 = 273.15+25              #[K]\n",
      "T2 = 273.15+400             #[K]\n",
      "R = 8.314                   #[J/(mol*K)]\n",
      "\n",
      "g0_NH3 = -16.5              #[kJ/mol]\n",
      "g0_N2 = 0                   #[kJ/mol]\n",
      "g0_H2 = 0                   #[kJ/mol]\n",
      "\n",
      "\n",
      "delta_g_0 = g0_NH3 - 0.5*g0_N2 - 1.5*g0_H2          #[kJ/mol]\n",
      "\n",
      "K_1 = math.exp(-delta_g_0*1000/(R*T1))          # Equilibrium consmath.tant of the reaction at temperature 298.15 K\n",
      "\n",
      "h0_NH3 = -46.1          #[kJ/mol]\n",
      "h0_N2 = 0               #[kJ/mol]\n",
      "h0_H2 = 0               #[kJ/mol]\n",
      "\n",
      "del_h_1 = h0_NH3 - 0.5*h0_N2 - 1.5*h0_H2        #[kJ/mol]\n",
      "\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",
      "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",
      "I = R*( del_a*T1 + del_b*T1**(2)/2 + del_c*T1**(3)/3 - del_d/T1)        #[J/mol]\n",
      "\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",
      "K_2 = K_1*math.exp(X)\n",
      "\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",
      "\n",
      "from scipy.optimize import fsolve \n",
      "import math \n",
      "\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",
      "\n",
      "\n",
      "\n",
      "K_298 = 778.            # at temperature 298.15K\n",
      "K_673 = 0.013           # at temperature 673.15K\n",
      "\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",
      "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",
      "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": [
      "\n",
      "from scipy.optimize import fsolve \n",
      "import math \n",
      "\n",
      "Temp = 273.15+400           #[K]\n",
      "P = 150*1.01325             #[bar]\n",
      "\n",
      "K_673 = 0.013\n",
      "\n",
      "K = K_673*(P/1)**(1.5+0.5-1)\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.5)\n",
      "\n",
      "y_NH3 = (0+e)/(2-e)\n",
      "\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": [
      "\n",
      "from scipy.optimize import fsolve \n",
      "import math \n",
      "\n",
      "T = 273.15+400              #[K] given temperature\n",
      "P = 150*1.01325             #[bar] given pressure\n",
      "\n",
      "K_673 = 0.013\n",
      "\n",
      "K_v = (10**((0.1191849/T + 91.87212/T**(2) + 25122730/T**(4))*P))**(-1)\n",
      "\n",
      "K = (K_673/K_v)*(P/1)**(1.5+0.5-1)\n",
      "\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",
      "y_NH3 = (0+e)/(2-e)\n",
      "\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",
      "\n",
      "from scipy.optimize import fsolve \n",
      "import math \n",
      "\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",
      "delta_g_0 = 10.54*1000          #[J/mol]\n",
      "\n",
      "K = math.exp((-delta_g_0)/(R*T))\n",
      "\n",
      "\n",
      "\n",
      "def f(e): \n",
      "\t return  (e*e)/((1-e)*(1-e))-K\n",
      "e = fsolve(f,0)\n",
      "\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",
      "delta_v = v_C2H5OOC2H5 + v_H2O - v_C2H5OH - v_CH3COOH       #[ml/mol]\n",
      "\n",
      "\n",
      "\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",
      "a = e_1/e\n",
      "\n",
      "\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": [
      "\n",
      "import math \n",
      "\n",
      "P = 150.            #[atm] given pressure\n",
      "T = 400.            #[C] temperature\n",
      "K = 0.013\n",
      "K_v = 0.84\n",
      "delta_v = 1.5+0.5-1\n",
      "\n",
      "\n",
      "K_p = (K/K_v)*(1/1)**(delta_v)              #[1/bar]\n",
      "\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": {}
  }
 ]
}