{
 "metadata": {
  "name": "",
  "signature": "sha256:81c0b2f6374783dbad513f5ebbb51829b49d5e29c2d28b8cf1616c5d410d60b5"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 4 : The Second Law of Thermodynamics"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.1  Page No : 148"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#given data\n",
      "t1 = 1000.;  \t\t\t#(unit:fahrenheit) \t\t\t#Source temperature\n",
      "t2 = 80.;   \t\t\t#(unit:fahrenheit) \t\t\t#Sink temperature\n",
      "#solution\n",
      "#converting temperatures to absolute temperatures;\n",
      "T1 = t1+460; \t\t\t#Source temperature \t\t\t#Unit:R\n",
      "T2 = t2+460; \t\t\t#Sink temperature \t\t\t#Unit:R\n",
      "\n",
      "print \"Solution for a\";\n",
      "ans = ((T1-T2)/T1)*100;\t\t\t#(ans in %)  \t\t\t#Efficiency of the engine\n",
      "print \"Efficiency of the engine is %.2f percentage\"%(ans);\n",
      "\n",
      "print \"Solution for b\";\n",
      "T1 = 2000+460; \t\t\t#Source temperature \t\t\t#Unit:R\n",
      "T2 = t2+460;  \t\t\t#Sink temperature \t\t\t#Unit:R\n",
      "ans = ((T1-T2)/T1)*100;\t\t\t#(ans in %) \t\t\t#Efficiency of the engine\n",
      "print \"When the upper tempretrature is increased upto certain ,Efficiency of the engine is %.2f percentage \"%(ans);\n",
      "\n",
      "print \"Solution for c\";\n",
      "T1 = t1+460; \t\t\t#Source temperature \t\t\t#Unit:R\n",
      "T2 = 160+460;  \t\t\t#Sink temperature \t\t\t#Unit:R\n",
      "ans = ((T1-T2)/T1)*100;\t\t\t#(ans in %) \t\t\t#Efficiency of the engine\n",
      "print \"When the lower tempretrature is increased upto certain ,Efficiency of the engine is %.2f percentage \"%(ans);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Solution for a\n",
        "Efficiency of the engine is 63.01 percentage\n",
        "Solution for b\n",
        "When the upper tempretrature is increased upto certain ,Efficiency of the engine is 78.05 percentage \n",
        "Solution for c\n",
        "When the lower tempretrature is increased upto certain ,Efficiency of the engine is 57.53 percentage \n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.2  Page No : 149"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#given data\n",
      "Qin = 100.; \t\t\t#heat added to the cycle \n",
      "\n",
      "print \"In problem 4.1\"\n",
      "#given data\n",
      "t1 = 1000.;  \t\t\t#(unit:fahrenheit) \t\t\t#Source temperature\n",
      "t2 = 80.;   \t\t\t#(unit:fahrenheit)  \t\t\t#Sink temperature\n",
      "#solution\n",
      "#converting temperatures to absolute temperatures;\n",
      "T1 = t1+460; \t\t\t#Source temperature \t\t\t#Unit:R\n",
      "T2 = t2+460;  \t\t\t#Sink temperature \t\t\t#Unit:R\n",
      "print \"Solution for a\";\n",
      "print \"Efficiency of the engine is %.2f percentage\"%(((T1-T2)/T1)*100);\n",
      "\n",
      "print \"Now in problem 4.2\"\n",
      "W = 0.63*Qin; \t\t\t#W = W/J; \t\t\t#Efficiency in problem 4.1 \n",
      "W = Qin*(W/Qin); \t\t\t#amount of work\n",
      "Qr = Qin-W; \t\t\t#Qin-Qr = W/J  \t\t\t#Qr = heat rejected by the cycle\n",
      "print \"The heat removed from the reservoir %.2f units\"%(Qr);"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "In problem 4.1\n",
        "Solution for a\n",
        "Efficiency of the engine is 63.01 percentage\n",
        "Now in problem 4.2\n",
        "The heat removed from the reservoir 37.00 units\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.3  Page No : 149"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#given data\n",
      "t1 = 70.; \t\t\t#(unit:fahrenheit) \t\t\t#Source temperature\n",
      "t2 = 15.; \t\t\t#(unit:fahrenheit)  \t\t\t#Sink temperature\n",
      "Qin = 125000.; \t\t\t#(unit = Btu/hr) \t\t\t#Qin = heat added to the cycle\n",
      "\n",
      "# Calculations and Results\n",
      "#converting temperatures to absolute temperatures;\n",
      "T1 = t1+460; \t\t\t#Source temperature \t\t\t#Unit:R\n",
      "T2 = t2+460; \t\t\t#Sink temperature \t\t\t#Unit:R\n",
      "Qr = Qin*(T2/T1); \t\t\t#Qr = heat rejected by the cycle\n",
      "print \"Qr is %.2f in Btu/hr\"%(Qr);\n",
      "work = Qin-Qr; \t\t\t#reversed cycle requires atleast input \t\t\t#work \t\t\t#btu/hr\n",
      "print \"Work is %.2f in Btu/hr\"%(work);\n",
      "# 1 hp  =  33000 ft*LBf/min \n",
      "# 1 Btu  =  778 ft*LBf \t\t\t#1 hr  =  60 min\n",
      "print \"Minimum horsepower input required is %.2f hp\"%((work*778/60*33000));\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Qr is 112028.30 in Btu/hr\n",
        "Work is 12971.70 in Btu/hr\n",
        "Minimum horsepower input required is 5550589622.64 hp\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.4  Page No : 150"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "W = (50.*33000)/778;\t\t\t#output \t\t\t#W = W/J\n",
      "# 1 hp  =  33000 ft*LBf/min \n",
      "# 1 Btu  =  778 ft*LBf\n",
      "print \"Output is %.2f in Btu/min\"%(W);\n",
      "t1 = 1000.; \t\t\t#Source temperature \t\t\t#(unit:fahrenheit)\n",
      "t2 = 100.;  \t\t\t#Sink temperature \t\t\t#(unit:fahrenheit)\n",
      "#converting temperatures to absolute temperatures;\n",
      "T1 = t1+460; \t\t\t#Source temperature \t\t\t#Unit:R\n",
      "T2 = t2+460; \t\t\t#Sink temperature \t\t\t#Unit:R\n",
      "n = (1-(T2/T1))*100; \t\t\t#efficiency\n",
      "print \"Efficiency is %.2f percentage\"%(n);\t\t\t#in %)\n",
      "#n = (W/J)/Qin\n",
      "Qin = W/(n/100);\t\t\t#(unit Btu/hr) \t\t\t#Qin = heat added to the cycle\n",
      "print \"Heat added to the cycle is %.2f in  Btu/min\"%(Qin);\n",
      "Qr = Qin*(1-(n/100));\t\t\t#(unit Btu/hr) \t\t\t#Qr = heat rejected by the cycle\n",
      "print \"Heat rejected by the cycle is %.2f in  Btu/min \"%(Qr);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Output is 2120.82 in Btu/min\n",
        "Efficiency is 61.64 percentage\n",
        "Heat added to the cycle is 3440.45 in  Btu/min\n",
        "Heat rejected by the cycle is 1319.62 in  Btu/min \n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.5  Page No : 151"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "t1 = 700.; \t\t\t#Source temperature \t\t\t#Unit:Celcius\n",
      "t2 = 20.;  \t\t\t#Sink temperature \t\t\t#Unit:Celcius\n",
      "#converting in F\n",
      "T1 = t1+273;  \t\t\t#Source temperature \t\t\t#Unit:R\n",
      "T2 = t2+273; \t\t\t#Sink temperature \t\t\t#Unit:R\n",
      "n = (T1-T2)/T1*100; \t\t\t#Efficiency\n",
      "print \"Efficiency is %.2f percentage\"%(n);\t\t\t#in %)\n",
      "output = 65;\t\t\t#in hp \t\t\t#Given\n",
      "work = output*0.746;\t\t\t#(unit kJ/s) \t\t\t# 1 hp  =  746 W\n",
      "print \"Work is %.2f kJ/s\"%(work);\n",
      "Qin = work/(n/100);\t\t\t#(unit kJ/s) \t\t\t#Qin = heat added to the cycle\n",
      "print \"Heat added to the cycle is %.2f kJ/s \"%(Qin);\n",
      "Qr = Qin*(1-(n/100));\t\t\t#(unit kJ/s) \t\t\t#Qr = heat rejected by the cycle\n",
      "print \"Heat rejected by the cycle is %.2f  kJ/s \"%(Qr);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Efficiency is 69.89 percentage\n",
        "Work is 48.49 kJ/s\n",
        "Heat added to the cycle is 69.38 kJ/s \n",
        "Heat rejected by the cycle is 20.89  kJ/s \n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.7  Page No : 152"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# given data\n",
      "t1 = 700.; \t\t\t#(unit:fahrenheit) \t\t\t#Source temperature\n",
      "t2 = 200.; \t\t\t#(unit:fahrenheit)  \t\t\t#Sink temperature\n",
      "#converting temperatures to absolute temperatures;\n",
      "T1 = t1+460;  \t\t\t#Source temperature \t\t\t#Unit:R\n",
      "T2 = t2+460; \t\t\t#Sink temperature \t\t\t#Unit:R\n",
      "#n1 = (T1-Ti)/T1 and n2 = (Ti-T2)/Ti \t\t\t#n1 & n2 are efficiency\n",
      "#(T1-Ti)/T1 = (Ti-T2)/Ti;\n",
      "Ti = math.sqrt(T1*T2); \t\t\t#Exhaust temperature  \t\t\t#Unit:R\n",
      "print \"Exhaust temperature of first engine is %.2f in R\"%(Ti);\n",
      "#converting absolute temperature to normal F temperature\n",
      "#Ti(fahrenheit) = Ti(R)-460;\n",
      "print \"Exhaust temperature of first engine is %.2f fahrenheit\"%(Ti-460);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Exhaust temperature of first engine is 874.99 in R\n",
        "Exhaust temperature of first engine is 414.99 fahrenheit\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.8  Page No : 157"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#For reversible isothermal process,\n",
      "q = 843.7; \t\t\t#Heat \t\t\t#Unit:Btu \t\t\t#at 200 psia\n",
      "t = 381.86; \t\t\t#(unit:fahrenheit) \t\t\t#temperature\n",
      "#\t\t\t#converting temperatures to absolute temperatures;\n",
      "T = t+460; \t\t\t#temperature \t\t\t#unit:R\n",
      "deltaS = (q/T); \t\t\t#Change in entropy  \t\t\t#Unit:Btu/lbm*R\n",
      "\n",
      "# Results\n",
      "print \"Change in entropy is %.2f  Btu/lbm*R\"%(deltaS); \t\t\t#1 LBm of saturated water\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in entropy is 1.00  Btu/lbm*R\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.9  Page No : 158"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#For reversible isothermal process,\n",
      "#In problem 4.8,\n",
      "q = 843.7; \t\t\t#Heat \t\t\t#Unit:Btu \t\t\t#at 200 psia\n",
      "t = 381.86; \t\t\t#(unit:fahrenheit) \n",
      "#converting temperatures to absolute temperatures;\n",
      "T = t+460; \t\t\t#Unit:R\"\n",
      "deltaS = (q/T);  \t\t\t#Change in entropy \t\t\t#Btu/lbm\n",
      "print \"Change in entropy is %.2f  Btu/lbm*R\"%(deltaS); \t\t\t#1 LBm of saturated water\n",
      "\n",
      "#In problem 4.9\n",
      "t1 = 381.86; \t\t\t#(unit:fahrenheit) \t\t\t#Source temperature\n",
      "t2 = 50.; \t\t\t#(unit:fahrenheit)  \t\t\t#Sink temperature\n",
      "#converting temperatures to absolute temperatures;\n",
      "T1 = t1+460;  \t\t\t#Source temperature \t\t\t#Unit:R\n",
      "T2 = t2+460; \t\t\t#Sink temperature \t\t\t#Unit:R\n",
      "qin = q;\t\t\t#heat added to the cycle \n",
      "n = (1-(T2/T1))*100; \t\t\t#Efficiency\n",
      "print \"Efficiency is %.2f percentage\"%(n);\n",
      "wbyJ = qin*n*0.01;\t\t\t#work output\n",
      "print \"Work output is %.2f Btu/lbm\"%(wbyJ);\n",
      "Qr = qin-wbyJ; \t\t\t#heat rejected\n",
      "print \"Heat rejected is %.2f Btu/lbm\"%(Qr);\n",
      "print \"As an alternative solution and refering to figure 4.12\"\n",
      "qin = T1*deltaS; \t\t\t#heat added \t\t\t#btu/lbm\n",
      "Qr = T2*deltaS; \t\t\t#Heat rejected \t\t\t#btu/lbm\n",
      "print \"Heat rejected is %.2f Btu/lbm\"%(Qr);\n",
      "wbyJ = qin-Qr; \t\t\t#Work output \t\t\t#Btu/lbm\n",
      "print \"Work output is %.2f Btu/lbm\"%(wbyJ);\n",
      "n = (wbyJ/qin)*100; \t\t\t#Efficiency\n",
      "print \"Efficiency is %.2f percentage\"%(n);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in entropy is 1.00  Btu/lbm*R\n",
        "Efficiency is 39.42 percentage\n",
        "Work output is 332.59 Btu/lbm\n",
        "Heat rejected is 511.11 Btu/lbm\n",
        "As an alternative solution and refering to figure 4.12\n",
        "Heat rejected is 511.11 Btu/lbm\n",
        "Work output is 332.59 Btu/lbm\n",
        "Efficiency is 39.42 percentage\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.10  Page No : 159"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given value\n",
      "hfg = 1959.7; \t\t\t#Unit:kJ/kg \t\t\t#Evaporative enthalpy\n",
      "T = 195.07+273; \t\t\t#Converted into Kelvin \t\t\t#Temperature\n",
      "\n",
      "# Calculations\n",
      "deltaS = hfg/T; \t\t\t#Change in entropy \t\t\t#kJ/kg*K\n",
      "\n",
      "# Results\n",
      "print \"Change in entropy at 1.4MPa for the vaporization of 1 kg is %.2f kJ/kg*K\"%(deltaS); \t\t\t#Values compares very closely to the Steam Tables value\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in entropy at 1.4MPa for the vaporization of 1 kg is 4.19 kJ/kg*K\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.11  Page No : 159"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Let is assume that a Carnot engine cycle operates between two temperatures in each case.\n",
      "t = 1000.; \t\t\t#(unit:fahrenheit) \n",
      "#converting temperatures to absolute temperatures;\n",
      "T1 = t+460;\n",
      "#T1*deltaS = Qin;\n",
      "Qin = 100.; \t\t\t#Unit:Btu \t\t\t#heat added to the cycle \n",
      "deltaS = Qin/T1; \t\t\t#Change in entropy \t\t\t#Btu/R\n",
      "T2 = 50.+460; \t\t\t#converting 50 F temperature to absolute temperature;\n",
      "Qr = T2*deltaS; \t\t\t#Heat rejected \t\t\t#Unit:Btu\n",
      "print \"%.2f Btu energy is unavailable with respect to a receiver at 50 fahrenheit \"%(Qr);\n",
      "T2 = 0+460; \t\t\t#converting 0 F temperature to absolute temperature;\n",
      "Qr = T2*deltaS; \t\t\t#Heat rejected \t\t\t#unit:Btu\n",
      "print \"%.2f Btu energy is unavailable with respect to a receiver at 0 fahrenheit \"%(Qr);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "34.93 Btu energy is unavailable with respect to a receiver at 50 fahrenheit \n",
        "31.51 Btu energy is unavailable with respect to a receiver at 0 fahrenheit \n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.12  Page No : 160"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "Qin = 1000; \t\t\t#Unit:Joule \t\t\t#heat entered to the system\n",
      "t = 500; \t\t\t#(unit:Celcius)  \t\t\t#temperature\n",
      "\t\t\t#converting temperature\n",
      "T1 = t+273; \t\t\t#Unit:Kelvin\n",
      "deltaS = Qin/T1; \t\t\t#Change in entropy \t\t\t#Unit:J/K\n",
      "print \"Solution for a\"\n",
      "T2 = 20+273; \t\t\t#converted 20 Celcius temperature to Kelvin;\n",
      "Qr = T2*deltaS; \t\t\t#Heat rejected at 20 celcius \t\t\t#Joule\n",
      "print \"%.2f Joule energy is unavailable with respect to a receiver at 20 Celcius\"%(Qr);\n",
      "\n",
      "print \"Solution for b\"\n",
      "T2 = 0+273; \t\t\t#converted 0 Celcius temperature to Kelvin\n",
      "Qr = T2*deltaS; \t\t\t#heat rejected at 0 celcius \t\t\t#Joule\n",
      "print \"%.2f Joule energy is unavailable with respect to a receiver at 0 Celcius\"%(Qr);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Solution for a\n",
        "293.00 Joule energy is unavailable with respect to a receiver at 20 Celcius\n",
        "Solution for b\n",
        "273.00 Joule energy is unavailable with respect to a receiver at 0 Celcius\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.13  Page No : 161"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#deltas = Cp*ln(T2/T1)\n",
      "#Multiplying both the sides of equation by the mass m,\n",
      "#DeltaS = m*Cp*ln(T2/T1)\n",
      "m = 6.; \t\t\t#mass \t\t\t#Unit:lbm\n",
      "Cp = 0.361; \t\t\t#Btu/lbm*R \t\t\t#Specific heat constant\n",
      "DeltaS = -0.7062; \t\t\t#Unit:Btu/R \t\t\t#change in entropy\n",
      "t = 1440.; \t\t\t#(unit:fahrenheit) \n",
      "#converting temperatures to absolute temperatures;\n",
      "T1 = t+460; \t\t\t#Unit:R\n",
      "#Rearranging the equation,\n",
      "T2 = T1*math.exp(DeltaS/(m*Cp)); \t\t\t#final temperature \t\t\t#Unit:R\n",
      "\n",
      "# Results\n",
      "print \"Final temperature is %.2f R\"%(T2);\n",
      "print \"or %.2f fahrenheit\"%(T2-460);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Final temperature is 1371.38 R\n",
        "or 911.38 fahrenheit\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.14  Page No : 162"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#1 lbm of water at 500F is mixed with 1 lbm of water at 100F\n",
      "m1 = 1.; \t\t\t#Unit:lbm \t\t\t#mass\n",
      "m2 = 1.; \t\t\t#Unit:lbm \t\t\t#mass\n",
      "c1 = 1.; \t\t\t#Specific heat constant\n",
      "c2 = 1.; \t\t\t#Specific heat constant\n",
      "t1 = 500.; \t\t\t#(unit:fahrenheit) \n",
      "t2 = 100.; \t\t\t#(unit:fahrenheit)\n",
      "cmix = 1.; \t\t\t#Specific heat constant of mixture\n",
      "#now, m1*c1*t1 +m2*c2*t2  =  (m1+m2)*cmix*t\n",
      "#So,\n",
      "t = ((m1*c1*t1)+(m2*c2*t2))/((m1+m2)*cmix) \t\t\t#resulting temperature of the mixture\n",
      "print \"The resulting temperature of the mixture is %.2f fahrenheit\"%(t);\n",
      "#For this problem,the hot steam is cooled\n",
      "deltas = cmix*math.log((t+460)/(t1+460)); \t\t\t#temperatures converted to absolute temperatures; \t\t\t#deltas = change in entropy \t\t\t#Unit:Btu/(lbm*R)\n",
      "#The cold steam is heated\n",
      "deltaS = cmix*math.log((t+460)/(t2+460)); \t\t\t#temperatures converted to absolute temperatures; \t\t\t#deltaS = change in entropy \t\t\t#Unit:Btu/(lbm*R)\n",
      "print \"The net change in entropy is %.2f Btu/lbm*R)\"%(deltaS+deltas);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The resulting temperature of the mixture is 300.00 fahrenheit\n",
        "The net change in entropy is 0.07 Btu/lbm*R)\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.15  Page No : 163"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#In problem 4.15,\n",
      "#1 lbm of water at 500F is mixed with 1 lbm of water at 100F\n",
      "m1 = 1; \t\t\t#Unit:lbm \t\t\t#mass\n",
      "m2 = 1; \t\t\t#Unit:lbm \t\t\t#mass\n",
      "c1 = 1; \t\t\t#Specific heat constant\n",
      "c2 = 1; \t\t\t#Specific heat constant\n",
      "t1 = 500; \t\t\t#(unit:fahrenheit)\n",
      "t2 = 100; \t\t\t#(unit:fahrenheit)\n",
      "cmix = 1; \t\t\t#Specific heat constant of mixture\n",
      "#now, m1*c1*t1 +m2*c2*t2  =  (m1+m2)*cmix*t  \t\t\t#So,\n",
      "t = ((m1*c1*t1)+(m2*c2*t2))/((m1+m2)*cmix) \t\t\t#resulting temperature of the mixture\n",
      "print \"In problem 4.14, The resulting temperature of the mixture is %.2f fahrenheit\"%(t);\n",
      "\n",
      "#Now,in problem 4.15,taking 0F as a reference temperature,\n",
      "#For hot fluid,\n",
      "deltas = cmix*math.log((t1+460)/(0+460)); \t\t\t#temperatures converted to absolute temperatures; \t\t\t#deltas = change in entropy \t\t\t#Unit:Btu/(lbm*R)\n",
      "#For cold fluid,\n",
      "s = cmix*math.log((t2+460)/(0+460)); \t\t\t#temperatures converted to absolute temperatures; \t\t\t#s = change in entropy \t\t\t#Unit:Btu/(lbm*R)\n",
      "#At final mixture temperature of t F,the entropy of each system above 0F is,for the hot fluid \n",
      "s1 = cmix*math.log((t+460)/(0+460)); \t\t\t#temperatures converted to absolute temperatures; \t\t\t#s1 = change in entropy \t\t\t#Unit:Btu/(lbm*R)\n",
      "#and for the cold fluid,\n",
      "s2 = cmix*math.log((t+460)/(0+460)); \t\t\t#temperatures converted to absolute temperatures; \t\t\t#s2 = change in entropy \t\t\t#Unit:Btu/(lbm*R)\n",
      "print \"The change in the entropy for hot fluid is %.2f Btu/lbm*R)\"%(s1-deltas);\n",
      "print \"The change in the entropy for cold fluid is %.2f Btu/lbm*R)\"%(s2-s);\n",
      "print \"The total change in entropy if %.2f Btu/lbm*R\"%(s1-deltas+s2-s);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "In problem 4.14, The resulting temperature of the mixture is 300.00 fahrenheit\n",
        "The change in the entropy for hot fluid is -0.69 Btu/lbm*R)\n",
        "The change in the entropy for cold fluid is 0.00 Btu/lbm*R)\n",
        "The total change in entropy if -0.69 Btu/lbm*R\n"
       ]
      }
     ],
     "prompt_number": 17
    }
   ],
   "metadata": {}
  }
 ]
}