summaryrefslogtreecommitdiff
path: root/Engineering_Thermodynamics_by__O._Singh/chapter5_3.ipynb
blob: cc42cd6f0f8f939d89f9a2fa70f65fdca8fb82b7 (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
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 5:Entropy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 5.1;pg no: 144"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 5.1, Page:144  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 5 Example 1\n",
      "entropy change may be given as,\n",
      "s2-s1=((Cp_air*log(T2/T1)-(R*log(p2/p1))\n",
      "here for throttling process h1=h2=>Cp_air*T1=Cp_air*T2=>T1=T2\n",
      "so change in entropy(deltaS)in KJ/kg K\n",
      "deltaS= 0.263\n"
     ]
    }
   ],
   "source": [
    "#cal of deltaS\n",
    "#intiation of all variables\n",
    "# Chapter 5\n",
    "import math\n",
    "print\"Example 5.1, Page:144  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 5 Example 1\")\n",
    "p1=5.;#initial pressure of air\n",
    "T1=(27.+273.);#temperature of air in K\n",
    "p2=2.;#final pressure of air in K\n",
    "R=0.287;#gas constant in KJ/kg K\n",
    "Cp_air=1.004;#specific heat of air at constant pressure in KJ/kg K\n",
    "print(\"entropy change may be given as,\")\n",
    "print(\"s2-s1=((Cp_air*log(T2/T1)-(R*log(p2/p1))\")\n",
    "print(\"here for throttling process h1=h2=>Cp_air*T1=Cp_air*T2=>T1=T2\")\n",
    "print(\"so change in entropy(deltaS)in KJ/kg K\")\n",
    "deltaS=(Cp_air*0)-(R*math.log(p2/p1))\n",
    "print(\"deltaS=\"),round(deltaS,3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 5.2;pg no: 144"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 5.2, Page:144  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 5 Example 2\n",
      "total entropy change=entropy change during water temperature rise(deltaS1)+entropy change during water to steam change(deltaS2)+entropy change during steam temperature rise(deltaS3)\n",
      "deltaS1=Q1/T1,where Q1=m*Cp*deltaT\n",
      "heat added for increasing water temperature from 27 to 100 degree celcius(Q1)in KJ\n",
      "Q1= 1533.0\n",
      "deltaS1=Q1/T1 in KJ/K 5.11\n",
      "now heat of vaporisation(Q2)=in KJ 11300.0\n",
      "entropy change during phase transformation(deltaS2)in KJ/K\n",
      "deltaS2= 30.29\n",
      "entropy change during steam temperature rise(deltaS3)in KJ/K\n",
      "deltaS3=m*Cp_steam*dT/T\n",
      "here Cp_steam=R*(3.5+1.2*T+0.14*T^2)*10^-3 in KJ/kg K\n",
      "R=in KJ/kg K 0.46\n",
      "now deltaS3=(m*R*(3.5+1.2*T+0.14*T^2)*10^-3)*dT/T in KJ/K\n",
      "total entropy change(deltaS) in KJ/K= 87.24\n"
     ]
    }
   ],
   "source": [
    "#cal of COP\n",
    "#intiation of all variables\n",
    "# Chapter 5\n",
    "print\"Example 5.2, Page:144  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 5 Example 2\")\n",
    "import scipy\n",
    "from scipy import integrate\n",
    "##just an example function\n",
    "def fun1(x):\n",
    "\ty=x*x\n",
    "\treturn y\n",
    "\n",
    "T1=(27.+273.);#temperature of water in K\n",
    "T2=(100.+273.);#steam temperature of water in K\n",
    "m=5.;#mass of water in kg\n",
    "q=2260.;#heat of vaporisation at 100 degree celcius in KJ/kg\n",
    "Cp=4.2;#specific heat of water at constant pressure in KJ/kg K\n",
    "M=18.;#molar mass for water/steam \n",
    "R1=8.314;#gas constant in KJ/kg K\n",
    "print(\"total entropy change=entropy change during water temperature rise(deltaS1)+entropy change during water to steam change(deltaS2)+entropy change during steam temperature rise(deltaS3)\")\n",
    "Q1=m*Cp*(T2-T1)\n",
    "print(\"deltaS1=Q1/T1,where Q1=m*Cp*deltaT\")\n",
    "print(\"heat added for increasing water temperature from 27 to 100 degree celcius(Q1)in KJ\")\n",
    "print(\"Q1=\"),round(Q1,2)\n",
    "deltaS1=Q1/T1\n",
    "print(\"deltaS1=Q1/T1 in KJ/K\"),round(deltaS1,2)\n",
    "Q2=m*q\n",
    "print(\"now heat of vaporisation(Q2)=in KJ\"),round(Q2,2)\n",
    "print(\"entropy change during phase transformation(deltaS2)in KJ/K\")\n",
    "deltaS2=Q2/T2\n",
    "print(\"deltaS2=\"),round(deltaS2,2)\n",
    "print(\"entropy change during steam temperature rise(deltaS3)in KJ/K\")\n",
    "print(\"deltaS3=m*Cp_steam*dT/T\")\n",
    "print(\"here Cp_steam=R*(3.5+1.2*T+0.14*T^2)*10^-3 in KJ/kg K\")\n",
    "R=R1/M\n",
    "print(\"R=in KJ/kg K\"),round(R,2)\n",
    "T2=(100+273.15);#steam temperature of water in K\n",
    "T3=(400+273.15);#temperature of steam in K\n",
    "print(\"now deltaS3=(m*R*(3.5+1.2*T+0.14*T^2)*10^-3)*dT/T in KJ/K\")\n",
    "#function y = f(T), y =(m*R*(3.5+1.2*T+0.14*T**2)*10**-3)/T , endfunction\n",
    "def fun1(x):\n",
    "\ty=(m*R*(3.5+1.2*T+0.14*T**2)*10**-3)/T\n",
    "\treturn y\n",
    "\n",
    "#deltaS3 =scipy.integrate.quad(f,T2, T3) \n",
    "deltaS3=51.84;#approximately\n",
    "deltaS=deltaS1+deltaS2+deltaS3\n",
    "print(\"total entropy change(deltaS) in KJ/K=\"),round(deltaS,2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 5.3;pg no: 145"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 5.3, Page:145  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 5 Example 3\n",
      "gas constant for oxygen(R)in KJ/kg K\n",
      "R= 0.26\n",
      "for reversible process the change in entropy may be given as\n",
      "deltaS=(Cp*log(T2/T1))-(R*log(p2/p1))in KJ/kg K\n",
      "so entropy change=deltaS= in (KJ/kg K) -0.29\n"
     ]
    }
   ],
   "source": [
    "#cal of entropy change\n",
    "#intiation of all variables\n",
    "# Chapter 5\n",
    "import math\n",
    "print\"Example 5.3, Page:145  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 5 Example 3\")\n",
    "R1=8.314;#gas constant in KJ/kg K\n",
    "M=32;#molar mass for O2 \n",
    "T1=(27+273);#initial temperature of O2 in K\n",
    "p1=125;#initial pressure of O2 in Kpa\n",
    "p2=375;#final pressure of O2 in Kpa\n",
    "Cp=1.004;#specific heat of air at constant pressure in KJ/kg K\n",
    "print(\"gas constant for oxygen(R)in KJ/kg K\")\n",
    "R=R1/M\n",
    "print(\"R=\"),round(R,2)\n",
    "print(\"for reversible process the change in entropy may be given as\")\n",
    "print(\"deltaS=(Cp*log(T2/T1))-(R*log(p2/p1))in KJ/kg K\")\n",
    "T2=T1;#isothermal process\n",
    "deltaS=(Cp*math.log(T2/T1))-(R*math.log(p2/p1))\n",
    "print(\"so entropy change=deltaS= in (KJ/kg K)\"),round(deltaS,2)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 5.4;pg no: 145"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 5.4, Page:145  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 5 Example 4\n",
      "entropy change in universe(deltaS_universe)=deltaS_block+deltaS_water\n",
      "where deltaS_block=m*C*log(T2/T1)\n",
      "here hot block is put into sea water,so block shall cool down upto sea water at 25 degree celcius as sea may be treated as sink\n",
      "therefore deltaS_block=in KJ/K -0.14\n",
      "heat loss by block =heat gained by water(Q)in KJ\n",
      "Q=-m*C*(T1-T2) -49.13\n",
      "therefore deltaS_water=-Q/T2 in KJ/K 0.16\n",
      "thus deltaS_universe=in J/K 27.16\n"
     ]
    }
   ],
   "source": [
    "#cal of deltaS_universe\n",
    "#intiation of all variables\n",
    "# Chapter 5\n",
    "import math\n",
    "print\"Example 5.4, Page:145  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 5 Example 4\")\n",
    "T1=(150+273.15);#temperature of copper block in K\n",
    "T2=(25+273.15);#temperature of sea water in K\n",
    "m=1;#mass of copper block in kg\n",
    "C=0.393;#heat capacity of copper in KJ/kg K\n",
    "print(\"entropy change in universe(deltaS_universe)=deltaS_block+deltaS_water\")\n",
    "print(\"where deltaS_block=m*C*log(T2/T1)\")\n",
    "print(\"here hot block is put into sea water,so block shall cool down upto sea water at 25 degree celcius as sea may be treated as sink\")\n",
    "deltaS_block=m*C*math.log(T2/T1)\n",
    "print(\"therefore deltaS_block=in KJ/K\"),round(deltaS_block,2)\n",
    "print(\"heat loss by block =heat gained by water(Q)in KJ\")\n",
    "Q=-m*C*(T1-T2)\n",
    "print(\"Q=-m*C*(T1-T2)\"),round(Q,2)\n",
    "deltaS_water=-Q/T2\n",
    "print(\"therefore deltaS_water=-Q/T2 in KJ/K\"),round(deltaS_water,2)\n",
    "deltaS_universe=(deltaS_block+deltaS_water)*1000\n",
    "print(\"thus deltaS_universe=in J/K\"),round(deltaS_universe,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 5.5;pg no: 146"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 5.5, Page:146  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 5 Example 5\n",
      "deltaS_universe=(deltaS_block+deltaS_seawater)\n",
      "since block and sea water both are at same temperature so,\n",
      "deltaS_universe=deltaS_seawater\n",
      "conservation of energy equation yields,\n",
      "Q-W=deltaU+deltaP.E+deltaK.E\n",
      "since in this case,W=0,deltaK.E=0,deltaU=0\n",
      "Q=deltaP.E\n",
      "change in potential energy=deltaP.E=m*g*h in J\n",
      "deltaS_universe=deltaS_seawater=Q/T in J/kg K\n",
      "entropy change of universe(deltaS_universe)in J/kg K 6.54\n"
     ]
    }
   ],
   "source": [
    "#cal of entropy change of universe\n",
    "#intiation of all variables\n",
    "# Chapter 5\n",
    "print\"Example 5.5, Page:146  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 5 Example 5\")\n",
    "m=1;#mass of copper block in kg\n",
    "T=(27+273);#temperature of copper block in K\n",
    "h=200;#height from which copper block dropped in sea water in m\n",
    "C=0.393;#heat capacity for copper in KJ/kg K\n",
    "g=9.81;#acceleration due to gravity in m/s^2\n",
    "print(\"deltaS_universe=(deltaS_block+deltaS_seawater)\")\n",
    "print(\"since block and sea water both are at same temperature so,\")\n",
    "print(\"deltaS_universe=deltaS_seawater\")\n",
    "print(\"conservation of energy equation yields,\")\n",
    "print(\"Q-W=deltaU+deltaP.E+deltaK.E\")\n",
    "print(\"since in this case,W=0,deltaK.E=0,deltaU=0\")\n",
    "deltaPE=m*g*h\n",
    "Q=deltaPE\n",
    "print(\"Q=deltaP.E\")\n",
    "print(\"change in potential energy=deltaP.E=m*g*h in J\")\n",
    "print(\"deltaS_universe=deltaS_seawater=Q/T in J/kg K\")\n",
    "deltaS_universe=Q/T\n",
    "print(\"entropy change of universe(deltaS_universe)in J/kg K\"),round(deltaS_universe,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 5.6;pg no: 146"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 5.6, Page:146  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 5 Example 6\n",
      "here deltaS_universe=deltaS_block1+deltaS_block2\n",
      "two blocks at different temperatures shall first attain equilibrium temperature.let equilibrium temperature be Tf\n",
      "then from energy conservation\n",
      "m1*Cp_1*(T1-Tf)=m2*Cp_2*(Tf-T2)\n",
      "Tf=in K 374.18\n",
      "hence,entropy change in block 1(deltaS1),due to temperature changing from Tf to T1\n",
      "deltaS1=in KJ/K -0.05\n",
      "entropy change in block 2(deltaS2)in KJ/K\n",
      "deltaS2= 0.06\n",
      "entropy change of universe(deltaS)=in KJ/K 0.01\n"
     ]
    }
   ],
   "source": [
    "#cal of entropy change of universe\n",
    "#intiation of all variables\n",
    "# Chapter 5\n",
    "import math\n",
    "print\"Example 5.6, Page:146  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 5 Example 6\")\n",
    "m1=1;#mass of first copper block in kg\n",
    "m2=0.5;#mass of second copper block in kg\n",
    "T1=(150+273.15);#temperature of first copper block in K\n",
    "T2=(0+273.15);#temperature of second copper block in K\n",
    "Cp_1=0.393;#heat capacity for copper block 1 in KJ/kg K\n",
    "Cp_2=0.381;#heat capacity for copper block 2 in KJ/kg K\n",
    "print(\"here deltaS_universe=deltaS_block1+deltaS_block2\")\n",
    "print(\"two blocks at different temperatures shall first attain equilibrium temperature.let equilibrium temperature be Tf\")\n",
    "print(\"then from energy conservation\")\n",
    "print(\"m1*Cp_1*(T1-Tf)=m2*Cp_2*(Tf-T2)\")\n",
    "Tf=((m1*Cp_1*T1)+(m2*Cp_2*T2))/(m1*Cp_1+m2*Cp_2)\n",
    "print(\"Tf=in K\"),round(Tf,2)\n",
    "print(\"hence,entropy change in block 1(deltaS1),due to temperature changing from Tf to T1\")\n",
    "deltaS1=m1*Cp_1*math.log(Tf/T1)\n",
    "print(\"deltaS1=in KJ/K\"),round(deltaS1,2)\n",
    "print(\"entropy change in block 2(deltaS2)in KJ/K\")\n",
    "deltaS2=m2*Cp_2*math.log(Tf/T2)\n",
    "print(\"deltaS2=\"),round(deltaS2,2)\n",
    "deltaS=deltaS1+deltaS2\n",
    "print(\"entropy change of universe(deltaS)=in KJ/K\"),round(deltaS,2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 5.7;pg no: 147"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 5.7, Page:147  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 5 Example 7\n",
      "NOTE=>in this question formula is derived which cannot be solve using python software\n"
     ]
    }
   ],
   "source": [
    "#intiation of all variables\n",
    "# Chapter 5\n",
    "print\"Example 5.7, Page:147  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 5 Example 7\")\n",
    "print(\"NOTE=>in this question formula is derived which cannot be solve using python software\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 5.8;pg no: 148"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 5.8, Page:148  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 5 Example 8\n",
      "for irreversible operation of engine,\n",
      "rate of entropy generation=Q1/T1+Q2/T2\n",
      "W=Q1-Q2=>Q2=Q1-W in MW 3.0\n",
      "entropy generated(deltaS_gen)in MW\n",
      "deltaS_gen= 0.01\n",
      "work lost(W_lost)in MW\n",
      "W_lost=T2*deltaS_gen 4.0\n"
     ]
    }
   ],
   "source": [
    "#cal of work lost\n",
    "#intiation of all variables\n",
    "# Chapter 5\n",
    "print\"Example 5.8, Page:148  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 5 Example 8\")\n",
    "T1=1800.;#temperature of high temperature reservoir in K\n",
    "T2=300.;#temperature of low temperature reservoir in K\n",
    "Q1=5.;#heat addition in MW\n",
    "W=2.;#work done in MW\n",
    "print(\"for irreversible operation of engine,\")\n",
    "print(\"rate of entropy generation=Q1/T1+Q2/T2\")\n",
    "Q2=Q1-W\n",
    "print(\"W=Q1-Q2=>Q2=Q1-W in MW\"),round(Q2,2)\n",
    "print(\"entropy generated(deltaS_gen)in MW\")\n",
    "deltaS_gen=Q1/T1+Q2/T2\n",
    "print(\"deltaS_gen=\"),round(deltaS_gen,2)\n",
    "Q1=-5;#heat addition in MW\n",
    "print(\"work lost(W_lost)in MW\")\n",
    "W_lost=T2*deltaS_gen\n",
    "print(\"W_lost=T2*deltaS_gen\"),round(W_lost)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 5.9;pg no: 148"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 5.9, Page:148  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 5 Example 9\n",
      "system and reservoir can be treated as source and sink.device thought of can be a carnot engine operating between these two limits.maximum heat available from system shall be the heat rejected till its temperature drops from 500 K to 300 K\n",
      "therefore,maximum heat(Q1)=(C*dT)in J\n",
      "here C=0.05*T^2+0.10*T+0.085 in J/K\n",
      "so Q1=(0.05*T^2+0.10*T+0.085)*dT\n",
      "entropy change of system,deltaS_system=C*dT/T in J/K\n",
      "so deltaS_system=(0.05*T^2+0.10*T+0.085)*dT/T\n",
      "deltaS_reservoir=Q2/T2=(Q1-W)/T2 also,we know from entropy principle,deltaS_universe is greater than equal to 0\n",
      "deltaS_universe=deltaS_system+deltaS_reservoir\n",
      "thus,upon substituting,deltaS_system+deltaS_reservoir is greater than equal to 0\n",
      "W is less than or equal to(Q1+deltaS_system*T2)/1000 in KJ\n",
      "hence maximum work in KJ= 435.34\n"
     ]
    }
   ],
   "source": [
    "#cal of COP\n",
    "#intiation of all variables\n",
    "# Chapter 5\n",
    "import math\n",
    "print\"Example 5.9, Page:148  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 5 Example 9\")\n",
    "import scipy\n",
    "from scipy import integrate\n",
    "\n",
    "def fun1(x):\n",
    "\ty=x*x\n",
    "\treturn y\n",
    "\n",
    "T1=500;#temperature of system in K\n",
    "T2=300;#temperature of reservoir in K\n",
    "print(\"system and reservoir can be treated as source and sink.device thought of can be a carnot engine operating between these two limits.maximum heat available from system shall be the heat rejected till its temperature drops from 500 K to 300 K\")\n",
    "print(\"therefore,maximum heat(Q1)=(C*dT)in J\")\n",
    "print(\"here C=0.05*T^2+0.10*T+0.085 in J/K\")\n",
    "print(\"so Q1=(0.05*T^2+0.10*T+0.085)*dT\")\n",
    "T=T1-T2\n",
    "#Q1=(0.05*T**2+0.10*T+0.085)*dT\n",
    "#function y = f(T), y = (0.05*T**2+0.10*T+0.085),endfunction\n",
    "#Q1 = scipy.integrate.quad(fun1,T1, T2)\n",
    "#Q1=-Q1\n",
    "Q1=1641.35*10**3\n",
    "print(\"entropy change of system,deltaS_system=C*dT/T in J/K\")\n",
    "print(\"so deltaS_system=(0.05*T^2+0.10*T+0.085)*dT/T\")\n",
    "#function y = k(T), y = (0.05*T**2+0.10*T+0.085)/T,endfunction\n",
    "def fun1(x):\n",
    "\ty = (0.05*T**2+0.10*T+0.085)/T\n",
    "\treturn y\n",
    "\n",
    "#deltaS_system = scipy.integrate.quad(k,T1, T2)\n",
    "deltaS_system=-4020.043\n",
    "print(\"deltaS_reservoir=Q2/T2=(Q1-W)/T2\"),\n",
    "print(\"also,we know from entropy principle,deltaS_universe is greater than equal to 0\")\n",
    "print(\"deltaS_universe=deltaS_system+deltaS_reservoir\")\n",
    "print(\"thus,upon substituting,deltaS_system+deltaS_reservoir is greater than equal to 0\")\n",
    "print(\"W is less than or equal to(Q1+deltaS_system*T2)/1000 in KJ\")\n",
    "W=(Q1+deltaS_system*T2)/1000\n",
    "print(\"hence maximum work in KJ=\"),round(W,2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 5.10;pg no: 149"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 5.10, Page:46  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 5 Example 10\n",
      "for reversible adiabatic process governing equation for expansion,\n",
      "P*V**1.4=constant\n",
      "also,for such process entropy change=0\n",
      "using p2/p1=(v1/v2)**1.4 or v=(p1*(v1**1.4)/p)**(1/1.4)\n",
      "final pressure(p2)in Mpa\n",
      "p2= 0.24\n",
      "from first law,second law and definition of enthalpy;\n",
      "dH=T*dS+v*dP\n",
      "for adiabatic process of reversible type,dS=0\n",
      "so dH=v*dP\n",
      "integrating both side H2-H1=deltaH=v*dP in KJ\n",
      "so enthalpy change(deltaH)in KJ=268.8\n",
      "and entropy change=0\n"
     ]
    }
   ],
   "source": [
    "#cal of deltaS\n",
    "#intiation of all variables\n",
    "# Chapter 5\n",
    "\n",
    "print\"Example 5.10, Page:46  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 5 Example 10\")\n",
    "import scipy\n",
    "from scipy import integrate\n",
    "\n",
    "def fun1(x):\n",
    "\ty=x*x\n",
    "\treturn y\n",
    "\n",
    "p1=3.;#initial pressure in Mpa\n",
    "v1=0.05;#initial volume in m**3\n",
    "v2=0.3;#final volume in m**3\n",
    "print(\"for reversible adiabatic process governing equation for expansion,\")\n",
    "print(\"P*V**1.4=constant\")\n",
    "print(\"also,for such process entropy change=0\")\n",
    "print(\"using p2/p1=(v1/v2)**1.4 or v=(p1*(v1**1.4)/p)**(1/1.4)\")\n",
    "print(\"final pressure(p2)in Mpa\")\n",
    "p2=p1*(v1/v2)**1.4\n",
    "print(\"p2=\"),round(p2,2)\n",
    "print(\"from first law,second law and definition of enthalpy;\")\n",
    "print(\"dH=T*dS+v*dP\")\n",
    "print(\"for adiabatic process of reversible type,dS=0\")\n",
    "dS=0;#for adiabatic process of reversible type\n",
    "print(\"so dH=v*dP\")\n",
    "print(\"integrating both side H2-H1=deltaH=v*dP in KJ\")\n",
    "p1=3.*1000.;#initial pressure in Kpa\n",
    "p2=244.;#final pressure in Kpa\n",
    "#function y = f(p), y =(p1*(v1**1.4)/p)**(1/1.4)\n",
    "def fun1(x):\n",
    "\ty=(p1*(v1**1.4)/p2)**(1/1.4)\n",
    "\treturn y\n",
    "\n",
    "deltaH = scipy.integrate.quad(fun1,p2,p1)\n",
    "print (\"so enthalpy change(deltaH)in KJ=268.8\")\n",
    "print(\"and entropy change=0\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 5.11;pg no: 150"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 5.11, Page:150  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 5 Example 11\n",
      "during free expansion temperature remains same and it is an irreversible process.for getting change in entropy let us approximate this expansion process as a reversible isothermal expansion\n",
      "a> change in entropy of air(deltaS_air)in J/K\n",
      "deltaS_air= 1321.68\n",
      "b> during free expansion on heat is gained or lost to surrounding so,\n",
      "deltaS_surrounding=0\n",
      "entropy change of surroundings=0\n",
      "c> entropy change of universe(deltaS_universe)in J/K\n",
      "deltaS_universe= 1321.68\n"
     ]
    }
   ],
   "source": [
    "#cal of deltaS_universe\n",
    "#intiation of all variables\n",
    "# Chapter 5\n",
    "import math\n",
    "print\"Example 5.11, Page:150  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 5 Example 11\")\n",
    "m=2;#mass of air in kg\n",
    "v1=1;#initial volume of air in m^3\n",
    "v2=10;#final volume of air in m^3\n",
    "R=287;#gas constant in J/kg K\n",
    "print(\"during free expansion temperature remains same and it is an irreversible process.for getting change in entropy let us approximate this expansion process as a reversible isothermal expansion\")\n",
    "print(\"a> change in entropy of air(deltaS_air)in J/K\")\n",
    "deltaS_air=m*R*math.log(v2/v1)\n",
    "print(\"deltaS_air=\"),round(deltaS_air,2)\n",
    "print(\"b> during free expansion on heat is gained or lost to surrounding so,\")\n",
    "print(\"deltaS_surrounding=0\")\n",
    "print(\"entropy change of surroundings=0\")\n",
    "deltaS_surrounding=0;#entropy change of surroundings\n",
    "print(\"c> entropy change of universe(deltaS_universe)in J/K\")\n",
    "deltaS_universe=deltaS_air+deltaS_surrounding\n",
    "print(\"deltaS_universe=\"),round(deltaS_universe,2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "##example 5.12;pg no: 150"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 5.12, Page:150  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 5 Example 12\n",
      "let initial and final states be denoted by 1 and 2\n",
      "for poly tropic process pressure and temperature can be related as\n",
      "(p2/p1)^((n-1)/n)=T2/T1\n",
      "so temperature after compression(T2)=in K 1128.94\n",
      "substituting in entropy change expression for polytropic process,\n",
      "entropy change(deltaS)inKJ/kg K\n",
      "deltaS= -0.24454\n",
      "NOTE=>answer given in book i.e -244.54 KJ/kg K is incorrect,correct answer is -.24454 KJ/kg K\n",
      "total entropy change(deltaS)=in J/K -122.27\n"
     ]
    }
   ],
   "source": [
    "#cal of total entropy change\n",
    "#intiation of all variables\n",
    "# Chapter 5\n",
    "import math\n",
    "print\"Example 5.12, Page:150  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 5 Example 12\")\n",
    "m=0.5;#mass of air in kg\n",
    "p1=1.013*10**5;#initial pressure of air in pa\n",
    "p2=0.8*10**6;#final pressure of air in pa\n",
    "T1=800;#initial temperature of air in K\n",
    "n=1.2;#polytropic expansion constant\n",
    "y=1.4;#expansion constant for air\n",
    "Cv=0.71;#specific heat at constant volume in KJ/kg K\n",
    "print(\"let initial and final states be denoted by 1 and 2\")\n",
    "print(\"for poly tropic process pressure and temperature can be related as\")\n",
    "print(\"(p2/p1)^((n-1)/n)=T2/T1\")\n",
    "T2=T1*(p2/p1)**((n-1)/n)\n",
    "print(\"so temperature after compression(T2)=in K\"),round(T2,2)\n",
    "print(\"substituting in entropy change expression for polytropic process,\") \n",
    "print(\"entropy change(deltaS)inKJ/kg K\")\n",
    "deltaS=Cv*((n-y)/(n-1))*math.log(T2/T1)\n",
    "print(\"deltaS=\"),round(deltaS,5)\n",
    "print(\"NOTE=>answer given in book i.e -244.54 KJ/kg K is incorrect,correct answer is -.24454 KJ/kg K\")\n",
    "deltaS=m*deltaS*1000\n",
    "print(\"total entropy change(deltaS)=in J/K\"),round(deltaS,2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 5.13;pg no: 151"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 5.13, Page:151  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 5 Example 13\n",
      "NOTE=>In question no. 13,formula for maximum work is derived which cannot be solve using python software\n"
     ]
    }
   ],
   "source": [
    "#intiation of all variables\n",
    "# Chapter 5\n",
    "print\"Example 5.13, Page:151  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 5 Example 13\")\n",
    "print(\"NOTE=>In question no. 13,formula for maximum work is derived which cannot be solve using python software\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 5.14;pg no: 152"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 5.14, Page:152  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 5 Example 14\n",
      "clausius inequality can be used for cyclic process as given below;consider 1 for source and 2 for sink\n",
      "K=dQ/T=Q1/T1-Q2/T2\n",
      "i> for Q2=200 kcal/s\n",
      "K=in kcal/s K 0.0\n",
      "as K is not greater than 0,therefore under these conditions engine is not possible\n",
      "ii> for Q2=400 kcal/s\n",
      "K=in kcal/s K -1.0\n",
      "as K is less than 0,so engine is feasible and cycle is reversible\n",
      "iii> for Q2=250 kcal/s\n",
      "K=in kcal/s K 0.0\n",
      "as K=0,so engine is feasible and cycle is reversible\n"
     ]
    }
   ],
   "source": [
    "#cal of deltaS\n",
    "#intiation of all variables\n",
    "# Chapter 5\n",
    "print\"Example 5.14, Page:152  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 5 Example 14\")\n",
    "Q1=500;#heat supplied by source in kcal/s\n",
    "T1=600;#temperature of source in K\n",
    "T2=300;#temperature of sink in K\n",
    "print(\"clausius inequality can be used for cyclic process as given below;consider 1 for source and 2 for sink\")\n",
    "print(\"K=dQ/T=Q1/T1-Q2/T2\")\n",
    "print(\"i> for Q2=200 kcal/s\")\n",
    "Q2=200;#heat rejected by sink in kcal/s\n",
    "K=Q1/T1-Q2/T2\n",
    "print(\"K=in kcal/s K\"),round(K,2)\n",
    "print(\"as K is not greater than 0,therefore under these conditions engine is not possible\")\n",
    "print(\"ii> for Q2=400 kcal/s\")\n",
    "Q2=400;#heat rejected by sink in kcal/s\n",
    "K=Q1/T1-Q2/T2\n",
    "print(\"K=in kcal/s K\"),round(K,2)\n",
    "print(\"as K is less than 0,so engine is feasible and cycle is reversible\")\n",
    "print(\"iii> for Q2=250 kcal/s\")\n",
    "Q2=250;#heat rejected by sink in kcal/s\n",
    "K=Q1/T1-Q2/T2\n",
    "print(\"K=in kcal/s K\"),round(K,2)\n",
    "print(\"as K=0,so engine is feasible and cycle is reversible\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 5.15;pg no: 152"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 5.15, Page:152  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 5 Example 15\n",
      "let the two points be given as states 1 and 2,\n",
      "let us assume flow to be from 1 to 2\n",
      "so entropy change(deltaS1_2)=s1-s2=in KJ/kg K -0.0\n",
      "deltaS1_2=s1-s2=0.01254 KJ/kg K\n",
      "it means s2 > s1 hence the assumption that flow is from 1 to 2 is correct as from second law of thermodynamics the entropy increases in a process i.e s2 is greater than or equal to s1\n",
      "hence flow occurs from 1 to 2 i.e from 0.5 MPa,400K to 0.3 Mpa & 350 K\n"
     ]
    }
   ],
   "source": [
    "#cal of deltaS\n",
    "#intiation of all variables\n",
    "# Chapter 5\n",
    "import math\n",
    "print\"Example 5.15, Page:152  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 5 Example 15\")\n",
    "p1=0.5;#initial pressure of air in Mpa\n",
    "T1=400;#initial temperature of air in K\n",
    "p2=0.3;#final pressure of air in Mpa\n",
    "T2=350;#initial temperature of air in K\n",
    "R=0.287;#gas constant in KJ/kg K\n",
    "Cp=1.004;#specific heat at constant pressure in KJ/kg K\n",
    "print(\"let the two points be given as states 1 and 2,\")\n",
    "print(\"let us assume flow to be from 1 to 2\")\n",
    "deltaS1_2=Cp*math.log(T1/T2)-R*math.log(p1/p2)\n",
    "print(\"so entropy change(deltaS1_2)=s1-s2=in KJ/kg K\"),round(deltaS1_2)\n",
    "print(\"deltaS1_2=s1-s2=0.01254 KJ/kg K\")\n",
    "print(\"it means s2 > s1 hence the assumption that flow is from 1 to 2 is correct as from second law of thermodynamics the entropy increases in a process i.e s2 is greater than or equal to s1\")\n",
    "print(\"hence flow occurs from 1 to 2 i.e from 0.5 MPa,400K to 0.3 Mpa & 350 K\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 5.16;pg no: 153"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 5.16, Page:46  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 5 Example 16\n",
      "NOTE=>In question no. 16,value of n is derived which cannot be solve using python software.\n"
     ]
    }
   ],
   "source": [
    "#cal of deltaS\n",
    "#intiation of all variables\n",
    "# Chapter 5\n",
    "print\"Example 5.16, Page:46  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 5 Example 16\")\n",
    "print(\"NOTE=>In question no. 16,value of n is derived which cannot be solve using python software.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 5.17;pg no: 153"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 5.17, Page:153  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 5 Example 17\n",
      "total heat added(Q)in KJ\n",
      "Q= 1800.0\n",
      "for heat addition process 1-2\n",
      "Q12=T1*(s2-s1)\n",
      "deltaS=s2-s1=in KJ/K 2.0\n",
      "or heat addition process 3-4\n",
      "Q34=T3*(s4-s3)\n",
      "deltaS=s4-s3=in KJ/K 2.0\n",
      "or heat rejected in process 5-6(Q56)in KJ\n",
      "Q56=T5*(s5-s6)=T5*((s2-s1)+(s4-s3))=T5*(deltaS+deltaS)= 1200.0\n",
      "net work done=net heat(W_net)in KJ\n",
      "W_net=(Q12+Q34)-Q56 600.0\n",
      "thermal efficiency of cycle(n)= 0.33\n",
      "or n=n*100 % 33.33\n",
      "so work done=600 KJ and thermal efficiency=33.33 %\n"
     ]
    }
   ],
   "source": [
    "#cal of work done and thermal efficiency\n",
    "#intiation of all variables\n",
    "# Chapter 5\n",
    "print\"Example 5.17, Page:153  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 5 Example 17\")\n",
    "Q12=1000.;#heat added during process 1-2 in KJ\n",
    "Q34=800.;#heat added during process 3-4 in KJ\n",
    "T1=500.;#operating temperature for process 1-2\n",
    "T3=400.;#operating temperature for process 3-4\n",
    "T5=300.;#operating temperature for process 5-6\n",
    "T2=T1;#isothermal process\n",
    "T4=T3;#isothermal process\n",
    "T6=T5;#isothermal process\n",
    "print(\"total heat added(Q)in KJ\")\n",
    "Q=Q12+Q34\n",
    "print(\"Q=\"),round(Q,2)\n",
    "print(\"for heat addition process 1-2\")\n",
    "print(\"Q12=T1*(s2-s1)\")\n",
    "deltaS=Q12/T1\n",
    "print(\"deltaS=s2-s1=in KJ/K\"),round(deltaS,2)\n",
    "print(\"or heat addition process 3-4\")\n",
    "print(\"Q34=T3*(s4-s3)\")\n",
    "deltaS=Q34/T3\n",
    "print(\"deltaS=s4-s3=in KJ/K\"),round(deltaS,2)\n",
    "print(\"or heat rejected in process 5-6(Q56)in KJ\")\n",
    "Q56=T5*(deltaS+deltaS)\n",
    "print(\"Q56=T5*(s5-s6)=T5*((s2-s1)+(s4-s3))=T5*(deltaS+deltaS)=\"),round(Q56,2)\n",
    "print(\"net work done=net heat(W_net)in KJ\")\n",
    "W_net=(Q12+Q34)-Q56\n",
    "print(\"W_net=(Q12+Q34)-Q56\"),round(W_net,2)\n",
    "n=W_net/Q\n",
    "print(\"thermal efficiency of cycle(n)=\"),round(n,2)\n",
    "n=n*100\n",
    "print(\"or n=n*100 %\"),round(n,2) \n",
    "print(\"so work done=600 KJ and thermal efficiency=33.33 %\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 5.18;pg no: 154"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 5.18, Page:154  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 5 Example 18\n",
      "let heat supplied by reservoir at 800 K,700 K,600 K be Q1_a , Q1_b , Q1_c\n",
      "here Q1-Q2=W\n",
      "so heat supplied by source(Q1)in KW= 30.0\n",
      "also given that,Q1_a=0.7*Q1_b.......eq 1\n",
      "Q1_c=Q1-(0.7*Q1_b+Q1_b)\n",
      "Q1_c=Q1-1.7*Q1_b........eq 2\n",
      "for reversible engine\n",
      "Q1_a/T1_a+Q1_b/T1_b+Q1_c/T1_c-Q2/T2=0......eq 3\n",
      "substitute eq 1 and eq 2 in eq 3 we get, \n",
      "heat supplied by reservoir of 700 K(Q1_b)in KJ/s\n",
      "Q1_b= 35.39\n",
      "so heat supplied by reservoir of 800 K(Q1_a)in KJ/s\n",
      "Q1_a= 24.78\n",
      "and heat supplied by reservoir of 600 K(Q1_c)in KJ/s\n",
      "Q1_c=Q1-1.7*Q1_b -30.17\n",
      "so heat supplied by reservoir at 800 K(Q1_a)= 24.78\n",
      "so heat supplied by reservoir at 700 K(Q1_b)= 35.39\n",
      "so heat supplied by reservoir at 600 K(Q1_c)= -30.17\n",
      "NOTE=>answer given in book for heat supplied by reservoir at 800 K,700 K,600 K i.e Q1_a=61.94 KJ/s,Q1_b=88.48 KJ/s,Q1_c=120.42 KJ/s is wrong hence correct answer is calculated above.\n"
     ]
    }
   ],
   "source": [
    "#cal of heat supplied by reservoir at 800,700,600\n",
    "#intiation of all variables\n",
    "# Chapter 5\n",
    "print\"Example 5.18, Page:154  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 5 Example 18\")\n",
    "T1_a=800.;#temperature of reservoir a in K\n",
    "T1_b=700.;#temperature of reservoir b in K\n",
    "T1_c=600.;#temperature of reservoir c in K\n",
    "T2=320.;#temperature of sink in K\n",
    "W=20.;#work done in KW\n",
    "Q2=10.;#heat rejected to sink in KW\n",
    "print(\"let heat supplied by reservoir at 800 K,700 K,600 K be Q1_a , Q1_b , Q1_c\")\n",
    "print(\"here Q1-Q2=W\")\n",
    "Q1=W+Q2\n",
    "print(\"so heat supplied by source(Q1)in KW=\"),round(Q1,2)\n",
    "print(\"also given that,Q1_a=0.7*Q1_b.......eq 1\")\n",
    "print(\"Q1_c=Q1-(0.7*Q1_b+Q1_b)\")\n",
    "print(\"Q1_c=Q1-1.7*Q1_b........eq 2\")\n",
    "print(\"for reversible engine\")\n",
    "print(\"Q1_a/T1_a+Q1_b/T1_b+Q1_c/T1_c-Q2/T2=0......eq 3\")\n",
    "print(\"substitute eq 1 and eq 2 in eq 3 we get, \")\n",
    "print(\"heat supplied by reservoir of 700 K(Q1_b)in KJ/s\")\n",
    "Q1_b=((Q2/T2)-(Q1/T1_c))/((0.7/T1_a)+(1/T1_b)-(1.7/T1_c))\n",
    "print(\"Q1_b=\"),round(Q1_b,2)\n",
    "print(\"so heat supplied by reservoir of 800 K(Q1_a)in KJ/s\")\n",
    "Q1_a=0.7*Q1_b\n",
    "print(\"Q1_a=\"),round(Q1_a,2)\n",
    "print(\"and heat supplied by reservoir of 600 K(Q1_c)in KJ/s\")\n",
    "Q1_c=Q1-1.7*Q1_b\n",
    "print(\"Q1_c=Q1-1.7*Q1_b\"),round(Q1_c,2)\n",
    "print(\"so heat supplied by reservoir at 800 K(Q1_a)=\"),round(Q1_a,2)\n",
    "print(\"so heat supplied by reservoir at 700 K(Q1_b)=\"),round(Q1_b,2)\n",
    "print(\"so heat supplied by reservoir at 600 K(Q1_c)=\"),round(Q1_c,2)\n",
    "print(\"NOTE=>answer given in book for heat supplied by reservoir at 800 K,700 K,600 K i.e Q1_a=61.94 KJ/s,Q1_b=88.48 KJ/s,Q1_c=120.42 KJ/s is wrong hence correct answer is calculated above.\")\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
}