{
 "metadata": {
  "name": "",
  "signature": "sha256:24bb4e51d6023f981d52e0e5400d7429d32a87d104b38eab26a2fc0c3b02030a"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 3 : Second Law of Thermodynamics"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.1 Page No : 6"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables :\n",
      "Q2 = 1800.;\t\t\t#KJ/hr\n",
      "Q2 = Q2/3600;\t\t\t#KJ/sec or KW\n",
      "W = 0.35;\t\t\t#KW\n",
      "\n",
      "# Calculations\n",
      "COP = Q2/W;\n",
      "\n",
      "# Results\n",
      "print \"COP is : %.4f\"%COP\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "COP is : 1.4286\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.2 Page No : 21"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables :\n",
      "Q2 = 1;\t\t\t#KJ/sec or KW\n",
      "W = 0.4;\t\t\t#KW\n",
      "T2 = -30+273;\t\t\t#K\n",
      "\n",
      "# Calculations and Results\n",
      "COP = Q2/W;\n",
      "print \"COP of refrigerator is : \",COP\n",
      "\n",
      "T1 = T2*(1+COP)/COP;\t\t\t#K\n",
      "print \"Temperature at which heat is rejected in K :  \",T1\n",
      "\n",
      "Q1 = Q2*(1+COP)/COP;\t\t\t#KW\n",
      "print \"Heat rejected per KW of cooling(KW) :  \",Q1\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "COP of refrigerator is :  2.5\n",
        "Temperature at which heat is rejected in K :   340.2\n",
        "Heat rejected per KW of cooling(KW) :   1.4\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.3 Page No : 22"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables :\n",
      "Q2 = 100.;\t\t\t#KJ/sec or KW\n",
      "T2 = -20.+273;\t\t\t#K\n",
      "T1 = 35.+273;\t\t\t#K\n",
      "\n",
      "# Calculations and Results\n",
      "COP = T2/(T1-T2);\n",
      "print \"COP  is : \",COP\n",
      "\n",
      "W = Q2/COP;\t\t\t#KW\n",
      "print \"Power input in KJ/s or KW : %.2f\"%W\n",
      "\n",
      "COPheatpump = T1/(T1-T2);\t\t\t#\n",
      "print \"COP as heat pump : \",COPheatpump\n",
      "\n",
      "Eta_engine = (1-T2/T1)*100;\n",
      "print \"Efficiency as an engine in : %.3f\"%(Eta_engine)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "COP  is :  4.6\n",
        "Power input in KJ/s or KW : 21.74\n",
        "COP as heat pump :  5.6\n",
        "Efficiency as an engine in : 17.857\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.4 Page No : 22"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables :\n",
      "Q2dot = 12000.;\t\t\t#KJ/hr\n",
      "Wdot = 0.75;\t\t\t#KW\n",
      "Wdot = Wdot*3600.;\t\t\t#KJ/hr\n",
      "\n",
      "# Calculations and Results\n",
      "COP = Q2dot/Wdot;\n",
      "print \"Coefficient of Performance  is : %.3f\"%COP\n",
      "\n",
      "Q1dot = Q2dot+Wdot;\t\t\t#KJ/hr\n",
      "print \"Heat transfer rate in condenser in KJ/hr : %.0f\"%Q1dot\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Coefficient of Performance  is : 4.444\n",
        "Heat transfer rate in condenser in KJ/hr : 14700\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.5 Page No : 23"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from numpy import *\t\t\n",
      "        \t\n",
      "# Variables :\n",
      "Eta1 = 25./100;\t\t\t#efficiency\n",
      "deltaT = 20.;\t\t\t#degree centigrade\n",
      "\n",
      "# Calculations\n",
      "#T2dash = T2-20;\t\t\t#K\n",
      "#T1dash = T1;\t\t\t#K\n",
      "deltaEta1 = 30./100;\n",
      "Eta_dash = 30./100;\t\t\t#efficiency\n",
      "#Eta1/Eta_dash = (1-T2dash/T1dash)/(1-T2/T1)\n",
      "#T1-T2 = 100;\n",
      "#0.75*T1-T2 = 0;\n",
      "A = array([[1, -1],[0.75, -1]])\n",
      "B = array([100,0])\n",
      "X = linalg.solve(A,B);\n",
      "#Solution for T1 and T2 by matrix\n",
      "T1 = X[0];\t\t\t#K\n",
      "T2 = X[1];\t\t\t#K\n",
      "\n",
      "# Results\n",
      "print \"Source temperature in K : %.0f\"%T1\n",
      "print \"Sink temperature in K : %.0f\"%T2\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Source temperature in K : 400\n",
        "Sink temperature in K : 300\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.6 Page No : 23"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables :\n",
      "T1 = 23.+273;\t\t\t#K\n",
      "COP_HP = 2.5;\n",
      "HeatLost = 60000.;\t\t\t#KJ/hr\n",
      "HeatGenerated = 4000.;\t\t\t#KJ/hr\n",
      "\n",
      "# Calculations\n",
      "Q1 = HeatLost-HeatGenerated;\t\t\t#KJ/hr\n",
      "W = Q1/COP_HP;\t\t\t#KJ/hr\n",
      "W = W/3600;\t\t\t#KJ/s or KW\n",
      "\n",
      "# Results\n",
      "print \"Power input in KW : %.3f\"%W\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Power input in KW : 6.222\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.7 Page No : 24"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables :\n",
      "T1 = 400.+273;\t\t\t#K\n",
      "T2 = 20.+273;\t\t\t#K\n",
      "T3 = 100.+273;\t\t\t#K\n",
      "T4 = T2;\t\t\t#K\n",
      "Q1 = 12000.;\t\t\t#KW\n",
      "Q3 = 25000.;\t\t\t#KW\n",
      "\n",
      "# Calculations and Results\n",
      "Eta1 = 1-T2/T1;\t\t\t#Efficiency\n",
      "W1 = Eta1*Q1;\t\t\t#KW\n",
      "print \"Power of Engine 1, W1 in KW : %.2f\"%W1\n",
      "Eta2 = 1-T4/T3;\t\t\t#Efficiency\n",
      "W2 = Eta2*Q3;\t\t\t#KW\n",
      "print \"Power of Engine 2, W2 in KW : %.2f\"%W2\n",
      "print (\"W1>W2, The engine 1 delivers more power.\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Power of Engine 1, W1 in KW : 6775.63\n",
        "Power of Engine 2, W2 in KW : 5361.93\n",
        "W1>W2, The engine 1 delivers more power.\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.8 Page No : 25"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from numpy import *\n",
      "\t\t\t\n",
      "# Variables :\n",
      "Wdot = 200.;\t\t\t#W\n",
      "t1 = 40.;\t\t\t#degree centigrade\n",
      "\n",
      "# Calculations\n",
      "#Q2dot = 20*(t1-t2);\t\t\t#W\n",
      "#COP = Q2dot/W2dot = T2/(T1-T2)\n",
      "#(t1-t2)/(W2dot/20) = (t1+273)/(t1-t2)\n",
      "#20*t1**2+20*t2**2-20*2*t1*t2-t1*Wdot-273*Wdot\n",
      "#(t2+273)/(t1-t2) = (t1-t2)/(Wdot/20)\n",
      "#t2**2-(2*t1+(Wdot/20))*t2-273*(Wdot/20)+t1**2\n",
      "P = array([1, -(2*t1+(Wdot/20)), -273*(Wdot/20)+t1**2])\n",
      "t2 = roots(P);\n",
      "t2 = t2[1];\t\t\t#degree C\n",
      "\n",
      "# Results\n",
      "#Taken only -ve value as t2 cant be greater than t1\n",
      "print \"Temperature of cold space(degree C) %.2f\"%t2\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Temperature of cold space(degree C) -11.17\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.10 Page No : 26"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables :\n",
      "m = 0.8;\t\t\t#Kg\n",
      "hi = 335.;\t\t\t#KJ/Kg-water\n",
      "T1 = 24.+273;\t\t\t#K\n",
      "T2 = 0.+273;\t\t\t#K\n",
      "Wdot = 400.;\t\t\t#W\n",
      "Wdot = Wdot/1000.;\t\t\t#KW\n",
      "\n",
      "# Calculations\n",
      "Q2 = m*hi;\t\t\t#KJ\n",
      "ActualCOP = T2/(T1-T2)*30/100;\n",
      "Q2dot = ActualCOP/Wdot;\t\t\t#KJ/s\n",
      "T = Q2/Q2dot;\t\t\t#sec\n",
      "\n",
      "# Results\n",
      "print \"Time required to freeze the water in sec : %.2f\"%T\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Time required to freeze the water in sec : 31.41\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.11 Page No : 26"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables :\n",
      "T1 = 727.+273;\t\t           \t#K\n",
      "T2 = 27.+273;\t\t        \t#K\n",
      "Wdot = 76.;\t\t\t             #KW\n",
      "FuelBurned = 4.;\t\t    \t#Kg/hr\n",
      "FuelBurned = 4./3600;\t\t\t#Kg/sec\n",
      "FuelHeatingValue = 75000.;\t\t\t#KJ/Kg\n",
      "\n",
      "# Calculations and Results\n",
      "Q1dot = FuelBurned*FuelHeatingValue;\t\t\t#KJ/s or KW\n",
      "Eta = Wdot/Q1dot*100;\t\t\t#%\n",
      "print \"Actual Efficiency of Engine in % : \",Eta\n",
      "\n",
      "Eta_c = (1-T2/T1)*100;\t\t\t#%\n",
      "print \"Carnot Efficiency of Engine in % : \",Eta_c\n",
      "print (\"Claim of inventor is wrong as actual efficiency is greater than carnot efficiency.\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Actual Efficiency of Engine in % :  91.2\n",
        "Carnot Efficiency of Engine in % :  70.0\n",
        "Claim of inventor is wrong as actual efficiency is greater than carnot efficiency.\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.12 Page No : 27"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables :\n",
      "T1 = 24.+273;\t\t\t#K\n",
      "T2 = 10.+273;\t\t\t#K\n",
      "Q1 = 1500.;\t\t\t#kJ/min\n",
      "Q1 = Q1/60.;\t\t\t#kW\n",
      "\n",
      "# Calculations\n",
      "COP_ideal = T1/(T1-T2);\n",
      "ActualCOP = COP_ideal*30/100;\n",
      "W = Q1/ActualCOP;\t\t\t#kW\n",
      "\n",
      "# Results\n",
      "print \"Power required in kW : %.3f\"%W\n",
      "\n",
      "#Answer is wrong in the book as calculation for Q1 is wrong.\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Power required in kW : 3.928\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.13 Page No : 27"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables :\n",
      "T1 = 450.;\t\t\t#K\n",
      "T2 = 280.;\t\t\t#K\n",
      "Q1 = 1200.;\t\t\t#KJ\n",
      "W = 0.15;\t\t\t#KWh\n",
      "W = W*3600.;\t\t\t#KJ\n",
      "\n",
      "# Calculations and Results\n",
      "Eta_a = W/Q1*100;\t\t\t#%\n",
      "print \"Actual Efficiency of Engine in % : \",Eta_a\n",
      "\n",
      "Eta_c = (1-T2/T1)*100;\t\t\t#%\n",
      "print \"Carnot Efficiency of Engine in %% : %.1f\"%(Eta_c)\n",
      "print (\"We would not issue a patent as actual efficiency is greater than carnot efficiency.\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Actual Efficiency of Engine in % :  45.0\n",
        "Carnot Efficiency of Engine in % : 37.8\n",
        "We would not issue a patent as actual efficiency is greater than carnot efficiency.\n"
       ]
      }
     ],
     "prompt_number": 33
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.14 Page No : 28"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables :\n",
      "T1 = 1000.;\t\t\t#K\n",
      "T3 = 100.;\t\t\t#K\n",
      "Q1 = 1680.;\t\t\t#KJ\n",
      "\n",
      "#Eta_a = Eta_b : 1-T2/T1 = 1-T3/T2\n",
      "T2 = math.sqrt(T1*T3);\t\t\t#K\n",
      "Eta_a = 1-T2/T1;\n",
      "Eta_b = Eta_a;\n",
      "W1 = Eta_a*Q1;\t\t\t#KJ\n",
      "Q2 = Q1-W1;\t\t\t#KJ\n",
      "Q3 = (1-Eta_b)*Q2;\t\t\t#KJ\n",
      "print \"Heat rejected by engine B in KJ : \",Q3\n",
      "print \"Temperature at which heat is rejected by engine A in K :  %.2f\"%T2\n",
      "print \"Workdone by engine A in KJ ; %.2f\"%W1\n",
      "\n",
      "W2 = Eta_b*Q2;\t\t\t#KJ\n",
      "print \"Workdone by engine B in KJ ; %.2f\"%W2\n",
      "\n",
      "#If W1 = W2\n",
      "#Q/T = constant\n",
      "T2 = (T1+T3)/2;\t\t\t#K\n",
      "Eta_a = (1-T2/T1)*100;\t\t\t#%\n",
      "Eta_b = (1-T3/T2)*100;\t\t\t#%\n",
      "print (\"If Engine A & B deliver equal work.\")\n",
      "print  \"of Engine A in %% : %.2f\"%Eta_a\n",
      "print  \"of Engine B in %% : %.2f\"%Eta_b\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Heat rejected by engine B in KJ :  168.0\n",
        "Temperature at which heat is rejected by engine A in K :  316.23\n",
        "Workdone by engine A in KJ ; 1148.74\n",
        "Workdone by engine B in KJ ; 363.26\n",
        "If Engine A & B deliver equal work.\n",
        "of Engine A in % : 45.00\n",
        "of Engine B in % : 81.82\n"
       ]
      }
     ],
     "prompt_number": 31
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.15 Page No : 29"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables :\n",
      "T1 = 800.+273;\t\t\t#K\n",
      "T2 = 30.+273;\t\t\t#K\n",
      "T3 = 30.+273;\t\t\t#K\n",
      "T4 = -15.+273;\t\t\t#K\n",
      "Q1 = 1900.;\t\t\t#KJ\n",
      "W2 = 290.;\t\t\t#KJ\n",
      "\n",
      "# Calculations and Results\n",
      "#Eta = 1-T2/T1 = W1/Q1\n",
      "W1 = (1-T2/T1)*Q1;\t\t\t#KJ\n",
      "Q2 = Q1-W1;\t\t\t#KJ\n",
      "W3 = W1-W2;\t\t\t#KJ\n",
      "\n",
      "#COP = T4/(T3-T4) = Q4/W3\n",
      "Q4 = T4/(T3-T4)*W3;\t\t\t#KJ\n",
      "print \"Heat absorbed by refrigerant in KJ : %.2f\"%Q4\n",
      "\n",
      "Q3 = W3+Q4;\t\t\t#KJ\n",
      "TotalHeat = Q2+Q3;\t\t\t#KJ\n",
      "print \"Total Heat transferred to reservoir at 30 degree centigrade in KJ : %.2f\"%TotalHeat\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Heat absorbed by refrigerant in KJ : 6154.54\n",
        "Total Heat transferred to reservoir at 30 degree centigrade in KJ : 7764.54\n"
       ]
      }
     ],
     "prompt_number": 34
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.16 Page No : 30"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables :\n",
      "T1 = 840.+273;\t\t\t#K\n",
      "T2 = 60.+273;\t\t\t#K\n",
      "T3 = 5.+273;\t\t\t#K\n",
      "W3 = 30.;\t\t\t#KW\n",
      "Q3 = 17.;\t\t\t#KJ/s\n",
      "\n",
      "# Calculations\n",
      "#Q3/T3 = Q4/T4\n",
      "T4 = T2;\t\t\t#K\n",
      "Q4 = Q3/T3*T4;\t\t\t#KJ/s\n",
      "W2 = Q4-Q3;\t\t\t#KJ/s\n",
      "W1 = W2+W3;\t\t\t#KJ/s\n",
      "Q1subQ2 = W1;\t\t\t#KJ/s\n",
      "#Q1/T1 = Q2/T2\n",
      "Q1ByQ2 = T1/T2;\n",
      "\t\t\t#Q1subQ2 = Q1subQ2*Q2-Q2\n",
      "Q2 = Q1subQ2/(Q1ByQ2-1);\t\t\t#KW\n",
      "Q1 = Q1ByQ2*Q2;\t\t\t#KW\n",
      "\n",
      "# Results\n",
      "print \"Rate of heat supply from 800 degree C source in KW : %.1f\"%Q1\n",
      "print \"Rate of heat rejection to sink in KW : %.3f\"%(Q2+Q4)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Rate of heat supply from 800 degree C source in KW : 47.6\n",
        "Rate of heat rejection to sink in KW : 34.607\n"
       ]
      }
     ],
     "prompt_number": 35
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.17 Page No : 31"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables :\n",
      "T1 = 27.+273;\t\t\t#K\n",
      "T2 = -23.+273;\t\t\t#K\n",
      "W = 1.;\t\t\t#KW\n",
      "Q2 = 20000.;\t\t\t#KJ/hr\n",
      "\n",
      "# Calculations and Results\n",
      "Q2 = Q2/3600;\t\t\t#KJ/s\n",
      "ActualCOP = Q2/W;\n",
      "print  \"COP of machine : %.3f\"%ActualCOP\n",
      "\n",
      "IdealCOP = T2/(T1-T2);\n",
      "print \"Ideal COP of machine : %.0f\"%IdealCOP\n",
      "print (\"ActualCOP>IdealCOP, Inventor's claim is wrong.\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "COP of machine : 5.556\n",
        "Ideal COP of machine : 5\n",
        "ActualCOP>IdealCOP, Inventor's claim is wrong.\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.18 Page No : 32"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from numpy import *\n",
      "\t\t\t\n",
      "# Variables :\n",
      "#Heat Pump in winter\n",
      "Q1 = 2400.;\t\t\t#KJ/hr/degree temperature difference\n",
      "t1 = 20.;\t\t\t#degreeC\n",
      "t2 = 0.;\t\t\t#degreeC\n",
      "\n",
      "# Calculations and Results\n",
      "Q1 = Q1*(t1-t2)/3600;\t\t\t#KJ/s\n",
      "T1 = t1+273;\t\t\t#K\n",
      "T2 = t2+273;\t\t\t#K\n",
      "COP = T1/(T1-T2);\n",
      "W = Q1/COP;\t\t\t#KW\n",
      "print \"Power required to drive heat pump in KW : %.2f\"%W\n",
      "\n",
      "#Refrigerating unit in summer\n",
      "T4 = 20+273;\t\t\t#K\n",
      "#Q4 = 2400*(T3-T4)/3600;\t\t\t#KJ/s\n",
      "Q3subQ4 = W;\t\t\t#KJ\n",
      "#COP = Q4/(Q3subQ4) = T4/(T3-T4);\n",
      "#T3**2-2*T3*T4+T4**2-T4*3600/2400*(Q3subQ4) = 0\n",
      "P = array([1, -2*T4, T4**2-T4*3600./2400*(Q3subQ4)])\n",
      "T3 = roots(P);\n",
      "T3 = T3[0];\t\t\t#K(Maximum outside temperature)\n",
      "print \"Maximum outside temperature in K : %.0f\"%T3\n",
      "print  \"in degree C : %.0f\"%(T3-273)\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Power required to drive heat pump in KW : 0.91\n",
        "Maximum outside temperature in K : 313\n",
        "in degree C : 40\n"
       ]
      }
     ],
     "prompt_number": 39
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.20 Page No : 34"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables :\n",
      "VcByVa = 14.;\t\t\t#Overall expansion ratio\n",
      "T1 = 257+273.;\t\t\t#K\n",
      "T2 = 27+273.;\t\t\t#K\n",
      "Gamma = 1.4;\n",
      "Ta = T1;\t\t\t#K\n",
      "Tb = T1;\t\t\t#K\n",
      "Tc = T2;\t\t\t#K\n",
      "Td = T2;\t\t\t#K\n",
      "\n",
      "# Calculations and Results\n",
      "VcByVb = (Tb/Tc)**(1/(Gamma-1));\t\t\t#Expansion ratio for Adiabatic Process : \n",
      "print  \"ratio for adiabatic process : %.2f\"%VcByVb\n",
      "\n",
      "VbByVa = VcByVa/VcByVb;\t\t\t#Expansion ratio for Isothermal Process : \n",
      "print \"Expansion ratio for Isothermal process : %.3f\"%VbByVa\n",
      "Eta = (1-T2/T1)*100;\t\t\t#%\n",
      "print \"Thermal Efficiency of carnot cycle in %% : %.1f\"%Eta\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "ratio for adiabatic process : 4.15\n",
        "Expansion ratio for Isothermal process : 3.375\n",
        "Thermal Efficiency of carnot cycle in % : 43.4\n"
       ]
      }
     ],
     "prompt_number": 40
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.21 Page No : 34"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables :\n",
      "W = 10.;\t\t\t#KW\n",
      "\t\t\t#For flat plate collector\n",
      "T1 = 90.+273;\t\t\t#K\n",
      "T2 = 27.+273;\t\t\t#K\n",
      "Tmax = T1;\t\t\t#K\n",
      "IE = 1.;\t\t\t#KW/m**2 incident energy\n",
      "EtaCollection = 60./100;\n",
      "\n",
      "# Calculations and Results\n",
      "#Eta = 1-T2/T1 = W/Q1\n",
      "Q1 = W/(1-T2/T1);\t\t\t#KJ/s\n",
      "A1 = Q1/IE/EtaCollection;\t\t\t#m**2\n",
      "print \"Solar Collector Area required in m**2 : %.3f\"%A1\n",
      "\n",
      "#For parabolic collector\n",
      "T3 = 250.+273;\t\t\t#K\n",
      "T4 = 27.+273;\t\t\t#K\n",
      "Tmax = T3;\t\t\t#K\n",
      "IE = 1.;\t\t\t#KW/m**2 incident energy\n",
      "EtaCollection = 50./100;\n",
      "\n",
      "#Eta = 1-T2/T1 = W/Q1\n",
      "Q3 = W/(1-T4/T3);\t\t\t#KJ/s\n",
      "A2 = Q3/IE/EtaCollection;\t\t\t#m**2\n",
      "print \"Parabolic Solar Collector Area required in m**2 : %.3f\"%A2\n",
      "\t\t\t#Answer of 2nd part is wrong in the book.\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Solar Collector Area required in m**2 : 96.032\n",
        "Parabolic Solar Collector Area required in m**2 : 46.906\n"
       ]
      }
     ],
     "prompt_number": 41
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.24 Page No : 37"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables :\n",
      "T1 = 40.+273;\t\t\t#K\n",
      "T2 = 5.+273;\t\t\t#K\n",
      "T3 = 400.+273;\t\t\t#K\n",
      "T4 = T1;\t\t\t#K\n",
      "Q2 = 1500.;\t\t\t#KJ/min\n",
      "\n",
      "# Calculations and Results\n",
      "COP_R = T2/(T1-T2);\n",
      "print \"COP of refrigerator is : %.3f\"%COP_R\n",
      "\n",
      "Q2dot = Q2/60;\t\t\t#KJ/s\n",
      "Wdot = Q2dot/COP_R;\t\t\t#KW\n",
      "print \"Work Input to refrigerator in KW : %.4f\"%Wdot\n",
      "\n",
      "Eta = (1-T4/T3);\t\t\t#%\n",
      "Q3dot = Wdot/Eta;\t\t\t#KW\n",
      "OverallCOP = Q2dot/Q3dot;\t\t\t#\n",
      "print \"Overall COP of refrigerator : %.4f\"%OverallCOP\n",
      "\t\t\t\n",
      "#Ans of overall COP is wrong in the book.\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "COP of refrigerator is : 7.943\n",
        "Work Input to refrigerator in KW : 3.1475\n",
        "Overall COP of refrigerator : 4.2488\n"
       ]
      }
     ],
     "prompt_number": 42
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.25 Page No : 38"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables :\n",
      "T1 = 1500.;\t\t\t#K\n",
      "T2 = 450.;\t\t\t#K\n",
      "T3 = 150.;\t\t\t#K\n",
      "Q3 = 250.;\t\t\t#KJ\n",
      "\n",
      "# Calculations and Results\n",
      "COP_CR = T3/(T2-T3);\n",
      "print \"COP of cold refrigerator is : %.1f\"%COP_CR\n",
      "\n",
      "COP_HR = T2/(T1-T2);\n",
      "print \"COP of hotter refrigerator is : %.4f\"%COP_HR\n",
      "COP = T3/(T1-T3);\n",
      "print \"COP of composite system is : %.3f\"%COP\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "COP of cold refrigerator is : 0.5\n",
        "COP of hotter refrigerator is : 0.4286\n",
        "COP of composite system is : 0.111\n"
       ]
      }
     ],
     "prompt_number": 43
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.26 Page No : 38"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables :\n",
      "T1 = 870.;\t\t\t#K\n",
      "T2 = 580.;\t\t\t#K\n",
      "T3 = 290.;\t\t\t#K\n",
      "Wdot = 85.;\t\t\t#KW\n",
      "Q3 = 3000.;\t\t\t#KJmin\n",
      "Q3 = Q3/60.;\t\t\t#KJ/s\n",
      "Q1plusQ2 = Wdot+Q3;\t\t\t#KJ\n",
      "\n",
      "#sigma(Q/T) = 0\n",
      "#Q1/T1+Q2/T2 = Q3/T3\n",
      "#Q1/T1+(Q1plusQ2-Q1)/T2-Q3/T3 = 0\n",
      "Q1 = (-Q3*T1*T2/T3+Q1plusQ2*T1)/(T1-T2);\t\t\t#KW\n",
      "print \"Heat Supplied by source1 in KW : %.0f\"%Q1\n",
      "\n",
      "Q2 = Q1plusQ2-Q1;\t\t\t#KW\n",
      "print \"Heat Supplied by source2 in KW : %.0f\"%Q2\n",
      "\n",
      "Eta = Wdot/(Q1+Q2)*100;\t\t\t#%\n",
      "print \"Efficiency of engine in %% : %.2f\"%Eta\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Heat Supplied by source1 in KW : 105\n",
        "Heat Supplied by source2 in KW : 30\n",
        "Efficiency of engine in % : 62.96\n"
       ]
      }
     ],
     "prompt_number": 45
    }
   ],
   "metadata": {}
  }
 ]
}