{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 5 - First Law of Thermodynamics"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 1 - Pg 59"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Calculate the change in internal energy\n",
      "#initialization of varaibles\n",
      "V1=10 #cu ft\n",
      "P1=15 #psia\n",
      "V2=5 #cu ft\n",
      "H=34.7 #Btu\n",
      "#calculations\n",
      "W=P1*(V2-V1)*144\n",
      "dE=-H-W/778.\n",
      "#results\n",
      "print '%s %.1f %s' %(\"Internal energy change =\",dE,\"Btu\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Internal energy change = -20.8 Btu\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2 - Pg 59"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Calculate the work done and the change in Internal energy\n",
      "#initialization of varaibles\n",
      "dT=35 #F\n",
      "H=34 #Btu\n",
      "cv=1.2 #B/lb F\n",
      "m= 2 #lb\n",
      "#calculations\n",
      "U=cv*dT*m\n",
      "W=H-U\n",
      "#results\n",
      "print '%s %d %s' %(\"Work done =\",W,\"Btu\")\n",
      "print '%s %.1f %s' %(\"\\n Internal energy change =\",U,\"Btu\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Work done = -50 Btu\n",
        "\n",
        " Internal energy change = 84.0 Btu\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3 - Pg 60"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Calculate the change in internal energy in both cases\n",
      "#initialization of varaibles\n",
      "p=500 #psia\n",
      "V2=0.9278 #cu ft\n",
      "V1=0.0197 #cu ft\n",
      "h2=1204.4 #B/lb\n",
      "h1=449.4 #B/lb\n",
      "#calculations\n",
      "W=p*(V2-V1)*144.\n",
      "du=h2-h1-144*p*(V2-V1)/778.\n",
      "du2=h2-h1-W/778.\n",
      "#results\n",
      "print '%s %.1f %s' %(\"Change in internal energy = \",du,\"Btu\")\n",
      "print '%s %.1f %s' %(\"\\n Method 2, Internal energy change = \",du2,\"Btu\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in internal energy =  671.0 Btu\n",
        "\n",
        " Method 2, Internal energy change =  671.0 Btu\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4a - Pg 61"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Calculate the heat liberated\n",
      "#initialization of varaibles\n",
      "import math\n",
      "P1=75. #psia\n",
      "P2=15. #psia\n",
      "V1=6. #cu ft\n",
      "g=1.2 #gamma\n",
      "m=3. #lb\n",
      "#calculations\n",
      "V2=V1*math.pow((P1/P2),(1/g))\n",
      "U=0.48*(P2*V2-P1*V1)\n",
      "W=(P2*V2-P1*V1)*144./((1-g)*778.)\n",
      "Q=U+W\n",
      "#results\n",
      "print '%s %.3f %s' %(\"Heat = \",Q,\"Btu\")\n",
      "#The answer given in textbook is wrong. please check using a calculator\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Heat =  47.162 Btu\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4b - Pg 62"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Calculate the net work done\n",
      "#initialization of varaibles\n",
      "import math\n",
      "P1=75. #psia\n",
      "P2=15. #psia\n",
      "V1=6. #cu ft\n",
      "g=1.2 #gamma\n",
      "m=3 #lb\n",
      "#calculations\n",
      "Q=30 #Btu\n",
      "V2=V1*math.pow((P1/P2),(1/g))\n",
      "U=0.48*(P2*V2-P1*V1)\n",
      "W=Q-U\n",
      "#results\n",
      "print '%s %.1f %s' %(\"Work done =\",W,\"  Btu\")\n",
      "#The answer given in textbook is wrong. please check using a calculator\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Work done = 80.8   Btu\n"
       ]
      }
     ],
     "prompt_number": 4
    }
   ],
   "metadata": {}
  }
 ]
}