summaryrefslogtreecommitdiff
path: root/_Engineering_Thermodynamics_by__O._Singh/chapter3_2.ipynb
blob: 22ed40c9536c31ea3c8bdef3b23944211687e42f (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
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 3:First Law of Thermo Dynamics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.1;pg no:76"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.1, Page:46  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 1\n",
      "a> work done on piston(W_piston)in KJ can be obtained as\n",
      "W_piston=pdv\n",
      "b> paddle work done on the system(W_paddle)=-4.88 KJ\n",
      "net work done of system(W_net)in KJ\n",
      "W_net=W_piston+W_paddle\n",
      "so work done on system(W_net)=1.435 KJ\n"
     ]
    }
   ],
   "source": [
    "#cal of work done on system\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "print\"Example 3.1, Page:46  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 1\")\n",
    "import scipy\n",
    "from scipy import integrate\n",
    "\n",
    "def fun1(x):\n",
    "\ty=x*x\n",
    "\treturn y\n",
    "\n",
    "p=689.;#pressure of gas in cylinder in kpa\n",
    "v1=0.04;#initial volume of fluid in m^3\n",
    "v2=0.045;#final volume of fluid in m^3\n",
    "W_paddle=-4.88;#paddle work done on the system in KJ\n",
    "print(\"a> work done on piston(W_piston)in KJ can be obtained as\")\n",
    "print(\"W_piston=pdv\")\n",
    "#function y = f(v), y=p, endfunction\n",
    "def fun1(x):\n",
    "\ty=p\n",
    "\treturn y\n",
    "\n",
    "W_piston=scipy.integrate.quad(fun1,v1,v2) \n",
    "print(\"b> paddle work done on the system(W_paddle)=-4.88 KJ\")\n",
    "print(\"net work done of system(W_net)in KJ\")\n",
    "print(\"W_net=W_piston+W_paddle\")\n",
    "print(\"so work done on system(W_net)=1.435 KJ\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.2;pg no:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.2, Page:76  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 2\n",
      "as the vessel is rigid therefore work done shall be zero\n",
      "W=0\n",
      "from first law of thermodynamics,heat required(Q)in KJ\n",
      "Q=U2-U1+W=Q=m(u2-u1)+W\n",
      "so heat required = 5.6\n"
     ]
    }
   ],
   "source": [
    "#cal of heat required\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "print\"Example 3.2, Page:76  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 2\")\n",
    "m=0.5;#mass of gas in kg\n",
    "u1=26.6;#internal energy of gas at 200 degree celcius\n",
    "u2=37.8;#internal energy of gas at 400 degree celcius\n",
    "W=0;#work done by vessel in KJ\n",
    "print(\"as the vessel is rigid therefore work done shall be zero\")\n",
    "print(\"W=0\")\n",
    "print(\"from first law of thermodynamics,heat required(Q)in KJ\")\n",
    "print(\"Q=U2-U1+W=Q=m(u2-u1)+W\")\n",
    "Q=m*(u2-u1)+W\n",
    "print(\"so heat required =\"),round(Q,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.3;pg no:77"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.3, Page:77  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 3\n",
      "by steady flow energy equation\n",
      "q+h1+C1^2/2+g*z1=h2+C2^2/2+g*z2+w\n",
      "let us assume changes in kinetic and potential energy is negligible,during flow the work interaction shall be zero\n",
      "q=h2-h1\n",
      "rate of heat removal(Q)in KJ/hr\n",
      "Q=m(h2-h1)=m*Cp*(T2-T1)\n",
      "heat should be removed at the rate=KJ/hr 40500.0\n"
     ]
    }
   ],
   "source": [
    "#cal of \"heat should be removed\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "print\"Example 3.3, Page:77  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 3\")\n",
    "m=50;#rate at which carbon dioxide passing through heat exchanger in kg/hr\n",
    "T2=800;#initial temperature of carbon dioxide in degree celcius\n",
    "T1=50;#final temperature of carbon dioxide in degree celcius\n",
    "Cp=1.08;#specific heat at constant pressure in KJ/kg K\n",
    "print(\"by steady flow energy equation\")\n",
    "print(\"q+h1+C1^2/2+g*z1=h2+C2^2/2+g*z2+w\")\n",
    "print(\"let us assume changes in kinetic and potential energy is negligible,during flow the work interaction shall be zero\")\n",
    "print(\"q=h2-h1\")\n",
    "print(\"rate of heat removal(Q)in KJ/hr\")\n",
    "print(\"Q=m(h2-h1)=m*Cp*(T2-T1)\")\n",
    "Q=m*Cp*(T2-T1)\n",
    "print(\"heat should be removed at the rate=KJ/hr\"),round(Q)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.4;pg no:77"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#cal of work done by surrounding on system\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "print\"Example 3.4, Page:77  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 4\")\n",
    "v=0.78;#volume of cylinder in m^3\n",
    "p=101.325;#atmospheric pressure in kPa\n",
    "print(\"total work done by the air at atmospheric pressure of 101.325 kPa\")\n",
    "print(\"W=(pdv)cylinder+(pdv)air\")\n",
    "print(\"0+p*(delta v)\")\n",
    "print(\"work done by air(W)=-p*v in KJ\")\n",
    "W=-p*v\n",
    "print(\"so work done by surrounding on system=KJ\"),round(-W,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.5:pg no:77"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.5, Page:77  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 5\n",
      "given p*v^1.3=constant\n",
      "assuming expansion to be quasi-static,the work may be given as\n",
      "W=m(p*dv)=(p2*V2-p1*V1)/(1-n)\n",
      "from internal energy relation,change in specific internal energy\n",
      "deltau=u2-u1=1.8*(p2*v2-p1*v1)in KJ/kg\n",
      "total change,deltaU=1.8*m*(p2*v2-p1*v1)=1.8*(p2*V2-p1*V1)in KJ\n",
      "using p1*V1^1.3=p2*V2^1.3\n",
      "V2=in m^3 0.85\n",
      "take V2=.852 m^3\n",
      "so deltaU in KJ\n",
      "and W in KJ 246.67\n",
      "from first law\n",
      "deltaQ=KJ 113.47\n",
      "heat interaction=113.5 KJ\n",
      "work interaction=246.7 KJ\n",
      "change in internal energy=-113.2 KJ\n"
     ]
    }
   ],
   "source": [
    "#cal of heat,work interaction and change in internal energy\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "print\"Example 3.5, Page:77  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 5\")\n",
    "m=5;#mass of gas in kg\n",
    "p1=1*10**3;#initial pressure of gas in KPa\n",
    "V1=0.5;#initial volume of gas in m^3\n",
    "p2=0.5*10**3;#final pressure of gas in KPa\n",
    "n=1.3;#expansion constant\n",
    "print(\"given p*v^1.3=constant\")\n",
    "print(\"assuming expansion to be quasi-static,the work may be given as\")\n",
    "print(\"W=m(p*dv)=(p2*V2-p1*V1)/(1-n)\")\n",
    "print(\"from internal energy relation,change in specific internal energy\")\n",
    "print(\"deltau=u2-u1=1.8*(p2*v2-p1*v1)in KJ/kg\")\n",
    "print(\"total change,deltaU=1.8*m*(p2*v2-p1*v1)=1.8*(p2*V2-p1*V1)in KJ\")\n",
    "print(\"using p1*V1^1.3=p2*V2^1.3\")\n",
    "V2=V1*(p1/p2)**(1/1.3)\n",
    "print(\"V2=in m^3\"),round(V2,2)\n",
    "print(\"take V2=.852 m^3\")\n",
    "V2=0.852;#final volume of gas in m^3\n",
    "print(\"so deltaU in KJ\")\n",
    "deltaU=1.8*(p2*V2-p1*V1)\n",
    "W=(p2*V2-p1*V1)/(1-n)\n",
    "print(\"and W in KJ\"),round(W,2)\n",
    "print(\"from first law\")\n",
    "deltaQ=deltaU+W\n",
    "print(\"deltaQ=KJ\"),round(deltaQ,2)\n",
    "print(\"heat interaction=113.5 KJ\")\n",
    "print(\"work interaction=246.7 KJ\")\n",
    "print(\"change in internal energy=-113.2 KJ\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.6;pg no:78"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.6, Page:78  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 6\n",
      "final state volume(v2)in m^3\n",
      "v2= 0.0\n",
      "take v2=0.03 m^3\n",
      "now internal energy of gas is given by U=7.5*p*v-425\n",
      "change in internal energy(deltaU)in KJ\n",
      "deltaU=U2-U1=7.5*p2*v2-7.5*p1*v1\n",
      "deltaU=7.5*10^3*(p2*v2-p1*v1) 75.0\n",
      "for quasi-static process\n",
      "work(W) in KJ,W=p*dv\n",
      "W=(p2*v2-p1*v1)/(1-n)\n",
      "from first law of thermodynamics,\n",
      "heat interaction(deltaQ)=deltaU+W\n",
      "heat=50 KJ\n",
      "work=25 KJ(-ve)\n",
      "internal energy change=75 KJ\n",
      "if 180 KJ heat transfer takes place,then from 1st law,\n",
      "deltaQ= 50.0\n",
      "since end states remain same,therefore deltaU i.e change in internal energy remains unaltered.\n",
      "W=KJ 105.0\n"
     ]
    }
   ],
   "source": [
    "#cal of heat,workinternal energy change\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "print\"Example 3.6, Page:78  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 6\")\n",
    "p1=1;#initial pressure of gas in MPa\n",
    "v1=0.05;#initial volume of gas in m^3\n",
    "p2=2;#final pressure of gas in MPa\n",
    "n=1.4;#expansion constant\n",
    "print(\"final state volume(v2)in m^3\")\n",
    "v2=((p1/p2)**(1/1.4))*v1\n",
    "print(\"v2=\"),round(v2,2)\n",
    "print(\"take v2=0.03 m^3\")\n",
    "v2=0.03;#final volume of gas in m^3\n",
    "print(\"now internal energy of gas is given by U=7.5*p*v-425\")\n",
    "print(\"change in internal energy(deltaU)in KJ\")\n",
    "print(\"deltaU=U2-U1=7.5*p2*v2-7.5*p1*v1\")\n",
    "deltaU=7.5*10**3*(p2*v2-p1*v1)\n",
    "print(\"deltaU=7.5*10^3*(p2*v2-p1*v1)\"),round(deltaU,2)\n",
    "print(\"for quasi-static process\")\n",
    "print(\"work(W) in KJ,W=p*dv\")\n",
    "W=((p2*v2-p1*v1)/(1-n))*10**3\n",
    "print(\"W=(p2*v2-p1*v1)/(1-n)\")\n",
    "print(\"from first law of thermodynamics,\")\n",
    "print(\"heat interaction(deltaQ)=deltaU+W\")\n",
    "deltaQ=deltaU+W\n",
    "print(\"heat=50 KJ\")\n",
    "print(\"work=25 KJ(-ve)\")\n",
    "print(\"internal energy change=75 KJ\")\n",
    "print(\"if 180 KJ heat transfer takes place,then from 1st law,\")\n",
    "print(\"deltaQ=\"),round(deltaQ,2)\n",
    "print(\"since end states remain same,therefore deltaU i.e change in internal energy remains unaltered.\")\n",
    "W=180-75\n",
    "print(\"W=KJ\"),round(W,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.7;pg no:79"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.7, Page:79  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 7\n",
      "characteristics gas constant(R)in J/kg K\n",
      "R= 519.64\n",
      "take R=0.520,KJ/kg K\n",
      "Cv=inKJ/kg K 1.18\n",
      "y= 1.44\n",
      "for polytropic process,v2=((p1/p2)^(1/n))*v1 in m^3\n",
      "now,T2=in K\n",
      "work(W)in KJ/kg\n",
      "W= -257.78\n",
      "for polytropic process,heat(Q)in KJ/K\n",
      "Q= 82.02\n"
     ]
    }
   ],
   "source": [
    "#cal of work and heat\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "print\"Example 3.7, Page:79  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 7\")\n",
    "M=16;#molecular weight of gas\n",
    "p1=101.3;#initial pressure of gas in KPa\n",
    "p2=600;#final pressure of gas in KPa\n",
    "T1=(273+20);#initial temperature of gas in K\n",
    "R1=8.3143*10**3;#universal gas constant in J/kg K\n",
    "Cp=1.7;#specific heat at constant pressure in KJ/kg K\n",
    "n=1.3;#expansion constant\n",
    "T2=((p2/p1)**(n-1/n))\n",
    "print(\"characteristics gas constant(R)in J/kg K\")\n",
    "R=R1/M\n",
    "print(\"R=\"),round(R,2)\n",
    "print(\"take R=0.520,KJ/kg K\")\n",
    "R=0.520;#characteristics gas constant in KJ/kg K\n",
    "Cv=Cp-R\n",
    "print(\"Cv=inKJ/kg K\"),round(Cv,2)\n",
    "y=Cp/Cv\n",
    "print(\"y=\"),round(y,2)\n",
    "y=1.44;#ratio of specific heat at constant pressure to constant volume\n",
    "print(\"for polytropic process,v2=((p1/p2)^(1/n))*v1 in m^3\")\n",
    "T2=T1*((p2/p1)**((n-1)/n))\n",
    "print(\"now,T2=in K\")\n",
    "print(\"work(W)in KJ/kg\")\n",
    "W=R*((T1-T2)/(n-1))\n",
    "print(\"W=\"),round(W,2)\n",
    "W=257.78034;#work done in KJ/kg\n",
    "print(\"for polytropic process,heat(Q)in KJ/K\")\n",
    "Q=((y-n)/(y-1))*W\n",
    "print(\"Q=\"),round(Q,2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.8;pg no:80"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.8, Page:80  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 8\n",
      "applying steady flow energy equation with inlet and exit states as 1,2 with no heat and work interaction and no change in potential energy\n",
      "h1+C1^2/2=h2+C2^2/2\n",
      "given that C1=0,negligible inlet velocity\n",
      "so C2=sqrt(2(h1-h2))=sqrt(2*Cp*(T1-T2))\n",
      "exit velocity(C2)in m/s 1098.2\n"
     ]
    }
   ],
   "source": [
    "#cal of exit velocity\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "import math\n",
    "print\"Example 3.8, Page:80  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 8\")\n",
    "T1=(627+273);#initial temperature of air in nozzle in K\n",
    "T2=(27+273);#temperature at which air leaves nozzle in K\n",
    "Cp=1.005*10**3;#specific heat at constant pressure in J/kg K\n",
    "C2=math.sqrt(2*Cp*(T1-T2))\n",
    "print(\"applying steady flow energy equation with inlet and exit states as 1,2 with no heat and work interaction and no change in potential energy\")\n",
    "print(\"h1+C1^2/2=h2+C2^2/2\")\n",
    "print(\"given that C1=0,negligible inlet velocity\")\n",
    "print(\"so C2=sqrt(2(h1-h2))=sqrt(2*Cp*(T1-T2))\")\n",
    "print(\"exit velocity(C2)in m/s\"),round(C2,1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.9;pg no:80"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.9, Page:80  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 9\n",
      "work interaction,W=-200 KJ/kg of air\n",
      "increase in enthalpy of air=100 KJ/kg of air\n",
      "total heat interaction,Q=heat transferred to water + heat transferred to atmosphere\n",
      "writing steady flow energy equation on compressor,for unit mass of air entering at 1 and leaving at 2\n",
      "h1+C1^2/2+g*z1+Q=h2+C2^2/2+g*z2+W\n",
      "assuming no change in potential energy and kinetic energy\n",
      "deltaK.E=deltaP.=0\n",
      "total heat interaction(Q)in KJ/kg of air\n",
      "Q= -100.0\n",
      "Q=heat transferred to water + heat transferred to atmosphere=Q1+Q2\n",
      "so heat transferred to atmosphere(Q2)in KJ/kg of air -10.0\n"
     ]
    }
   ],
   "source": [
    "#cal of heat transferred to atmosphere\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "print\"Example 3.9, Page:80  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 9\")\n",
    "W=-200;#shaft work in KJ/kg of air\n",
    "deltah=100;#increase in enthalpy in KJ/kg of air\n",
    "Q1=-90;#heat transferred to water in KJ/kg of air\n",
    "print(\"work interaction,W=-200 KJ/kg of air\")\n",
    "print(\"increase in enthalpy of air=100 KJ/kg of air\")\n",
    "print(\"total heat interaction,Q=heat transferred to water + heat transferred to atmosphere\")\n",
    "print(\"writing steady flow energy equation on compressor,for unit mass of air entering at 1 and leaving at 2\")\n",
    "print(\"h1+C1^2/2+g*z1+Q=h2+C2^2/2+g*z2+W\")\n",
    "print(\"assuming no change in potential energy and kinetic energy\")\n",
    "print(\"deltaK.E=deltaP.=0\")\n",
    "print(\"total heat interaction(Q)in KJ/kg of air\")\n",
    "Q=deltah+W\n",
    "print(\"Q=\"),round(Q,2)\n",
    "Q2=Q-Q1\n",
    "print(\"Q=heat transferred to water + heat transferred to atmosphere=Q1+Q2\")\n",
    "print(\"so heat transferred to atmosphere(Q2)in KJ/kg of air\"),round(Q2,2)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.10;pg no:81"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.10, Page:81  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 10\n",
      "above problem can be solved using steady flow energy equations upon hot water flow\n",
      "Q+m1*(h1+C1^2/2+g*z1)=W+m2*(h2+C2^2/2+g*z2)\n",
      "here total heat to be supplied(Q)in kcal/hr\n",
      "so heat lost by water(-ve),Q=-25000 kcal/hr\n",
      "there shall be no work interaction and change in kinetic energy,so,steady flow energy equation shall be,\n",
      "Q+m*(h1+g*z1)=m*(h2+g*z2)\n",
      "so water circulation rate(m)in kg/hr\n",
      "so m=Q*10^3*4.18/(g*deltaz-(h1-h2)*10^3*4.18\n",
      "water circulation rate=(m)in kg/min 11.91\n"
     ]
    }
   ],
   "source": [
    "#cal of water circulation rate\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "print\"Example 3.10, Page:81  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 10\")\n",
    "n=500;#total number of persons\n",
    "q=50;#heat requirement per person in kcal/hr\n",
    "h1=80;#enthalpy of hot water enter in pipe in kcal/kg\n",
    "h2=45;#enthalpy of hot water leaves the pipe in kcal/kg\n",
    "g=9.81;#acceleartion due to gravity in m/s^2\n",
    "deltaz=10;#difference in elevation of inlet and exit pipe in m\n",
    "print(\"above problem can be solved using steady flow energy equations upon hot water flow\")\n",
    "print(\"Q+m1*(h1+C1^2/2+g*z1)=W+m2*(h2+C2^2/2+g*z2)\")\n",
    "print(\"here total heat to be supplied(Q)in kcal/hr\")\n",
    "Q=n*q\n",
    "print(\"so heat lost by water(-ve),Q=-25000 kcal/hr\")\n",
    "Q=-25000#heat loss by water in kcal/hr\n",
    "print(\"there shall be no work interaction and change in kinetic energy,so,steady flow energy equation shall be,\")\n",
    "print(\"Q+m*(h1+g*z1)=m*(h2+g*z2)\")\n",
    "print(\"so water circulation rate(m)in kg/hr\")\n",
    "print(\"so m=Q*10^3*4.18/(g*deltaz-(h1-h2)*10^3*4.18\")\n",
    "m=Q*10**3*4.18/(g*deltaz-(h1-h2)*10**3*4.18)\n",
    "m=m/60\n",
    "print(\"water circulation rate=(m)in kg/min\"),round(m,2)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.11;pg no:81"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.11, Page:81  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 11\n",
      "let mass of steam to be supplied per kg of water lifted be(m) kg.applying law of energy conservation upon steam injector,for unit mass of water lifted\n",
      "energy with steam entering + energy with water entering = energy with mixture leaving + heat loss to surrounding\n",
      "m*(v1^2/2+h1*10^3*4.18)+h2*10^3*4.18+g*deltaz=(1+m)*(h3*10^3*4.18+v2^2/2)+m*q*10^3*4.18\n",
      "so steam suppling rate(m)in kg/s per kg of water\n",
      "m= 0.124\n",
      "NOTE=>here enthalpy of steam entering injector(h1)should be taken 720 kcal/kg instead of 72 kcal/kg otherwise the steam supplying rate comes wrong.\n"
     ]
    }
   ],
   "source": [
    "#cal of steam suppling rate\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "print\"Example 3.11, Page:81  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 11\")\n",
    "v1=50;#velocity of steam entering injector in m/s\n",
    "v2=25;#velocity of mixture leave injector in m/s\n",
    "h1=720;#enthalpy of steam entering injector in kcal/kg\n",
    "h2=24.6;#enthalpy of water entering injector in kcal/kg\n",
    "h3=100;#enthalpy of steam leaving injector in kcal/kg\n",
    "h4=100;#enthalpy of water leaving injector in kcal/kg\n",
    "deltaz=2;#depth from axis of injector in m\n",
    "q=12;#heat loss from injector to surrounding through injector\n",
    "g=9.81;#acceleration due to gravity in m/s^2\n",
    "print(\"let mass of steam to be supplied per kg of water lifted be(m) kg.applying law of energy conservation upon steam injector,for unit mass of water lifted\")\n",
    "print(\"energy with steam entering + energy with water entering = energy with mixture leaving + heat loss to surrounding\")\n",
    "print(\"m*(v1^2/2+h1*10^3*4.18)+h2*10^3*4.18+g*deltaz=(1+m)*(h3*10^3*4.18+v2^2/2)+m*q*10^3*4.18\")\n",
    "print(\"so steam suppling rate(m)in kg/s per kg of water\")\n",
    "m=((h3*10**3*4.18+v2**2/2)-(h2*10**3*4.18+g*deltaz))/((v1**2/2+h1*10**3*4.18)-(h3*10**3*4.18+v2**2/2)-(q*10**3*4.18))\n",
    "print(\"m=\"),round(m,3)\n",
    "print(\"NOTE=>here enthalpy of steam entering injector(h1)should be taken 720 kcal/kg instead of 72 kcal/kg otherwise the steam supplying rate comes wrong.\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.12;pg no:82"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.12, Page:82  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 12\n",
      "here let us assume that the pressure is always equal to atmospheric presure as ballon is flexible,inelastic and unstressed and no work is done for stretching ballon during its filling figure shows the boundary of system before and after filling ballon by firm line and dotted line respectively.\n",
      "displacement work, W=(p.dv)cylinder+(p.dv)ballon\n",
      "(p.dv)cylinder=0,as cylinder is rigid\n",
      "so work done by system upon atmosphere(W)in KJ, W=(p*deltav)/1000\n",
      "and work done by atmosphere=KJ 40.52\n"
     ]
    }
   ],
   "source": [
    "#cal of  work done by atmosphere\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "print\"Example 3.12, Page:82  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 12\")\n",
    "p=1.013*10**5;#atmospheric pressure in pa\n",
    "deltav=0.4;#change in volume in m^3\n",
    "print(\"here let us assume that the pressure is always equal to atmospheric presure as ballon is flexible,inelastic and unstressed and no work is done for stretching ballon during its filling figure shows the boundary of system before and after filling ballon by firm line and dotted line respectively.\")\n",
    "print(\"displacement work, W=(p.dv)cylinder+(p.dv)ballon\")\n",
    "print(\"(p.dv)cylinder=0,as cylinder is rigid\")\n",
    "print(\"so work done by system upon atmosphere(W)in KJ, W=(p*deltav)/1000\")\n",
    "W=(p*deltav)/1000\n",
    "print(\"and work done by atmosphere=KJ\"),round(W,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.13;pg no:82"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.13, Page:82  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 13\n",
      "work done by turbine(Wt)in J#s is 25% of heat added i.e Wt= 1250.0\n",
      "heat rejected by condensor(Qrejected)in J#s is 75% of head added i.e\n",
      "Qrejected= 3750.0\n",
      "and feed water pump work(Wp)in J#s is 0.2% of heat added i.e\n",
      "Wp=(-) 10.0\n",
      "capacity of generator(W)=in Kw 1.24\n"
     ]
    }
   ],
   "source": [
    "#cal of capacity of generator\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "print\"Example 3.13, Page:82  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 13\")\n",
    "Qadd=5000;#heat supplied in boiler in J#s\n",
    "Wt=.25*Qadd\n",
    "print(\"work done by turbine(Wt)in J#s is 25% of heat added i.e\"),\n",
    "print(\"Wt=\"),round(Wt,2)\n",
    "print(\"heat rejected by condensor(Qrejected)in J#s is 75% of head added i.e\")\n",
    "Qrejected=.75*Qadd\n",
    "print(\"Qrejected=\"),round(Qrejected,2)\n",
    "print(\"and feed water pump work(Wp)in J#s is 0.2% of heat added i.e\")\n",
    "Wp=0.002*Qadd\n",
    "print(\"Wp=(-)\"),round(Wp,2)\n",
    "W=(Wt-Wp)/1000\n",
    "print(\"capacity of generator(W)=in Kw\"),round(W,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.14;pg no:83"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.14, Page:83  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 14\n",
      "in heat exchanger upon applying S.F.E.E with assumption of no change in kinetic energy,no work interaction,no change in potential energy,for unit mass flow rate of air,\n",
      "h1+Q1_2=h2\n",
      "Q1_2=h2-h1\n",
      "so heat transfer to air in heat exchanger(Q1_2)in KJ\n",
      "Q1_2= 726.61\n",
      "in gas turbine let us use S.F.E.E,assuming no change in potential energy,for unit mass flow rate of air\n",
      "h2+C2^2#2=h3+C3^2/2+Wt\n",
      "Wt=(h2-h3)+(C2^2-C3^2)/2\n",
      "so power output from turbine(Wt)in KJ#s\n",
      "Wt= 1.0\n",
      "applying S.F.E.E upon nozzle assuming no change in potential energy,no work and heat interactions,for unit mass flow rate,\n",
      "h3+C=h4+C4^2/2\n",
      "C4^2#2=(h3-h4)+C3^2/2\n",
      "velocity at exit of nozzle(C4)in m#s\n",
      "C4= 14.3\n"
     ]
    }
   ],
   "source": [
    "#cal of velocity at exit of nozzle\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "import math\n",
    "print\"Example 3.14, Page:83  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 14\")\n",
    "T1=(27+273);##ambient temperature in K\n",
    "T2=(750+273);##temperature of heated air inside heat exchanger in K\n",
    "T3=(600+273);##temperature of hot air leaves turbine in K\n",
    "T4=(500+273);##temperature at which air leaves nozzle in K\n",
    "Cp=1.005;##specific heat at constant pressure in KJ#kg K\n",
    "C2=50;##velocity of hot air enter into gas turbine in m#s\n",
    "C3=60;##velocity of air leaving turbine enters a nozzle in m#s\n",
    "print(\"in heat exchanger upon applying S.F.E.E with assumption of no change in kinetic energy,no work interaction,no change in potential energy,for unit mass flow rate of air,\")\n",
    "print(\"h1+Q1_2=h2\")\n",
    "print(\"Q1_2=h2-h1\")\n",
    "print(\"so heat transfer to air in heat exchanger(Q1_2)in KJ\")\n",
    "Q1_2=Cp*(T2-T1)\n",
    "print(\"Q1_2=\"),round(Q1_2,2)\n",
    "print(\"in gas turbine let us use S.F.E.E,assuming no change in potential energy,for unit mass flow rate of air\")\n",
    "print(\"h2+C2^2#2=h3+C3^2/2+Wt\")\n",
    "print(\"Wt=(h2-h3)+(C2^2-C3^2)/2\")\n",
    "print(\"so power output from turbine(Wt)in KJ#s\")\n",
    "Wt=Cp*(T2-T3)+(C2**2-C3**2)*10**-3/2\n",
    "print(\"Wt=\"),round(Cp,2)\n",
    "print(\"applying S.F.E.E upon nozzle assuming no change in potential energy,no work and heat interactions,for unit mass flow rate,\")\n",
    "print(\"h3+C=h4+C4^2/2\")\n",
    "print(\"C4^2#2=(h3-h4)+C3^2/2\")\n",
    "print(\"velocity at exit of nozzle(C4)in m#s\")\n",
    "C4=math.sqrt(2*(Cp*(T3-T4)+C3**2*10**-3/2))\n",
    "print(\"C4=\"),round(C4,2)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.15;pg no:85"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.15, Page:85  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 15\n",
      "for constant pressure heating,say state changes from 1 to 2\n",
      "Wa=p1*dv\n",
      "Wa=p1*(v2-v1)\n",
      "it is given that v2=2v1\n",
      "so Wa=p1*v1=R*T1\n",
      "for subsequent expansion at constant temperature say state from 2 to 3\n",
      "also given that v3/v1=6,v3/v2=3\n",
      "so work=Wb=p*dv\n",
      "on solving above we get Wb=R*T2*ln(v3#v2)=R*T2*log3\n",
      "temperature at 2 can be given by perfect gas consideration as,\n",
      "T2/T1=v2/v1\n",
      "or T2=2*T1\n",
      "now total work done by air W=Wa+Wb=R*T1+R*T2*log3=R*T1+2*R*T1*log3 in KJ\n",
      "so W in KJ= 10632.69\n"
     ]
    }
   ],
   "source": [
    "#cal of total work done by ai\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "import math\n",
    "print\"Example 3.15, Page:85  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 15\")\n",
    "T1=400;##initial temperature of gas in K\n",
    "R=8.314;##gas constant in \n",
    "print(\"for constant pressure heating,say state changes from 1 to 2\")\n",
    "print(\"Wa=p1*dv\")\n",
    "print(\"Wa=p1*(v2-v1)\")\n",
    "print(\"it is given that v2=2v1\")\n",
    "print(\"so Wa=p1*v1=R*T1\")\n",
    "print(\"for subsequent expansion at constant temperature say state from 2 to 3\")\n",
    "print(\"also given that v3/v1=6,v3/v2=3\")\n",
    "print(\"so work=Wb=p*dv\")\n",
    "print(\"on solving above we get Wb=R*T2*ln(v3#v2)=R*T2*log3\")\n",
    "print(\"temperature at 2 can be given by perfect gas consideration as,\")\n",
    "print(\"T2/T1=v2/v1\")\n",
    "print(\"or T2=2*T1\")\n",
    "print(\"now total work done by air W=Wa+Wb=R*T1+R*T2*log3=R*T1+2*R*T1*log3 in KJ\")\n",
    "W=R*T1+2*R*T1*math.log(3)\n",
    "print(\"so W in KJ=\"),round(W,2)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.16;pg no:85"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.16, Page:85  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 16\n",
      "NOTE=>this question contain derivation which cannot be solve using scilab so we use the result of derivation to proceed further \n",
      "we get W=(Vf-Vi)*((Pi+Pf)/2)\n",
      "also final volume of gas in m^3 is Vf=3*Vi\n",
      "now work done by gas(W)in J 750000.0\n"
     ]
    }
   ],
   "source": [
    "#cal of work done by gas\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "print\"Example 3.16, Page:85  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 16\")\n",
    "Pi=0.5*10**6;##initial pressure of gas in pa\n",
    "Vi=0.5;##initial volume of gas in m^3\n",
    "Pf=1*10**6;##final pressure of gas in pa\n",
    "print(\"NOTE=>this question contain derivation which cannot be solve using scilab so we use the result of derivation to proceed further \")\n",
    "print(\"we get W=(Vf-Vi)*((Pi+Pf)/2)\")\n",
    "print(\"also final volume of gas in m^3 is Vf=3*Vi\") \n",
    "Vf=3*Vi\n",
    "W=(Vf-Vi)*((Pi+Pf)/2)\n",
    "print(\"now work done by gas(W)in J\"),round(W,2)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.17;pg no:87"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.17, Page:87  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 17\n",
      "with the heating of N2 it will get expanded while H2 gets compressed simultaneously.compression of H2 in insulated chamber may be considered of adiabatic type.\n",
      "adiabatic index of compression of H2 can be obtained as,\n",
      "Cp_H2=\n",
      "y_H2=Cp_H2/(Cp_H2-R_H2) 1.4\n",
      "adiabatic index of expansion for N2,Cp_N2=R_N2*(y_N2#(y_N2-1))\n",
      "y_N2= 1.4\n",
      "i>for hydrogen,p1*v1^y=p2*v2^y\n",
      "so final pressure of H2(p2)in pa\n",
      "p2= 1324078.55\n",
      "ii>since partition remains in equlibrium throughout hence no work is done by partition.it is  a case similar to free expansion \n",
      "partition work=0\n",
      "iii>work done upon H2(W_H2)in J,\n",
      "W_H2= -200054.06\n",
      "work done upon H2(W_H2)=-2*10^5 J\n",
      "so work done by N2(W_N2)=2*10^5 J \n",
      "iv>heat added to N2 can be obtained using  first law of thermodynamics as\n",
      "Q_N2=deltaU_N2+W_N2=>Q_N2=m*Cv_N2*(T2-T1)+W_N2\n",
      "final temperature of N2 can be obtained considering it as perfect gas\n",
      "therefore, T2=(p2*v2*T1)#(p1*v1)\n",
      "here p2=final pressure of N2 which will be equal to that of H2 as the partition is free and frictionless\n",
      "p2=1.324*10^6 pa,v2=0.75 m^3\n",
      "so now final temperature of N2(T2)in K= 1191.67\n",
      "mass of N2(m)in kg= 2.81\n",
      "specific heat at constant volume(Cv_N2)in KJ/kg K,Cv_N2= 1.0\n",
      "heat added to N2,(Q_N2)in KJ\n",
      "Q_N2= 2052.89\n"
     ]
    }
   ],
   "source": [
    "#cal of \n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "print\"Example 3.17, Page:87  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 17\")\n",
    "Cp_H2=14.307;##specific heat of H2 at constant pressure in KJ#kg K\n",
    "R_H2=4.1240;##gas constant for H2 in KJ#kg K\n",
    "Cp_N2=1.039;##specific heat of N2 at constant pressure in KJ#kg K\n",
    "R_N2=0.2968;##gas constant for N2 in KJ#kg K\n",
    "T1=(27+273);##ambient temperature in K\n",
    "v1=0.5;##initial volume of H2 in m^3\n",
    "p1=0.5*10**6;##initial pressure of H2 in pa \n",
    "v2=0.25;##final volume of H2 in m^3 \n",
    "p2=1.324*10**6;##final pressure of H2 in pa\n",
    "print(\"with the heating of N2 it will get expanded while H2 gets compressed simultaneously.compression of H2 in insulated chamber may be considered of adiabatic type.\")\n",
    "print(\"adiabatic index of compression of H2 can be obtained as,\")\n",
    "print(\"Cp_H2=\")\n",
    "y_H2=Cp_H2/(Cp_H2-R_H2)\n",
    "print(\"y_H2=Cp_H2/(Cp_H2-R_H2)\"),round(y_H2,2)\n",
    "print(\"adiabatic index of expansion for N2,Cp_N2=R_N2*(y_N2#(y_N2-1))\")\n",
    "y_N2=Cp_N2/(Cp_N2-R_N2)\n",
    "print(\"y_N2=\"),round(y_N2,2)\n",
    "print(\"i>for hydrogen,p1*v1^y=p2*v2^y\")\n",
    "print(\"so final pressure of H2(p2)in pa\")\n",
    "p2=p1*(v1/v2)**y_H2\n",
    "print(\"p2=\"),round(p2,2)\n",
    "print(\"ii>since partition remains in equlibrium throughout hence no work is done by partition.it is  a case similar to free expansion \")\n",
    "print(\"partition work=0\")\n",
    "print(\"iii>work done upon H2(W_H2)in J,\")\n",
    "W_H2=(p1*v1-p2*v2)/(y_H2-1)\n",
    "print(\"W_H2=\"),round(W_H2,2)\n",
    "print(\"work done upon H2(W_H2)=-2*10^5 J\")\n",
    "W_N2=2*10**5;##work done by N2 in J\n",
    "print(\"so work done by N2(W_N2)=2*10^5 J \")\n",
    "print(\"iv>heat added to N2 can be obtained using  first law of thermodynamics as\")\n",
    "print(\"Q_N2=deltaU_N2+W_N2=>Q_N2=m*Cv_N2*(T2-T1)+W_N2\")\n",
    "print(\"final temperature of N2 can be obtained considering it as perfect gas\")\n",
    "print(\"therefore, T2=(p2*v2*T1)#(p1*v1)\")\n",
    "print(\"here p2=final pressure of N2 which will be equal to that of H2 as the partition is free and frictionless\")\n",
    "print(\"p2=1.324*10^6 pa,v2=0.75 m^3\")\n",
    "v2=0.75;##final volume of N2 in m^3\n",
    "T2=(p2*v2*T1)/(p1*v1)\n",
    "print(\"so now final temperature of N2(T2)in K=\"),round(T2,2)\n",
    "T2=1191.6;##T2 approx. equal to 1191.6 K\n",
    "m=(p1*v1)/(R_N2*1000*T1)\n",
    "print(\"mass of N2(m)in kg=\"),round(m,2)\n",
    "m=2.8;##m approx equal to 2.8 kg\n",
    "Cv_N2=Cp_N2-R_N2\n",
    "print(\"specific heat at constant volume(Cv_N2)in KJ/kg K,Cv_N2=\"),round(Cv_N2)\n",
    "print(\"heat added to N2,(Q_N2)in KJ\")\n",
    "Q_N2=((m*Cv_N2*1000*(T2-T1))+W_N2)/1000\n",
    "print(\"Q_N2=\"),round(Q_N2,2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.18;pg no:88"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.18, Page:88  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 18\n",
      "let initial states and final states of air inside cylinder be given by m1,p1,v1,,T1 and m2,p2,v2,T2 respectively.it is case of emptying of cylinder\n",
      "initial mass of air(m1)in kg\n",
      "m1= 9.29\n",
      "for adiabatic expansion during release of air through valve from 0.5 Mpa to atmospheric pressure\n",
      "T2=in K 237.64\n",
      "final mass of air left in tank(m2)in kg\n",
      "m2= 2.97\n",
      "writing down energy equation for unsteady flow system\n",
      "(m1-m2)*(h2+C^2/2)=(m1*u1-m2*u2)\n",
      "or (m1-m2)*C^2/2=(m1*u1-m2*u2)-(m1-m2)*h2\n",
      "kinetic energy available for running turbine(W)in KJ\n",
      "W=(m1*u1-m2*u2)-(m1-m2)*h2=(m1*Cv_air*1000*T1-m2*Cv_air*1000*T2)-(m1-m2)*Cp_air*1000*T2\n",
      "W=(m1*Cv_air*1000*T1-m2*Cv_air*1000*T2)-(m1-m2)*Cp_air*1000*T2\n",
      "amount of work available=KJ 482.67\n"
     ]
    }
   ],
   "source": [
    "#cal of amount of work available\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "print\"Example 3.18, Page:88  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 18\")\n",
    "p1=0.5*10**6;#initial pressure of air in pa\n",
    "p2=1.013*10**5;#atmospheric pressure in pa\n",
    "v1=2;#initial volume of air in m^3\n",
    "v2=v1;#final volume of air in m^3\n",
    "T1=375;#initial temperature of air in K\n",
    "Cp_air=1.003;#specific heat at consatnt pressure in KJ/kg K\n",
    "Cv_air=0.716;#specific heat at consatnt volume in KJ/kg K\n",
    "R_air=0.287;#gas constant in KJ/kg K\n",
    "y=1.4;#expansion constant for air\n",
    "print(\"let initial states and final states of air inside cylinder be given by m1,p1,v1,,T1 and m2,p2,v2,T2 respectively.it is case of emptying of cylinder\")\n",
    "print(\"initial mass of air(m1)in kg\")\n",
    "m1=(p1*v1)/(R_air*1000*T1)\n",
    "print(\"m1=\"),round(m1,2)\n",
    "print(\"for adiabatic expansion during release of air through valve from 0.5 Mpa to atmospheric pressure\")\n",
    "T2=T1*(p2/p1)**((y-1)/y)\n",
    "print(\"T2=in K\"),round(T2,2)\n",
    "print(\"final mass of air left in tank(m2)in kg\")\n",
    "m2=(p2*v2)/(R_air*1000*T2)\n",
    "print(\"m2=\"),round(m2,2)\n",
    "print(\"writing down energy equation for unsteady flow system\")\n",
    "print(\"(m1-m2)*(h2+C^2/2)=(m1*u1-m2*u2)\")\n",
    "print(\"or (m1-m2)*C^2/2=(m1*u1-m2*u2)-(m1-m2)*h2\")\n",
    "print(\"kinetic energy available for running turbine(W)in KJ\")\n",
    "print(\"W=(m1*u1-m2*u2)-(m1-m2)*h2=(m1*Cv_air*1000*T1-m2*Cv_air*1000*T2)-(m1-m2)*Cp_air*1000*T2\")\n",
    "print(\"W=(m1*Cv_air*1000*T1-m2*Cv_air*1000*T2)-(m1-m2)*Cp_air*1000*T2\")\n",
    "W=((m1*Cv_air*1000*T1-m2*Cv_air*1000*T2)-(m1-m2)*Cp_air*1000*T2)/1000\n",
    "print(\"amount of work available=KJ\"),round(W,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.19;pg no:89"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.19, Page:89  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 19\n",
      "using perfect gas equation for the two chambers having initial states  as 1 and 2 and final states as 3\n",
      "n1= 0.1\n",
      "now n2= 0.12\n",
      "for tank being insulated and rigid we can assume,deltaU=0,W=0,Q=0,so writing deltaU,\n",
      "deltaU=n1*Cv*(T3-T1)+n2*Cv*(T3-T2)\n",
      "final temperature of gas(T3)in K\n",
      "T3= 409.09\n",
      "using perfect gas equation for final mixture,\n",
      "final pressure of gas(p3)in Mpa\n",
      "p3= 750000.0\n",
      "so final pressure and temperature =0.75 Mpa and 409.11 K\n"
     ]
    }
   ],
   "source": [
    "#cal of final pressure and temperature\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "print\"Example 3.19, Page:89  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 19\")\n",
    "p1=0.5*10**6;#initial pressure of air in pa\n",
    "v1=0.5;#initial volume of air in m^3\n",
    "T1=(27+273);#initial temperature of air in K\n",
    "p2=1*10**6;#final pressure of air in pa\n",
    "v2=0.5;#final volume of air in m^3\n",
    "T2=500;#final temperature of air in K\n",
    "R=8314;#gas constant in J/kg K\n",
    "Cv=0.716;#specific heat at constant volume in KJ/kg K\n",
    "print(\"using perfect gas equation for the two chambers having initial states  as 1 and 2 and final states as 3\")\n",
    "n1=(p1*v1)/(R*T1)\n",
    "print(\"n1=\"),round(n1,2)\n",
    "n2=(p2*v2)/(R*T2)\n",
    "print(\"now n2=\"),round(n2,2)\n",
    "print(\"for tank being insulated and rigid we can assume,deltaU=0,W=0,Q=0,so writing deltaU,\")\n",
    "deltaU=0;#change in internal energy\n",
    "print(\"deltaU=n1*Cv*(T3-T1)+n2*Cv*(T3-T2)\")\n",
    "print(\"final temperature of gas(T3)in K\")\n",
    "T3=(deltaU+Cv*(n1*T1+n2*T2))/(Cv*(n1+n2))\n",
    "print(\"T3=\"),round(T3,2)\n",
    "print(\"using perfect gas equation for final mixture,\")\n",
    "print(\"final pressure of gas(p3)in Mpa\")\n",
    "p3=((n1+n2)*R*T3)/(v1+v2)\n",
    "print(\"p3=\"),round(p3,3)\n",
    "print(\"so final pressure and temperature =0.75 Mpa and 409.11 K\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.20;pg no:90"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.20, Page:90  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 20\n",
      "printlacement work,W=p*(v1-v2)in N.m -50675.0\n",
      "so heat transfer(Q)in N.m\n",
      "Q=-W 50675.0\n"
     ]
    }
   ],
   "source": [
    "#cal of heat transfer\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "print\"Example 3.20, Page:90  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 20\")\n",
    "v1=0;#initial volume of air inside bottle in m^3\n",
    "v2=0.5;#final volume of air inside bottle in m^3\n",
    "p=1.0135*10**5;#atmospheric pressure in pa\n",
    "W=p*(v1-v2)\n",
    "print(\"printlacement work,W=p*(v1-v2)in N.m\"),round(W,2)\n",
    "print(\"so heat transfer(Q)in N.m\")\n",
    "Q=-W\n",
    "print(\"Q=-W\"),round(Q,2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.21;pg no:90"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.21, Page:90  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 21\n",
      "here turbogenerator is fed with compressed air from a compressed air bottle.pressure inside bottle gradually decreases from 35 bar to 1 bar.expansion from 35 bar to 1 bar occurs isentropically.thus,for the initial and final states of pressure,volume,temperatureand mass inside bottle being given as p1,v1,T1 & m1 and p2,v2,T2 & m2 respectively.it is transient flow process similar to emptying of the bottle.\n",
      "(p2/p1)^((y-1)/y)=(T2/T1)\n",
      "final temperature of air(T2)in K\n",
      "T2= 113.34\n",
      "by perfect gas law,initial mass in bottle(m1)in kg\n",
      "m1= 11.69\n",
      "final mass in bottle(m2)in kg\n",
      "m2= 0.92\n",
      "energy available for running turbo generator or work(W)in KJ\n",
      "W+(m1-m2)*h2=m1*u1-m2*u2\n",
      "W= 1325.42\n",
      "this is maximum work that can be had from the emptying of compresssed air bottle between given pressure limits\n",
      "turbogenerator actual output(P1)=5 KJ/s\n",
      "input to turbogenerator(P2)in KJ/s\n",
      "time duration for which turbogenerator can be run(deltat)in seconds\n",
      "deltat= 159.05\n",
      "duration=160 seconds approx.\n"
     ]
    }
   ],
   "source": [
    "#cal of time duration for which turbogenerator can be run\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "print\"Example 3.21, Page:90  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 21\")\n",
    "p1=35.*10**5;#initial pressure of air in pa\n",
    "v1=0.3;#initial volume of air in m^3\n",
    "T1=(313.);#initial temperature of air in K\n",
    "p2=1.*10**5;#final pressure of air in pa\n",
    "v2=0.3;#final volume of air in m^3\n",
    "y=1.4;#expansion constant\n",
    "R=0.287;#gas constant in KJ/kg K\n",
    "Cv=0.718;#specific heat at constant volume in KJ/kg K\n",
    "Cp=1.005;#specific heat at constant pressure in KJ/kg K\n",
    "print(\"here turbogenerator is fed with compressed air from a compressed air bottle.pressure inside bottle gradually decreases from 35 bar to 1 bar.expansion from 35 bar to 1 bar occurs isentropically.thus,for the initial and final states of pressure,volume,temperatureand mass inside bottle being given as p1,v1,T1 & m1 and p2,v2,T2 & m2 respectively.it is transient flow process similar to emptying of the bottle.\")\n",
    "print(\"(p2/p1)^((y-1)/y)=(T2/T1)\")\n",
    "print(\"final temperature of air(T2)in K\")\n",
    "T2=T1*(p2/p1)**((y-1)/y)\n",
    "print(\"T2=\"),round(T2,2)\n",
    "print(\"by perfect gas law,initial mass in bottle(m1)in kg\")\n",
    "m1=(p1*v1)/(R*1000.*T1)\n",
    "print(\"m1=\"),round(m1,2)\n",
    "print(\"final mass in bottle(m2)in kg\")\n",
    "m2=(p2*v2)/(R*1000.*T2)\n",
    "print(\"m2=\"),round(m2,2)\n",
    "print(\"energy available for running turbo generator or work(W)in KJ\")\n",
    "print(\"W+(m1-m2)*h2=m1*u1-m2*u2\")\n",
    "W=(m1*Cv*T1-m2*Cv*T2)-(m1-m2)*Cp*T2\n",
    "print(\"W=\"),round(W,2)\n",
    "print(\"this is maximum work that can be had from the emptying of compresssed air bottle between given pressure limits\")\n",
    "print(\"turbogenerator actual output(P1)=5 KJ/s\")\n",
    "P1=5;#turbogenerator actual output in KJ/s\n",
    "print(\"input to turbogenerator(P2)in KJ/s\")\n",
    "P2=P1/0.6\n",
    "print(\"time duration for which turbogenerator can be run(deltat)in seconds\")\n",
    "deltat=W/P2\n",
    "print(\"deltat=\"),round(deltat,2)\n",
    "print(\"duration=160 seconds approx.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.22;pg no:91"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.22, Page:91  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 22\n",
      "different states as described in the problem are denoted as 1,2and 3 and shown on p-V diagram\n",
      "process 1-2 is polytropic process with index 1.2\n",
      "(T2/T1)=(p2/p1)^((n-1)/n)\n",
      "final temperature of air(T2)in K\n",
      "T2= 457.68\n",
      "at state 1,p1*v1=m*R*T1\n",
      "initial volume of air(v1)in m^3\n",
      "v1= 2.01\n",
      "final volume of air(v2)in m^3\n",
      "for process 1-2,v2= 0.53\n",
      "for process 2-3 is constant pressure process so p2*v2/T2=p3*v3/T3\n",
      "v3=v2*T3/T2 in m^3\n",
      "here process 3-1 is isothermal process so T1=T3\n",
      "during process 1-2 the compression work(W1_2)in KJ\n",
      "W1_2=(m*R*(T2-T1)/(1-n))\n",
      "work during process 2-3(W2_3)in KJ,\n",
      "W2_3=p2*(v3-v2)/1000\n",
      "work during process 3-1(W3_1)in KJ\n",
      "W3_1= 485.0\n",
      "net work done(W_net)in KJ\n",
      "W_net=W1_2+W2_3+W3_1 -71.28\n",
      "net work=-71.27 KJ\n",
      "here -ve workshows work done upon the system.since it is cycle,so\n",
      "W_net=Q_net\n",
      "phi dW=phi dQ=-71.27 KJ\n",
      "heat transferred from system=71.27 KJ\n"
     ]
    }
   ],
   "source": [
    "#cal of network,heat transferred from system\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "import math\n",
    "print\"Example 3.22, Page:91  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 22\")\n",
    "p1=1.5*10**5;#initial pressure of air in pa\n",
    "T1=(77+273);#initial temperature of air in K\n",
    "p2=7.5*10**5;#final pressure of air in pa\n",
    "n=1.2;#expansion constant for process 1-2\n",
    "R=0.287;#gas constant in KJ/kg K\n",
    "m=3.;#mass of air in kg\n",
    "print(\"different states as described in the problem are denoted as 1,2and 3 and shown on p-V diagram\")\n",
    "print(\"process 1-2 is polytropic process with index 1.2\")\n",
    "print(\"(T2/T1)=(p2/p1)^((n-1)/n)\")\n",
    "print(\"final temperature of air(T2)in K\")\n",
    "T2=T1*((p2/p1)**((n-1)/n))\n",
    "print(\"T2=\"),round(T2,2)\n",
    "print(\"at state 1,p1*v1=m*R*T1\")\n",
    "print(\"initial volume of air(v1)in m^3\")\n",
    "v1=(m*R*1000*T1)/p1\n",
    "print(\"v1=\"),round(v1,2)\n",
    "print(\"final volume of air(v2)in m^3\")\n",
    "v2=((p1*v1**n)/p2)**(1/n)\n",
    "print(\"for process 1-2,v2=\"),round(v2,2)\n",
    "print(\"for process 2-3 is constant pressure process so p2*v2/T2=p3*v3/T3\")\n",
    "print(\"v3=v2*T3/T2 in m^3\")\n",
    "print(\"here process 3-1 is isothermal process so T1=T3\")\n",
    "T3=T1;#process 3-1 is isothermal\n",
    "v3=v2*T3/T2\n",
    "print(\"during process 1-2 the compression work(W1_2)in KJ\")\n",
    "print(\"W1_2=(m*R*(T2-T1)/(1-n))\")\n",
    "W1_2=(m*R*(T2-T1)/(1-n))\n",
    "print(\"work during process 2-3(W2_3)in KJ,\")\n",
    "print(\"W2_3=p2*(v3-v2)/1000\")\n",
    "W2_3=p2*(v3-v2)/1000\n",
    "print(\"work during process 3-1(W3_1)in KJ\")\n",
    "p3=p2;#pressure is constant for process 2-3\n",
    "W3_1=p3*v3*math.log(v1/v3)/1000\n",
    "print(\"W3_1=\"),round(W3_1,2)\n",
    "print(\"net work done(W_net)in KJ\")\n",
    "W_net=W1_2+W2_3+W3_1\n",
    "print(\"W_net=W1_2+W2_3+W3_1\"),round(W_net,2)\n",
    "print(\"net work=-71.27 KJ\")\n",
    "print(\"here -ve workshows work done upon the system.since it is cycle,so\")\n",
    "print(\"W_net=Q_net\")\n",
    "print(\"phi dW=phi dQ=-71.27 KJ\")\n",
    "print(\"heat transferred from system=71.27 KJ\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 3.23;pg no:93"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 3.23, Page:93  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 3 Example 23\n",
      "initial mass of air in bottle(m1)in kg \n",
      "m1= 6.97\n",
      "now final temperature(T2)in K\n",
      "T2= 0.0\n",
      "final mass of air in bottle(m2)in kg\n",
      "m2= 0.82\n",
      "energy available for running of turbine due to emptying of bottle(W)in KJ\n",
      "W= 639.09\n",
      "work available from turbine=639.27KJ\n"
     ]
    }
   ],
   "source": [
    "#cal of work available from turbine\n",
    "#intiation of all variables\n",
    "# Chapter 3\n",
    "print\"Example 3.23, Page:93  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 3 Example 23\")\n",
    "Cp=1.005;#specific heat at constant pressure in KJ/kg K\n",
    "Cv=0.718;#specific heat at constant volume in KJ/kg K\n",
    "y=1.4;#expansion constant \n",
    "p1=40*10**5;#initial temperature of air in pa\n",
    "v1=0.15;#initial volume of air in m^3\n",
    "T1=(27+273);#initial temperature of air in K\n",
    "p2=2*10**5;#final temperature of air in pa\n",
    "v2=0.15;#final volume of air in m^3\n",
    "R=0.287;#gas constant in KJ/kg K\n",
    "print(\"initial mass of air in bottle(m1)in kg \")\n",
    "m1=(p1*v1)/(R*1000*T1)\n",
    "print(\"m1=\"),round(m1,2)\n",
    "print(\"now final temperature(T2)in K\")\n",
    "T2=T1*(p2/p1)**((y-1)/y)\n",
    "print(\"T2=\"),round(T2,2)\n",
    "T2=127.36;#take T2=127.36 approx.\n",
    "print(\"final mass of air in bottle(m2)in kg\")\n",
    "m2=(p2*v2)/(R*1000*T2)\n",
    "print(\"m2=\"),round(m2,2)\n",
    "m2=0.821;#take m2=0.821 approx.\n",
    "print(\"energy available for running of turbine due to emptying of bottle(W)in KJ\")\n",
    "W=(m1*Cv*T1-m2*Cv*T2)-(m1-m2)*Cp*T2\n",
    "print(\"W=\"),round(W,2)\n",
    "print(\"work available from turbine=639.27KJ\")\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}