summaryrefslogtreecommitdiff
path: root/Applied_Thermodynamics_by_Onkar_Singh/Chapter4.ipynb
blob: bac8596d7d001bda0bf1755c843d012f887b5716 (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
{
 "metadata": {
  "name": "",
  "signature": "sha256:e33e7b5760e325e5ce218821a1f69234bfd752dae7d88964f3e66dde5271fa8e"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 4: Second Law of Thermodynamics"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2, page no. 114"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "T1 = 400+273.0 #Highest temperature(in K):\n",
      "T2 = 15+273.0 #Lowest temperature(in K):\n",
      "w = 200  #Work produced(in kJ):\n",
      "\n",
      "#Calculation:\n",
      "Q1 = w/(1-T2/T1) #Heat to be supplied(in kJ): #Ratio of Q1 to Q2 is same as T1 to T2\n",
      "#Results:\n",
      "print \"Heat to be supplied: \",round(Q1,1),\"KJ\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Heat to be supplied:  349.6 KJ\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3, page no. 115"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "\n",
      "#Variable Declaration: \n",
      "T1 = 42+273.0 #Upper temperature(in K):\n",
      "T2 = 4+273.0 #Lower temperature(in K):\n",
      "Q2 = 2.0 #Rate at which heat is extracted(in kJ/s):\n",
      "\n",
      "#Calculation:\n",
      "Q1 = T1/T2*Q2 #Heat to be supplied(in kJ/s):\n",
      "P = Q1-Q2 #Power required(in kW):\n",
      "\n",
      "#Results:\n",
      "print \"Power required for driving the refrigerator: \",round(P,3),\"KW\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Power required for driving the refrigerator:  0.274 KW\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4, page no. 115"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "  \n",
      "#Variable Declaration: \n",
      "T1 = 827+273.0 #Source temperature(in K):\n",
      "T2 = 27+273.0 #Sink temperature(in K):\n",
      "T3 = -13+273.0 #Temperature in the refrigerator(in K):\n",
      "Q1 = 2000.0 #Heat input(in kJ):\n",
      "W = 300.0 #Net work available(in kJ):\n",
      "\n",
      "#Calculation:\n",
      "Q2 = Q1*T2/T1 #Rate at which heat is extracted(in kJ):\n",
      "We = Q1-Q2 #Work in the engine(in kJ):\n",
      "Wr = We-W #Work in the refrigerator(in kJ):\n",
      "Q3 = Wr/(T2/T3-1) #Heat transferred to the refrigerant(in kJ):\n",
      "Q4 = Q3+Wr #Heat transferred to reservoir by refrigerant(in kJ):\n",
      "Wt = Q2+Q4 #Total heat transferred to low temperature reservoir(in kJ):\n",
      "\n",
      "#Results:\n",
      "print \"Heat transferred to refrigerant: \",round(Q3,2),\"KJ\"\n",
      "print \"Total heat transferred to low temperature reservoir: \",round(Wt,2),\"KJ\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Heat transferred to refrigerant:  7504.55 KJ\n",
        "Total heat transferred to low temperature reservoir:  9204.55 KJ\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5, page no. 116"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "T1 = 25+273.15 #Temperature inside the house(in K):\n",
      "T2 = -1+273.15 #Temperature outside the house(in K):\n",
      "Q1 = 125.0 #Heating load(in MJ/h):\n",
      "\n",
      "#Calculation:\n",
      "COP = 1/(1-T2/T1) #COP:\n",
      "W = Q1/COP #Minimum power required(in MJ/h):\n",
      "\n",
      "#Results:\n",
      "print \"Minimum power required: \",round(W,2), \"MJ/h\"\n",
      "print \"Minimum power required: \",round(W*10**3/3600,2), \"KW\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Minimum power required:  10.9 MJ/h\n",
        "Minimum power required:  3.03 KW\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 6, page no. 117"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "T1 = -15+273.16 #Inside temperature(in K):\n",
      "T2 = 35+273 #Atmospheric temperature(in K):\n",
      "Q2 = 140.8 #Heat to be extracted (in kW):\n",
      "\n",
      "#Calculation:\n",
      "COP1 = 1/(T2/T1-1) #Carnot COP of plant:\n",
      "COP = COP1/4 #Actual COP:\n",
      "W = Q2/COP #Power required(in kW):\n",
      "\n",
      "#Results:\n",
      "print \"Power required: \",round(W,2),\"KW\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Power required:  108.73 KW\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7, page no. 117"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "T1 = 1150+273.0 #Maximum temperature(in K):\n",
      "T2 = 27+273.0 #Minimum temperature(in K):\n",
      "\n",
      "#Calculation:\n",
      "n = 1-(T2/T1) #Efficiency:\n",
      "\n",
      "#Results:\n",
      "print \"Efficiency: \",round(n*100,2),\"%\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Efficiency:  78.92 %\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8, page no. 117"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "T1 = 27+273 #Maximum temperature(in K):\n",
      "T2 = -8+273 #Minimum temperature(in K):\n",
      "Q = 7.5/60 #Leakage(in kJ/s):\n",
      "\n",
      "#Calculation:\n",
      "W = (T1-T2)*Q/T2 #Power required(in kW):\n",
      "\n",
      "#Results:\n",
      "print \"Power required: \"  ,round(W,4),\"KW\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Power required:  0.0165 KW\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9, page no. 118"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from sympy import *\n",
      "from sympy import symbols,simplify,numer,denom,collect,Wild\n",
      "from sympy.solvers import solve\n",
      "\n",
      "#Variable Declaration:\n",
      "Tso = 1100                                       #Temperature of Source (K):\n",
      "Ts = 300                                         #Temperature of Sink (K):\n",
      "W1,Q1,T1,W2,Q2,T2,W3,Q3,T3 = symbols('W1,Q1,T1,W2,Q2,T2,W3,Q3,T3')      #Creating symbolic Variables required:\n",
      "p = Wild('p')\n",
      "q = Wild('q')\n",
      "\n",
      "#Calculations:\n",
      "HE1 = 1-T2/Tso                                  #Engine 1 Efficiency:\n",
      "Q1 = W1/HE1\n",
      "Q2 = Q1 - W1       #Energy balance equation:\n",
      "#W2byW1 = simplify((Q2*(1-(T3/T2)))/W1)\n",
      "W2byW1 = (T2-T3)/(1100-T2)\n",
      "EQ1 = 3*numer(W2byW1)-2*denom(W2byW1)           #Creating EQ1 using above symbolic manipulation and given W1:W2 ratio of 3:2\n",
      "HE2 = simplify(1 - T3/T2)                       #Engine 2 Efficiency:\n",
      "Q2 = W2 + Q3             #Energy balance equation:\n",
      "\n",
      "\n",
      "expr = W2*denom(HE2)-Q2*numer(HE2)\n",
      "a = collect(simplify(expr),[W2,Q3]).match(-p*Q3+q)\n",
      "\n",
      "Q3 = a[q]/a[p]\n",
      "HE3 = simplify(1-Ts/T3)\n",
      "#W3byW2 = HE3*Q3/W2\n",
      "W3byW2 = (T3/(T2-T3))*((T3-300)/T3)\n",
      "EQ2 = 2*numer(W3byW2)-1*denom(W3byW2)           #Creating EQ1 using above symbolic manipulation and given W2:W3 ratio of 2:1\n",
      "Sol = solve([EQ1,EQ2],[T2,T3])                  #Solving the two generated symbolic equations:\n",
      "\n",
      "#Results:\n",
      "print \"Intermediate Temperature, T2: \",Sol[T2],\"K\"\n",
      "print \"Intermediate Temperature, T3: \",round(Sol[T3],2),\"K\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Intermediate Temperature, T2:  700 K\n",
        "Intermediate Temperature, T3:  433.33 K\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 10, page no. 119"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "#Variable Declaration: \n",
      "T1 = 800.0 #Temperature at which heat is receieved (in K):\n",
      "T2 = 280.0 #Temperature maintained by the carnot engine(in K):\n",
      "\n",
      "#Calculation:\n",
      "T = 2*T1*T2/(T1+T2) #Temperature at which heat is rejected(in K):\n",
      "n = (T1-T)/T1 #Efficiency:\n",
      "COP = T2/(T-T2) #COP of refrigerator:\n",
      "\n",
      "#Results:\n",
      "print \"Efficiency: \",round(n,4)\n",
      "print \"COP of refrigerator: \" ,round(COP,3)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Efficiency:  0.4815\n",
        "COP of refrigerator:  2.077\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 11, page no. 120"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math\n",
      "#Variable Declaration: \n",
      "n = 0.5 #Efficiency of carnot cycle:\n",
      "m = 0.5 #Mass of air(in kg):\n",
      "p2 = 7*10**5 #Initial pressure(in Pa):\n",
      "v2 = 0.12 #Initial volume(in m**3):\n",
      "Q23 = 40 #Heat transferred during the process 2-3(in kJ):\n",
      "Cp = 1.008 #Specific heat at const pressure(in kJ/kg):\n",
      "Cv = 0.721 #Specific heat at const volume(in kJ/kg):\n",
      "Ra = 287 #Gas constant for air:\n",
      "Q12 = 0 #Heat transfer in process 1-2(in kJ):\n",
      "Q34 = 0 #Heat transfer in process 3-4(in kJ):\n",
      "\n",
      "#Calculation:\n",
      "T2 = p2*v2/(m*Ra)   #Maximum temperature of the cycle(in K):\n",
      "T1 = T2/2  #Minimum temperature(in K):\n",
      "v3 = v2*(math.e**(Q23/(m*Ra*10**(-3)*T2)))  #Volume at state 3(in m**3):\n",
      "r = Cp/Cv  #Compression factor:\n",
      "p1 = p2/((T2/T1)**(r/(r-1)))   #Pressure at point 1(in Pa):\n",
      "v1 = m*Ra*T1/p1    #Volume at point 1(in m**3):\n",
      "T3 = T2        #Temperature at state 3(in K):\n",
      "T4 = T1   #Temperature at state 4(in K):\n",
      "W12 = -m*Cv*(T2-T1)  #During process 1-2, work done(in kJ):\n",
      "W23 = Q23 #Work done in process 2-3(in kJ):\n",
      "W34 = -m*Cv*(T4-T3)  #During process 3-4, work done(in kJ):\n",
      "W41 = -W23  #During process 4-1, work done(in kJ):\n",
      "Q41 = -Q23 #Heat transfer in process 4-1(in kJ):\n",
      "\n",
      "#Results:\n",
      "print \"Process    Heat transfer    Work interaction\"\n",
      "print \"  1-2           \",Q12,\"KJ        \",round(W12,2)\n",
      "print \"  2-3           \",Q23,\"KJ        \",W23\n",
      "print \"  3-4           \",Q34,\"KJ        \",round(W34,2)\n",
      "print \"  4-1          \",Q41,\"KJ       \",W41\n",
      "print \"Maximum temperature of the cycle: \",round(T2,2),\"KJ\"\n",
      "print \"Minimum temperature of the cycle: \",round(T1,2),\"KJ\"\n",
      "print \"Volume at the end of the expansion:\",round(v3,4),\"m**3\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Process    Heat transfer    Work interaction\n",
        "  1-2            0 KJ         -105.51\n",
        "  2-3            40 KJ         40\n",
        "  3-4            0 KJ         105.51\n",
        "  4-1           -40 KJ        -40\n",
        "Maximum temperature of the cycle:  585.37 KJ\n",
        "Minimum temperature of the cycle:  292.68 KJ\n",
        "Volume at the end of the expansion: 0.1932 m**3\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12, page no. 122"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "Q1 = 5000 #Heat drawn from 400 K reservoir(in kJ):\n",
      "W = 840        #Work output(in kJ):\n",
      "\n",
      "#Calculation:\n",
      "Q2 = 3*(Q1/2-W) #Value of heat from heat engine(in kJ):\n",
      "Q3 = Q1-W-Q2 #Value of heat to heat engine(in kJ):\n",
      "\n",
      "#Results:\n",
      "print \"Q2 =\",Q2,\"kJ from heat engine\"\n",
      "print \"Q3 =\",-Q3,\"kJ to heat engine\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Q2 = 4980 kJ from heat engine\n",
        "Q3 = 820 kJ to heat engine\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 13, page no. 123"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "T3 = 3+273 #Temperature of the reservoir(in K):\n",
      "T1 = 77+273 #Lower temperature limit(in K):\n",
      "T2 = 1077+273 #Higher temperature limit(in K):\n",
      "E = 100         #Energy supplied to the reservoir(in kJ/s):\n",
      "\n",
      "#Calculation:\n",
      "n = 1-T1/T2 #Efficiency:\n",
      "Q1 = 26.71 #Solving all the equations, we get: #It is given that Q2+Q4 = E #We get Q4 = 1.27*Q3\t\t\n",
      "#COP for heat pump  =  Q4/(Q4-Q3)  =  T1/(T1-T3)\t\t\t\t#We get Q2 = 0.2593*Q1\t\t\t\t#n = 1-Q2/Q1\t\t\t\t\n",
      "#Energy taken from the reservoir Q1 can be found by solving the simultaneous equations\n",
      "\n",
      "#Results:\n",
      "print \"Energy taken from reservoir at 1077\u00baC: \",round(Q1,2),\"KJ\"\t\t\t\t#Results: "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Energy taken from reservoir at 1077\u00baC:  26.71 KJ\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 14, page no. 124"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "Qs = 2000.0 #Heat supplied(in kJ/s):\n",
      "Tso = 1500 #Temperature of source(in K):\n",
      "Tr = 15+273 #Temperature at which heat is rejected(in K):\n",
      "Qt = 3000 #Total heat received(in kJ/s):\n",
      "\n",
      "#Calculation:\n",
      "Qr = Qt-Qs #Heat rejected(in kJ/s):\n",
      "Ts = Qt/(Qs/Tso+Qr/Tr) #Temperature of the sink(in K):\n",
      "\n",
      "#Results: \n",
      "print \"Temperature of the sink: \",round(Ts,2),\"K\" "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Temperature of the sink:  624.28 K\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 15, page no. 124"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "#Variable Declaration: \n",
      "T1 = 500+273.0 #Maximum temperature(in K):\n",
      "T2 = 200+273.0 #Minimum temperature(in K):\n",
      "T3 = 450+273.0 #Temperature of the body(in K):\n",
      "\n",
      "#Calculation:\n",
      "n = 1-T2/T1 #Efficiency:\n",
      "r1 = n  #Ratio of W to Q1:\n",
      "COP = T3/(T3-T2) #COP of pump:\n",
      "r2 = COP*2/3 #Ratio of Q3 to W:\n",
      "r3 = r1*r2 #Ratio of Q3 to Q1:\n",
      "\n",
      "#Results:\n",
      "print \"Ratio of heat rejected to body at 450C to the heat supplied by the reservoir: \",round(r3,4)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Ratio of heat rejected to body at 450C to the heat supplied by the reservoir:  0.7483\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17, page no. 126"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from sympy import *\n",
      "\n",
      "#Variable Declaration:\n",
      "W,Q1,Q2,Q3,T1,T2,T3 = symbols('W,Q1,Q2,Q3,T1,T2,T3')        #Creating symbolic variables:\n",
      "\n",
      "#Calculations:\n",
      "n = 1 - T3/T1                                               #Efficiency of heat engine:\n",
      "COP = T2/(T3-T2)                                            #COP of refrigerator:\n",
      "r = 1/(n*COP)                                               #Ratio of Q1:Q3 :\n",
      "\n",
      "#Results:\n",
      "print \"Ratio of heat supplied from source to heat absorbed from cold body: \",(simplify(r))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Ratio of heat supplied from source to heat absorbed from cold body:  "
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "-T1*(T2 - T3)/(T2*(T1 - T3))\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 18, page no. 127"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "T1 = 900+273.0 #Maximum temperature(in K):\n",
      "T2 = 50+273.0 #Minimum temperature(in K):\n",
      "T3 = 50+273.0 #Temperature of the 3rd reservoir(in K):\n",
      "T4 = 10+273.0 #Temperature of the 4th reservoir(in K):\n",
      "Q3 = 15.0   #Heat picked up by Carnot cycle(in kW):\n",
      "E = 25.0  #Energy required to run a machine(in kW):\n",
      "\n",
      "#Calculation:\n",
      "n = 1-T2/T1 #Efficiency:\n",
      "Q4 = Q3*T3/T4 #From the relation of COP:\n",
      "Whp = Q4-Q3 #Work by heat pump(in kW):\n",
      "Whe = Whp+E #Work in the heat engine(in kW):\n",
      "Q1 = Whe/n #Heat from source at 1173 K(in kW):\n",
      "Q2 = Q1-Whe #Heat rejected to the reservoir from engine 1(in kW):\n",
      "Qt = Q2+Q4 #Total heat rejected to the reservoir(in kW):\n",
      "\n",
      "#Results:\n",
      "print \"Heat rejected to the reservoir: \",round(Qt,3),\"KW\" \n",
      "print \"Heat received from the highest temperature reservoir: \",round(Q1,3),\"KW\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Heat rejected to the reservoir:  27.426 KW\n",
        "Heat received from the highest temperature reservoir:  37.426 KW\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 19, page no. 128"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "\n",
      "#Variable Declaration: \n",
      "v1 = 1.8 #Volume of 1st tank(in m**3):\n",
      "v2 = 3.6 #Volume of 2nd tank(in m**3):\n",
      "p1 = 12  #Initial pressure(in bar):\n",
      "T1 = 40+273 #Initial temperature(in K):\n",
      "R = 0.208 #Gas constant for argon(in kJ/kg.K):\n",
      "\n",
      "#Calculation:\n",
      "pf = p1*v1/(v1+v2) #By gas law for final and initial state:\n",
      "\n",
      "#Results:\n",
      "print \"Final pressure: \",round(pf),\"bar\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Final pressure:  4.0 bar\n"
       ]
      }
     ],
     "prompt_number": 18
    }
   ],
   "metadata": {}
  }
 ]
}