summaryrefslogtreecommitdiff
path: root/Engineering_Thermodynamics_by__O._Singh/chapter9_3.ipynb
blob: 606321b3ae7905f73446bf1f0ec9b6461d7e34b9 (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
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#Chapter 9:Gas Power Cycles"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 9.1;pg no: 334"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 9.1, Page:334  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 9 Example 1\n",
      "SI engine operate on otto cycle.consider working fluid to be perfect gas.\n",
      "here,y=Cp/Cv\n",
      "Cp-Cv=R in KJ/kg K\n",
      "compression ratio,r=V1/V2=(0.15+V2)/V2\n",
      "so V2=0.15/(r-1) in m^3\n",
      "so V2=0.03 m^3\n",
      "total cylinder volume=V1=r*V2  m^3\n",
      "from perfect gas law,P*V=m*R*T\n",
      "so m=P1*V1/(R*T1) in kg\n",
      "from state 1 to 2 by P*V^y=P2*V2^y\n",
      "so P2=P1*(V1/V2)^y in KPa\n",
      "also,P1*V1/T1=P2*V2/T2\n",
      "so T2=P2*V2*T1/(P1*V1)in K\n",
      "from heat addition process 2-3\n",
      "Q23=m*CV*(T3-T2)\n",
      "T3=T2+(Q23/(m*Cv))in K\n",
      "also from,P3*V3/T3=P2*V2/T2\n",
      "P3=P2*V2*T3/(V3*T2) in KPa\n",
      "for adiabatic expansion 3-4,\n",
      "P3*V3^y=P4*V4^y\n",
      "and V4=V1\n",
      "hence,P4=P3*V3^y/V1^y in KPa\n",
      "and from P3*V3/T3=P4*V4/T4\n",
      "T4=P4*V4*T3/(P3*V3) in K\n",
      "entropy change from 2-3 and 4-1 are same,and can be given as,\n",
      "S3-S2=S4-S1=m*Cv*log(T4/T1)\n",
      "so entropy change,deltaS_32=deltaS_41 in KJ/K\n",
      "heat rejected,Q41=m*Cv*(T4-T1) in KJ\n",
      "net work(W) in KJ= 76.75\n",
      "efficiency(n)= 0.51\n",
      "in percentage 51.16\n",
      "mean effective pressure(mep)=work/volume change in KPa= 511.64\n",
      "so mep=511.67 KPa\n"
     ]
    }
   ],
   "source": [
    "#cal of mean effective pressure\n",
    "#intiation of all variables\n",
    "# Chapter 9\n",
    "import math\n",
    "print\"Example 9.1, Page:334  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 9 Example 1\")\n",
    "Cp=1;#specific heat at constant pressure in KJ/kg K\n",
    "Cv=0.71;#specific heat at constant volume in KJ/kg K\n",
    "P1=98;#pressure at begining of compression in KPa\n",
    "T1=(60+273.15);#temperature at begining of compression in K\n",
    "Q23=150;#heat supplied in KJ/kg\n",
    "r=6;#compression ratio\n",
    "R=0.287;#gas constant in KJ/kg K\n",
    "print(\"SI engine operate on otto cycle.consider working fluid to be perfect gas.\")\n",
    "print(\"here,y=Cp/Cv\")\n",
    "y=Cp/Cv\n",
    "y=1.4;#approx.\n",
    "print(\"Cp-Cv=R in KJ/kg K\")\n",
    "R=Cp-Cv\n",
    "print(\"compression ratio,r=V1/V2=(0.15+V2)/V2\")\n",
    "print(\"so V2=0.15/(r-1) in m^3\")\n",
    "V2=0.15/(r-1)\n",
    "print(\"so V2=0.03 m^3\")\n",
    "print(\"total cylinder volume=V1=r*V2  m^3\")\n",
    "V1=r*V2\n",
    "print(\"from perfect gas law,P*V=m*R*T\")\n",
    "print(\"so m=P1*V1/(R*T1) in kg\")\n",
    "m=P1*V1/(R*T1)\n",
    "m=0.183;#approx.\n",
    "print(\"from state 1 to 2 by P*V^y=P2*V2^y\")\n",
    "print(\"so P2=P1*(V1/V2)^y in KPa\")\n",
    "P2=P1*(V1/V2)**y\n",
    "print(\"also,P1*V1/T1=P2*V2/T2\")\n",
    "print(\"so T2=P2*V2*T1/(P1*V1)in K\")\n",
    "T2=P2*V2*T1/(P1*V1)\n",
    "print(\"from heat addition process 2-3\")\n",
    "print(\"Q23=m*CV*(T3-T2)\")\n",
    "print(\"T3=T2+(Q23/(m*Cv))in K\")\n",
    "T3=T2+(Q23/(m*Cv))\n",
    "print(\"also from,P3*V3/T3=P2*V2/T2\")\n",
    "print(\"P3=P2*V2*T3/(V3*T2) in KPa\")\n",
    "V3=V2;#constant volume process\n",
    "P3=P2*V2*T3/(V3*T2) \n",
    "print(\"for adiabatic expansion 3-4,\")\n",
    "print(\"P3*V3^y=P4*V4^y\")\n",
    "print(\"and V4=V1\")\n",
    "V4=V1;\n",
    "print(\"hence,P4=P3*V3^y/V1^y in KPa\")\n",
    "P4=P3*V3**y/V1**y\n",
    "print(\"and from P3*V3/T3=P4*V4/T4\")\n",
    "print(\"T4=P4*V4*T3/(P3*V3) in K\")\n",
    "T4=P4*V4*T3/(P3*V3)\n",
    "print(\"entropy change from 2-3 and 4-1 are same,and can be given as,\")\n",
    "print(\"S3-S2=S4-S1=m*Cv*log(T4/T1)\")\n",
    "print(\"so entropy change,deltaS_32=deltaS_41 in KJ/K\")\n",
    "deltaS_32=m*Cv*math.log(T4/T1)\n",
    "deltaS_41=deltaS_32;\n",
    "print(\"heat rejected,Q41=m*Cv*(T4-T1) in KJ\")\n",
    "Q41=m*Cv*(T4-T1)\n",
    "W=Q23-Q41\n",
    "print(\"net work(W) in KJ=\"),round(W,2)\n",
    "n=W/Q23\n",
    "print(\"efficiency(n)=\"),round(W/Q23,2)\n",
    "print(\"in percentage\"),round(n*100,2)\n",
    "mep=W/0.15\n",
    "print(\"mean effective pressure(mep)=work/volume change in KPa=\"),round(W/0.15,2)\n",
    "print(\"so mep=511.67 KPa\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 9.2;pg no: 336"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 9.2, Page:336  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 9 Example 2\n",
      "as given\n",
      "Va=V2+(7/8)*(V1-V2)\n",
      "Vb=V2+(1/8)*(V1-V2)\n",
      "and also\n",
      "Pa*Va^y=Pb*Vb^y\n",
      "so (Va/Vb)=(Pb/Pa)^(1/y)\n",
      "also substituting for Va and Vb\n",
      "(V2+(7/8)*(V1-V2))/(V2+(1/8)*(V1-V2))=5.18\n",
      "so V1/V2=r=1+(4.18*8/1.82) 19.37\n",
      "it gives r=19.37 or V1/V2=19.37,compression ratio=19.37\n",
      "as given;cut off occurs at(V1-V2)/15 volume\n",
      "V3=V2+(V1-V2)/15\n",
      "cut off ratio,rho=V3/V2\n",
      "air standard efficiency for diesel cycle(n_airstandard)= 0.63\n",
      "in percentage 63.23\n",
      "overall efficiency(n_overall)=n_airstandard*n_ite*n_mech 0.253\n",
      "in percentage 25.3\n",
      "fuel consumption,bhp/hr in kg= 0.26\n",
      "so compression ratio=19.37\n",
      "air standard efficiency=63.25%\n",
      "fuel consumption,bhp/hr=0.255 kg\n"
     ]
    }
   ],
   "source": [
    "#cal of compression ratio,air standard efficiency,fuel consumption,bhp/hr\n",
    "#intiation of all variables\n",
    "# Chapter 9\n",
    "print\"Example 9.2, Page:336  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 9 Example 2\")\n",
    "Pa=138;#pressure during compression at 1/8 of stroke in KPa\n",
    "Pb=1.38*10**3;#pressure during compression at 7/8 of stroke in KPa\n",
    "n_ite=0.5;#indicated thermal efficiency\n",
    "n_mech=0.8;#mechanical efficiency\n",
    "C=41800;#calorific value in KJ/kg\n",
    "y=1.4;#expansion constant\n",
    "print(\"as given\")\n",
    "print(\"Va=V2+(7/8)*(V1-V2)\")\n",
    "print(\"Vb=V2+(1/8)*(V1-V2)\")\n",
    "print(\"and also\")\n",
    "print(\"Pa*Va^y=Pb*Vb^y\")\n",
    "print(\"so (Va/Vb)=(Pb/Pa)^(1/y)\")\n",
    "(Pb/Pa)**(1/y)\n",
    "print(\"also substituting for Va and Vb\")\n",
    "print(\"(V2+(7/8)*(V1-V2))/(V2+(1/8)*(V1-V2))=5.18\")\n",
    "r=1+(4.18*8/1.82)\n",
    "print(\"so V1/V2=r=1+(4.18*8/1.82)\"),round(r,2)\n",
    "print(\"it gives r=19.37 or V1/V2=19.37,compression ratio=19.37\")\n",
    "print(\"as given;cut off occurs at(V1-V2)/15 volume\")\n",
    "print(\"V3=V2+(V1-V2)/15\")\n",
    "print(\"cut off ratio,rho=V3/V2\")\n",
    "rho=1+(r-1)/15\n",
    "n_airstandard=1-(1/(r**(y-1)*y))*((rho**y-1)/(rho-1))\n",
    "print(\"air standard efficiency for diesel cycle(n_airstandard)=\"),round(n_airstandard,2)\n",
    "print(\"in percentage\"),round(n_airstandard*100,2)\n",
    "n_airstandard=0.6325;\n",
    "n_overall=n_airstandard*n_ite*n_mech\n",
    "print(\"overall efficiency(n_overall)=n_airstandard*n_ite*n_mech\"),round(n_overall,3)\n",
    "print(\"in percentage\"),round(n_overall*100,2)\n",
    "n_overall=0.253;\n",
    "75*60*60/(n_overall*C*100)\n",
    "print(\"fuel consumption,bhp/hr in kg=\"),round(75*60*60/(n_overall*C*100),2)\n",
    "print(\"so compression ratio=19.37\")\n",
    "print(\"air standard efficiency=63.25%\")\n",
    "print(\"fuel consumption,bhp/hr=0.255 kg\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 9.3;pg no: 338"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 9.3, Page:338  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 9 Example 3\n",
      "1-2-3-4=cycle a\n",
      "1-2_a-3_a-4_a-5=cycle b\n",
      "here Cp/Cv=y\n",
      "and R=0.293 KJ/kg K\n",
      "let us consider 1 kg of air for perfect gas,\n",
      "P*V=m*R*T\n",
      "so V1=m*R*T1/P1 in m^3\n",
      "at state 3,\n",
      "P3*V3=m*R*T3\n",
      "so T3/V2=P3/(m*R)\n",
      "so T3=17064.8*V2............eq1\n",
      "for cycle a and also for cycle b\n",
      "T3_a=17064.8*V2_a.............eq2\n",
      "a> for otto cycle,\n",
      "Q23=Cv*(T3-T2)\n",
      "so T3-T2=Q23/Cv\n",
      "and T2=T3-2394.36.............eq3\n",
      "from gas law,P2*V2/T2=P3*V3/T3\n",
      "here V2=V3 and using eq 3,we get\n",
      "so P2/(T3-2394.36)=5000/T3\n",
      "substituting T3 as function of V2\n",
      "P2/(17064.8*V2-2394.36)=5000/(17064.8*V2)\n",
      "P2=5000*(17064.8*V2-2394.36)/(17064.8*V2)\n",
      "also P1*V1^y=P2*V2^y\n",
      "or 103*(1.06)^1.4=(5000*(17064.8*V2-2394.36)/(17064.8*V2))*V2^1.4\n",
      "upon solving it yields\n",
      "381.4*V2=17064.8*V2^2.4-2394.36*V2^1.4\n",
      "or V2^1.4-0.140*V2^0.4-.022=0\n",
      "by hit and trial it yields,V2=0.18 \n",
      "thus compression ratio,r=V1/V2\n",
      "otto cycle efficiency,n_otto=1-(1/r)^(y-1)\n",
      "in percentage\n",
      "b> for mixed or dual cycle\n",
      "Cp*(T4_a-T3_a)=Cv*(T3_a-T2_a)=1700/2=850\n",
      "or T3_a-T2_a=850/Cv\n",
      "or T2_a=T3_a-1197.2 .............eq4 \n",
      "also P2_a*V2_a/T2_a=P3_a*V3_a/T3_a\n",
      "P2_a*V2_a/(T3_a-1197.2)=5000*V2_a/T3_a\n",
      "or P2_a/(T3_a-1197.2)=5000/T3_a\n",
      "also we had seen earlier that T3_a=17064.8*V2_a\n",
      "so P2_a/(17064.8*V2_a-1197.2)=5000/(17064.8*V2_a)\n",
      "so P2_a=5000*(17064.8*V2_a-1197.2)/(17064.8*V2_a).....................eq5\n",
      "or for adiabatic process,1-2_a\n",
      "P1*V1^y=P2*V2^y\n",
      "so 1.3*(1.06)^1.4=V2_a^1.4*(5000-(359.78/V2_a))\n",
      "or V2_a^1.4-0.07*V2_a^0.4-0.022=0\n",
      "by hit and trial \n",
      "V2_a=0.122 m^3\n",
      "therefore upon substituting V2_a,\n",
      "by eq 5,P2_a in KPa\n",
      "by eq 2,T3_a in K\n",
      "by eq 4,T2_a in K\n",
      "from constant pressure heat addition\n",
      "Cp*(T4_a-T3_a)=850\n",
      "so T4_a=T3_a+(850/Cp) in K\n",
      "also P4_a*V4_a/T4_a= P3_a*V3_a/T3_a\n",
      "so V4_a=P3_a*V3_a*T4_a/(T3_a*P4_a) in m^3 \n",
      "here P3_a=P4_a and V2_a=V3_a\n",
      "using adiabatic formulations V4_a=0.172 m^3\n",
      "(V5/V4_a)^(y-1)=(T4_a/T5),here V5=V1\n",
      "so T5=T4_a/(V5/V4_a)^(y-1) in K\n",
      "heat rejected in process 5-1,Q51=Cv*(T5-T1) in KJ\n",
      "efficiency of mixed cycle(n_mixed)= 0.57\n",
      "in percentage 56.55\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'NOTE=>In this question temperature difference (T3-T2) for part a> in book is calculated wrong i.e 2328.77,which is corrected above and comes to be 2394.36,however it doesnt effect the efficiency of any part of this question.'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#cal of comparing efficiency of two cycles\n",
    "#intiation of all variables\n",
    "# Chapter 9\n",
    "print\"Example 9.3, Page:338  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 9 Example 3\")\n",
    "T1=(100+273.15);#temperature at beginning of compresssion in K\n",
    "P1=103;#pressure at beginning of compresssion in KPa\n",
    "Cp=1.003;#specific heat at constant pressure in KJ/kg K\n",
    "Cv=0.71;#specific heat at constant volume in KJ/kg K\n",
    "Q23=1700;#heat added during combustion in KJ/kg\n",
    "P3=5000;#maximum pressure in cylinder in KPa\n",
    "print(\"1-2-3-4=cycle a\")\n",
    "print(\"1-2_a-3_a-4_a-5=cycle b\")\n",
    "print(\"here Cp/Cv=y\")\n",
    "y=Cp/Cv\n",
    "y=1.4;#approx.\n",
    "print(\"and R=0.293 KJ/kg K\")\n",
    "R=0.293;\n",
    "print(\"let us consider 1 kg of air for perfect gas,\")\n",
    "m=1;#mass of air in kg\n",
    "print(\"P*V=m*R*T\")\n",
    "print(\"so V1=m*R*T1/P1 in m^3\")\n",
    "V1=m*R*T1/P1\n",
    "print(\"at state 3,\")\n",
    "print(\"P3*V3=m*R*T3\")\n",
    "print(\"so T3/V2=P3/(m*R)\")\n",
    "P3/(m*R)\n",
    "print(\"so T3=17064.8*V2............eq1\")\n",
    "print(\"for cycle a and also for cycle b\")\n",
    "print(\"T3_a=17064.8*V2_a.............eq2\")\n",
    "print(\"a> for otto cycle,\")\n",
    "print(\"Q23=Cv*(T3-T2)\")\n",
    "print(\"so T3-T2=Q23/Cv\")\n",
    "Q23/Cv\n",
    "print(\"and T2=T3-2394.36.............eq3\")\n",
    "print(\"from gas law,P2*V2/T2=P3*V3/T3\")\n",
    "print(\"here V2=V3 and using eq 3,we get\")\n",
    "print(\"so P2/(T3-2394.36)=5000/T3\")\n",
    "print(\"substituting T3 as function of V2\")\n",
    "print(\"P2/(17064.8*V2-2394.36)=5000/(17064.8*V2)\")\n",
    "print(\"P2=5000*(17064.8*V2-2394.36)/(17064.8*V2)\")\n",
    "print(\"also P1*V1^y=P2*V2^y\")\n",
    "print(\"or 103*(1.06)^1.4=(5000*(17064.8*V2-2394.36)/(17064.8*V2))*V2^1.4\")\n",
    "print(\"upon solving it yields\")\n",
    "print(\"381.4*V2=17064.8*V2^2.4-2394.36*V2^1.4\")\n",
    "print(\"or V2^1.4-0.140*V2^0.4-.022=0\")\n",
    "print(\"by hit and trial it yields,V2=0.18 \")\n",
    "V2=0.18;\n",
    "print(\"thus compression ratio,r=V1/V2\")\n",
    "r=V1/V2\n",
    "print(\"otto cycle efficiency,n_otto=1-(1/r)^(y-1)\")\n",
    "n_otto=1-(1/r)**(y-1)\n",
    "print(\"in percentage\")\n",
    "n_otto=n_otto*100\n",
    "print(\"b> for mixed or dual cycle\")\n",
    "print(\"Cp*(T4_a-T3_a)=Cv*(T3_a-T2_a)=1700/2=850\")\n",
    "print(\"or T3_a-T2_a=850/Cv\")\n",
    "850/Cv\n",
    "print(\"or T2_a=T3_a-1197.2 .............eq4 \")\n",
    "print(\"also P2_a*V2_a/T2_a=P3_a*V3_a/T3_a\")\n",
    "print(\"P2_a*V2_a/(T3_a-1197.2)=5000*V2_a/T3_a\")\n",
    "print(\"or P2_a/(T3_a-1197.2)=5000/T3_a\")\n",
    "print(\"also we had seen earlier that T3_a=17064.8*V2_a\")\n",
    "print(\"so P2_a/(17064.8*V2_a-1197.2)=5000/(17064.8*V2_a)\")\n",
    "print(\"so P2_a=5000*(17064.8*V2_a-1197.2)/(17064.8*V2_a).....................eq5\")\n",
    "print(\"or for adiabatic process,1-2_a\")\n",
    "print(\"P1*V1^y=P2*V2^y\")\n",
    "print(\"so 1.3*(1.06)^1.4=V2_a^1.4*(5000-(359.78/V2_a))\")\n",
    "print(\"or V2_a^1.4-0.07*V2_a^0.4-0.022=0\")\n",
    "print(\"by hit and trial \")\n",
    "print(\"V2_a=0.122 m^3\")\n",
    "V2_a=0.122;\n",
    "print(\"therefore upon substituting V2_a,\")\n",
    "print(\"by eq 5,P2_a in KPa\")\n",
    "P2_a=5000*(17064.8*V2_a-1197.2)/(17064.8*V2_a)\n",
    "print(\"by eq 2,T3_a in K\")\n",
    "T3_a=17064.8*V2_a\n",
    "print(\"by eq 4,T2_a in K\")\n",
    "T2_a=T3_a-1197.2\n",
    "print(\"from constant pressure heat addition\")\n",
    "print(\"Cp*(T4_a-T3_a)=850\")\n",
    "print(\"so T4_a=T3_a+(850/Cp) in K\")\n",
    "T4_a=T3_a+(850/Cp)\n",
    "print(\"also P4_a*V4_a/T4_a= P3_a*V3_a/T3_a\")\n",
    "print(\"so V4_a=P3_a*V3_a*T4_a/(T3_a*P4_a) in m^3 \")\n",
    "print(\"here P3_a=P4_a and V2_a=V3_a\")\n",
    "V4_a=V2_a*T4_a/(T3_a)\n",
    "print(\"using adiabatic formulations V4_a=0.172 m^3\")\n",
    "print(\"(V5/V4_a)^(y-1)=(T4_a/T5),here V5=V1\")\n",
    "V5=V1;\n",
    "print(\"so T5=T4_a/(V5/V4_a)^(y-1) in K\")\n",
    "T5=T4_a/(V5/V4_a)**(y-1)\n",
    "print(\"heat rejected in process 5-1,Q51=Cv*(T5-T1) in KJ\")\n",
    "Q51=Cv*(T5-T1)\n",
    "n_mixed=(Q23-Q51)/Q23\n",
    "print(\"efficiency of mixed cycle(n_mixed)=\"),round(n_mixed,2)\n",
    "print(\"in percentage\"),round(n_mixed*100,2)\n",
    "(\"NOTE=>In this question temperature difference (T3-T2) for part a> in book is calculated wrong i.e 2328.77,which is corrected above and comes to be 2394.36,however it doesnt effect the efficiency of any part of this question.\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 9.4;pg no: 341"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 9.4, Page:341  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 9 Example 4\n",
      "optimum pressure ratio for maximum work output,\n",
      "rp=(T_max/T_min)^((y)/(2*(y-1)))\n",
      "so p2/p1=11.3,For process 1-2, T2/T1=(p2/p1)^(y/(y-1))\n",
      "so T2=T1*(p2/p1)^((y-1)/y)in K\n",
      "For process 3-4,\n",
      "T3/T4=(p3/p4)^((y-1)/y)=(p2/p1)^((y-1)/y)\n",
      "so T4=T3/(rp)^((y-1)/y)in K\n",
      "heat supplied,Q23=Cp*(T3-T2)in KJ/kg\n",
      "compressor work,Wc in KJ/kg= 301.5\n",
      "turbine work,Wt in KJ/kg= 603.0\n",
      "thermal efficiency=net work/heat supplied= 0.5\n",
      "so compressor work=301.5 KJ/kg,turbine work=603 KJ/kg,thermal efficiency=50%\n"
     ]
    }
   ],
   "source": [
    "#cal of thermal efficiency,turbine and compressor work\n",
    "#intiation of all variables\n",
    "# Chapter 9\n",
    "print\"Example 9.4, Page:341  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 9 Example 4\")\n",
    "T3=1200;#maximum temperature in K\n",
    "T1=300;#minimum temperature in K\n",
    "y=1.4;#expansion constant\n",
    "Cp=1.005;#specific heat at constant pressure in KJ/kg K\n",
    "print(\"optimum pressure ratio for maximum work output,\")\n",
    "print(\"rp=(T_max/T_min)^((y)/(2*(y-1)))\")\n",
    "T_max=T3;\n",
    "T_min=T1;\n",
    "rp=(T_max/T_min)**((y)/(2*(y-1)))\n",
    "print(\"so p2/p1=11.3,For process 1-2, T2/T1=(p2/p1)^(y/(y-1))\")\n",
    "print(\"so T2=T1*(p2/p1)^((y-1)/y)in K\")\n",
    "T2=T1*(rp)**((y-1)/y)\n",
    "print(\"For process 3-4,\")\n",
    "print(\"T3/T4=(p3/p4)^((y-1)/y)=(p2/p1)^((y-1)/y)\")\n",
    "print(\"so T4=T3/(rp)^((y-1)/y)in K\")\n",
    "T4=T3/(rp)**((y-1)/y)\n",
    "print(\"heat supplied,Q23=Cp*(T3-T2)in KJ/kg\")\n",
    "Q23=Cp*(T3-T2)\n",
    "Wc=Cp*(T2-T1)\n",
    "print(\"compressor work,Wc in KJ/kg=\"),round(Wc,2)\n",
    "Wt=Cp*(T3-T4)\n",
    "print(\"turbine work,Wt in KJ/kg=\"),round(Wt,2)\n",
    "(Wt-Wc)/Q23\n",
    "print(\"thermal efficiency=net work/heat supplied=\"),round((Wt-Wc)/Q23,2)\n",
    "print(\"so compressor work=301.5 KJ/kg,turbine work=603 KJ/kg,thermal efficiency=50%\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 9.5;pg no: 342"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 9.5, Page:342  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 9 Example 5\n",
      "gas turbine cycle is shown by 1-2-3-4 on T-S diagram,\n",
      "for process 1-2 being isentropic,\n",
      "T2/T1=(P2/P1)^((y-1)/y)\n",
      "so T2=T1*(P2/P1)^((y-1)/y) in K\n",
      "considering compressor efficiency,n_compr=(T2-T1)/(T2_a-T1)\n",
      "so T2_a=T1+((T2-T1)/n_compr)in K\n",
      "during process 2-3 due to combustion of unit mass of compressed the energy balance shall be as under,\n",
      "heat added=mf*q\n",
      "=((ma+mf)*Cp_comb*T3)-(ma*Cp_air*T2)\n",
      "or (mf/ma)*q=((1+(mf/ma))*Cp_comb*T3)-(Cp_air*T2_a)\n",
      "so T3=((mf/ma)*q+(Cp_air*T2_a))/((1+(mf/ma))*Cp_comb)in K\n",
      "for expansion 3-4 being\n",
      "T4/T3=(P4/P3)^((n-1)/n)\n",
      "so T4=T3*(P4/P3)^((n-1)/n) in K\n",
      "actaul temperature at turbine inlet considering internal efficiency of turbine,\n",
      "n_turb=(T3-T4_a)/(T3-T4)\n",
      "so T4_a=T3-(n_turb*(T3-T4)) in K\n",
      "compressor work,per kg of air compressed(Wc) in KJ/kg of air= 234.42\n",
      "so compressor work=234.42 KJ/kg of air\n",
      "turbine work,per kg of air compressed(Wt) in KJ/kg of air= 414.71\n",
      "so turbine work=414.71 KJ/kg of air\n",
      "net work(W_net) in KJ/kg of air= 180.29\n",
      "heat supplied(Q) in KJ/kg of air= 751.16\n",
      "thermal efficiency(n)= 0.24\n",
      "in percentage 24.0\n",
      "so thermal efficiency=24%\n"
     ]
    }
   ],
   "source": [
    "#cal of thermal efficiency,turbine and compressor work\n",
    "#intiation of all variables\n",
    "# Chapter 9\n",
    "print\"Example 9.5, Page:342  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 9 Example 5\")\n",
    "P1=1*10**5;#initial pressure in Pa\n",
    "P4=P1;#constant pressure process\n",
    "T1=300;#initial temperature in K\n",
    "P2=6.2*10**5;#pressure after compression in Pa\n",
    "P3=P2;#constant pressure process\n",
    "k=0.017;#fuel to air ratio\n",
    "n_compr=0.88;#compressor efficiency\n",
    "q=44186;#heating value of fuel in KJ/kg\n",
    "n_turb=0.9;#turbine internal efficiency\n",
    "Cp_comb=1.147;#specific heat of combustion at constant pressure in KJ/kg K\n",
    "Cp_air=1.005;#specific heat of air at constant pressure in KJ/kg K\n",
    "y=1.4;#expansion constant\n",
    "n=1.33;#expansion constant for polytropic constant\n",
    "print(\"gas turbine cycle is shown by 1-2-3-4 on T-S diagram,\")\n",
    "print(\"for process 1-2 being isentropic,\")\n",
    "print(\"T2/T1=(P2/P1)^((y-1)/y)\")\n",
    "print(\"so T2=T1*(P2/P1)^((y-1)/y) in K\")\n",
    "T2=T1*(P2/P1)**((y-1)/y)\n",
    "print(\"considering compressor efficiency,n_compr=(T2-T1)/(T2_a-T1)\")\n",
    "print(\"so T2_a=T1+((T2-T1)/n_compr)in K\")\n",
    "T2_a=T1+((T2-T1)/n_compr)\n",
    "print(\"during process 2-3 due to combustion of unit mass of compressed the energy balance shall be as under,\")\n",
    "print(\"heat added=mf*q\")\n",
    "print(\"=((ma+mf)*Cp_comb*T3)-(ma*Cp_air*T2)\")\n",
    "print(\"or (mf/ma)*q=((1+(mf/ma))*Cp_comb*T3)-(Cp_air*T2_a)\")\n",
    "print(\"so T3=((mf/ma)*q+(Cp_air*T2_a))/((1+(mf/ma))*Cp_comb)in K\")\n",
    "T3=((k)*q+(Cp_air*T2_a))/((1+(k))*Cp_comb)\n",
    "print(\"for expansion 3-4 being\")\n",
    "print(\"T4/T3=(P4/P3)^((n-1)/n)\")\n",
    "print(\"so T4=T3*(P4/P3)^((n-1)/n) in K\")\n",
    "T4=T3*(P4/P3)**((n-1)/n)\n",
    "print(\"actaul temperature at turbine inlet considering internal efficiency of turbine,\")\n",
    "print(\"n_turb=(T3-T4_a)/(T3-T4)\")\n",
    "print(\"so T4_a=T3-(n_turb*(T3-T4)) in K\")\n",
    "T4_a=T3-(n_turb*(T3-T4))\n",
    "Wc=Cp_air*(T2_a-T1)\n",
    "print(\"compressor work,per kg of air compressed(Wc) in KJ/kg of air=\"),round(Wc,2)\n",
    "print(\"so compressor work=234.42 KJ/kg of air\")\n",
    "Wt=Cp_comb*(T3-T4_a)\n",
    "print(\"turbine work,per kg of air compressed(Wt) in KJ/kg of air=\"),round(Wt,2)\n",
    "print(\"so turbine work=414.71 KJ/kg of air\")\n",
    "W_net=Wt-Wc\n",
    "print(\"net work(W_net) in KJ/kg of air=\"),round(W_net,2)\n",
    "Q=k*q\n",
    "print(\"heat supplied(Q) in KJ/kg of air=\"),round(Q,2)\n",
    "n=W_net/Q\n",
    "print(\"thermal efficiency(n)=\"),round(n,2)\n",
    "print(\"in percentage\"),round(n*100,2)\n",
    "print(\"so thermal efficiency=24%\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 9.6;pg no: 343"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 9.6, Page:343  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 9 Example 6\n",
      "NOTE=>In this question formula for overall pressure ratio is derived,which cannot be done using scilab,so using this formula we proceed further.\n",
      "overall pressure ratio(rp)= 13.59\n",
      "so overall optimum pressure ratio=13.6\n"
     ]
    }
   ],
   "source": [
    "#cal of overall optimum pressure ratio\n",
    "#intiation of all variables\n",
    "# Chapter 9\n",
    "print\"Example 9.6, Page:343  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 9 Example 6\")\n",
    "T1=300;#minimum temperature in brayton cycle in K\n",
    "T5=1200;#maximum temperature in brayton cycle in K\n",
    "n_isen_c=0.85;#isentropic efficiency of compressor\n",
    "n_isen_t=0.9;#isentropic efficiency of turbine\n",
    "y=1.4;#expansion constant\n",
    "print(\"NOTE=>In this question formula for overall pressure ratio is derived,which cannot be done using scilab,so using this formula we proceed further.\")\n",
    "rp=(T1/(T5*n_isen_c*n_isen_t))**((2*y)/(3*(1-y)))\n",
    "print(\"overall pressure ratio(rp)=\"),round(rp,2)\n",
    "print(\"so overall optimum pressure ratio=13.6\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 9.7;pg no: 346"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 9.7, Page:346  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 9 Example 7\n",
      "i> theoretically state of air at exit can be determined by the given stage pressure ratio of 1.35.Let pressure at inlet to first stage P1 and subsequent intermediate pressure be P2,P3,P4,P5,P6,P7,P8 and exit pressure being P9.\n",
      "therefore,P2/P1=P3/P2=P4/P3=P5/P4=P6/P5=P7/P6=P8/P7=P9/P8=r=1.35\n",
      "or P9/P1=k=(1.35)^8 11.03\n",
      "or theoretically,the temperature at exit of compressor can be predicted considering isentropic compression of air(y=1.4)\n",
      "T9/T1=(P9/P1)^((y-1)/y)\n",
      "so T9 in K= 621.47\n",
      "considering overall efficiency of compression 82% the actual temperature at compressor exit can be obtained\n",
      "(T9-T1)/(T9_actual-T1)=0.82\n",
      "so T9_actual=T1+((T9-T1)/0.82) in K 689.19\n",
      "let the actual index of compression be n, then\n",
      "(T9_actual/T1)=(P9/P1)^((n-1)/n)\n",
      "so n=log(P9/P1)/(log(P9/P1)-log(T9-actual/T1))\n",
      "so state of air at exit of compressor,pressure=11.03 bar and temperature=689.18 K\n",
      "ii> let polytropic efficiency be n_polytropic for compressor then,\n",
      "(n-1)/n=((y-1)/y)*(1/n_polytropic)\n",
      "so n_polytropic= 0.87\n",
      "in percentage 86.9\n",
      "so ploytropic efficiency=86.88%\n",
      "iii> stage efficiency can be estimated for any stage.say first stage.\n",
      "ideal state at exit of compressor stage=T2/T1=(P2/P1)^((y-1)/y)\n",
      "so T2=T1*(P2/P1)^((y-1)/y) in K\n",
      "actual temperature at exit of first stage can be estimated using polytropic index 1.49.\n",
      "T2_actual/T1=(P2/P1)^((n-1)/n)\n",
      "so T2_actual=T1*(P2/P1)^((n-1)/n) in K\n",
      "stage efficiency for first stage,ns_1= 0.86\n",
      "in percentage 86.33\n",
      "actual temperature at exit of second stage,\n",
      "T3_actual/T2_actual=(P3/P2)^((n-1)/n)\n",
      "so T3_actual=T2_actual*(P3/P2)^((n-1)/n) in K\n",
      "ideal temperature at exit of second stage\n",
      "T3/T2_actual=(P3/P2)^((n-1)/n)\n",
      "so T3=T2_actual*(P3/P2)^((y-1)/y) in K\n",
      "stage efficiency for second stage,ns_2= 0.86\n",
      "in percentage 86.33\n",
      "actual rtemperature at exit of third stage,\n",
      "T4_actual/T3_actual=(P4/P3)^((n-1)/n)\n",
      "so T4_actual in K= 420.83\n",
      "ideal temperature at exit of third stage,\n",
      "T4/T3_actual=(P4/P3)^((n-1)/n)\n",
      "so T4 in K= 415.42\n",
      "stage efficiency for third stage,ns_3= 0.86\n",
      "in percentage= 8632.9\n",
      "so stage efficiency=86.4%\n",
      "iv> from steady flow energy equation,\n",
      "Wc=dw=dh and dh=du+p*dv+v*dp\n",
      "dh=dq+v*dp\n",
      "dq=0 in adiabatic process\n",
      "dh=v*dp\n",
      "Wc=v*dp\n",
      "here for polytropic compression \n",
      "P*V^1.49=constant i.e n=1.49\n",
      "Wc in KJ/s= 16419.87\n",
      "due to overall efficiency being 90% the actual compressor work(Wc_actual) in KJ/s= 14777.89\n",
      "so power required to drive compressor =14777.89 KJ/s\n"
     ]
    }
   ],
   "source": [
    "#cal of state of air at exit of compressor,polytropic efficiency,efficiency of each sate,power\n",
    "#intiation of all variables\n",
    "# Chapter 9\n",
    "import math\n",
    "print\"Example 9.7, Page:346  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 9 Example 7\")\n",
    "T1=313.;#air entering temperature in K\n",
    "P1=1*10**5;#air entering pressure in Pa\n",
    "m=50.;#flow rate through compressor in kg/s\n",
    "R=0.287;#gas constant in KJ/kg K\n",
    "print(\"i> theoretically state of air at exit can be determined by the given stage pressure ratio of 1.35.Let pressure at inlet to first stage P1 and subsequent intermediate pressure be P2,P3,P4,P5,P6,P7,P8 and exit pressure being P9.\")\n",
    "print(\"therefore,P2/P1=P3/P2=P4/P3=P5/P4=P6/P5=P7/P6=P8/P7=P9/P8=r=1.35\")\n",
    "r=1.35;#compression ratio\n",
    "k=(1.35)**8\n",
    "print(\"or P9/P1=k=(1.35)^8\"),round(k,2)\n",
    "k=11.03;#approx.\n",
    "print(\"or theoretically,the temperature at exit of compressor can be predicted considering isentropic compression of air(y=1.4)\")\n",
    "y=1.4;#expansion constant \n",
    "print(\"T9/T1=(P9/P1)^((y-1)/y)\")\n",
    "T9=T1*(k)**((y-1)/y)\n",
    "print(\"so T9 in K=\"),round(T9,2)\n",
    "print(\"considering overall efficiency of compression 82% the actual temperature at compressor exit can be obtained\")\n",
    "print(\"(T9-T1)/(T9_actual-T1)=0.82\")\n",
    "T9_actual=T1+((T9-T1)/0.82)\n",
    "print(\"so T9_actual=T1+((T9-T1)/0.82) in K\"),round(T9_actual,2)\n",
    "print(\"let the actual index of compression be n, then\")\n",
    "print(\"(T9_actual/T1)=(P9/P1)^((n-1)/n)\")\n",
    "print(\"so n=log(P9/P1)/(log(P9/P1)-log(T9-actual/T1))\")\n",
    "n=math.log(k)/(math.log(k)-math.log(T9_actual/T1))\n",
    "print(\"so state of air at exit of compressor,pressure=11.03 bar and temperature=689.18 K\")\n",
    "print(\"ii> let polytropic efficiency be n_polytropic for compressor then,\")\n",
    "print(\"(n-1)/n=((y-1)/y)*(1/n_polytropic)\")\n",
    "n_polytropic=((y-1)/y)/((n-1)/n)\n",
    "print(\"so n_polytropic=\"),round(n_polytropic,2)\n",
    "print(\"in percentage\"),round(n_polytropic*100,2)\n",
    "print(\"so ploytropic efficiency=86.88%\")\n",
    "print(\"iii> stage efficiency can be estimated for any stage.say first stage.\")\n",
    "print(\"ideal state at exit of compressor stage=T2/T1=(P2/P1)^((y-1)/y)\")\n",
    "print(\"so T2=T1*(P2/P1)^((y-1)/y) in K\")\n",
    "T2=T1*(r)**((y-1)/y)\n",
    "print(\"actual temperature at exit of first stage can be estimated using polytropic index 1.49.\")\n",
    "print(\"T2_actual/T1=(P2/P1)^((n-1)/n)\")\n",
    "print(\"so T2_actual=T1*(P2/P1)^((n-1)/n) in K\")\n",
    "T2_actual=T1*(r)**((n-1)/n)\n",
    "ns_1=(T2-T1)/(T2_actual-T1)\n",
    "print(\"stage efficiency for first stage,ns_1=\"),round(ns_1,2)\n",
    "print(\"in percentage\"),round(ns_1*100,2)\n",
    "print(\"actual temperature at exit of second stage,\")\n",
    "print(\"T3_actual/T2_actual=(P3/P2)^((n-1)/n)\")\n",
    "print(\"so T3_actual=T2_actual*(P3/P2)^((n-1)/n) in K\")\n",
    "T3_actual=T2_actual*(r)**((n-1)/n)\n",
    "print(\"ideal temperature at exit of second stage\")\n",
    "print(\"T3/T2_actual=(P3/P2)^((n-1)/n)\")\n",
    "print(\"so T3=T2_actual*(P3/P2)^((y-1)/y) in K\")\n",
    "T3=T2_actual*(r)**((y-1)/y)\n",
    "ns_2=(T3-T2_actual)/(T3_actual-T2_actual)\n",
    "print(\"stage efficiency for second stage,ns_2=\"),round(ns_2,2)\n",
    "print(\"in percentage\"),round(ns_2*100,2)\n",
    "print(\"actual rtemperature at exit of third stage,\")\n",
    "print(\"T4_actual/T3_actual=(P4/P3)^((n-1)/n)\")\n",
    "T4_actual=T3_actual*(r)**((n-1)/n)\n",
    "print(\"so T4_actual in K=\"),round(T4_actual,2)\n",
    "print(\"ideal temperature at exit of third stage,\")\n",
    "print(\"T4/T3_actual=(P4/P3)^((n-1)/n)\")\n",
    "T4=T3_actual*(r)**((y-1)/y)\n",
    "print(\"so T4 in K=\"),round(T4,2)\n",
    "ns_3=(T4-T3_actual)/(T4_actual-T3_actual)\n",
    "print(\"stage efficiency for third stage,ns_3=\"),round(ns_3,2)\n",
    "ns_3=ns_3*100\n",
    "print(\"in percentage=\"),round(ns_3*100,2)\n",
    "print(\"so stage efficiency=86.4%\")\n",
    "print(\"iv> from steady flow energy equation,\")\n",
    "print(\"Wc=dw=dh and dh=du+p*dv+v*dp\")\n",
    "print(\"dh=dq+v*dp\")\n",
    "print(\"dq=0 in adiabatic process\")\n",
    "print(\"dh=v*dp\")\n",
    "print(\"Wc=v*dp\")\n",
    "print(\"here for polytropic compression \")\n",
    "print(\"P*V^1.49=constant i.e n=1.49\")\n",
    "n=1.49;\n",
    "Wc=(n/(n-1))*m*R*T1*(((k)**((n-1)/n))-1)\n",
    "print(\"Wc in KJ/s=\"),round(Wc,2)\n",
    "Wc_actual=Wc*0.9\n",
    "print(\"due to overall efficiency being 90% the actual compressor work(Wc_actual) in KJ/s=\"),round(Wc*0.9,2)\n",
    "print(\"so power required to drive compressor =14777.89 KJ/s\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 9.8;pg no: 349"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 9.8, Page:349  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 9 Example 8\n",
      "In question no.8,expression for air standard cycle efficiency is derived which cannot be solve using python software.\n"
     ]
    }
   ],
   "source": [
    "#intiation of all variables\n",
    "# Chapter 9\n",
    "print\"Example 9.8, Page:349  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 9 Example 8\")\n",
    "print(\"In question no.8,expression for air standard cycle efficiency is derived which cannot be solve using python software.\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 9.9;pg no: 350"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 9.9, Page:350  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 9 Example 9\n",
      "using polytropic efficiency the index of compression and expansion can be obtained as under,\n",
      "let compression index be nc,\n",
      "(nc-1)/nc=(y-1)/(y*n_poly_c)\n",
      "so nc=1/(1-((y-1)/(y*n_poly_c)))\n",
      "let expansion index be nt,\n",
      "(nt-1)/nt=(n_poly_T*(y-1))/y\n",
      "so nt=1/(1-((n_poly_T*(y-1))/y))\n",
      "For process 1-2\n",
      "T2/T1=(p2/p1)^((nc-1)/nc)\n",
      "so T2=T1*(p2/p1)^((nc-1)/nc)in K\n",
      "also T4/T3=(p4/p3)^((nt-1)/nt)\n",
      "so T4=T3*(p4/p3)^((nt-1)/nt)in K\n",
      "using heat exchanger effectivenesss,\n",
      "epsilon=(T5-T2)/(T4-T2)\n",
      "so T5=T2+(epsilon*(T4-T2))in K\n",
      "heat added in combustion chamber,q_add=Cp*(T3-T5)in KJ/kg\n",
      "compressor work,Wc=Cp*(T2-T1)in \n",
      "turbine work,Wt=Cp*(T3-T4)in KJ/kg\n",
      "cycle efficiency= 0.33\n",
      "in percentage 32.79\n",
      "work ratio= 0.33\n",
      "specific work output in KJ/kg= 152.56\n",
      "so cycle efficiency=32.79%,work ratio=0.334,specific work output=152.56 KJ/kg\n"
     ]
    }
   ],
   "source": [
    "#cal of cycle efficiency,work ratio,specific work output\n",
    "#intiation of all variables\n",
    "# Chapter 9\n",
    "print\"Example 9.9, Page:350  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 9 Example 9\")\n",
    "y=1.4;#expansion constant\n",
    "n_poly_c=0.85;#ploytropic efficiency of compressor\n",
    "n_poly_T=0.90;#ploytropic efficiency of Turbine\n",
    "r=8.;#compression ratio\n",
    "T1=(27.+273.);#temperature of air in compressor in K\n",
    "T3=1100.;#temperature of air leaving combustion chamber in K\n",
    "epsilon=0.8;#effectiveness of heat exchanger\n",
    "Cp=1.0032;#specific heat at constant pressure in KJ/kg K\n",
    "print(\"using polytropic efficiency the index of compression and expansion can be obtained as under,\")\n",
    "print(\"let compression index be nc,\")\n",
    "print(\"(nc-1)/nc=(y-1)/(y*n_poly_c)\")\n",
    "print(\"so nc=1/(1-((y-1)/(y*n_poly_c)))\")\n",
    "nc=1/(1-((y-1)/(y*n_poly_c)))\n",
    "print(\"let expansion index be nt,\")\n",
    "print(\"(nt-1)/nt=(n_poly_T*(y-1))/y\")\n",
    "print(\"so nt=1/(1-((n_poly_T*(y-1))/y))\")\n",
    "nt=1/(1-((n_poly_T*(y-1))/y))\n",
    "print(\"For process 1-2\")\n",
    "print(\"T2/T1=(p2/p1)^((nc-1)/nc)\")\n",
    "print(\"so T2=T1*(p2/p1)^((nc-1)/nc)in K\")\n",
    "T2=T1*(r)**((nc-1)/nc)\n",
    "print(\"also T4/T3=(p4/p3)^((nt-1)/nt)\")\n",
    "print(\"so T4=T3*(p4/p3)^((nt-1)/nt)in K\")\n",
    "T4=T3*(1/r)**((nt-1)/nt)\n",
    "print(\"using heat exchanger effectivenesss,\") \n",
    "print(\"epsilon=(T5-T2)/(T4-T2)\")\n",
    "print(\"so T5=T2+(epsilon*(T4-T2))in K\")\n",
    "T5=T2+(epsilon*(T4-T2))\n",
    "print(\"heat added in combustion chamber,q_add=Cp*(T3-T5)in KJ/kg\")\n",
    "q_add=Cp*(T3-T5)\n",
    "print(\"compressor work,Wc=Cp*(T2-T1)in \")\n",
    "Wc=Cp*(T2-T1)\n",
    "print(\"turbine work,Wt=Cp*(T3-T4)in KJ/kg\")\n",
    "Wt=Cp*(T3-T4)\n",
    "(Wt-Wc)/q_add\n",
    "print(\"cycle efficiency=\"),round((Wt-Wc)/q_add,2)\n",
    "print(\"in percentage\"),round((Wt-Wc)*100/q_add,2)\n",
    "(Wt-Wc)/Wt\n",
    "print(\"work ratio=\"),round((Wt-Wc)/Wt,2)\n",
    "print(\"specific work output in KJ/kg=\"),round(Wt-Wc,2)\n",
    "print(\"so cycle efficiency=32.79%,work ratio=0.334,specific work output=152.56 KJ/kg\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 9.10;pg no: 351"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 9.10, Page:351  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 9 Example 10\n",
      "for process 1-2_a\n",
      "T2_a/T1=(p2_a/p1)^((y-1)/y)\n",
      "so T2_a=T1*(p2_a/p1)^((y-1)/y) in K\n",
      "nc=(T2_a-T1)/(T2-T1)\n",
      "so T2=T1+((T2_a-T1)/nc) in K\n",
      "for process 3-4_a,\n",
      "T4_a/T3=(p4/p3)^((y-1)/y)\n",
      "so T4_a=T3*(p4/p3)^((y-1)/y)in K\n",
      "Compressor work per kg,Wc=Cp*(T2-T1) in KJ/kg\n",
      "Turbine work per kg,Wt=Cp*(T3-T4)in KJ/kg\n",
      "net output,W_net=Wt-Wc={Wc-(Cp*(T3-T4))} in KJ/kg\n",
      "heat added,q_add=Cp*(T3-T2) in KJ/kg\n",
      "thermal efficiency,n=W_net/q_add\n",
      "n={Wc-(Cp*(T3-T4))}/q_add\n",
      "so T4=T3-((Wc-(n*q_add))/Cp)in K\n",
      "therefore,isentropic efficiency of turbine,nt=(T3-T4)/(T3-T4_a) 0.297\n",
      "in percentage 29.7\n",
      "so turbine isentropic efficiency=29.69%\n"
     ]
    }
   ],
   "source": [
    "#cal of isentropic efficiency of turbine\n",
    "#intiation of all variables\n",
    "# Chapter 9\n",
    "print\"Example 9.10, Page:351  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 9 Example 10\")\n",
    "T1=(27+273);#temperature of air in compressor in K\n",
    "p1=1*10**5;#pressure of air in compressor in Pa\n",
    "p2=5*10**5;#pressure of air after compression in Pa\n",
    "p3=p2-0.2*10**5;#pressure drop in Pa\n",
    "p4=1*10**5;#pressure to which expansion occur in turbine in Pa\n",
    "nc=0.85;#isentropic efficiency\n",
    "T3=1000;#temperature of air in combustion chamber in K\n",
    "n=0.2;#thermal efficiency of plant\n",
    "y=1.4;#expansion constant\n",
    "Cp=1.0032;#specific heat at constant pressure in KJ/kg K\n",
    "print(\"for process 1-2_a\")\n",
    "print(\"T2_a/T1=(p2_a/p1)^((y-1)/y)\")\n",
    "print(\"so T2_a=T1*(p2_a/p1)^((y-1)/y) in K\")\n",
    "T2_a=T1*(p2/p1)**((y-1)/y)\n",
    "print(\"nc=(T2_a-T1)/(T2-T1)\")\n",
    "print(\"so T2=T1+((T2_a-T1)/nc) in K\")\n",
    "T2=T1+((T2_a-T1)/nc)\n",
    "print(\"for process 3-4_a,\")\n",
    "print(\"T4_a/T3=(p4/p3)^((y-1)/y)\")\n",
    "print(\"so T4_a=T3*(p4/p3)^((y-1)/y)in K\")\n",
    "T4_a=T3*(p4/p3)**((y-1)/y)\n",
    "print(\"Compressor work per kg,Wc=Cp*(T2-T1) in KJ/kg\")\n",
    "Wc=Cp*(T2-T1)\n",
    "print(\"Turbine work per kg,Wt=Cp*(T3-T4)in KJ/kg\")\n",
    "print(\"net output,W_net=Wt-Wc={Wc-(Cp*(T3-T4))} in KJ/kg\")\n",
    "print(\"heat added,q_add=Cp*(T3-T2) in KJ/kg\")\n",
    "q_add=Cp*(T3-T2)\n",
    "print(\"thermal efficiency,n=W_net/q_add\")\n",
    "print(\"n={Wc-(Cp*(T3-T4))}/q_add\")\n",
    "print(\"so T4=T3-((Wc-(n*q_add))/Cp)in K\")\n",
    "T4=T3-((Wc-(n*q_add))/Cp)\n",
    "nt=(T3-T4)/(T3-T4_a)\n",
    "print(\"therefore,isentropic efficiency of turbine,nt=(T3-T4)/(T3-T4_a)\"),round((T3-T4)/(T3-T4_a),3)\n",
    "print(\"in percentage\"),round(nt*100,2)\n",
    "print(\"so turbine isentropic efficiency=29.69%\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 9.11;pg no: 352"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 9.11, Page:352  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 9 Example 11\n",
      "for perfect intercooling the pressure ratio of each compression stage(k)\n",
      "k=sqrt(r)\n",
      "for process 1-2_a,T2_a/T1=(P2/P1)^((y-1)/y)\n",
      "so T2_a=T1*(k)^((y-1)/y)in K\n",
      "considering isentropic efficiency of compression,\n",
      "nc=(T2_a-T1)/(T2-T1)\n",
      "so T2=T1+((T2_a-T1)/nc)in K\n",
      "for process 3-4,\n",
      "T4_a/T3=(P4/P3)^((y-1)/y)\n",
      "so T4_a=T3*(P4/P3)^((y-1)/y) in K\n",
      "again due to compression efficiency,nc=(T4_a-T3)/(T4-T3)\n",
      "so T4=T3+((T4_a-T3)/nc)in K\n",
      "total compressor work,Wc=2*Cp*(T4-T3) in KJ/kg\n",
      "for expansion process 5-6_a,\n",
      "T6_a/T5=(P6/P5)^((y-1)/y)\n",
      "so T6_a=T5*(P6/P5)^((y-1)/y) in K\n",
      "considering expansion efficiency,ne=(T5-T6)/(T5-T6_a)\n",
      "T6=T5-(ne*(T5-T6_a)) in K\n",
      "for expansion in 7-8_a\n",
      "T8_a/T7=(P8/P7)^((y-1)/y)\n",
      "so T8_a=T7*(P8/P7)^((y-1)/y) in K\n",
      "considering expansion efficiency,ne=(T7-T8)/(T7-T8_a)\n",
      "so T8=T7-(ne*(T7-T8_a))in K\n",
      "expansion work output per kg of air(Wt)=Cp*(T5-T6)+Cp*(T7-T8) in KJ/kg\n",
      "heat added per kg air(q_add)=Cp*(T5-T4)+Cp*(T7-T6) in KJ/kg\n",
      "fuel required per kg of air,mf=q_add/C 0.02\n",
      "air-fuel ratio=1/mf 51.08\n",
      "net output(W) in KJ/kg= 229.2\n",
      "output for air flowing at 30 kg/s,=W*m in KW 6876.05\n",
      "thermal efficiency= 0.28\n",
      "in percentage 27.88\n",
      "so thermal efficiency=27.87%,net output=6876.05 KW,A/F ratio=51.07\n",
      "NOTE=>In this question,expansion work is calculated wrong in book,so it is corrected above and answers vary accordingly.\n"
     ]
    }
   ],
   "source": [
    "#cal of thermal efficiency,net output,A/F ratio\n",
    "#intiation of all variables\n",
    "# Chapter 9\n",
    "import math\n",
    "print\"Example 9.11, Page:352  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 9 Example 11\")\n",
    "P1=1.*10**5;#initial pressure in Pa\n",
    "T1=(27.+273.);#initial temperature in K\n",
    "T3=T1;\n",
    "r=10.;#pressure ratio\n",
    "T5=1000.;#maximum temperature in cycle in K\n",
    "P6=3.*10**5;#first stage expansion pressure in Pa\n",
    "T7=995.;#first stage reheated temperature in K\n",
    "C=42000.;#calorific value of fuel in KJ/kg\n",
    "Cp=1.0032;#specific heat at constant pressure in KJ/kg K\n",
    "m=30.;#air flow rate in kg/s\n",
    "nc=0.85;#isentropic efficiency of compression\n",
    "ne=0.9;#isentropic efficiency of expansion\n",
    "y=1.4;#expansion constant\n",
    "print(\"for perfect intercooling the pressure ratio of each compression stage(k)\")\n",
    "print(\"k=sqrt(r)\")\n",
    "k=math.sqrt(r)\n",
    "k=3.16;#approx.\n",
    "print(\"for process 1-2_a,T2_a/T1=(P2/P1)^((y-1)/y)\")\n",
    "print(\"so T2_a=T1*(k)^((y-1)/y)in K\")\n",
    "T2_a=T1*(k)**((y-1)/y)\n",
    "print(\"considering isentropic efficiency of compression,\")\n",
    "print(\"nc=(T2_a-T1)/(T2-T1)\")\n",
    "print(\"so T2=T1+((T2_a-T1)/nc)in K\")\n",
    "T2=T1+((T2_a-T1)/nc)\n",
    "print(\"for process 3-4,\")\n",
    "print(\"T4_a/T3=(P4/P3)^((y-1)/y)\")\n",
    "print(\"so T4_a=T3*(P4/P3)^((y-1)/y) in K\")\n",
    "T4_a=T3*(k)**((y-1)/y)\n",
    "print(\"again due to compression efficiency,nc=(T4_a-T3)/(T4-T3)\")\n",
    "print(\"so T4=T3+((T4_a-T3)/nc)in K\")\n",
    "T4=T3+((T4_a-T3)/nc)\n",
    "print(\"total compressor work,Wc=2*Cp*(T4-T3) in KJ/kg\")\n",
    "Wc=2*Cp*(T4-T3)\n",
    "print(\"for expansion process 5-6_a,\")\n",
    "print(\"T6_a/T5=(P6/P5)^((y-1)/y)\")\n",
    "print(\"so T6_a=T5*(P6/P5)^((y-1)/y) in K\")\n",
    "P5=10.*10**5;#pressure in Pa\n",
    "T6_a=T5*(P6/P5)**((y-1)/y)\n",
    "print(\"considering expansion efficiency,ne=(T5-T6)/(T5-T6_a)\")\n",
    "print(\"T6=T5-(ne*(T5-T6_a)) in K\")\n",
    "T6=T5-(ne*(T5-T6_a))\n",
    "print(\"for expansion in 7-8_a\")\n",
    "print(\"T8_a/T7=(P8/P7)^((y-1)/y)\")\n",
    "print(\"so T8_a=T7*(P8/P7)^((y-1)/y) in K\")\n",
    "P8=P1;#constant pressure process\n",
    "P7=P6;#constant pressure process\n",
    "T8_a=T7*(P8/P7)**((y-1)/y)\n",
    "print(\"considering expansion efficiency,ne=(T7-T8)/(T7-T8_a)\")\n",
    "print(\"so T8=T7-(ne*(T7-T8_a))in K\")\n",
    "T8=T7-(ne*(T7-T8_a))\n",
    "print(\"expansion work output per kg of air(Wt)=Cp*(T5-T6)+Cp*(T7-T8) in KJ/kg\")\n",
    "Wt=Cp*(T5-T6)+Cp*(T7-T8)\n",
    "print(\"heat added per kg air(q_add)=Cp*(T5-T4)+Cp*(T7-T6) in KJ/kg\")\n",
    "q_add=Cp*(T5-T4)+Cp*(T7-T6)\n",
    "mf=q_add/C\n",
    "print(\"fuel required per kg of air,mf=q_add/C\"),round(q_add/C,2)\n",
    "print(\"air-fuel ratio=1/mf\"),round(1/mf,2)\n",
    "W=Wt-Wc\n",
    "print(\"net output(W) in KJ/kg=\"),round(Wt-Wc,2)\n",
    "print(\"output for air flowing at 30 kg/s,=W*m in KW\"),round(W*m,2)\n",
    "W/q_add\n",
    "print(\"thermal efficiency=\"),round(W/q_add,2)\n",
    "print(\"in percentage\"),round(W*100/q_add,2)\n",
    "print(\"so thermal efficiency=27.87%,net output=6876.05 KW,A/F ratio=51.07\")\n",
    "print(\"NOTE=>In this question,expansion work is calculated wrong in book,so it is corrected above and answers vary accordingly.\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 9.12;pg no: 354"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 9.12, Page:354  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 9 Example 12\n",
      "for process 1-2,\n",
      "T2/T1=(P2/P1)^((y-1)/y)\n",
      "so T2=T1*(P2/P1)^((y-1)/y) in K\n",
      "for process 3-4,\n",
      "T4/T3=(P4/P3)^((y-1)/y)\n",
      "so T4=T3*(P4/P3)^((y-1)/y) in K\n",
      "for process 6-7,\n",
      "T7/T6=(P7/P6)^((y-1)/y)\n",
      "so T7=T6*(P7/P6)^((y-1)/y) in K\n",
      "for process 8-9,\n",
      "T9/T8=(P9/P8)^((y-1)/y)\n",
      "T9=T8*(P9/P8)^((y-1)/y) in K\n",
      "in regenerator,effectiveness=(T5-T4)/(T9-T4)\n",
      "T5=T4+(ne*(T9-T4))in K\n",
      "compressor  work per kg air,Wc=Cp*(T2-T1)+Cp*(T4-T3) in KJ/kg\n",
      "turbine work per kg air,Wt in KJ/kg= 660.84\n",
      "heat added per kg air,q_add in KJ/kg= 765.43\n",
      "total fuel required per kg of air= 0.02\n",
      "net work,W_net in KJ/kg= 450.85\n",
      "cycle thermal efficiency,n= 0.59\n",
      "in percentage 58.9\n",
      "fuel required per kg air in combustion chamber 1,Cp*(T8-T7)/C= 0.0056\n",
      "fuel required per kg air in combustion chamber2,Cp*(T6-T5)/C= 0.0126\n",
      "so fuel-air ratio in two combustion chambers=0.0126,0.0056\n",
      "total turbine work=660.85 KJ/kg\n",
      "cycle thermal efficiency=58.9%\n",
      "NOTE=>In this question,fuel required per kg air in combustion chamber 1 and 2 are calculated wrong in book,so it is corrected above and answers vary accordingly. \n"
     ]
    }
   ],
   "source": [
    "#cal of fuel-air ratio in two combustion chambers,total turbine work,cycle thermal efficiency\n",
    "#intiation of all variables\n",
    "# Chapter 9\n",
    "print\"Example 9.12, Page:354  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 9 Example 12\")\n",
    "P1=1.*10**5;#initial pressure in Pa\n",
    "P9=P1;\n",
    "T1=300.;#initial temperature in K\n",
    "P2=4.*10**5;#pressure of air in intercooler in Pa\n",
    "P3=P2;\n",
    "T3=290.;#temperature of air in intercooler in K\n",
    "T6=1300.;#temperature of combustion chamber in K\n",
    "P4=8.*10**5;#pressure of air after compression in Pa\n",
    "P6=P4;\n",
    "T8=1300.;#temperature after reheating in K\n",
    "P8=4.*10**5;#pressure after expansion in Pa\n",
    "P7=P8;\n",
    "C=42000.;#heating value of fuel in KJ/kg\n",
    "y=1.4;#expansion constant\n",
    "ne=0.8;#effectiveness of regenerator\n",
    "Cp=1.0032;#specific heat at constant pressure in KJ/kg K\n",
    "print(\"for process 1-2,\")\n",
    "print(\"T2/T1=(P2/P1)^((y-1)/y)\")\n",
    "print(\"so T2=T1*(P2/P1)^((y-1)/y) in K\")\n",
    "T2=T1*(P2/P1)**((y-1)/y)\n",
    "print(\"for process 3-4,\")\n",
    "print(\"T4/T3=(P4/P3)^((y-1)/y)\")\n",
    "print(\"so T4=T3*(P4/P3)^((y-1)/y) in K\")\n",
    "T4=T3*(P4/P3)**((y-1)/y)\n",
    "print(\"for process 6-7,\")\n",
    "print(\"T7/T6=(P7/P6)^((y-1)/y)\")\n",
    "print(\"so T7=T6*(P7/P6)^((y-1)/y) in K\")\n",
    "T7=T6*(P7/P6)**((y-1)/y)\n",
    "print(\"for process 8-9,\")\n",
    "print(\"T9/T8=(P9/P8)^((y-1)/y)\")\n",
    "print(\"T9=T8*(P9/P8)^((y-1)/y) in K\")\n",
    "T9=T8*(P9/P8)**((y-1)/y)\n",
    "print(\"in regenerator,effectiveness=(T5-T4)/(T9-T4)\")\n",
    "print(\"T5=T4+(ne*(T9-T4))in K\")\n",
    "T5=T4+(ne*(T9-T4))\n",
    "print(\"compressor  work per kg air,Wc=Cp*(T2-T1)+Cp*(T4-T3) in KJ/kg\")\n",
    "Wc=Cp*(T2-T1)+Cp*(T4-T3)\n",
    "Wt=Cp*(T6-T7)+Cp*(T8-T9)\n",
    "print(\"turbine work per kg air,Wt in KJ/kg=\"),round(Wt,2)\n",
    "q_add=Cp*(T6-T5)+Cp*(T8-T7)\n",
    "print(\"heat added per kg air,q_add in KJ/kg=\"),round(q_add,2)\n",
    "q_add/C\n",
    "print(\"total fuel required per kg of air=\"),round(q_add/C,2)\n",
    "W_net=Wt-Wc\n",
    "print(\"net work,W_net in KJ/kg=\"),round(W_net,2)\n",
    "n=W_net/q_add\n",
    "print(\"cycle thermal efficiency,n=\"),round(n,2)\n",
    "print(\"in percentage\"),round(n*100,2)\n",
    "print(\"fuel required per kg air in combustion chamber 1,Cp*(T8-T7)/C=\"),round(Cp*(T8-T7)/C,4)\n",
    "print(\"fuel required per kg air in combustion chamber2,Cp*(T6-T5)/C=\"),round(Cp*(T6-T5)/C,4)\n",
    "print(\"so fuel-air ratio in two combustion chambers=0.0126,0.0056\")\n",
    "print(\"total turbine work=660.85 KJ/kg\")\n",
    "print(\"cycle thermal efficiency=58.9%\")\n",
    "print(\"NOTE=>In this question,fuel required per kg air in combustion chamber 1 and 2 are calculated wrong in book,so it is corrected above and answers vary accordingly. \")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 9.13;pg no: 356"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 9.13, Page:356  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 9 Example 13\n",
      "work done per kg of air,W=R*(T2-T1)*log(r) in KJ/kg\n",
      "heat added per kg of air,q=R*T2*log(r)+(1-epsilon)*Cv*(T2-T1) in KJ/kg\n",
      "for 30 KJ/s heat supplied,the mass of air/s(m)=q_add/q in kg/s\n",
      "mass of air per cycle=m/n in kg/cycle\n",
      "brake output in KW= 17.12\n",
      "stroke volume,V in m^3= 0.0117\n",
      "brake output=17.11 KW\n",
      "stroke volume=0.0116 m^3\n"
     ]
    }
   ],
   "source": [
    "#cal of brake output,stroke volume\n",
    "#intiation of all variables\n",
    "# Chapter 9\n",
    "import math\n",
    "print\"Example 9.13, Page:356  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 9 Example 13\")\n",
    "T2=700.;#highest temperature of stirling engine in K\n",
    "T1=300.;#lowest temperature of stirling engine in K\n",
    "r=3.;#compression ratio\n",
    "q_add=30.;#heat addition in KJ/s\n",
    "epsilon=0.9;#regenerator efficiency\n",
    "P=1*10**5;#pressure at begining of compression in Pa\n",
    "n=100.;#number of cycle per minute\n",
    "Cv=0.72;#specific heat at constant volume in KJ/kg K\n",
    "R=29.27;#gas constant in KJ/kg K\n",
    "print(\"work done per kg of air,W=R*(T2-T1)*log(r) in KJ/kg\")\n",
    "W=R*(T2-T1)*math.log(r)\n",
    "print(\"heat added per kg of air,q=R*T2*log(r)+(1-epsilon)*Cv*(T2-T1) in KJ/kg\")\n",
    "q=R*T2*math.log(r)+(1-epsilon)*Cv*(T2-T1)\n",
    "print(\"for 30 KJ/s heat supplied,the mass of air/s(m)=q_add/q in kg/s\")\n",
    "m=q_add/q\n",
    "print(\"mass of air per cycle=m/n in kg/cycle\")\n",
    "m/n\n",
    "print(\"brake output in KW=\"),round(W*m,2)\n",
    "m=1.33*10**-4;#mass of air per cycle in kg/cycle\n",
    "T=T1;\n",
    "V=m*R*T*1000/P\n",
    "print(\"stroke volume,V in m^3=\"),round(V,4)\n",
    "print(\"brake output=17.11 KW\")\n",
    "print(\"stroke volume=0.0116 m^3\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 9.14;pg no: 357"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 9.14, Page:357  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 9 Example 14\n",
      "In question no.14,various expression is derived which cannot be solved using python software.\n"
     ]
    }
   ],
   "source": [
    "#cal of compression ratio,air standard efficiency,fuel consumption,bhp/hr\n",
    "#intiation of all variables\n",
    "# Chapter 9\n",
    "print\"Example 9.14, Page:357  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 9 Example 14\")\n",
    "print(\"In question no.14,various expression is derived which cannot be solved using python software.\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 9.15;pg no: 361"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 9.15, Page:361  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 9 Example 15\n",
      "In gas turbine cycle,T2/T1=(P2/P1)^((y-1)/y)\n",
      "so T2=T1*(P2/P1)^((y-1)/y)in K\n",
      "T4/T3=(P4/P3)^((y-1)/y)\n",
      "so T4=T3*(P4/P3)^((y-1)/y) in K\n",
      "compressor work per kg,Wc=Cp*(T2-T1) in KJ/kg\n",
      "turbine work per kg,Wt=Cp*(T3-T4) in KJ/kg \n",
      "heat added in combustion chamber per kg,q_add=Cp*(T3-T2) in KJ/kg \n",
      "net gas turbine output,W_net_GT=Wt-Wc in KJ/kg air\n",
      "heat recovered in HRSG for steam generation per kg of air\n",
      "q_HRGC=Cp*(T4-T5)in KJ/kg\n",
      "at inlet to steam in turbine,\n",
      "from steam table,ha=3177.2 KJ/kg,sa=6.5408 KJ/kg K\n",
      "for expansion in steam turbine,sa=sb\n",
      "let dryness fraction at state b be x\n",
      "also from steam table,at 15KPa, sf=0.7549 KJ/kg K,sfg=7.2536 KJ/kg K,hf=225.94 KJ/kg,hfg=2373.1 KJ/kg\n",
      "sb=sf+x*sfg\n",
      "so x=(sb-sf)/sfg \n",
      "so hb=hf+x*hfg in KJ/kg K\n",
      "at exit of condenser,hc=hf ,vc=0.001014 m^3/kg from steam table\n",
      "at exit of feed pump,hd=hd-hc\n",
      "hd=vc*(Pg-Pc)*100 in KJ/kg\n",
      "heat added per kg of steam =ha-hd in KJ/kg\n",
      "mass of steam generated per kg of air in kg steam per kg air= 0.119\n",
      "net steam turbine cycle output,W_net_ST in KJ/kg= 677.4\n",
      "steam cycle output per kg of air(W_net_ST) in KJ/kg air= 80.61\n",
      "total combined cycle output in KJ/kg air=  486.88\n",
      "combined cycle efficiency,n_cc=(W_net_GT+W_net_ST)/q_add 0.58\n",
      "in percentage 57.77\n",
      "In absence of steam cycle,gas turbine cycle efficiency,n_GT= 0.48\n",
      "in percentage 48.21\n",
      "thus ,efficiency is seen to increase in combined cycle upto 57.77% as compared to gas turbine offering 48.21% efficiency.\n",
      "overall efficiency=57.77%\n",
      "steam per kg of air=0.119 kg steam per/kg air\n"
     ]
    }
   ],
   "source": [
    "#cal of overall efficiency,steam per kg of air\n",
    "#intiation of all variables\n",
    "# Chapter 9\n",
    "print\"Example 9.15, Page:361  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 9 Example 15\")\n",
    "r=10.;#pressure ratio\n",
    "Cp=1.0032;#specific heat of air in KJ/kg K\n",
    "y=1.4;#expansion constant\n",
    "T3=1400.;#inlet temperature of gas turbine in K\n",
    "T1=(17.+273.);#ambient temperature in K\n",
    "P1=1.*10**5;#ambient pressure in Pa\n",
    "Pc=15.;#condensor pressure in KPa\n",
    "Pg=6.*1000;#pressure of steam in generator in KPa\n",
    "T5=420.;#temperature of exhaust from gas turbine in K\n",
    "print(\"In gas turbine cycle,T2/T1=(P2/P1)^((y-1)/y)\")\n",
    "print(\"so T2=T1*(P2/P1)^((y-1)/y)in K\")\n",
    "T2=T1*(r)**((y-1)/y)\n",
    "print(\"T4/T3=(P4/P3)^((y-1)/y)\")\n",
    "print(\"so T4=T3*(P4/P3)^((y-1)/y) in K\")\n",
    "T4=T3*(1/r)**((y-1)/y)\n",
    "print(\"compressor work per kg,Wc=Cp*(T2-T1) in KJ/kg\")\n",
    "Wc=Cp*(T2-T1)\n",
    "print(\"turbine work per kg,Wt=Cp*(T3-T4) in KJ/kg \")\n",
    "Wt=Cp*(T3-T4)\n",
    "print(\"heat added in combustion chamber per kg,q_add=Cp*(T3-T2) in KJ/kg \")\n",
    "q_add=Cp*(T3-T2)\n",
    "print(\"net gas turbine output,W_net_GT=Wt-Wc in KJ/kg air\")\n",
    "W_net_GT=Wt-Wc\n",
    "print(\"heat recovered in HRSG for steam generation per kg of air\")\n",
    "print(\"q_HRGC=Cp*(T4-T5)in KJ/kg\")\n",
    "q_HRGC=Cp*(T4-T5)\n",
    "print(\"at inlet to steam in turbine,\")\n",
    "print(\"from steam table,ha=3177.2 KJ/kg,sa=6.5408 KJ/kg K\")\n",
    "ha=3177.2;\n",
    "sa=6.5408;\n",
    "print(\"for expansion in steam turbine,sa=sb\")\n",
    "sb=sa;\n",
    "print(\"let dryness fraction at state b be x\")\n",
    "print(\"also from steam table,at 15KPa, sf=0.7549 KJ/kg K,sfg=7.2536 KJ/kg K,hf=225.94 KJ/kg,hfg=2373.1 KJ/kg\")\n",
    "sf=0.7549;\n",
    "sfg=7.2536;\n",
    "hf=225.94;\n",
    "hfg=2373.1;\n",
    "print(\"sb=sf+x*sfg\")\n",
    "print(\"so x=(sb-sf)/sfg \")\n",
    "x=(sb-sf)/sfg\n",
    "print(\"so hb=hf+x*hfg in KJ/kg K\")\n",
    "hb=hf+x*hfg\n",
    "print(\"at exit of condenser,hc=hf ,vc=0.001014 m^3/kg from steam table\")\n",
    "hc=hf;\n",
    "vc=0.001014;\n",
    "print(\"at exit of feed pump,hd=hd-hc\")\n",
    "print(\"hd=vc*(Pg-Pc)*100 in KJ/kg\")\n",
    "hd=vc*(Pg-Pc)*100\n",
    "print(\"heat added per kg of steam =ha-hd in KJ/kg\")\n",
    "ha-hd\n",
    "print(\"mass of steam generated per kg of air in kg steam per kg air=\"),round(q_HRGC/(ha-hd),3)\n",
    "W_net_ST=(ha-hb)-(hd-hc)\n",
    "print(\"net steam turbine cycle output,W_net_ST in KJ/kg=\"),round(W_net_ST,2)\n",
    "W_net_ST=W_net_ST*0.119 \n",
    "print(\"steam cycle output per kg of air(W_net_ST) in KJ/kg air=\"),round(W_net_ST,2)\n",
    "(W_net_GT+W_net_ST)\n",
    "print(\"total combined cycle output in KJ/kg air= \"),round((W_net_GT+W_net_ST),2)\n",
    "n_cc=(W_net_GT+W_net_ST)/q_add\n",
    "print(\"combined cycle efficiency,n_cc=(W_net_GT+W_net_ST)/q_add\"),round(n_cc,2)\n",
    "print(\"in percentage\"),round(n_cc*100,2)\n",
    "n_GT=W_net_GT/q_add\n",
    "print(\"In absence of steam cycle,gas turbine cycle efficiency,n_GT=\"),round(n_GT,2)\n",
    "print(\"in percentage\"),round(n_GT*100,2)\n",
    "print(\"thus ,efficiency is seen to increase in combined cycle upto 57.77% as compared to gas turbine offering 48.21% efficiency.\")\n",
    "print(\"overall efficiency=57.77%\")\n",
    "print(\"steam per kg of air=0.119 kg steam per/kg air\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 9.16;pg no: 363"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 9.16, Page:363  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 9 Example 16\n",
      "here P4/P1=P3/P1=70............eq1\n",
      "compression ratio,V1/V2=V1/V3=15.............eq2\n",
      "heat added at constant volume= heat added at constant pressure\n",
      "Q23=Q34\n",
      "m*Cv*(T3-T2)=m*Cp*(T4-T3)\n",
      "(T3-T2)=y*(T4-T3)\n",
      "for process 1-2;\n",
      "T2/T1=(P2/P1)^((y-1)/y)\n",
      "T2/T1=(V1/V2)^(y-1)\n",
      "so T2=T1*(V1/V2)^(y-1) in K\n",
      "and (P2/P1)=(V1/V2)^y\n",
      "so P2=P1*(V1/V2)^y in Pa...........eq3\n",
      "for process 2-3,\n",
      "P2/P3=T2/T3\n",
      "so T3=T2*P3/P2\n",
      "using eq 1 and 3,we get\n",
      "T3=T2*k/r^y in K\n",
      "using equal heat additions for processes 2-3 and 3-4,\n",
      "(T3-T2)=y*(T4-T3)\n",
      "so T4=T3+((T3-T2)/y) in K\n",
      "for process 3-4,\n",
      "V3/V4=T3/T4\n",
      "(V3/V1)*(V1/V4)=T3/T4\n",
      "so (V1/V4)=(T3/T4)*r\n",
      "so V1/V4=11.88 and V5/V4=11.88\n",
      "for process 4-5,\n",
      "P4/P5=(V5/V4)^y,or T4/T5=(V5/V4)^(y-1)\n",
      "so T5=T4/((V5/V4)^(y-1))\n",
      "air standard thermal efficiency(n)=1-(heat rejected/heat added)\n",
      "n=1-(m*Cv*(T5-T1)/(m*Cp*(T4-T3)+m*Cv*(T3-T2)))\n",
      "n= 0.65\n",
      "air standard thermal efficiency=0.6529\n",
      "in percentage 65.29\n",
      "so air standard thermal efficiency=65.29%\n",
      "Actual thermal efficiency may be different from theoretical efficiency due to following reasons\n",
      "a> Air standard cycle analysis considers air as the working fluid while in actual cycle it is not air throughtout the cycle.Actual working fluid which are combustion products do not behave as perfect gas.\n",
      "b> Heat addition does not occur isochorically in actual process.Also combustion is accompanied by inefficiency such as incomplete combustion,dissociation of combustion products,etc.\n",
      "c> Specific heat variation occurs in actual processes where as in air standard cycle analysis specific heat variation neglected.Also during adiabatic process theoretically no heat loss occur while actually these processes are accompanied by heat losses.\n"
     ]
    }
   ],
   "source": [
    "#cal of air standard thermal efficiency\n",
    "#intiation of all variables\n",
    "# Chapter 9\n",
    "print\"Example 9.16, Page:363  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 9 Example 16\")\n",
    "T1=(27+273);#temperature at begining of compression in K\n",
    "k=70;#ration of maximum to minimum pressures\n",
    "r=15;#compression ratio\n",
    "y=1.4;#expansion constant\n",
    "print(\"here P4/P1=P3/P1=70............eq1\")\n",
    "print(\"compression ratio,V1/V2=V1/V3=15.............eq2\")\n",
    "print(\"heat added at constant volume= heat added at constant pressure\")\n",
    "print(\"Q23=Q34\")\n",
    "print(\"m*Cv*(T3-T2)=m*Cp*(T4-T3)\")\n",
    "print(\"(T3-T2)=y*(T4-T3)\")\n",
    "print(\"for process 1-2;\")\n",
    "print(\"T2/T1=(P2/P1)^((y-1)/y)\")\n",
    "print(\"T2/T1=(V1/V2)^(y-1)\")\n",
    "print(\"so T2=T1*(V1/V2)^(y-1) in K\")\n",
    "T2=T1*(r)**(y-1)\n",
    "print(\"and (P2/P1)=(V1/V2)^y\")\n",
    "print(\"so P2=P1*(V1/V2)^y in Pa...........eq3\")\n",
    "print(\"for process 2-3,\")\n",
    "print(\"P2/P3=T2/T3\")\n",
    "print(\"so T3=T2*P3/P2\")\n",
    "print(\"using eq 1 and 3,we get\")\n",
    "print(\"T3=T2*k/r^y in K\")\n",
    "T3=T2*k/r**y \n",
    "print(\"using equal heat additions for processes 2-3 and 3-4,\")\n",
    "print(\"(T3-T2)=y*(T4-T3)\")\n",
    "print(\"so T4=T3+((T3-T2)/y) in K\")\n",
    "T4=T3+((T3-T2)/y)\n",
    "print(\"for process 3-4,\")\n",
    "print(\"V3/V4=T3/T4\")\n",
    "print(\"(V3/V1)*(V1/V4)=T3/T4\")\n",
    "print(\"so (V1/V4)=(T3/T4)*r\")\n",
    "(T3/T4)*r\n",
    "print(\"so V1/V4=11.88 and V5/V4=11.88\")\n",
    "print(\"for process 4-5,\")\n",
    "print(\"P4/P5=(V5/V4)^y,or T4/T5=(V5/V4)^(y-1)\")\n",
    "print(\"so T5=T4/((V5/V4)^(y-1))\")\n",
    "T5=T4/(11.88)**(y-1)\n",
    "print(\"air standard thermal efficiency(n)=1-(heat rejected/heat added)\")\n",
    "print(\"n=1-(m*Cv*(T5-T1)/(m*Cp*(T4-T3)+m*Cv*(T3-T2)))\")\n",
    "n=1-((T5-T1)/(y*(T4-T3)+(T3-T2)))\n",
    "print(\"n=\"),round(n,2)\n",
    "print(\"air standard thermal efficiency=0.6529\")\n",
    "print(\"in percentage\"),round(n*100,2)\n",
    "print(\"so air standard thermal efficiency=65.29%\")\n",
    "print(\"Actual thermal efficiency may be different from theoretical efficiency due to following reasons\")\n",
    "print(\"a> Air standard cycle analysis considers air as the working fluid while in actual cycle it is not air throughtout the cycle.Actual working fluid which are combustion products do not behave as perfect gas.\")\n",
    "print(\"b> Heat addition does not occur isochorically in actual process.Also combustion is accompanied by inefficiency such as incomplete combustion,dissociation of combustion products,etc.\")\n",
    "print(\"c> Specific heat variation occurs in actual processes where as in air standard cycle analysis specific heat variation neglected.Also during adiabatic process theoretically no heat loss occur while actually these processes are accompanied by heat losses.\")\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
}