{
 "metadata": {
  "name": "",
  "signature": "sha256:15d0388b2c544d629a9ec990a9a36b6e26ea291bc7812312e5319e0c4bde1ab8"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 7 - The second law"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2 - Pg 112"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the entropy in parts ab,ac and efficiency\n",
      "#Initialization of variables\n",
      "import math\n",
      "cv=0.175 #Btu/lbm R\n",
      "R0=1.986\n",
      "M=29\n",
      "T2=1040 #R\n",
      "T1=520 #R\n",
      "#calculations\n",
      "cp=cv+R0/M\n",
      "sab=cv*math.log(T2/T1)\n",
      "sac=cp*math.log(T2/T1)\n",
      "dqab=cv*(T2-T1)\n",
      "dqca=cp*(T1-T2)\n",
      "dqrev=T2*(sac-sab)\n",
      "eta=(dqab+dqrev+dqca)/(dqab+dqrev)*100\n",
      "#results\n",
      "print '%s %.4f %s' %(\"Entropy in ab part =\",sab,\"Btu/lbm R\")\n",
      "print '%s %.4f %s' %(\"\\n Entropy in ac part =\",sac,\" Btu/lbm R\")\n",
      "print '%s %.2f %s' %(\"\\n Efficiency =\",eta,\" percent\")\n",
      "print '%s' %(\"The answers are a bit different due to rounding off error in textbook\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Entropy in ab part = 0.1213 Btu/lbm R\n",
        "\n",
        " Entropy in ac part = 0.1688  Btu/lbm R\n",
        "\n",
        " Efficiency = 9.80  percent\n",
        "The answers are a bit different due to rounding off error in textbook\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3 - Pg 115"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the change in entropy of the process\n",
      "#Initialization of variables\n",
      "import math\n",
      "tc=32. #F\n",
      "th=80. #F\n",
      "mw=5 #lbm\n",
      "mi=1 #lbm\n",
      "P=14.7 #psia\n",
      "cp=1\n",
      "#calculations\n",
      "t= (-144*mi+tc*mi+th*mw)/(mw+mi)\n",
      "ds1=144/(tc+460)\n",
      "ds2=cp*math.log((460+t)/(460+tc))\n",
      "dsice=ds1+ds2\n",
      "dswater=mw*cp*math.log((t+460)/(460+th))\n",
      "ds=dsice+dswater\n",
      "#results\n",
      "print '%s %.4f %s' %(\"Change in entropy of the process =\",ds,\"Btu/R\")\n",
      "print '%s' %(\"The answer is a bit different due to rounding off error in textbook\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in entropy of the process = 0.0192 Btu/R\n",
        "The answer is a bit different due to rounding off error in textbook\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4 - Pg 119"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the change in available energy\n",
      "#Initialization of variables\n",
      "import math\n",
      "cp=1\n",
      "T2=60. #F\n",
      "T1=100. #F\n",
      "ta=32. #F\n",
      "#calculations\n",
      "dq=cp*(T2-T1)\n",
      "ds=cp*math.log((460+T2)/(460+T1))\n",
      "dE=dq-ds*(ta+460)\n",
      "#results\n",
      "print '%s %.1f %s' %(\"Change in available energy =\",dE,\"Btu/lbm\")\n",
      "print '%s' %(\"The answer is a bit different due to rounding off error in textbook\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in available energy = -3.5 Btu/lbm\n",
        "The answer is a bit different due to rounding off error in textbook\n"
       ]
      }
     ],
     "prompt_number": 3
    }
   ],
   "metadata": {}
  }
 ]
}