summaryrefslogtreecommitdiff
path: root/Chemical_Engineering_Thermodynamics_by_Y_V_C_Rao/ch4.ipynb
blob: 5433cf7c22dca2995130229a41a0d1792c65322c (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
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 4 : First law of thermodynamics and its applications"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.1  Page No : 94"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "Q1 = 50.;\t\t\t #Energy added as heat in kJ when the system undergoes a process 1-2\n",
      "W1 = 30.;\t\t\t #Work done by the system in kJ during the process 1-2\n",
      "Q2 = -40.;\t\t\t #Energy rejected as heat in kJ during the process 2-3\n",
      "W2 = -50.;\t\t\t #Work done on the system in kJ during the process 2-3\n",
      "Q3 = 0.\t    \t\t #System undergoes an adiabatic process to return to initial state\n",
      "\n",
      "# Calculations\n",
      "U2_1 = Q1-W1\n",
      "U3_2 = Q2-W2\n",
      "U1_3 = (-U2_1)-(U3_2)\n",
      "W3 = Q3-U1_3\n",
      "net_work = W1+W2+W3\n",
      "\n",
      "# Results\n",
      "print ' The net work done by the system =  %d kJ'%(net_work);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The net work done by the system =  10 kJ\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.3  Page No : 96"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "V = 1.  \t\t\t #volume of tank in m**3;\n",
      "N = 200.;\t\t\t #number of moles of carbon dioxide in tank in mol\n",
      "T1 = 25.;\t\t\t #ambient temperature in degree celsius\n",
      "I = 5.; \t\t\t #current in amperes passed through the resistor place in the tank\n",
      "Voltage = 440.\t\t #voltage in volts existing across the resistor\n",
      "t = 10.;\t\t\t #time in minutes for which the current is passed\n",
      "a = 363.077*10**-3\t\t\t #van der waals constant in Pa (m**3/mol)**2\n",
      "b = 0.043*10**-3\t\t\t #van der waals constant in m**3/mol\n",
      "Cv = 32.34\t\t\t #molar heat capacity at constant volume in J/molK\n",
      "R = 8.314\t\t\t #universal gas constant in J/molK\n",
      "\n",
      "# Calculations\n",
      "MV = V/N;\t\t\t # Calculations of molar volume in m**3/mol\n",
      "Q = 0.  \t\t\t #energy transfer as heat during the process\n",
      "W_Pdv = 0.;\t\t\t #mechanical work done by the system\n",
      "W_elec = -(Voltage*I*t*60)*(10**-6)\n",
      "U2_1 = Q-(W_Pdv+W_elec);\t\t\t\n",
      "T2 = ((U2_1*10**6)/(N*Cv))+(T1+273.15)\n",
      "P = (((R*T2)/(MV-b))-(a/(MV**2)))*10**-3\n",
      "\n",
      "# Results\n",
      "print ' The final pressure =  %0.3f kPa '%(P);\n",
      "print ' The final temperature =  %0.2f K'%(T2);\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The final pressure =  827.832 kPa \n",
        " The final temperature =  502.23 K\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.4  Page No : 97"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "V = 0.1;\t\t\t #volume of tank in m**3\n",
      "T1 = 200.;\t\t\t #initial temperature of saturated steam inside the tank in degree celsius\n",
      "T2 = 150.;\t\t\t #temperature in degree celsius that the tank attains after some time due to poor insulation\n",
      "P1 = 15.549;\t\t\t #pressure in bar obtained from steam tables corresponding to T1\n",
      "vg1 = 0.1272;\t\t\t #specific volume of saturated vapour in m**3/kg obtained from steam tables corresponding to T1\n",
      "hg1 = 2790.9;\t\t\t #specific enthalpy of saturated vapour in kJ/kg obtained from steam tables corresponding to T1\n",
      "P2 = 4.76;\t\t\t #pressure in bar obtained from steam tables corresponding to T2\n",
      "vf = 0.0010908;\t\t\t #specific volume of saturated liquid in m**3/kg obtained from steam tables corresponding to T2\n",
      "vg2 = 0.3924;\t\t\t #specific volume of saturated vapour in m**3/kg obtained from steam tables corresponding to T2\n",
      "hf = 632.15;\t\t\t #specific enthalpy of saturated liquid in kJ/kg obtained from steam tables corresponding to T1\n",
      "hg2 = 2745.4;\t\t\t #specific enthalpy of saturated vapour in kJ/kg obtained from steam tables corresponding to T1\n",
      "\n",
      "# Calculations\n",
      "ug1 = ((hg1*10**3)-(P1*10**5*vg1))*10**-3\n",
      "uf = ((hf*10**3)-(P2*10**5*vf))*10**-3\n",
      "ug2 = ((hg2*10**3)-(P2*10**5*vg2))*10**-3\n",
      "v2 = vg1\n",
      "X2 = (v2-vf)/(vg2-vf)\n",
      "u2 = (X2*ug2)+((1-X2)*uf)\n",
      "m = V/vg1\n",
      "Q = m*(u2-ug1)\n",
      "mf = m*(1-X2)\n",
      "mg = m*X2\n",
      "\n",
      "# Results\n",
      "print ' The energy transferred as heat =  %f kJ'%(Q);\n",
      "print ' The mass of liquid in the tank in the final state =  %0.3f kg'%(mf)\n",
      "print ' The mass of vapour in the tank in the final state =  %0.3f kg'%(mg)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The energy transferred as heat =  -1053.825572 kJ\n",
        " The mass of liquid in the tank in the final state =  0.533 kg\n",
        " The mass of vapour in the tank in the final state =  0.253 kg\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.5  Page No : 102"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "W = 1.;\t    \t\t #weight of steam in kg in the piston cylinder assembly\n",
      "X = 0.8;\t\t\t #quality of steam (no unit)\n",
      "T1 = 150.;\t\t\t #initial temperature of steam in degree celsius\n",
      "T2 = 200.;\t\t\t #final temperature of steam in degree celsius\n",
      "P1 = 476.;\t\t\t #pressure in kPa obatined from steam tables (corresponding to T1)\n",
      "vf = 0.0010908;\t\t\t #specific volume of saturated liquid in m**3/kg obatined from steam tables (corresponding to T1)\n",
      "vg = 0.3924;\t\t\t #specific volume of satuarted vapour in m**3/kg obatined from steam tables (corresponding to T1)\n",
      "hf = 632.15;\t\t\t #specific enthalpy of saturated liquid in kJ/kg obtained from steam tables (corresponding to T1)\n",
      "hg = 2745.4;\t\t\t #specific enthalpy of saturated vapour in kJ/kg obtained from steam tables (corresponding to T1)\n",
      "\n",
      "# Calculations\n",
      "V1 = (X*vg)+((1-X)*vf)\n",
      "h1 = (X*hg)+((1-X)*hf)\n",
      "P2 = 0.476;\t\t\t \n",
      "P_int1 = 0.4;\t\t\n",
      "P_int2 = 0.5;\t\t\n",
      "V_int1 = 0.5343;\t\n",
      "V_int2 = 0.4250;\t\n",
      "h_int1 = 2860.4;\t\n",
      "h_int2 = 2855.1;\t\n",
      "V2 = (((P2-P_int1)/(P_int2-P_int1))*(V_int2-V_int1))+V_int1\n",
      "h2 = (((P2-P_int1)/(P_int2-P_int1))*(h_int2-h_int1))+h_int1\n",
      "Q = (h2-h1)*W\n",
      "W = P1*(V2-V1)*W\n",
      "\n",
      "# Results\n",
      "print ' The work done by steam =  %0.2f kJ '%(W);\n",
      "print ' The net energy transferred as heat  =  %0.2f kJ'%(Q);\n",
      "print ' The final state of superheated steam,Pressure = %0.3f MPa '%(P2);\n",
      "print ' The final state of superheated steam,Temperature = %d degree celsius '%(T2);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The work done by steam =  65.26 kJ \n",
        " The net energy transferred as heat  =  533.62 kJ\n",
        " The final state of superheated steam,Pressure = 0.476 MPa \n",
        " The final state of superheated steam,Temperature = 200 degree celsius \n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.6  Page No : 103"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "W = 1.  \t\t\t #weight of steam in kg in the piston cylinder assembly\n",
      "X = 0.8;\t\t\t #quality of steam (no unit)\n",
      "T1 = 150.\t\t\t #initial temperature  of steam in degree celsius\n",
      "I = 5.  \t\t\t #current passed in Amperes\n",
      "V = 220.\t\t\t #voltage in volts across the resistor\n",
      "t = 10. \t\t\t #time for which the current is passed in minutes\n",
      "P1 = 476.\t\t\t #pressure in kPa obatined from steam tables (corresponding to T1)\n",
      "vf = 0.0010908;\t\t\t #specific volume of saturated liquid in m**3/kg obatined from steam tables (corresponding to T1)\n",
      "vg = 0.3924;\t\t\t #specific volume of satuarted vapour in m**3/kg obatined from steam tables (corresponding to T1)\n",
      "hf = 632.15;\t\t\t #specific enthalpy of saturated liquid in kJ/kg obtained from steam tables (corresponding to T1)\n",
      "hg = 2745.4;\t\t\t #specific enthalpy of saturated vapour in kJ/kg obtained from steam tables (corresponding to T1)\n",
      "\n",
      "# Calculations\n",
      "V1 = (X*vg)+((1-X)*vf);\t\n",
      "h1 = (X*hg)+((1-X)*hf);\t\n",
      "Ws = -V*I*t*60*10**-3;\t\n",
      "h2 = h1-Ws;\t\t\t \n",
      "P2 = 0.476;\t\t\t \n",
      "T_int1 = 200;\t\t\n",
      "T_int2 = 300;\t\t\n",
      "V_int1 = 0.4512;\t\n",
      "V_int2 = 0.5544;\t\n",
      "h_int1 = 2856.37;\t\n",
      "h_int2 = 3065.38;\t\n",
      "V2 = (((h2-h_int1)/(h_int2-h_int1))*(V_int2-V_int1))+V_int1;\n",
      "T2 = (((h2-h_int1)/(h_int2-h_int1))*(T_int2-T_int1))+T_int1;\n",
      "W = (P1*10**3*(V2-V1)*W)*10**-3\n",
      "\n",
      "# Results\n",
      "print ' The work done by steam =  %0.2f kJ '%(W);\n",
      "print ' The final temperature =  %0.2f degree celsius'%(T2);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The work done by steam =  94.94 kJ \n",
        " The final temperature =  260.47 degree celsius\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.7  Page No : 104"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "N = 1.\t\t\t     #number of moles of carbon dioxide in kmol\n",
      "T1 = 298.\t\t\t #initial temperature in K\n",
      "T2 = 600.\t\t\t #final raised temperature in K\n",
      "a = 45.369\t\t\t #coefficient in the specific heat capacity expression where Cp = a+bT+eT**-2\n",
      "b = 8.688*10**-3\t\t\t #coefficient in the specific heat capacity expression where Cp = a+bT+eT**-2\n",
      "e = -9.619*10**5\t\t\t #coefficient in the specific heat capacity expression where Cp = a+bT+eT**-2\n",
      "\n",
      "# Calculations\n",
      "Q = N*10**3*((a*(T2-T1)+((b/2)*(T2**2-T1**2))-(e*((1./T2)-(1./T1)))))*10**-6\n",
      "\n",
      "# Results\n",
      "print ' The amount of energy to be transferred as heat =  %0.3f MJ'%(Q);"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The amount of energy to be transferred as heat =  13.255 MJ\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.8  Page No : 104"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "T1 = 298.   \t\t\t #initial temperature in K\n",
      "T2 = 600.\t    \t\t #final raised temperature in K\n",
      "a = 45.369;\t\t    \t #coefficient in the specific heat capacity expression where Cp = a+bT+eT**-2\n",
      "b = 8.688*10**-3;\t\t\t #coefficient in the specific heat capacity expression where Cp = a+bT+eT**-2\n",
      "e = -9.619*10**5;\t\t\t #coefficient in the specific heat capacity expression where Cp = a+bT+eT**-2\n",
      "\n",
      "# Calculations\n",
      "Cpm = ((a*(T2-T1))+((b/2)*(T2**2-T1**2))-(e*((1./T2)-(1./T1))))/(T2-T1)\n",
      "\n",
      "# Results\n",
      "print ' The isobaric molar heat capacity =  %0.2f J/molK'%(Cpm);"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The isobaric molar heat capacity =  43.89 J/molK\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.9  Page No : 105"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "N = 1.\t    \t\t #number of moles of carbon dioxide in kmol\n",
      "T1 = 298.\t\t\t #initial temperature in K\n",
      "T2 = 600.\t\t\t #final raised temperature in K\n",
      "a = 45.369;\t\t\t #coefficient in the specific heat capacity expression where Cp = a+bT+eT**-2\n",
      "b = 8.688*10**-3;\t\t\t #coefficient in the specific heat capacity expression where Cp = a+bT+eT**-2\n",
      "e = -9.619*10**5;\t\t\t #coefficient in the specific heat capacity expression where Cp = a+bT+eT**-2\n",
      "\n",
      "# Calculations\n",
      "Cpm = ((a*(T2-T1))+((b/2)*(T2**2-T1**2))-(e*((1./T2)-(1./T1))))/(T2-T1)\n",
      "Q = N*10**3*Cpm*(T2-T1)*10**-6\n",
      "\n",
      "# Results\n",
      "print ' The amount of energy to be transferred as heat =  %0.3f MJ '%(Q);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The amount of energy to be transferred as heat =  13.255 MJ \n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.10  Page No : 105"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "N = 100.\t\t\t #number of moles of carbon dioxide in mol\n",
      "T1 = 298.\t\t\t #initial temperature in K\n",
      "Q = 1.  \t\t\t #energy added as heat in MJ\n",
      "a = 45.369;\t\t\t #coefficient in the specific heat capacity expression where Cp = a+bT+eT**-2\n",
      "b = 8.688*10**-3;\t\t\t #coefficient in the specific heat capacity expression where Cp = a+bT+eT**-2\n",
      "e = -9.619*10**5;\t\t\t #coefficient in the specific heat capacity expression where Cp = a+bT+eT**-2\n",
      "\n",
      "# Calculations\n",
      "delh = Q*10**6/N\n",
      "Tguess = 520.\t\n",
      "Cpm_guess = a+(b*((T1+Tguess)/2))+(e/(T1*Tguess))\n",
      "T2_guess = T1+(delh/Cpm_guess)\n",
      "tolerance = 1e-6;\t\t\t\n",
      "while abs(T2_guess-Tguess)>tolerance:\n",
      "    Tguess = T2_guess;\n",
      "    Cpm_guess = a+(b*((T1+Tguess)/2))+(e/(T1*Tguess));\n",
      "    T2_guess = T1+(delh/Cpm_guess)\n",
      "\n",
      "T2 = T2_guess\n",
      "\n",
      "# Results\n",
      "print ' The final temperature =  %0.1f K'%(T2)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The final temperature =  531.1 K\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.11  Page No : 107"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "volume_ratio = 1./15\t #final volume to the initial volume of air at the end of compression stroke (no unit)\n",
      "gaamma = 1.4\t\t\t #ratio of the molar heat capacities at constant pressure and constant volume for air (no unit)\n",
      "T1 = 300.\t\t\t     #initial temperature of air in K\n",
      "P1 = 0.1;\t\t\t    #initial pressure of air in MPa\n",
      "R = 8.314;\t\t\t    #universal gas constant in J/molK\n",
      "\n",
      "# Calculations\n",
      "T2 = T1*((1./volume_ratio)**(gaamma-1))\n",
      "P2 = P1*((1./volume_ratio)**(gaamma))\n",
      "W = (R*(T1-T2)*10**-3)/(gaamma-1)\n",
      "\n",
      "# Results\n",
      "print ' The final temperature =  %0.2f K'%(T2);\n",
      "print ' The final pressure =  %0.4f MPa'%(P2);\n",
      "print ' Work done per mole of air =  %0.3f kJ/mol'%(W);"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The final temperature =  886.25 K\n",
        " The final pressure =  4.4313 MPa\n",
        " Work done per mole of air =  -12.185 kJ/mol\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.12  Page No : 110"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "volume_ratio = 1./15;\t\t\t #final volume to the initial volume of ideal gas at the end of compression (no unit)\n",
      "T1 = 300.   \t\t\t #initial temperature of ideal gas in K\n",
      "P1 = 0.1;\t    \t\t #initial pressure of ideal gas in MPa\n",
      "R = 8.314;\t\t    \t #universal gas constant in J/molK\n",
      "n = 1.2;\t\t\t     #index of expansion (no unit)\n",
      "gaamma = 1.4;\t\t\t #ratio of the molar heat capacities at constant pressure and constant volume for ideal gas (no unit)\n",
      "\n",
      "# Calculations\n",
      "P2 = P1*((1./volume_ratio)**n)\n",
      "T2 = T1*(P2/P1)*(volume_ratio)\n",
      "W = (R*(T1-T2)*10**-3)/(n-1)\n",
      "del_u = (R*(T2-T1)*10**-3)/(gaamma-1)\n",
      "q = del_u+W\n",
      "\n",
      "# Results\n",
      "print ' The final pressure =  %0.3f MPa'%(P2);\n",
      "print ' The final temperature =  %0.1f K'%(T2);\n",
      "print ' Work done on the gas =  %f kJ/mol'%(W);\n",
      "print ' Heat interaction during the process =  %f kJ/mol'%(q)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The final pressure =  2.578 MPa\n",
        " The final temperature =  515.6 K\n",
        " Work done on the gas =  -8.963805 kJ/mol\n",
        " Heat interaction during the process =  -4.481902 kJ/mol\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.13  Page No : 112"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "V = 1.;\t    \t\t #volume of tank in m**3\n",
      "T0 = 300.\t\t\t #initial temperature of ideal gas in K\n",
      "P0 = 0.1\t\t\t #initial pressure of ideal gas in MPa\n",
      "T = 500.\t\t\t #temperature of ideal gas in the pipeline in K\n",
      "P = 3.\t\t    \t #pressure of ideal gas in the pipeline in MPa\n",
      "R = 8.314;\t\t\t #universal gas constant in J/molK\n",
      "gaamma = 1.4;\t\t\t #ratio of the molar heat capacities at constant pressure and constant volume for ideal gas (no unit)\n",
      "\n",
      "# Calculations\n",
      "Pf = 3.\n",
      "Tf = (Pf*10**6)/((((Pf*10**6)-(P0*10**6))/(gaamma*T))+((P0*10**6)/T0));\n",
      "N = (V/R)*(((Pf*10**6)/Tf)-((P0*10**6)/T0));\n",
      "\n",
      "# Results\n",
      "print ' The final temperature =  %0.1f K'%(Tf);\n",
      "print ' The amount of gas that has entered the tank =  %0.2f mol'%(N);"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The final temperature =  670.2 K\n",
        " The amount of gas that has entered the tank =  498.30 mol\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.14  Page No : 113"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from scipy.optimize import fsolve\n",
      "\n",
      "# Variables\n",
      "V = 3.  \t\t\t #volume of tank in m**3\n",
      "T0 = 100.;\t\t\t #initial temperature of steam in degree celsius\n",
      "T = 300.;\t\t\t #temperature of superheated steam in the pipeline in degree celsius\n",
      "P = 3.;\t\t\t     #pressure of superheated steam in the pipeline in MPa\n",
      "R = 8.314;\t\t\t #universal gas constant in J/molK\n",
      "\n",
      "# Calculations\n",
      "Ps = 101.33\n",
      "vg = 1.673\n",
      "hg = 2676.0\n",
      "h = 2995.1\n",
      "u0 = ((hg*10**3)-(Ps*10**3*vg))*10**-3\n",
      "m0 = V/vg;\t\t\t\n",
      "\n",
      "Tf = 418.\n",
      "vf = 0.102329\n",
      "uf = 2965.78\n",
      "\n",
      "mf_guess = V/vf\n",
      "\n",
      "def solver_func(ui):\n",
      "    return (mf_guess*ui)-(m0*u0)-((mf_guess-m0)*h);\n",
      "\n",
      "uf_solved = fsolve(solver_func,mf_guess)\n",
      "mf = mf_guess\n",
      "mass = mf-m0\n",
      "\n",
      "# Results\n",
      "print \" The final state of steamsuperheated, Pressure = %d MPa\"%(P);\n",
      "print \" The final state of steamsuperheated, Temperature = %d degree celsius\"%(Tf);\n",
      "print \" The mass of steam that entered the tank = %0.3f kg\"%(mass);"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The final state of steamsuperheated, Pressure = 3 MPa\n",
        " The final state of steamsuperheated, Temperature = 418 degree celsius\n",
        " The mass of steam that entered the tank = 27.524 kg\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.15  Page No : 115"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "V = 0.1;\t\t\t #volume of cylinder in m**3\n",
      "T0 = 300.\t\t\t #initial temperature of nitrogen in K\n",
      "P0 = 14.\t\t\t #initial pressure of nitrogen in MPa\n",
      "P = 0.1;\t\t\t #ambient pressure in MPa\n",
      "Pf = 2. \t\t\t #final pressure of nitrogen in MPa\n",
      "R = 8.314;\t\t\t #universal gas constant in J/molK\n",
      "gaamma = 1.4;\t\t #ratio of the molar heat capacities at constant pressure and constant volume for nitrogen (no unit)\n",
      "\n",
      "# Calculations\n",
      "def solver_func(Ti):\n",
      "    return ((P0*10**6)-(Pf*10**6))-((gaamma/2)*(T0+Ti)*(((P0*10**6)/T0)-((Pf*10**6)/Ti)));\n",
      "\n",
      "Tguess = 300.\n",
      "Tf = fsolve(solver_func,Tguess)\n",
      "\n",
      "N = (V/R)*(((P0*10**6)/T0)-((Pf*10**6)/Tf));\n",
      "\n",
      "# Results\n",
      "print ' The final temperature =  %0.1f K'%(Tf);\n",
      "print ' The amount of gas that has escaped from the cylinder =  %0.2f mol'%(N);"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The final temperature =  181.2 K\n",
        " The amount of gas that has escaped from the cylinder =  428.52 mol\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.16  Page No : 118"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "T0 = 300.;\t\t\t #initial temperature of superheated steam in degree celsius\n",
      "P0 = 3.;\t\t\t #initial pressure of superheated steam in MPa\n",
      "Xe = 0.85;\t\t\t #quality of steam leaving the turbine (no unit)\n",
      "Tf = 45.;\t\t\t #final temperature of steam leaving the turbine in degree celsius\n",
      "Vi = 10.;\t\t\t #velocity of steam at the entrance in m/s\n",
      "Ve = 40.;\t\t\t #exit velocity of steam in m/s\n",
      "Zi = 10.;\t\t\t #elevation at the entrance in m\n",
      "Ze = 4.;\t\t\t #elevation at the exit in m\n",
      "m = 1.;\t\t\t #mass flow rate of steam through turbine in kg/s\n",
      "g = 9.81;\t\t\t #accleration due to gravity in m/s**2\n",
      "\n",
      "# Calculations\n",
      "hi = 2995.1\n",
      "hf = 188.35\n",
      "hg = 2583.3\n",
      "he = ((1-Xe)*hf)+(Xe*hg)\n",
      "Q = 0.\t\t\t \n",
      "enthalpy_change = (he*10**3)-(hi*10**3)\n",
      "KE_change = ((Ve**2)-(Vi**2))/2\n",
      "PE_change = g*(Ze-Zi);\t\t\t\n",
      "Ws = Q-(m*(enthalpy_change+KE_change+PE_change)*10**-3)\n",
      "err_KE = ((KE_change)/(Ws*10**3))*100;\t\n",
      "err_PE = ((abs (PE_change)/(Ws*10**3)))*100\n",
      "err = err_KE+err_PE\n",
      "\n",
      "# Results\n",
      "print ' The percentage error when Kinetic energy change is ignored =  %0.3f '%(err_KE);\n",
      "print ' The percentage error when Potential energy change is ignored =  %0.4f '%(err_PE);\n",
      "print ' The percentage error when both Kinetic and Potential energy changes are ignored =  %f '%(err);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The percentage error when Kinetic energy change is ignored =  0.097 \n",
        " The percentage error when Potential energy change is ignored =  0.0076 \n",
        " The percentage error when both Kinetic and Potential energy changes are ignored =  0.104999 \n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.17  Page No : 119"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# Variables\n",
      "Pi = 5.;\t\t\t #pressure of dry saturated steam at the entrance in bar\n",
      "Pe = 2.;\t\t\t #pressure of dry saturated steam at the exit in bar\n",
      "Vi = 3.;\t\t\t #velocity of dry saturated steam at the entrance in m/s\n",
      "m = 1.; \t\t\t #flow rate of steam through the nozzle in kg/s\n",
      "g = 9.81;\t\t\t #acceleration due to gravity in m/s**2\n",
      "\n",
      "# Calculations\n",
      "hi = 2747.5\n",
      "he = 2706.3\n",
      "ve = 0.8854\n",
      "Zi = 0;\t\t\n",
      "Ze = 0;\t\t\n",
      "Q = 0;\t\t\n",
      "Ws = 0;\t\t\n",
      "Ve = math.sqrt (2*(((Q-Ws)/m)-(g*(Zi-Ze))-((he*10**3)-(hi*10**3)))+(Vi**2))\n",
      "A = (m*ve)/Ve\n",
      "\n",
      "# Results\n",
      "print ' The velocity of dry saturated steam at the exit =  %0.2f m/s'%(Ve);\n",
      "print ' The cross sectional area of the nozzle at the exit =  %0.3e m**2'%(A);"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The velocity of dry saturated steam at the exit =  287.07 m/s\n",
        " The cross sectional area of the nozzle at the exit =  3.084e-03 m**2\n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.18  Page No : 123"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "T1 = 270.\t\t\t #temperature of wet steam in degree celsius\n",
      "T2 = 120.\t\t\t #final temperature of superheated steam in degree celsius\n",
      "P = 0.1;\t\t\t #pressure of superheated steam in MPa\n",
      "\n",
      "# Calculations\n",
      "hf = 1185.2 \t\t\t\n",
      "hg = 2789.9\t    \t\t\n",
      "he = 2716.04\t\t\t\n",
      "Xi = (he-hf)/(hg-hf);\t\n",
      "\n",
      "# Results\n",
      "print ' The quality of wet steam =  %0.3f '%(Xi);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The quality of wet steam =  0.954 \n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.20  Page No : 128"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "del_H = -90.135;\t\t\t #standard enthalpy change for the reaction CO(g)+2H2(g)--->CH3OH(g) at 298.15K in kJ\n",
      "\n",
      "# Calculations\n",
      "del_H1 = 2*del_H\n",
      "del_H2 = (1./2)*del_H\n",
      "\n",
      "# Results\n",
      "print ' The standard enthalpy change for the reaction 2COg)+4H2g)---->2CH3OHg \\\n",
      ") at 298.15K =  %0.2f kJ'%(del_H1);\n",
      "print ' The standard enthalpy change for the reaction 1./2)COg)+H2g)---->1./2\\\n",
      ")CH3OHg) at 298.15K =  %0.4f kJ'%(del_H2 );\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The standard enthalpy change for the reaction 2COg)+4H2g)---->2CH3OHg ) at 298.15K =  -180.27 kJ\n",
        " The standard enthalpy change for the reaction 1./2)COg)+H2g)---->1./2)CH3OHg) at 298.15K =  -45.0675 kJ\n"
       ]
      }
     ],
     "prompt_number": 21
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.22  Page No : 130"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "del_Hf_C4H10 = -74.943;\t\t\t #smath.tan(math.radiansard enthalpy of formation of C4H10(g) at 298.15K in kJ\n",
      "del_Hf_CO2 = -393.978;\t\t\t #smath.tan(math.radiansard enthalpy of formation of CO2(g) at 298.15K in kJ\n",
      "del_Hf_H2O = -241.997;\t\t\t #smath.tan(math.radiansard enthalpy of formation of H2O(g) at 298.15K in kJ\n",
      "\n",
      "# Calculations\n",
      "\n",
      "del_Hr = (5*del_Hf_H2O)+(4*del_Hf_CO2)-(del_Hf_C4H10);\n",
      "\n",
      "# Results\n",
      "print ' The standard enthalpy change for the reaction C4H10g)+13\\\n",
      "/2)O2g)---->4CO2g)+5H2Og) at 298.15K =  %0.3f kJ'%(del_Hr);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The standard enthalpy change for the reaction C4H10g)+13/2)O2g)---->4CO2g)+5H2Og) at 298.15K =  -2710.954 kJ\n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.23  Page No : 131"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "del_Hf_C4H10 = -74.943;\t\t\t #smath.tan(math.radiansard enthalpy of formation of C4H10(g) at 298.15K in kJ\n",
      "del_Hf_CO2 = -393.978;\t\t\t #smath.tan(math.radiansard enthalpy of formation of CO2(g) at 298.15K in kJ\n",
      "del_Hf_H2O = -241.997;\t\t\t #smath.tan(math.radiansard enthalpy of formation of H2O(g) at 298.15K in kJ\n",
      "del_H_vap = 43.966;\t\t\t #enthalpy of vaporization of H2O at 298.15K in kJ/mol\n",
      "\n",
      "# Calculations\n",
      "\n",
      "del_H1 = 0.\n",
      "del_H2 = 5*(-del_H_vap)\n",
      "del_H3 = 0.\n",
      "\n",
      "del_H = (5*del_Hf_H2O)+(4*del_Hf_CO2)-(del_Hf_C4H10);\n",
      "del_net_H = (del_H)+(del_H1)+(del_H2)+(del_H3)\n",
      "\n",
      "# Results\n",
      "print ' The standard enthalpy change for the reaction C4H10g)+13/2)O2g)---->4CO2g\\\n",
      ")+5H2Ol) at 298.15K =  %0.3f kJ'%(del_net_H);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The standard enthalpy change for the reaction C4H10g)+13/2)O2g)---->4CO2g)+5H2Ol) at 298.15K =  -2930.784 kJ\n"
       ]
      }
     ],
     "prompt_number": 23
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.24  Page No : 132"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "del_H_comb = 2880.44;\t\t\t #gross heating value of n-buatne gas at 298.15K in kJ/mol\n",
      "del_Hf_CO2 = -393.978;\t\t\t #standard enthalpy of formation of CO2(g) at 298.15K in kJ\n",
      "del_Hf_H2O = -285.958;\t\t\t #standard enthalpy of formation of H2O(l) at 298.15K in kJ\n",
      "del_Hf_O2 = 0.;\t\t        \t #standard enthalpy of formation of O2(g) at 298.15K in kJ\n",
      "\t\t\t \n",
      "# Calculations\n",
      "n_CO2 = 4.\n",
      "n_H2O = 5.\n",
      "n_O2 = -13./2\n",
      "n_C4H10 = -1.\n",
      "\t\t\t \n",
      "del_Hf_C4H10 = (n_CO2*del_Hf_CO2)+(n_H2O*del_Hf_H2O)+(n_O2*del_Hf_O2)-(-del_H_comb);\n",
      "\n",
      "\n",
      "# Results\n",
      "print ' The standard enthalpy of formation of n-butane gas at 298.15K =  %0.3f kJ'%(del_Hf_C4H10);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The standard enthalpy of formation of n-butane gas at 298.15K =  -125.262 kJ\n"
       ]
      }
     ],
     "prompt_number": 24
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.25  Page No : 133"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "del_Hc_A = -890.94;\t\t\t #enthalpy change accompanying reaction A in kJ\n",
      "del_Hc_B = -283.18;\t\t\t #enthalpy change accompanying reaction B in kJ\n",
      "del_Hc_C = -286.03;\t\t\t #enthalpy change accompanying reaction C in kJ\n",
      "del_H_vap = -43.966;\t\t\t #enthalpy change of vaporization of H2O at 298.15K in kJ/mol\n",
      "\n",
      "# Calculations\n",
      "del_H0 = (del_Hc_A)-(del_Hc_B)-(3*del_Hc_C)+(del_H_vap)\n",
      "\n",
      "# Results\n",
      "print ' The standard enthalpy change at 298.15K for the reaction \\\n",
      "CH4g)+H2Og)--->COg)+3H2g) =  %0.3f kJ'%(del_H0);\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The standard enthalpy change at 298.15K for the reaction CH4g)+H2Og)--->COg)+3H2g) =  206.364 kJ\n"
       ]
      }
     ],
     "prompt_number": 25
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.26  Page No : 135"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "#The reaction is : C2H4(g)+H2O(g)--->C2H5OH(g)\n",
      "del_H_vap = 43.82\n",
      "\n",
      "del_Hf = [52.335,-241.997,0,-277.819]\n",
      "a = [4.196,28.850,20.691,0]\t\n",
      "b = [154.565*10**-3,12.055*10**-3,205.346*10**-3,0]\n",
      "c = [-81.076*10**-6,0,-99.793*10**-6,0]\n",
      "d = [16.813*10**-9,0,18.825*10**-9,0]\t\n",
      "e = [0,1.006*10**5,0,0];\t\t\n",
      "\n",
      "T1 = 298.15\t\t\n",
      "T2 = 400.\t\t\t\n",
      "n_C2H4 = -1.\n",
      "n_H2O = -1.\n",
      "n_C2H5OH = 1.\n",
      "\n",
      "# Calculations\n",
      "\n",
      "del_Hf_C2H5OH_g = del_Hf[3]+del_H_vap;\n",
      "del_Hr = (n_C2H5OH*del_Hf_C2H5OH_g)+(n_C2H4*del_Hf[0])+(n_H2O*del_Hf[1])\n",
      "del_a = (n_C2H4*a[0])+(n_H2O*a[1])+(n_C2H5OH*a[2])\t\t\t \n",
      "del_b = (n_C2H4*b[0])+(n_H2O*b[1])+(n_C2H5OH*b[2])\t\t\t \n",
      "del_c = (n_C2H4*c[0])+(n_H2O*c[1])+(n_C2H5OH*c[2])\t\t\t \n",
      "del_d = (n_C2H4*d[0])+(n_H2O*d[1])+(n_C2H5OH*d[2])\t\t\t \n",
      "del_e = (n_C2H4*e[0])+(n_H2O*e[1])+(n_C2H5OH*e[2])\t\t\t \n",
      "del_H0 = (del_Hr*10**3)-((del_a*T1)+((del_b/2)*T1**2)+((del_c/3)*T1**3)+((del_d/4)*T1**4)-(del_e/T1))\n",
      "del_Hr_T2 = (del_H0+((del_a*T2)+((del_b/2)*T2**2)+((del_c/3)*T2**3)+((del_d/4)*T2**4)-(del_e/T2)))*10**-3;\n",
      "\n",
      "# Results\n",
      "print ' The standard enthalpy change at 400K for the reaction\\\n",
      " C2H4g)+H2Og)--->C2H5OHg) =  %f kJ'%(del_Hr_T2);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The standard enthalpy change at 400K for the reaction C2H4g)+H2Og)--->C2H5OHg) =  -44.529472 kJ\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.28  Page No : 137"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from scipy.optimize import fsolve \n",
      "import math \n",
      "\n",
      "# Variables\n",
      " \n",
      "#The combustion reaction of methane is given by:\n",
      "# CH4(g)+2O2(g)--->CO2(g)+2H2O(g)\n",
      "\n",
      "n_O2 = 2.\t\t\t # stoichiometric amount of oxygen required for combustion\n",
      "n_CH4 = 1.\t\t\t #number of moles of CH4(g) in moles\n",
      "n_CO2 = 1.\t\t\t #number of moles of CO2(g) formed in the combustion reaction in moles\n",
      "n_H2O = 2.\t\t\t #number of moles of H2O(g) formed in the combustion reaction in moles\n",
      "del_Hf = [-74.943,0,-393.978,-241.997];\t\t\t # standard enthalpies of formation of CH4(g),O2(g),CO2(g),H2O(g) at 298.15K in kJ\n",
      "a = [45.369,28.850,30.255,27.270];\t\t\t     #coefficients to compute isobaric molar heat capacity of CO2(g),H2O(g),O2(g),N2(g) in J/molK\n",
      "b = [8.688*10**-3,12.055*10**-3,4.207*10**-3,4.930*10**-3];\t\t\t #coefficients to compute isobaric molar heat capacity of CO2(g),H2O(g),O2(g),N2(g) in J/molK\n",
      "c = [0,0,0,0];  \t    \t\t #coefficients to compute isobaric molar heat capacity of CO2(g),H2O(g),O2(g),N2(g) in J/molK\n",
      "d = [0,0,0,0];\t    \t    \t #coefficients to compute isobaric molar heat capacity of CO2(g),H2O(g),O2(g),N2(g) in J/molK\n",
      "e = [-9.619*10**5,1.006*10**5,-1.887*10**5,0.333*10**5];\t\t\t #coefficients to compute isobaric molar heat capacity of CO2(g),H2O(g),O2(g),N2(g) in J/molK\n",
      "per_excess_air = 50. \t\t\t #percentage excess of air supplied to the adiabatic burner\n",
      "T_amb = 298.15\t\t\t # temperature at which air and methane enter the burner in K\n",
      "per_N2 = 79.\t\t\t #percentage of N2 in the air supplied\n",
      "per_O2 = 21.\t\t\t #percentage of O2 in the air supplied\n",
      "\n",
      "# Calculations\n",
      "n_O2_actual = (1+(per_excess_air/100))*n_O2\n",
      "n_N2 = n_O2_actual*(per_N2/per_O2);\t\t\t\n",
      "n_O2_residual = n_O2_actual-n_O2;\t\t\t\n",
      "\n",
      "del_Hr = (n_CO2*del_Hf[2])+(n_H2O*del_Hf[3])-(n_O2*del_Hf[1])-(n_CH4*del_Hf[0])\n",
      "\n",
      "del_a = (n_CO2*a[0])+(n_H2O*a[1])+(n_O2_residual*a[2])+(n_N2*a[3])\n",
      "del_b = (n_CO2*b[0])+(n_H2O*b[1])+(n_O2_residual*b[2])+(n_N2*b[3])\n",
      "del_c = (n_CO2*c[0])+(n_H2O*c[1])+(n_O2_residual*c[2])+(n_N2*c[3])\n",
      "del_d = (n_CO2*d[0])+(n_H2O*d[1])+(n_O2_residual*d[2])+(n_N2*d[3])\n",
      "del_e = (n_CO2*e[0])+(n_H2O*e[1])+(n_O2_residual*e[2])+(n_N2*e[3]);\t\n",
      "tguess = 500.\n",
      "\n",
      "def solver_func(ti):\n",
      "    return (-(del_Hr*10**3))-((del_a*(ti-T_amb))+((del_b/2)*((ti**2)-(T_amb**2)))+((del_c/3)*((ti**3)-(T_amb**3)))+((del_d/4)*((ti**4)-(T_amb**4)))+(del_e*((1./T_amb)-(1./ti))));\n",
      "\n",
      "T = fsolve(solver_func,tguess)\n",
      "\n",
      "# Results\n",
      "print ' The flame temperature when methane is burned with 50 percent excess air \\\n",
      "in an adiabatic burner =  %f K'%(T);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The flame temperature when methane is burned with 50 percent excess air in an adiabatic burner =  1793.784965 K\n"
       ]
      }
     ],
     "prompt_number": 29
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 4.29  Page No : 139"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "T_exit = 550.\t\t\t #temperature in K at which the combustion products leave the boiler\n",
      "percent_molar_comp_prdct = [6.28,3.14,7.85,82.73];\t\t\t # percentage molar composition of the combustion products CO2(g),CO(g),O2(g),N2(g) on dry basis\n",
      "T_ent = 298.15;\t\t\t #temperature in K at which Propane and air enter the combustion chamber\n",
      "del_Hf = [-393.978,-110.532,-241.997,0,0,-103.833];\t\t\t #smath.tan(math.radiansard enthalpies of formation of CO2(g),CO(g),H2O(g),O2(g),N2(g),C3H8(g) at 298.15K in kJ\n",
      "a = [45.369,28.068,30.255,27.270,28.850];\t\t\t #coefficients to compute isobaric molar heat capacity of CO2(g),CO(g),O2(g),N2(g),H2O(g) in J/molK\n",
      "\n",
      "#coefficients to compute isobaric molar heat capacity of CO2(g),CO(g),O2(g),N2(g),H2O(g) in J/molK\n",
      "b = [8.688*10**-3,4.631*10**-3,4.207*10**-3,4.930*10**-3,12.055*10**-3];\n",
      "c = [0,0,0,0,0];\t\t\t #coefficients to compute isobaric molar heat capacity of CO2(g),CO(g),O2(g),N2(g),H2O(g) in J/molK\n",
      "d = [0,0,0,0,0];\t\t\t #coefficients to compute isobaric molar heat capacity of CO2(g),CO(g),O2(g),N2(g),H2O(g) in J/molK\n",
      "e = [-9.619*10**5,-0.258*10**5,-1.887*10**5,0.333*10**5,1.006*10**5];\t\t\t #coefficients to compute isobaric molar heat capacity of CO2(g),CO(g),O2(g),N2(g),H2O(g) in J/molK\n",
      "per_N2 = 79.\t\t\t #percentage of nitrogen in air\n",
      "per_O2 = 21.\t\t\t #percentage of oxygen in air\n",
      "molar_mass_propane = 44.*10**-3;\t\t\t #molar mass of propane in kg/mole\n",
      "\n",
      "# Calculations\n",
      "# TAKE BASIS AS 100 mol OF  DRY COMBUSTION PRODUCTS\n",
      "n_CO2 = percent_molar_comp_prdct[0]\t\t\t #number of moles of CO2(g) in the product stream\n",
      "n_CO = percent_molar_comp_prdct[1]\t\t\t #number of moles of CO(g) in the product stream\n",
      "n_O2 = percent_molar_comp_prdct[2]\t\t\t #number of moles of O2(g) in the product stream\n",
      "n_N2 = percent_molar_comp_prdct[3]\t\t\t #number of moles of N2(g) in the product stream\n",
      "\n",
      "x = (n_CO2+n_CO)/3;\n",
      "\n",
      "y = (2*n_N2)/(2*(per_N2/per_O2));\n",
      "\n",
      "z = (2*y)-(2*n_CO2)-(n_CO)-(2*n_O2);\n",
      "\n",
      "n_H2O = z\n",
      "n_C3H8 = x\n",
      "\n",
      "del_Hr = (n_CO2*del_Hf[0])+(n_CO*del_Hf[1])+(n_H2O*del_Hf[2])-(n_C3H8*del_Hf[5]);\n",
      "\n",
      "del_a = (n_CO2*a[0])+(n_CO*a[1])+(n_O2*a[2])+(n_N2*a[3])+(n_H2O*a[4])\t\n",
      "del_b = (n_CO2*b[0])+(n_CO*b[1])+(n_O2*b[2])+(n_N2*b[3])+(n_H2O*b[4])\t\n",
      "del_c = (n_CO2*c[0])+(n_CO*c[1])+(n_O2*c[2])+(n_N2*c[3])+(n_H2O*c[4])\t\n",
      "del_d = (n_CO2*d[0])+(n_CO*d[1])+(n_O2*d[2])+(n_N2*d[3])+(n_H2O*d[4])\t\n",
      "del_e = (n_CO2*e[0])+(n_CO*e[1])+(n_O2*e[2])+(n_N2*e[3])+(n_H2O*e[4])\t\n",
      "\n",
      "#calulation of del_Hp J\n",
      "del_Hp = (del_a*(T_exit-T_ent))+((del_b/2)*((T_exit**2)-(T_ent**2)))+((del_c/3)*((T_exit**3)-(T_ent**3)))+((del_d/4)*((T_exit**4)-(T_ent**4)))-(del_e*((1./T_exit)-(1./T_ent)));\n",
      "del_H = ((del_Hr*10**3)+(del_Hp))*10**-3;\t\t\t \n",
      "mass_propane = n_C3H8*molar_mass_propane;\t\t\t \n",
      "energy = (-(del_H*10**3)/mass_propane)*10**-6;\t\t\n",
      "       \n",
      "# Results\n",
      "print ' The energy transferred as heat per kg propane =  %f MJ'%(energy);     \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The energy transferred as heat per kg propane =  33.741510 MJ\n"
       ]
      }
     ],
     "prompt_number": 31
    }
   ],
   "metadata": {}
  }
 ]
}