{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h1>Chapter 6: THE SECOND LAW OF THERMODYNAMICS</h1>"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h2>Example 6.01, page: 133</h2>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "import math\n",
      "\n",
      "# Initialization  of  Variable\n",
      "W = 410 #kJ\n",
      "Qin = 1000 #kJ\n",
      "Th = 500 #K\n",
      "Tc = 300 #K\n",
      "\n",
      "#calculations:\n",
      "#cycle thermal efficiency\n",
      "n = W/Qin\n",
      "#maximum thermal efficiency\n",
      "nmax = 1 - Tc/Th\n",
      "\n",
      "#Results\n",
      "print  \"cycle thermal efficiency is\", n*100,\"% and maximum thermal efficiency is\",nmax*100,\"%\"\n",
      "if (n >nmax):\n",
      "    print \"Since the thermal efficiency of the actual cycle exceeds the maximum theoretical value, the claim cannot be valid\"\n",
      "else:\n",
      "    print \"Since the thermal efficiency of the actual cycle is less than the maximum theoretical value, the claim is valid\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "cycle thermal efficiency is 41.0 % and maximum thermal efficiency is 40.0 %\n",
        "Since the thermal efficiency of the actual cycle exceeds the maximum theoretical value, the claim cannot be valid\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h2>Example 6.02, page: 134</h2>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "import math\n",
      "\n",
      "# Initialization  of  Variable\n",
      "Qcdot = 8000 #kJ/h\n",
      "Tc = -5 #degC\n",
      "Th = 22 #degC\n",
      "Wdotcycle = 3200 #kJ/h\n",
      "\n",
      "#calculations:\n",
      "#coefficient of performance of the refrigerator\n",
      "beta = Qcdot/Wdotcycle\n",
      "#coefficient of performance of a reversible refrigeration cycle\n",
      "betamax = (Tc+273)/(Th-Tc)\n",
      "\n",
      "#Results\n",
      "print  \"coefficient of performance of the refrigerator is\", beta\n",
      "print  \"coefficient of performance of a reversible refrigeration cycle\", round(betamax,1)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "coefficient of performance of the refrigerator is 2.5\n",
        "coefficient of performance of a reversible refrigeration cycle 9.9\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h2>Example 6.03, page: 135</h2>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "import math\n",
      "\n",
      "# Initialization  of  Variable\n",
      "Qh = 6E5 #Btu/day\n",
      "Th = 70 #degF\n",
      "Tc = 32 #degF\n",
      "cost = 8 #cents/kW\n",
      "\n",
      "#calculations:\n",
      "#temps in Rankine\n",
      "Thr = ((Th - 32)*5/9 +273)*1.8\n",
      "Tcr = ((Tc - 32)*5/9 +273)*1.8\n",
      "#Work\n",
      "Wcycle = (1 - Tcr/Thr)*Qh\n",
      "#costperday\n",
      "cpd = (Wcycle/3413)*cost/100 #$/day\n",
      "\n",
      "#Results\n",
      "print  \"minimum theoretical work input is\", round(Wcycle,1),\"Btu/day\"\n",
      "print  \"minimum theoretical cost per day is\", round(cpd,2),\"$/day\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "minimum theoretical work input is 43067.6 Btu/day\n",
        "minimum theoretical cost per day is 1.01 $/day\n"
       ]
      }
     ],
     "prompt_number": 3
    }
   ],
   "metadata": {}
  }
 ]
}