summaryrefslogtreecommitdiff
path: root/Physical_And_Chemical_Equilibrium_For_Chemical_Engineers/ch8.ipynb
blob: 494454b7e864b97300131eff9c27201d378840b8 (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
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
{
 "metadata": {
  "name": "",
  "signature": "sha256:d221da8e75f5f6adc3adedef3c1ac8c09cdf0ffedf5eae70dc97519a155edf88"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 8 : Vapor Liquid Equilibrium VLE at Low Pressures"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 8.1  Page: 163"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "import math \n",
      "\n",
      "x_acetone = 0.05            # Mole fraction of Acetone in liquid\n",
      "x_water = (1-x_acetone)\n",
      "y_acetone = 0.6381          # Mole fraction of Acetone in vapour\n",
      "y_water = (1-y_acetone)\n",
      "\n",
      "K_acetone = y_acetone/x_acetone\n",
      "K_water = y_water/x_water\n",
      "a = K_acetone/K_water\n",
      "\n",
      "print \"The K factor of acetone is %f\"%(K_acetone)\n",
      "print \" The K factor of water is    %f\"%(K_water)\n",
      "print \" The relative volatility is  %f\"%(a)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The K factor of acetone is 12.762000\n",
        " The K factor of water is    0.380947\n",
        " The relative volatility is  33.500691\n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 8.2  Page: 165\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "import math \n",
      "\n",
      "P = 1.          #[atm]\n",
      "Temp = 74.8     #[C]\n",
      "A_a = 7.02447\n",
      "B_a = 1161\n",
      "C_a = 224\n",
      "p_acetone = 10**(A_a-B_a/(Temp+C_a))            #[mmHg]\n",
      "A_w = 7.94917\n",
      "B_w = 1657.462\n",
      "C_w = 227.02\n",
      "\n",
      "p_water = 10**(A_w-B_w/(Temp+C_w))              #[mmHg]\n",
      "p_acetone = p_acetone/760                       #[atm]\n",
      "p_water = p_water/760                           #[atm]\n",
      "y_acetone = 0.6381\n",
      "x_acetone = 0.05\n",
      "y_water = (1-y_acetone)\n",
      "x_water =(1-x_acetone)\n",
      "Y_acetone = y_acetone*P/(x_acetone*p_acetone)\n",
      "Y_water = y_water*P/(x_water*p_water)\n",
      "\n",
      "print \"Liquid-phase activity coefficient for acetone is %f\"%(Y_acetone)\n",
      "print \" Liquid-phase activity coefficient for water is   %f\"%(Y_water)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Liquid-phase activity coefficient for acetone is 7.043759\n",
        " Liquid-phase activity coefficient for water is   1.009407\n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 8.3  Page: 167\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "import math \n",
      "\n",
      "x_a = 0.05          # mole fraction of acetone in liquid phase\n",
      "x_w = (1-x_a)       # mole fraction of the water in the liquid phase\n",
      "P = 1.00            #[atm] Total pressure in vapor phase\n",
      "\n",
      "T_1 = 80.           #[C]\n",
      "A_a = 7.02447\n",
      "B_a = 1161.\n",
      "C_a = 224.\n",
      "A_w = 7.94917\n",
      "B_w = 1657.462\n",
      "C_w = 227.02\n",
      "\n",
      "p_a_1 = (1./760)*10**(A_a - B_a/(T_1+C_a))      #[atm]\n",
      "p_w_1 = (1./760)*10**(A_w - B_w/(T_1+C_w))      #[atm]\n",
      "\n",
      "y_a_1 = (x_a*p_a_1)/P\n",
      "y_w_1 = (x_w*p_w_1)/P\n",
      "\n",
      "y_1 = (y_a_1 + y_w_1)\n",
      "\n",
      "T_2 = 96.4060           #[C]\n",
      "\n",
      "p_a_2 = (1./760)*10**(A_a - B_a/(T_2+C_a))       #[atm]\n",
      "p_w_2 = (1./760)*10**(A_w - B_w/(T_2+C_w))      #[atm]\n",
      "\n",
      "y_a_2 = (x_a*p_a_2)/P\n",
      "y_w_2 = (x_w*p_w_2)/P\n",
      "\n",
      "y_2 = (y_a_2 + y_w_2)\n",
      "T_e = 74.8                  #[C] Boiling temperature\n",
      "y_a_e = 0.6381              # vapor phase composition of acetone\n",
      "\n",
      "print \" Comparison of experimental values to those computed by the ideal solution assumption x_acetone = 0.05 and P = 1.00 atm\"\n",
      "print \" \\t\\t\\t Experimental Values from Table 8.1 \\t\\t\\t\\tValues calculated assuming idea solution\"\n",
      "print \" Equilibriumboiling) \\t\\t%0.1f \\t\\t\\t\\t\\t\\t\\t\\t\\t %0.1f  temperature T deg C\"%(T_e,T_2)\n",
      "print \" Mole fraction acetone \\t\\t%f \\t\\t\\t\\t\\t\\t\\t\\t %f  in the vapor phase y_a)\"%(y_a_e,y_a_2)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Comparison of experimental values to those computed by the ideal solution assumption x_acetone = 0.05 and P = 1.00 atm\n",
        " \t\t\t Experimental Values from Table 8.1 \t\t\t\tValues calculated assuming idea solution\n",
        " Equilibriumboiling) \t\t74.8 \t\t\t\t\t\t\t\t\t 96.4  temperature T deg C\n",
        " Mole fraction acetone \t\t0.638100 \t\t\t\t\t\t\t\t 0.165615  in the vapor phase y_a)\n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 8.4  Page: 177\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math \n",
      "\n",
      "n_water = 80.                       #[mol]\n",
      "n_bumath_tanol = 20.                #[mol]\n",
      "n_total = n_water+n_bumath_tanol    #[mol]\n",
      "\n",
      "x_feed = 0.8\n",
      "x_a_1 = 0.65\n",
      "x_a_2 = 0.98\n",
      "\n",
      "n_1 = (x_feed-x_a_2)/(x_a_1-x_a_2)*n_total          #[mol]\n",
      "n_2 = (n_total-n_1)                                 #[mol]\n",
      "n_a_1 = 0.65*n_1                                    #[mol]\n",
      "n_a_2 = 0.98*n_2                                    #[mol]\n",
      "\n",
      "print \" Total moles of water present in the first phase is  %f mol\"%(n_a_1)\n",
      "print \" Total moles of water present in the second phase is %f mol\"%(n_a_2)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Total moles of water present in the first phase is  35.454545 mol\n",
        " Total moles of water present in the second phase is 44.545455 mol\n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 8.5  Page: 178\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "import math \n",
      "\n",
      "P = 1.              #[atm]\n",
      "y_water = 0.60\n",
      "x_water_1 = 0.22\n",
      "x_water_2 = 0.99\n",
      "\n",
      "print \" The equilibrium amount of water in liquid at bubble-point for the dew-point composition y_water=60 mol%% is %f mol%% water\"%(x_water_1)\n",
      "print \" The equilibrium amount of water in liquid at bubble-point for the dew-point composition y_water=90 mol%% is %f mol%% water\"%(x_water_2)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The equilibrium amount of water in liquid at bubble-point for the dew-point composition y_water=60 mol% is 0.220000 mol% water\n",
        " The equilibrium amount of water in liquid at bubble-point for the dew-point composition y_water=90 mol% is 0.990000 mol% water\n"
       ]
      }
     ],
     "prompt_number": 23
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 8.6  Page: 178\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math \n",
      "\n",
      "P = 1.00            #[atm] assumed total vapor pressure\n",
      "P1 = 14.7           #[psia]\n",
      "x_1_water = 0.65\n",
      "x_1_bumath_tanol = (1-x_1_water)\n",
      "x_2_water = 0.98\n",
      "x_2_bumath_tanol = (1-x_2_water)\n",
      "y_water = 0.73\n",
      "y_bumath_tanol = (1-y_water)\n",
      "T = 92.             #[C]\n",
      "\n",
      "A_w = 7.94917\n",
      "B_w = 1657.462\n",
      "C_w = 227.02\n",
      "\n",
      "A_b = 7.838\n",
      "B_b = 1558.190\n",
      "C_b = 196.881\n",
      "\n",
      "p_water = (14.7/760)*10**(A_w - B_w/(T+C_w))\n",
      "p_bumath_tanol = (14.7/760)*10**(A_b - B_b/(T+C_b))\n",
      "\n",
      "f_water = (y_water*P)\n",
      "f_bumath_tanol = (y_bumath_tanol*P)\n",
      "\n",
      "Y_water_1 = (y_water*P1)/(x_1_water*p_water)\n",
      "Y_bumath_tanol_1 = (y_bumath_tanol*P1)/(x_1_bumath_tanol*p_bumath_tanol)\n",
      "\n",
      "Y_water_2 = (y_water*P1)/(x_2_water*p_water)\n",
      "Y_bumath_tanol_2 = (y_bumath_tanol*P1)/(x_2_bumath_tanol*p_bumath_tanol)\n",
      "\n",
      "print \" Four activity coefficients and fufacities are shown in the following table:\"\n",
      "print \"Phase \\t x_water \\t f_wateratm \\t Y_water \\t x_butanol \\t f_butanolatm \\t\\t Y_butanol\"\n",
      "print \" 1 \\t %f \\t %f \\t %f \\t %f \\t %f \\t\\t %f \"%(x_1_water,f_water,Y_water_1,x_1_bumath_tanol,f_bumath_tanol,Y_bumath_tanol_1)\n",
      "print \" 2 \\t %f \\t %f \\t %0.2f \\t\\t %f \\t %f \\t\\t %f \"%(x_2_water,f_water,Y_water_2,x_2_bumath_tanol,f_bumath_tanol,Y_bumath_tanol_2)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Four activity coefficients and fufacities are shown in the following table:\n",
        "Phase \t x_water \t f_wateratm \t Y_water \t x_butanol \t f_butanolatm \t\t Y_butanol\n",
        " 1 \t 0.650000 \t 0.730000 \t 1.504988 \t 0.350000 \t 0.270000 \t\t 2.108586 \n",
        " 2 \t 0.980000 \t 0.730000 \t 1.00 \t\t 0.020000 \t 0.270000 \t\t 36.900247 \n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 8.7   Page: 179\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math \n",
      "\n",
      "P = 1.              #[atm] Total pressure in the vapor phase\n",
      "\n",
      "\n",
      "T = 89.             #[C]\n",
      "A_w = 7.94917\n",
      "B_w = 1657.462\n",
      "C_w = 227.02\n",
      "\n",
      "A_b = 7.838\n",
      "B_b = 1558.190\n",
      "C_b = 196.881\n",
      "\n",
      "p_water = (1./760)*10**(A_w - B_w/(T+C_w))\n",
      "p_bumath_tanol = (1./760)*10**(A_b - B_b/(T+C_b))\n",
      "\n",
      "y_water = p_water/P\n",
      "y_bumath_tanol = p_bumath_tanol/P\n",
      "y = y_water + y_bumath_tanol\n",
      "\n",
      "\n",
      "print \" Boiling point of the two phase system is %0.0f deg C\"%(T)\n",
      "print \" In vapor phase mole fraction of the water is %0.2f\"%(y_water)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Boiling point of the two phase system is 89 deg C\n",
        " In vapor phase mole fraction of the water is 0.67\n"
       ]
      }
     ],
     "prompt_number": 25
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 8.8   Page: 184\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "import math \n",
      "\n",
      "Temp = 68.          #[F]\n",
      "P = 1.              #[atm]\n",
      "\n",
      "Temp = 273.15+(Temp-32)*5./9        #[K]\n",
      "P = P*1.01325                       #[bar]\n",
      "T_c = 647.1         #[K]\n",
      "P_c = 220.55        #[bar]\n",
      "T_r = Temp/T_c\n",
      "P_r = P/P_c\n",
      "w = 0.345\n",
      "f_T_r = (0.083-0.422/T_r**(1.6))+w*(0.139-0.172/T_r**(4.2))\n",
      "f_by_P = math.exp(P_r/T_r*f_T_r)\n",
      "\n",
      "print \"The value of the f/P for water vapour in the hypothetical state is %0.2f\"%(f_by_P)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of the f/P for water vapour in the hypothetical state is 0.97\n"
       ]
      }
     ],
     "prompt_number": 26
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 8.9   Page: 189\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "import math \n",
      "\n",
      "x_a = 0.1238\n",
      "x_b = (1-x_a)\n",
      "T = 85.3            #[C] Given boiling temperature\n",
      "\n",
      "A_a = 8.04494\n",
      "B_a = 1554.3\n",
      "C_a = 222.65\n",
      "\n",
      "A_b = 7.96681\n",
      "B_b = 1668.21\n",
      "C_b = 228.0\n",
      "\n",
      "p_a = (1./760)*10**(A_a - B_a/(T+C_a))\n",
      "p_b = (1./760)*10**(A_b - B_b/(T+C_b))\n",
      "\n",
      "A = 0.7292\n",
      "B = 0.4104\n",
      "\n",
      "Y_a = 10**((B**(2)*A*x_b**(2))/(A*x_a+B*x_b)**(2))\n",
      "Y_b = 10**((A**(2)*B*x_a**(2))/(A*x_a+B*x_b)**(2))\n",
      "\n",
      "\n",
      "P = (Y_a*p_a*x_a)+(Y_b*p_b*x_b)             #[atm]\n",
      "\n",
      "y_a = (Y_a*p_a*x_a)/P\n",
      "y_b = (Y_b*p_b*x_b)/P\n",
      "\n",
      "print \" Boiling pressure of the liquid at 85.3 deg C is %0.4f atm\"%(P)\n",
      "print \" Mole fraction of ethanaol in vapor phase is     %0.4f\"%(y_a)\n",
      "print \" Mole fraction of water in the vapor phase is    %0.4f\"%(y_b)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Boiling pressure of the liquid at 85.3 deg C is 0.9991 atm\n",
        " Mole fraction of ethanaol in vapor phase is     0.4741\n",
        " Mole fraction of water in the vapor phase is    0.5259\n"
       ]
      }
     ],
     "prompt_number": 27
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 8.10   Page: 191\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "import math \n",
      "\n",
      "x_a = 0.2608\n",
      "x_b = (1-x_a)\n",
      "P = 1.00            #[atm] Given boiling pressure\n",
      "\n",
      "\n",
      "A_a = 8.04494\n",
      "B_a = 1554.3\n",
      "C_a = 222.65\n",
      "\n",
      "A_b = 7.96681\n",
      "B_b = 1668.21\n",
      "C_b = 228.0\n",
      "\n",
      "\n",
      "A = 0.7292\n",
      "B = 0.4104\n",
      "\n",
      "Y_a = 10**((B**(2)*A*x_b**(2))/(A*x_a+B*x_b)**(2))\n",
      "Y_b = 10**((A**(2)*B*x_a**(2))/(A*x_a+B*x_b)**(2))\n",
      "\n",
      "T = 80.\n",
      "err = 1.\n",
      "\n",
      "while err > 10**(-3):\n",
      "    P_a = (10**(8.04494 - 1554.3/(222.65 + T)))/760\n",
      "    P_b = (10**(7.96681 - 1668.21/(228 + T)))/760\n",
      "    y_a = Y_a*P_a*x_a/P\n",
      "    y_b = Y_b*P_b*x_b/P\n",
      "    err = abs((y_a + y_b) - 1)\n",
      "    T = T + 0.01\n",
      "\n",
      "print \" Boiling temperature of the liquid at 1 atm pressure is %0.4f atm\"%(T)\n",
      "print \" Mole fraction of ethanaol in vapor phase is     \\t%0.4f\"%(y_a)\n",
      "print \" Mole fraction of water in the vapor phase is    \\t%0.4f\"%(y_b)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Boiling temperature of the liquid at 1 atm pressure is 82.0300 atm\n",
        " Mole fraction of ethanaol in vapor phase is     \t0.5680\n",
        " Mole fraction of water in the vapor phase is    \t0.4312\n"
       ]
      }
     ],
     "prompt_number": 28
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 8.11  Page: 192\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "import math \n",
      "\n",
      "y_a = 0.6122\n",
      "y_b = (1-y_a)\n",
      "T = 80.7            #[C] Given boiling temperature\n",
      "\n",
      "\n",
      "A_a = 8.04494\n",
      "B_a = 1554.3\n",
      "C_a = 222.65\n",
      "\n",
      "A_b = 7.96681\n",
      "B_b = 1668.21\n",
      "C_b = 228.0\n",
      "\n",
      "p_a = (1./760)*10**(A_a - B_a/(T+C_a))\n",
      "p_b = (1./760)*10**(A_b - B_b/(T+C_b))\n",
      "\n",
      "A = 0.7292\n",
      "B = 0.4104\n",
      "\n",
      "\n",
      "x_a = 0.6122            # Initial assumption of liquid phase composition of ethanol\n",
      "x_b = 0.3               # Initial assumption of liquid phase composition water\n",
      "P = 0.80                #[atm]\n",
      "err = 1\n",
      "\n",
      "while err > 2* 10**(-2):\n",
      "    P = P + 0.01\n",
      "    Y_a = 10**((B**(2)*A*x_b**(2))/(A*x_a+B*x_b)**(2))\n",
      "    Y_b = 10**((A**(2)*B*x_a**(2))/(A*x_a+B*x_b)**(2))\n",
      "\n",
      "    err = abs((x_a + x_b) - 1)\n",
      "    x_a = y_a*P/(Y_a*p_a)\n",
      "    x_b = y_b*P/(Y_b*p_b)\n",
      "\n",
      "print \" Boiling pressure of the liquid at 80.7 deg C is %0.4f atm\"%(P)\n",
      "print \" Mole fraction of ethanaol in liquid phase is     %0.4f\"%(x_a)\n",
      "print \" Mole fraction of water in the liquid phase is    %0.4f\"%(x_b)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Boiling pressure of the liquid at 80.7 deg C is 0.9900 atm\n",
        " Mole fraction of ethanaol in liquid phase is     0.3730\n",
        " Mole fraction of water in the liquid phase is    0.6205\n"
       ]
      }
     ],
     "prompt_number": 29
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 8.12  Page: 193\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math \n",
      "\n",
      "y_a = 0.1700\n",
      "y_b = (1-y_a)\n",
      "P = 1.00            #[atm] Given boiling pressure\n",
      "\n",
      "\n",
      "A_a = 8.04494\n",
      "B_a = 1554.3\n",
      "C_a = 222.65\n",
      "\n",
      "A_b = 7.96681\n",
      "B_b = 1668.21\n",
      "C_b = 228.0\n",
      "\n",
      "\n",
      "A = 0.7292\n",
      "B = 0.4104\n",
      "\n",
      "\n",
      "\n",
      "x_a = 0.0100            # Initial assumption of liquid phase composition of ethanol\n",
      "x_b = 0.9               # Initial assumption of liquid phase composition water\n",
      "T = 80.                 #[C] Initial guess of the temperature\n",
      "err = 1\n",
      "\n",
      "while err >  1./16*10**(-2):\n",
      "    P_a = (10**(8.04494 - 1554.3/(222.65 + T)))/760\n",
      "    P_b = (10**(7.96681 - 1668.21/(228 + T)))/760\n",
      "    \n",
      "    Y_a = 10**((B**(2)*A*x_b**(2))/(A*x_a+B*x_b)**(2))\n",
      "    Y_b = 10**((A**(2)*B*x_a**(2))/(A*x_a+B*x_b)**(2))\n",
      "    \n",
      "    x_a = y_a*P/(Y_a*P_a)\n",
      "    x_b = y_b*P/(Y_b*P_b)\n",
      "\n",
      "    err = abs((x_a + x_b) - 1)\n",
      "    T = T + 0.01\n",
      "\n",
      "\n",
      "print \" Equilibrium Temperature of the system at pressure 1 atm  is %0.4f atm\"%(T)\n",
      "print \" Mole fraction of ethanaol in liquid phase is     %0.4f\"%(x_a)\n",
      "print \" Mole fraction of water in the liquid phase is    %0.4f\"%(x_b)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Equilibrium Temperature of the system at pressure 1 atm  is 95.3500 atm\n",
        " Mole fraction of ethanaol in liquid phase is     0.0187\n",
        " Mole fraction of water in the liquid phase is    0.9816\n"
       ]
      }
     ],
     "prompt_number": 30
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 8.13   Page: 194\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math \n",
      "\n",
      "x_aF = 0.126\n",
      "x_bF = (1-x_aF)\n",
      "P = 1.00            #[atm] Given total pressure\n",
      "T = 91.8            #[C]\n",
      "\n",
      "x_a = 0.0401\n",
      "x_b = (1 - x_a)\n",
      "\n",
      "y_a = 0.2859\n",
      "y_b = ( 1 - y_a)\n",
      "\n",
      "V_by_F = ( x_aF - x_a )/(y_a - x_a)\n",
      "\n",
      "print \" Mole fraction of the ethanol in the liquid phase in equilibrium at the given condition is %f\"%(x_a)\n",
      "print \" Mole fraction of the water in the liquid phase in equilibrium at the given condition is %f\"%(x_b)\n",
      "print \" Mole fraction of the ethanol in the vapour phase in equilibrium at the given condition is %f\"%(y_a)\n",
      "print \" Mole fraction of the water in the vapour phase in equilibrium at the given condition is %f\"%(y_b)\n",
      "print \" Vapor fraction of the given water-ethanol mixture after the flash in equilibrium is %f\"%(V_by_F)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Mole fraction of the ethanol in the liquid phase in equilibrium at the given condition is 0.040100\n",
        " Mole fraction of the water in the liquid phase in equilibrium at the given condition is 0.959900\n",
        " Mole fraction of the ethanol in the vapour phase in equilibrium at the given condition is 0.285900\n",
        " Mole fraction of the water in the vapour phase in equilibrium at the given condition is 0.714100\n",
        " Vapor fraction of the given water-ethanol mixture after the flash in equilibrium is 0.349471\n"
       ]
      }
     ],
     "prompt_number": 31
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 8.14  Page: 198\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math \n",
      "\n",
      "P = 100.                    #[psia]\n",
      "x_a = 0.05                  # Mole fraction of methane \n",
      "x_b = 0.40                  # Mole fraction of bumath.tane \n",
      "x_c = 0.55                  # mole fraction of penmath.tane\n",
      "\n",
      "\n",
      "T = [[15.8 ,0.087, 0.024],[16,0.105, 0.026],[16.2, 0.115, 0.03],[16.8 ,0.13, 0.035],[17.2 ,0.15, 0.04],[17.8, 0.17, 0.045],[18.2, 0.175, 0.0472727]]\n",
      "print \" Calculations for the various assumed temperatures are given in the table below\"\n",
      "print \" Temperature \\t\\t    y_a \\t\\t   y_b \\t\\t\\t   y_c \\t\\t\\t   y \"\n",
      "\n",
      "T_b = 0         #[F] Bubble point\n",
      "j=0\n",
      "for i in range(7):\n",
      "        y_a = x_a*T[i][j]\n",
      "        y_b = x_b*T[i][j+1]\n",
      "        y_c = x_c*T[i][j+2]\n",
      "        y = y_a + y_b + y_c\n",
      "        T_b = T_b + 5\n",
      "        print \" %f \\t\\t %f \\t\\t %f \\t\\t %f \\t\\t %f \"%(T_b,y_a,y_b,y_c,y)\n",
      "\n",
      "print \"  For the temperature 30 deg F the summation of the mole fractions in the vapor phase is close enough to unity so bubble point is 30 degF\"\n",
      "print \" And compositions in the vapor phase are the values given in the above table corresonding to the temperature 30 deg F i.e.\"\n",
      "print \" y_methane = %f  y_bumath.tane = %f  y_penmath.tane = %f\"%(y_a,y_b,y_c)\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Calculations for the various assumed temperatures are given in the table below\n",
        " Temperature \t\t    y_a \t\t   y_b \t\t\t   y_c \t\t\t   y \n",
        " 5.000000 \t\t 0.790000 \t\t 0.034800 \t\t 0.013200 \t\t 0.838000 \n",
        " 10.000000 \t\t 0.800000 \t\t 0.042000 \t\t 0.014300 \t\t 0.856300 \n",
        " 15.000000 \t\t 0.810000 \t\t 0.046000 \t\t 0.016500 \t\t 0.872500 \n",
        " 20.000000 \t\t 0.840000 \t\t 0.052000 \t\t 0.019250 \t\t 0.911250 \n",
        " 25.000000 \t\t 0.860000 \t\t 0.060000 \t\t 0.022000 \t\t 0.942000 \n",
        " 30.000000 \t\t 0.890000 \t\t 0.068000 \t\t 0.024750 \t\t 0.982750 \n",
        " 35.000000 \t\t 0.910000 \t\t 0.070000 \t\t 0.026000 \t\t 1.006000 \n",
        "  For the temperature 30 deg F the summation of the mole fractions in the vapor phase is close enough to unity so bubble point is 30 degF\n",
        " And compositions in the vapor phase are the values given in the above table corresonding to the temperature 30 deg F i.e.\n",
        " y_methane = 0.910000  y_bumath.tane = 0.070000  y_penmath.tane = 0.026000\n"
       ]
      }
     ],
     "prompt_number": 32
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 8.15  Page: 199\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math \n",
      "\n",
      "n_sugar = 1.                #[mol]\n",
      "n_water = 1000/18.          #[mol]\n",
      "x_sugar = n_sugar/(n_sugar+n_water)\n",
      "x_water = n_water/(n_sugar+n_water)\n",
      "p_water = 1.                #[atm]\n",
      "p_sugar = 0.                #[atm]\n",
      "\n",
      "P = x_water*p_water+x_sugar*p_sugar         #[atm]\n",
      "P_1 = 1.                    #[atm]\n",
      "p_water = P_1/x_water       #[atm]\n",
      "T = 100.51                  #[C]\n",
      "T_eb = T-100                #[C]\n",
      "\n",
      "print \"Vapour pressure of this solution at the 100C is  %.3f atm\"%(P)\n",
      "print \"The temperature at which this solution will boil at 1 atm is %.2f C\"%(T)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Vapour pressure of this solution at the 100C is  0.982 atm\n",
        "The temperature at which this solution will boil at 1 atm is 100.51 C\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 8.16  Page: 201\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from scipy.optimize import fsolve \n",
      "import math \n",
      "\n",
      "n_sugar = 1.            #[mol]\n",
      "n_water = 1000/18.      #[mol]\n",
      "x_sugar = n_sugar/(n_sugar+n_water)\n",
      "x_water = n_water/(n_sugar+n_water)\n",
      "\n",
      "\n",
      "p_sugar = 0\n",
      "p_ice_by_p_water = x_water\n",
      "\n",
      "\n",
      "def f(T): \n",
      "\t return  1+0.0096686*T+4.0176*10**(-5)*T**(2)-p_ice_by_p_water\n",
      "T = fsolve(f,0)\n",
      "\n",
      "print \"Freezing-point temperature of the given solution is %f C\"%(T)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Freezing-point temperature of the given solution is -1.842891 C\n"
       ]
      }
     ],
     "prompt_number": 34
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}