{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 13 - Mixtures"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 1 - Pg 314"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#For the mixture, determine the molefractions, average mol. wt., specific gas constant, volume and density, partial pressures and volumes\n",
      "#Initialization of variables\n",
      "m1=10. #lbm\n",
      "m2=15. #lnm\n",
      "p=50. #psia\n",
      "t=60.+460 #R\n",
      "M1=32.\n",
      "M2=28.02\n",
      "R0=1545 \n",
      "#calculations\n",
      "n1=m1/M1\n",
      "n2=m2/M2\n",
      "x1=n1/(n1+n2)\n",
      "x2=n2/(n1+n2)\n",
      "M=x1*M1+x2*M2\n",
      "R=R0/M\n",
      "V=(n1+n2)*R0*t/p/144.\n",
      "rho=p*144/(R0*t)\n",
      "rho2=M*rho\n",
      "p1=x1*p\n",
      "p2=x2*p\n",
      "v1=x1*V\n",
      "v2=x2*V\n",
      "#results\n",
      "print '%s' %(\"part a\")\n",
      "print '%s %.3f %s %.3f %s' %(\"Mole fractions of oxygen and nitrogen are\",x1,\" and\",x2,\"respectively\")\n",
      "print '%s' %(\"part b\")\n",
      "print '%s %.1f' %(\"Average molecular weight (gm) =\",M)\n",
      "print '%s' %(\"part c\")\n",
      "print '%s %.2f %s' %(\"specific gas constant =\",R,\"psia ft^3/lbm R\")\n",
      "print '%s' %(\"part d\")\n",
      "print '%s %.1f %s' %(\"volume of mixture =\",V,\"ft^3\")\n",
      "print '%s %.5f %s %.3f %s' %(\"density of mixture is\",rho, \"mole/ft^3 and\",rho2, \"lbm/ft^3\")\n",
      "print '%s' %(\"part e\")\n",
      "print '%s %.2f %s %.2f %s' %(\"partial pressures of oxygen and nitrogen are\",p1, \"psia and\",p2, \"psia respectively\")\n",
      "print '%s %.2f %s %.2f %s' %(\"partial volumes of oxygen and nitrogen are\",v1, \"ft^3 and\",v2, \"ft^3 respectively\")\n",
      "print '%s' %(\"The answers are a bit different due to rounding off error in textbook\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "part a\n",
        "Mole fractions of oxygen and nitrogen are 0.369  and 0.631 respectively\n",
        "part b\n",
        "Average molecular weight (gm) = 29.5\n",
        "part c\n",
        "specific gas constant = 52.40 psia ft^3/lbm R\n",
        "part d\n",
        "volume of mixture = 94.6 ft^3\n",
        "density of mixture is 0.00896 mole/ft^3 and 0.264 lbm/ft^3\n",
        "part e\n",
        "partial pressures of oxygen and nitrogen are 18.43 psia and 31.57 psia respectively\n",
        "partial volumes of oxygen and nitrogen are 34.87 ft^3 and 59.73 ft^3 respectively\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 2 - Pg 316"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the gravimetric analysis\n",
      "#Initialization of variables\n",
      "m1=5.28\n",
      "m2=1.28\n",
      "m3=23.52\n",
      "#calculations\n",
      "m=m1+m2+m3\n",
      "x1=m1/m\n",
      "x2=m2/m\n",
      "x3=m3/m\n",
      "C=12./44. *m1/ m\n",
      "O=(32./44. *m1 + m2)/m\n",
      "N=m3/m\n",
      "sum1=(x1+x2+x3)*100\n",
      "sum2=(C+N+O)*100\n",
      "#results\n",
      "print '%s %.1f %s %.1f %s %.1f %s' %(\"From gravimetric analysis, co2 =\",x1*100,\" percent , o2 =\",x2*100,\"percent and n2 =\",x3*100,\"percent\")\n",
      "print '%s %.2f %s %.2f %s %.2f %s' %(\"\\n From ultimate analysis, co2 =\",C*100,\"percent , o2 =\",O*100,\"percent and n2 =\",N*100,\"percent\")\n",
      "print '%s %.1f %s' %(\"\\n Sum in case 1 =\",sum1,\"percent\")\n",
      "print '%s %.1f %s' %(\"\\n Sum in case 2 =\",sum2,\"percent\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "From gravimetric analysis, co2 = 17.6  percent , o2 = 4.3 percent and n2 = 78.2 percent\n",
        "\n",
        " From ultimate analysis, co2 = 4.79 percent , o2 = 17.02 percent and n2 = 78.19 percent\n",
        "\n",
        " Sum in case 1 = 100.0 percent\n",
        "\n",
        " Sum in case 2 = 100.0 percent\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3 - Pg 318"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the entropy of the mixture\n",
      "#Initialization of variables\n",
      "import math\n",
      "x1=1./3.\n",
      "n1=1\n",
      "n2=2\n",
      "x2=2./3.\n",
      "p=12.7 #psia\n",
      "cp1=7.01 #Btu/mole R\n",
      "cp2=6.94 #Btu/mole R\n",
      "R0=1.986\n",
      "T2=460+86.6 #R\n",
      "T1=460 #R\n",
      "p0=14.7 #psia\n",
      "#calculations\n",
      "p1=x1*p\n",
      "p2=x2*p\n",
      "ds1= cp1*math.log(T2/T1) - R0*math.log(p1/p0)\n",
      "ds2= cp2*math.log(T2/T1) - R0*math.log(p2/p0)\n",
      "S=n1*ds1+n2*ds2\n",
      "#results\n",
      "print '%s %.2f %s' %(\"Entropy of mixture =\",S,\"Btu/R\")\n",
      "print '%s' %(\"\\n the answer given in textbook is wrong. please check using a calculator\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Entropy of mixture = 8.27 Btu/R\n",
        "\n",
        " the answer given in textbook is wrong. please check using a calculator\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4 - Pg 319"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the change in internal energy and entropy of the gas\n",
      "#Initialization of variables\n",
      "import math\n",
      "c1=4.97 #Btu/mol R\n",
      "c2=5.02 #Btu/mol R\n",
      "n1=2\n",
      "n2=1\n",
      "T1=86.6+460 #R\n",
      "T2=50.+460 #R\n",
      "#calculations\n",
      "du=(n1*c1+n2*c2)*(T2-T1)\n",
      "ds=(n1*c1+n2*c2)*math.log(T2/T1)\n",
      "#results\n",
      "print '%s %d %s' %(\"Change in internal energy =\",du,\"Btu\")\n",
      "print '%s %.3f %s' %(\"\\n Change in entropy =\",ds,\"Btu/R\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in internal energy = -547 Btu\n",
        "\n",
        " Change in entropy = -1.037 Btu/R\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5 - Pg 320"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the pressure and mixing temperature of the mixture\n",
      "#Initialization of variables\n",
      "n1=1.\n",
      "n2=2.\n",
      "c1=5.02\n",
      "c2=4.97\n",
      "t1=60. #F\n",
      "t2=100. #F\n",
      "R0=10.73\n",
      "p1=30. #psia\n",
      "p2=10. #psia\n",
      "#calcualtions\n",
      "t=(n1*c1*t1+n2*c2*t2)/(n1*c1+n2*c2)\n",
      "V1= n1*R0*(t1+460)/p1\n",
      "V2=n2*R0*(t2+460)/p2\n",
      "V=V1+V2\n",
      "pm=(n1+n2)*R0*(t+460)/V\n",
      "#results\n",
      "print '%s %.1f %s' %(\"Pressure of mixture =\",pm,\"psia\")\n",
      "print '%s %.1f %s' %(\"\\n Mixing temperature =\",t,\"F\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Pressure of mixture = 12.7 psia\n",
        "\n",
        " Mixing temperature = 86.6 F\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 6 - Pg 320"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the change in entropy in all cases\n",
      "#Initialization of variables\n",
      "import math\n",
      "T2=546.6 #R\n",
      "T1=520. #R\n",
      "T3=560. #R\n",
      "v2=1389.2\n",
      "v1=186.2\n",
      "R0=1.986\n",
      "c1=5.02\n",
      "c2=4.97\n",
      "n1=1\n",
      "n2=2\n",
      "v3=1203.\n",
      "#calculations\n",
      "ds1=n1*c1*math.log(T2/T1) + n1*R0*math.log(v2/v1)\n",
      "ds2=n2*c2*math.log(T2/T3)+n2*R0*math.log(v2/v3)\n",
      "ds=ds1+ds2\n",
      "ds3=n1*c1*math.log(T2/T1)+n2*c2*math.log(T2/T3)\n",
      "ds4=n2*R0*math.log(v2/v3)+ n1*R0*math.log(v2/v1)\n",
      "dss=ds3+ds4\n",
      "#results\n",
      "print '%s %.3f %s' %(\"Change in  entropy for gas 1 =\",ds1,\"Btu/R\")\n",
      "print '%s %.3f %s' %(\"\\n Change in  entropy for gas 1 =\",ds2,\"Btu/R\")\n",
      "print '%s %.3f %s' %(\"\\n Net change in entropy =\",ds,\" Btu/R\")\n",
      "print '%s %.3f %s' %(\"\\n In case 2, change in entropy =\",dss,\" Btu/R\")\n",
      "print '%s' %(\"The answer is a bit different due to rounding off error in the textbook\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in  entropy for gas 1 = 4.242 Btu/R\n",
        "\n",
        " Change in  entropy for gas 1 = 0.331 Btu/R\n",
        "\n",
        " Net change in entropy = 4.572  Btu/R\n",
        "\n",
        " In case 2, change in entropy = 4.572  Btu/R\n",
        "The answer is a bit different due to rounding off error in the textbook\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7 - Pg 322"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the final temperature and changes in entropy of air and water\n",
      "#Initialization of variables\n",
      "import math\n",
      "m1=1 #lbm\n",
      "m2=0.94 #lbm\n",
      "M1=29.\n",
      "M2=18.\n",
      "p1=50. #psia\n",
      "p2=100. #psia\n",
      "t1=250. +460 #R\n",
      "R0=1.986\n",
      "cpa=6.96\n",
      "cpb=8.01\n",
      "#calculations\n",
      "xa = (m1/M1)/((m1/M1)+ m2/M2)\n",
      "xb=1-xa\n",
      "t2=t1*math.pow((p2/p1),(R0/(xa*cpa+xb*cpb)))\n",
      "d=R0/(xa*cpa+xb*cpb)\n",
      "k=1/(1-d)\n",
      "dsa=cpa*math.log(t2/t1) -R0*math.log(p2/p1)\n",
      "dSa=(m1/M1)*dsa\n",
      "dSw=-dSa\n",
      "dsw=dSw*M2/m2\n",
      "#results\n",
      "print '%s %d %s' %(\"Final remperature =\",t2,\"R\")\n",
      "print '%s %.3f %s %.5f %s' %(\"\\n Change in entropy of air =\",dsa,\" btu/mole R and\",dSa, \"Btu/R\")\n",
      "print '%s %.4f %s %.5f %s' %(\"\\n Change in entropy of water =\",dsw,\" btu/mole R and\",dSw, \"Btu/R\")\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": [
        "Final remperature = 851 R\n",
        "\n",
        " Change in entropy of air = -0.115  btu/mole R and -0.00395 Btu/R\n",
        "\n",
        " Change in entropy of water = 0.0757  btu/mole R and 0.00395 Btu/R\n",
        "The answers are a bit different due to rounding off error in textbook\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8 - Pg 323"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the volume occupied and mass of steam\n",
      "#Initialization of variables\n",
      "T=250. + 460 #R\n",
      "p=29.825 #psia\n",
      "pt=50. #psia\n",
      "vg=13.821 #ft^3/lbm\n",
      "M=29.\n",
      "R=10.73\n",
      "#calculations\n",
      "pa=pt-p\n",
      "V=1/M *R*T/pa\n",
      "ma=V/vg\n",
      "xa=p/pt\n",
      "mb=xa/M *18/(1-xa)\n",
      "#results\n",
      "print '%s %.2f %s' %(\"In case 1, volume occupied =\",V,\"ft^3\")\n",
      "print '%s %.2f %s' %(\"\\n In case 1, mass of steam =\",ma,\" lbm steam\")\n",
      "print '%s %.3f %s' %(\"\\n In case 2, mass of steam =\",mb,\" lbm steam\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "In case 1, volume occupied = 13.02 ft^3\n",
        "\n",
        " In case 1, mass of steam = 0.94  lbm steam\n",
        "\n",
        " In case 2, mass of steam = 0.918  lbm steam\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9 - Pg 324"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the percentage of alcohol evaporated\n",
      "#Initialization of variables\n",
      "ps=0.64 #psia\n",
      "p=14.7 #psia\n",
      "M=29\n",
      "M2=46\n",
      "#calculations\n",
      "xa=ps/p\n",
      "mb=xa*9/M *M2/(1-xa)*100\n",
      "#results\n",
      "print '%s %.1f %s' %(\"percentage of alcohol evaporated =\",mb,\"percent\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "percentage of alcohol evaporated = 65.0 percent\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 10 - Pg 324"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the partial pressure of water vapor\n",
      "#Initialization of variables\n",
      "ps=0.5069 #psia\n",
      "p=20 #psia\n",
      "m1=0.01\n",
      "m2=1\n",
      "M1=18.\n",
      "M2=29.\n",
      "#calculations\n",
      "xw= (m1/M1)/(m1/M1+m2/M2)\n",
      "pw=xw*p\n",
      "#results\n",
      "print '%s %.3f %s' %(\"partial pressure of water vapor =\",pw,\"psia\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "partial pressure of water vapor = 0.317 psia\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 11 - Pg 327"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the pressure, dew temperature of water. Calculate the density of water, air,specific humidity and the degree of saturation\n",
      "#Initialization of variables\n",
      "t1=80+460. #R\n",
      "ps=0.5069 #psia\n",
      "print '%s' %(\"from steam tables,\")\n",
      "vs=633.1 #ft^3/lbm\n",
      "phi=0.3\n",
      "R=85.6\n",
      "Ra=53.3\n",
      "p=14.696\n",
      "#calculations\n",
      "tdew=46 #F\n",
      "pw=phi*ps\n",
      "rhos=1/vs\n",
      "rhow=phi*rhos\n",
      "rhow2= pw*144/(R*t1)\n",
      "pa=p-pw\n",
      "rhoa= pa*144/(Ra*t1)\n",
      "w=rhow/rhoa\n",
      "mu=phi*(p-ps)/(p-pw)\n",
      "Ws=0.622*(ps/(p-ps))\n",
      "mu2=w/Ws\n",
      "#results\n",
      "print '%s' %(\"part a\")\n",
      "print '%s %.5f %s' %(\"partial pressure of water =\",pw,\"psia\")\n",
      "print '%s %d %s' %(\"\\n dew temperature =\",tdew,\"F\")\n",
      "print '%s' %(\"part b\")\n",
      "print '%s %.6f %s' %(\"density of water =\",rhow,\"lbm/ft^3\")\n",
      "print '%s %.6f %s' %(\"\\n in case 2, density of water =\",rhow2,\"lbm/ft^3\")\n",
      "print '%s %.6f %s' %(\"\\n density of air =\",rhoa,\"lbm/ft^3\")\n",
      "print '%s' %(\"part c\")\n",
      "print '%s %.4f %s' %(\"specific humidity  =\",w,\"lbm steam/lbm air\")\n",
      "print '%s' %(\"part d\")\n",
      "print '%s %.3f' %(\"In method 1, Degree of saturation = \",mu)\n",
      "print '%s %.3f' %(\"\\n In method 2, Degree of saturation = \",mu2)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "from steam tables,\n",
        "part a\n",
        "partial pressure of water = 0.15207 psia\n",
        "\n",
        " dew temperature = 46 F\n",
        "part b\n",
        "density of water = 0.000474 lbm/ft^3\n",
        "\n",
        " in case 2, density of water = 0.000474 lbm/ft^3\n",
        "\n",
        " density of air = 0.072765 lbm/ft^3\n",
        "part c\n",
        "specific humidity  = 0.0065 lbm steam/lbm air\n",
        "part d\n",
        "In method 1, Degree of saturation =  0.293\n",
        "\n",
        " In method 2, Degree of saturation =  0.293\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12 - Pg 328"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the change in moisture content \n",
      "#Initialization of variables\n",
      "p=14.696 #psia\n",
      "ps=0.0808  #psia\n",
      "ps2=0.5069 #psia\n",
      "phi2=0.5\n",
      "phi=0.6\n",
      "grain=7000\n",
      "#calculations\n",
      "pw=phi*ps\n",
      "w1=0.622*pw/(p-pw)\n",
      "pw2=phi2*ps2\n",
      "w2=0.622*pw2/(p-pw2)\n",
      "dw=w2-w1\n",
      "dwg=dw*grain\n",
      "#results\n",
      "print '%s %.6f %s' %(\"change in moisture content =\",dw,\"lbm water/lbm dry air\")\n",
      "print '%s %.2f %s' %(\"\\n in grains, change =\",dwg,\"grains water/lbm dry air\")\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": [
        "change in moisture content = 0.008857 lbm water/lbm dry air\n",
        "\n",
        " in grains, change = 62.00 grains water/lbm dry air\n",
        "The answers are a bit different due to rounding off error in textbook\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 13 - Pg 335"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Calculate the humidity ratio, relative humidity and dew point of the gas\n",
      "#Initialization of variables\n",
      "t1=80. #F\n",
      "t2=60. #F\n",
      "p=14.696 #psia\n",
      "ps=0.507 #psia\n",
      "pss=0.256 #psia\n",
      "cp=0.24\n",
      "#calculations\n",
      "ws=0.622*pss/(p-pss)\n",
      "w=(cp*(t2-t1) + ws*1060)/(1060+ 0.45*(t1-t2))\n",
      "pw=w*p/(0.622+w)\n",
      "phi=pw/ps*100\n",
      "td=46. #F\n",
      "#results\n",
      "print '%s %.4f %s' %(\"\\n humidity ratio =\",w,\"lbm/lbm dry air\")\n",
      "print '%s %.1f %s' %(\"\\n relative humidity  =\",phi,\" percent\")\n",
      "print '%s %d %s' %(\"\\n Dew point =\",td,\"F\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        " humidity ratio = 0.0064 lbm/lbm dry air\n",
        "\n",
        " relative humidity  = 29.7  percent\n",
        "\n",
        " Dew point = 46 F\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 14 - Pg 335"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the enthalpy and sigma function of the mixture\n",
      "#Initialization of variables\n",
      "W=0.0065  #lbm/lbm of dry air\n",
      "t=80. #F\n",
      "td=60. #F\n",
      "#calculations\n",
      "H=0.24*t+W*(1060+0.45*t)\n",
      "sig=H-W*(td-32)\n",
      "Ws=0.0111\n",
      "H2=0.24*td+Ws*(1060+0.45*td)\n",
      "sig2=H2-Ws*(td-32)\n",
      "#results\n",
      "print '%s %.2f %s' %(\"In case 1, enthalpy =\",H,\"Btu/lbm dry air\")\n",
      "print '%s %.2f %s' %(\"\\n In case 1, sigma function =\",sig,\"Btu/lbm dry air\")\n",
      "print '%s %.2f %s' %(\"\\n In case 2, enthalpy =\",H2,\"Btu/lbm dry air\")\n",
      "print '%s %.2f %s' %(\"\\n In case 2, sigma function =\",sig2,\"Btu/lbm dry air\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "In case 1, enthalpy = 26.32 Btu/lbm dry air\n",
        "\n",
        " In case 1, sigma function = 26.14 Btu/lbm dry air\n",
        "\n",
        " In case 2, enthalpy = 26.47 Btu/lbm dry air\n",
        "\n",
        " In case 2, sigma function = 26.15 Btu/lbm dry air\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 15 - Pg 336"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the enthalpy and heat added\n",
      "#Initialization of variables\n",
      "t1=30. #F\n",
      "t2=60. #F\n",
      "t3=80. #F\n",
      "W1=0.00206\n",
      "W2=0.01090\n",
      "#calculations\n",
      "cm1=0.24+0.45*W1\n",
      "H1=cm1*t1+W1*1060\n",
      "cm2=0.24+0.45*W2\n",
      "H2=cm2*t3+W2*1060\n",
      "hf=t2-32\n",
      "dq=H2-H1-(W2-W1)*hf\n",
      "#results\n",
      "print '%s %.2f %s' %(\"In case 1, Enthalpy =\",H1,\"Btu/lbm dry air\")\n",
      "print '%s %.2f %s' %(\"\\n In case 2, Enthalpy =\",H2,\"Btu/lbm dry air\")\n",
      "print '%s %.2f %s' %(\"\\n Heat added =\",dq,\"Btu/lbm dry air\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "In case 1, Enthalpy = 9.41 Btu/lbm dry air\n",
        "\n",
        " In case 2, Enthalpy = 31.15 Btu/lbm dry air\n",
        "\n",
        " Heat added = 21.49 Btu/lbm dry air\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16 - Pg 337"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the partial pressure and dew temperature of water. Calculate the density of water and air and also the specific humidity\n",
      "#Initialization of variables\n",
      "pw=0.15#psia\n",
      "print '%s' %(\"using psychrometric charts,\")\n",
      "tdew=46. #F\n",
      "#calculations\n",
      "va=13.74 #ft^3/lbm dry air\n",
      "rhoa=1/va\n",
      "V=13.74\n",
      "mw=46./7000.\n",
      "rhow=mw/V\n",
      "w=0.00657\n",
      "#results\n",
      "print '%s' %(\"part a\")\n",
      "print '%s %.2f %s' %(\"partial pressure of water =\",pw,\"psia\")\n",
      "print '%s %d %s' %(\"\\n dew temperature =\",tdew,\"F\")\n",
      "print '%s' %(\"part b\")\n",
      "print '%s %.6f %s' %(\"density of water =\",rhow,\"lbm/ft^3\")\n",
      "print '%s %.4f %s' %(\"\\n density of air =\",rhoa,\"lbm/ft^3\")\n",
      "print '%s' %(\"part c\")\n",
      "print '%s %.5f %s' %(\"specific humidity  =\",w,\"lbm steam/lbm air\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "using psychrometric charts,\n",
        "part a\n",
        "partial pressure of water = 0.15 psia\n",
        "\n",
        " dew temperature = 46 F\n",
        "part b\n",
        "density of water = 0.000478 lbm/ft^3\n",
        "\n",
        " density of air = 0.0728 lbm/ft^3\n",
        "part c\n",
        "specific humidity  = 0.00657 lbm steam/lbm air\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17 - Pg 337"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the change in enthalpy\n",
      "#Initialization of variables\n",
      "W1=0.00206 #lbm/lbm dry air\n",
      "W2=0.01090 #lbm/lbm dry air\n",
      "t=60 #F\n",
      "#calculations\n",
      "dw=W1-W2\n",
      "hs=144.4\n",
      "hs2=66.8-32\n",
      "w1=14.4 #Btu/lbm\n",
      "ws1=20 #Btu/lbm\n",
      "w2=76.3 #Btu/lbm\n",
      "ws2=98.5 #Btu/lbm\n",
      "dwh1=-(w1-ws1)/7000. *hs\n",
      "H1=9.3+dwh1\n",
      "dwh2=(w2-ws2)/7000. *hs2\n",
      "H2=31.3+dwh2\n",
      "dwc=dw*(t-32)\n",
      "dq=H2-H1+dwc\n",
      "#results\n",
      "print '%s %.2f %s' %(\"Enthalpy change =\",dq,\"Btu/lbm dry air\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enthalpy change = 21.53 Btu/lbm dry air\n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 18 - Pg 339"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the humidity and temperature of the gas\n",
      "#Initialization of variables\n",
      "print '%s' %(\"From psychrometric charts,\")\n",
      "va1=13. #ft^3/lbm dry air\n",
      "va2=13.88 #ft^3/lbm dry air\n",
      "flow=2000. #cfm\n",
      "#calculations\n",
      "ma1= flow/va1\n",
      "ma2=flow/va2\n",
      "t=62.5 # F\n",
      "phi=0.83 #percent\n",
      "#results\n",
      "print '%s %.2f' %(\"humidity = \",phi)\n",
      "print '%s %.1f %s' %(\"\\n Temperature =\",t,\"F\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "From psychrometric charts,\n",
        "humidity =  0.83\n",
        "\n",
        " Temperature = 62.5 F\n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 19 - Pg 341"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the dry bulb temperature and percentage humidity\n",
      "#Initialization of variables\n",
      "t=90 #F\n",
      "ts=67.2 #F\n",
      "phi=0.3\n",
      "per=0.8\n",
      "#calculations\n",
      "dep=t-ts\n",
      "dt=dep*per\n",
      "tf=t-dt\n",
      "print '%s' %(\"from psychrometric charts,\")\n",
      "phi2=0.8\n",
      "#results\n",
      "print '%s %.2f %s' %(\"Dry bulb temperature =\",tf,\"F\")\n",
      "print '%s %.2f' %(\"\\n percent humidity  =\",phi2)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "from psychrometric charts,\n",
        "Dry bulb temperature = 71.76 F\n",
        "\n",
        " percent humidity  = 0.80\n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 20 - Pg 342"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the cooling range, approach and amount of water cooled and percentage of water lost by evaporation\n",
      "#Initialization of variables\n",
      "m=1 #lbm\n",
      "t1=100. #F\n",
      "t2=75. #F\n",
      "db=65. #F\n",
      "print '%s' %(\"From psychrometric charts,\")\n",
      "t11=82 #F\n",
      "phi1=0.4\n",
      "H1=30 #Btu/lbm dry air\n",
      "w1=65 #grains/lbm dry air\n",
      "w2=250 #grains/lbm dry air\n",
      "#calculations\n",
      "cr=t1-t2\n",
      "appr=t2-db\n",
      "dmf3=(w2-w1)*0.0001427\n",
      "hf3=68\n",
      "hf4=43\n",
      "H2=62.2\n",
      "H1=30\n",
      "mf4= (H1-H2+ dmf3*hf3)/(hf4-hf3)\n",
      "per=dmf3/(dmf3+mf4)*100\n",
      "#results\n",
      "print '%s %d %s' %(\"cooling range =\",cr,\"F\")\n",
      "print '%s %d %s' %(\"\\n Approach =\",appr,\"F\")\n",
      "print '%s %.3f %s' %(\"\\n amount of water cooled per pound of dry air =\",mf4,\"lbm dry air/lbm dry air\")\n",
      "print '%s %.2f %s' %(\"\\n percentage of water lost by evaporation =\",per,\"percent\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "From psychrometric charts,\n",
        "cooling range = 25 F\n",
        "\n",
        " Approach = 10 F\n",
        "\n",
        " amount of water cooled per pound of dry air = 1.216 lbm dry air/lbm dry air\n",
        "\n",
        " percentage of water lost by evaporation = 2.12 percent\n"
       ]
      }
     ],
     "prompt_number": 21
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 21 - Pg 348"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the pressure and error in both cases\n",
      "#Initialization of variables\n",
      "R0=0.73 #atm ft^3/mol R\n",
      "a1=578.9\n",
      "a2=3675\n",
      "b1=0.684\n",
      "b2=1.944\n",
      "n1=0.396 #mol\n",
      "n2=0.604 #mol\n",
      "V=8.518 #ft^3\n",
      "T=460+460. #R\n",
      "#calculations\n",
      "p1=R0*n1*T/(V-n1*b1) - a1*n1*n1 /V/V\n",
      "p2= R0*n2*T/(V-n2*b2) -a2*n2*n2 /V/V\n",
      "p=p1+p2\n",
      "pa=(n1+n2)*R0*T/V\n",
      "err=(pa-p)/p*100\n",
      "pb=58.7 #atm\n",
      "err2= (p-pb)/p*100\n",
      "#results\n",
      "print '%s %.1f %s' %(\"Pressure =\",p,\" atm\")\n",
      "print '%s %.1f %s' %(\"\\n Pressure in case 2 =\",pb,\"atm\")\n",
      "print '%s %.1f %s' %(\"\\n error in ideal case =\",err,\" percent\")\n",
      "print '%s %.1f %s' %(\"\\n error in  case 2 =\",err2,\" percent\")\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": [
        "Pressure = 67.8  atm\n",
        "\n",
        " Pressure in case 2 = 58.7 atm\n",
        "\n",
        " error in ideal case = 16.4  percent\n",
        "\n",
        " error in  case 2 = 13.4  percent\n",
        "The answer is a bit different due to rounding off error in textbook\n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 22 - Pg 350"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the pressure using both cases\n",
      "#Initialization of variables\n",
      "p1=45.8 #atm\n",
      "p2=36 #atm\n",
      "t1=343.3 #R\n",
      "t2=766.8 #R\n",
      "n1=0.396 #mol\n",
      "n2=0.604 #mol\n",
      "V=8.518 #ft^3\n",
      "R0=0.73\n",
      "T=920 #R\n",
      "#calcualtions\n",
      "vr1=p1*(V/n1)/(R0*t1)\n",
      "vr2=p2*(V/n2)/(R0*t2)\n",
      "tr1=T/t1\n",
      "tr2=T/t2\n",
      "print '%s' %(\"From compressibility charts,\")\n",
      "z1=1\n",
      "z2=0.79\n",
      "Z=n1*z1+n2*z2\n",
      "p=Z*R0*T/V\n",
      "p2=62. #atm\n",
      "err=(p-p2)/p*100\n",
      "#results\n",
      "print '%s %.1f %s' %(\"In case 1, pressure =\",p,\"atm\")\n",
      "print '%s %d %s' %(\"\\n In case 2, pressure using trail and error method =\",p2,\"atm\")\n",
      "print '%s %d %s' %(\"\\n Error =\",err,\"percent\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "From compressibility charts,\n",
        "In case 1, pressure = 68.8 atm\n",
        "\n",
        " In case 2, pressure using trail and error method = 62 atm\n",
        "\n",
        " Error = 9 percent\n"
       ]
      }
     ],
     "prompt_number": 23
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 23 - Pg 351"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the pressure required\n",
      "#Initialization of variables\n",
      "t1=343.3 #R\n",
      "t2=766.8 #R\n",
      "n1=0.396 #mol\n",
      "n2=0.604 #mol\n",
      "V=8.518 #ft^3\n",
      "p1=45.8 #atm\n",
      "p2=36 #atm\n",
      "R0=0.73\n",
      "T=920 #R\n",
      "#calculations\n",
      "tcd=n1*t1+n2*t2\n",
      "pcd=n1*p1+n2*p2\n",
      "Tr=T/tcd\n",
      "Vr=pcd*V/(R0*tcd)\n",
      "Z=0.87\n",
      "p=Z*R0*T/V\n",
      "#results\n",
      "print '%s %.1f %s' %(\"Pressure =\",p,\"atm\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Pressure = 68.6 atm\n"
       ]
      }
     ],
     "prompt_number": 24
    }
   ],
   "metadata": {}
  }
 ]
}