{
 "metadata": {
  "name": "ch1_2",
  "signature": "sha256:05ef5db2afef7232054abda0278780d1df8c92b807546fcd7648e8885fa4539f"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 1 :  Introduction"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example - 1.1  Page number - 6"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# \n",
      "# Variables\n",
      "#(a)\n",
      " \n",
      "m = 50.;\t\t\t#[kg] - Mass of piston\n",
      "A = 0.05;\t\t\t#[m**(2)] - Area of piston\n",
      "g = 9.81;\t\t\t#[m/s**(2)] - Acceleration due to gravity\n",
      "Po = 101325;\t\t\t#[N/m**(2)] - Atmospheric pressure\n",
      "\n",
      "# Calculations and Results\n",
      "P = (m*g/A)+Po;\t\t\t#[N/m**(2)]\n",
      "P = P/100000.;\t\t\t#[bar]\n",
      "print \" (a).Pressure = %f bar\"%P\n",
      "\n",
      "#(b)\n",
      "print \" (b).Since the piston weight and surroundings pressure are the same, \\\n",
      "the gas pressure in the piston-cylinder assembly remains %f bar\"%P\n",
      "\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " (a).Pressure = 1.111350 bar\n",
        " (b).Since the piston weight and surroundings pressure are the same, the gas pressure in the piston-cylinder assembly remains 1.111350 bar\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example - 1.2 Page number - 8\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "\n",
      "# Variables\n",
      "P = 1.;\t\t\t#[atm] - Atmospheric pressure\n",
      "P = 101325.;\t\t\t#[N/m**(2)]\n",
      "R = 8.314;\t\t\t#[J/mol*K] - Universal gas constant\n",
      "T = 30.;\t\t\t#[C] - Temperature of air\n",
      "T = 30.+273.15;\t\t\t#[K]\n",
      "V = 5.*5*5;\t\t\t#[m**(3)] - Volume of the room\n",
      "\n",
      "# Calculations\n",
      "#The number of moles of air is given by\n",
      "n = (P*V)/(R*T)\t\t\t#[mol]\n",
      "\n",
      "#Molecular weight of air(21 vol% O2 and 79 vol% N2)=(0.21*32)+(0.79*28)=  28.84 g/mol\n",
      "m = n*28.84;\t\t\t#[g]\n",
      "m = m/1000.;\t\t\t#[kg]\n",
      "\n",
      "# Results\n",
      "print \"The mass of air is, m = %f kg\"%m\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The mass of air is, m = 144.928664 kg\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example - 1.3 Page number - 13\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "\n",
      "# Variables\n",
      "P1 = 3.;\t\t\t# [bar]  - initial pressure\n",
      "V1 = 0.5;\t\t\t# [m**(3)] - initial volume\n",
      "V2 = 1.0;\t\t\t# [m**(3)] - final volume\n",
      "import math\n",
      "#(a)\n",
      "n = 1.5;\n",
      "\n",
      "# Calculations and Results\n",
      "#Let P*V**(n)=C \t\t\t# Variables relation\n",
      "#W (work done per mole)= (integrate('P'%'V'%V1%V2))\n",
      "#and thus    W=((P2*V2)-(P1*V1))/(1-n)\n",
      "#The above math.expression is valid for all values of n%except n=1.0\n",
      "P2 = (P1*((V1/V2)**(n)))\t\t\t#[bar] \t\t\t#pressure at state 2\n",
      "\n",
      "#we have%(V1/V2)=(V1t/(V2t)%since the number  of moles are constant.Thus\n",
      "W = ((P2*V2)-(P1*V1))/(1-n)*10**(5)\t\t\t#[J]\n",
      "W = W/1000.;\t\t\t#[kJ]\n",
      "print \" (a).The work done (for n=1.5) is %f kJ\"%W\n",
      "\n",
      "#(b)\n",
      "#For n=1.0%we have% PV=C.\n",
      "# w(wok done per mol)= (integrate('P'%'V'%V1%V2)) = (integrate('C/V'%'V'%V1%V2)) = C*ln(V2/V1)=P1*V1*ln(V2/V1)\n",
      "W1 = P1*V1*math.log(V2/V1)*10**(5)\t\t\t#[J]\n",
      "W1 = W1/1000.;\t\t\t#[kJ]\n",
      "print \" (b).The work done (for n=1.0) is %f kJ\"%W1\n",
      "\n",
      "#(c)\n",
      "#For n=0%we get P=Constant and thus\n",
      "P = P1;\t\t\t#[bar]\n",
      "# w =(integrate('P'%'V'%V1%V2)) = P*(V2-V1)\n",
      "W2 = P*(V2-V1)*10**(5)\t\t\t#[J]\n",
      "W2 = W2/1000.;\t\t\t#[kJ]\n",
      "print \" (c).The work done (for n=0) is %f kJ\"%W2\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " (a).The work done (for n=1.5) is 87.867966 kJ\n",
        " (b).The work done (for n=1.0) is 103.972077 kJ\n",
        " (c).The work done (for n=0) is 150.000000 kJ\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example - 1.4 Page number - 17\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "\n",
      "# Variables\n",
      "#(a)\n",
      "# Variables\n",
      "V = 9.;\t\t\t# [m/s] - velocity\n",
      "d = 1.;\t\t\t#[m] - diameter\n",
      "A = 3.14*(d/2)**(2)\t\t\t#[m**(2)] - area\n",
      "P = 1.;\t\t\t#[atm] - pressure\n",
      "P = 101325.;\t\t\t# [N/m**(2)]\n",
      "T = 300.;\t\t\t#[K] - Temperature\n",
      "R =  8.314;\t\t\t#[J/mol*K] - Universal gas constant\n",
      "\n",
      "# Calculations and Results\n",
      "E = (V**(2))/2.;\t\t\t#[J/kg]\n",
      "print \" (a).The wind energy per unit mass of air is %f J/kg\"%E\n",
      "\n",
      "#(b)\n",
      "# Molecular weight of air(21 vol% O2 and 79 vol% N2)=(0.21*32)+(0.79*28)=  28.84 g/mol\n",
      "M = 28.84*10**(-3)\t\t\t#[kg/mol]\n",
      "r = (P*M)/(R*T)\t\t\t#[kg/m**(3)] - density\n",
      "m = r*V*A;\t\t\t# [kg/s] - mass flow rate of air\n",
      "pi = m*E;\t\t\t#[Watt] - power input\n",
      "print \" (b).The wind power input to the turbine is %f Watt\"%pi\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " (a).The wind energy per unit mass of air is 40.500000 J/kg\n",
        " (b).The wind power input to the turbine is 335.233787 Watt\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example - 1.5 Page number - 23\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Given\n",
      "P = 1.;\t\t\t        # [bar] - atospheric pressure\n",
      "P1guz = 0.75;\t\t\t# [bar] - gauze pressure in 1st evaporator\n",
      "P2Vguz = 0.25;\t\t\t# [bar] - vaccum gauze pressure in 2nd evaporator\n",
      "\n",
      "# Calculations\n",
      "P1abs = P + P1guz;\t\t\t# [bar] - absolute pressure in 1st evaporator\n",
      "P2abs = P - P2Vguz;\t\t\t# [bar] -absolute pressure in 2nd evaporator\n",
      "\n",
      "# Results\n",
      "#From saturated steam table as reported in the book\n",
      "print \" For P1abs (absolute pressure) = %f bar\"%P1abs\n",
      "print \" The saturation temperature in first evaporator  is 116.04 C\"\n",
      "print \" For P2abs (absolute pressure) = %f bar\"%P2abs\n",
      "print \" The saturation temperature in second evaporator  is 91.76 C\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " For P1abs (absolute pressure) = 1.750000 bar\n",
        " The saturation temperature in first evaporator  is 116.04 C\n",
        " For P2abs (absolute pressure) = 0.750000 bar\n",
        " The saturation temperature in second evaporator  is 91.76 C\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example - 1.6 Page number - 23\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Variables\n",
      "V = 1.;\t\t\t    # [kg] - volume of tank\n",
      "P = 10.;\t\t\t# [bar] - pressure\n",
      "\n",
      "#Here degree of freedom =1(C=1%P=2%threfore F=1)\n",
      "#From steam table at 10 bar as reported in the book\n",
      "V_liq = 0.001127;\t\t\t# [m**(3)/kg] - volume in liquid phase\n",
      "V_vap = 0.19444;\t\t\t# [m**(3)/kg] - volume in vapour phase\n",
      "\n",
      "# Calculations\n",
      "#x*Vv=(1-x)*Vl \t\t\t# since two volumes are equal\n",
      "x = (V_liq/(V_liq+V_vap))\t\t\t# [kg]\n",
      "y = (1-x)\t\t\t#[kg]\n",
      "\n",
      "# Results\n",
      "print \" Mass of saturated vapour is %f kg\"%x\n",
      "print \" Mass of saturated liquid is %f kg\"%y\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Mass of saturated vapour is 0.005763 kg\n",
        " Mass of saturated liquid is 0.994237 kg\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example - 1.7 Page number - 23"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Variables\n",
      "V = 1.;\t\t\t# [m**(3)] - volume of tank\n",
      "M = 10.;\t\t\t# [m**(3)] - total mass\n",
      "T = (90+273.15)\t\t\t#[K] - temperature\n",
      "\n",
      "#From steam table at 90 C as reported in the book\n",
      "#vapour pressure(pressure of rigid tank) = 70.14[kPa] = 0.7014[bar]\n",
      "print \" Pressure of tank = 0.7014 bar\"\n",
      "\n",
      "# Calculations and Results\n",
      "V_liq_sat=0.001036;\t\t\t# [m**(3)/kg] - saturated liquid specific volume\n",
      "V_vap_sat=2.36056;\t\t\t# [m**(3)/kg] - saturated vapour specific volume\n",
      "\n",
      "#1=(V_liq_sat*(10-x))+(V_vap_sat*x)\n",
      "x = (1-(10*V_liq_sat))/(V_vap_sat-V_liq_sat)\t\t\t#[kg]\n",
      "y = (10-x)\t\t\t#[kg]\n",
      "\n",
      "print \" The amount of saturated liquid is %f kg\"%y\n",
      "print \" The amount of saturated vapour is %f kg \"%x\n",
      "\n",
      "z = y*V_liq_sat;\t\t\t#[m**(3)] - Volume of saturated liquid \n",
      "w = x*V_vap_sat;\t\t\t#[m**(3)] - Volume of saturated vapour\n",
      "\n",
      "print \" Total volume of saturated liquid is %f m**(3)\"%z\n",
      "print \" Total volume of saturated vapour is %f m**(3)\"%w\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Pressure of tank = 0.7014 bar\n",
        " The amount of saturated liquid is 9.580576 kg\n",
        " The amount of saturated vapour is 0.419424 kg \n",
        " Total volume of saturated liquid is 0.009925 m**(3)\n",
        " Total volume of saturated vapour is 0.990075 m**(3)\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example - 1.8 Page number - 24"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Variables\n",
      "V = 10.;\t\t\t# [m**(3)] - volume of vessel\n",
      "P_1 = 1.;\t\t\t# [bar] - initial pressure\n",
      "V_liq_sat = 0.05;\t\t\t# [m**(3)] - saturated liquid volume\n",
      "V_gas_sat = 9.95;\t\t\t# [m**(3)] - saturated vapour volume\n",
      "\n",
      "#At 1 bar pressure\n",
      "V_liq_1 = 0.001043;\t\t\t# [m**(3/kg)] - specific saturated liquid volume\n",
      "U_liq_1 = 417.33;\t\t\t# [kJ/kg] - specific internal energy\n",
      "V_gas_1 = 1.69400;\t\t\t# [m**(3/kg)] - specific saturated vapour volume\n",
      "U_gas_1 = 2506.06;\t\t\t# [kJ/kg]\n",
      "\n",
      "# Calculations\n",
      "M_liq_1 = V_liq_sat/V_liq_1;\t\t\t# [kg] - mass of saturated liqid\n",
      "M_gas_1 = V_gas_sat/V_gas_1;\t\t\t# [kg] - mass of saturated vapour\n",
      "M = (M_liq_1+M_gas_1)\t\t\t# [kg] - total mass\n",
      "U_1t = (M_liq_1*U_liq_1)+(M_gas_1*U_gas_1)\t\t\t# [kJ] - initial internal energy\n",
      "V_gas_2 = (V/M)\t\t\t#[m**(3/kg)]\n",
      "\n",
      "#from steam table at 10 bar pressure as reported in the book\n",
      "V_vap_2 = 0.19444;\t\t\t# [m**(3/kg)]\n",
      "U_vap_2 = 2583.64;\t\t\t# [kJ/kg]\n",
      "\n",
      "#from steam table at 11 bar pressure as reported in the book\n",
      "V_vap_3 = 0.17753;\t\t\t#[m**(3/kg)]\n",
      "U_vap_3 = 2586.40;\t\t\t#[kJ/kg]\n",
      "\n",
      "#Now computing pressure when molar volume of saturated vapour=Vg_2\n",
      "#By interpolation (P2-10)/(11-10)=(Vg_2-Vv_2)/(Vv_3-Vv_2)\n",
      "P_2 = (((V_gas_2 - V_vap_2)/(V_vap_3 - V_vap_2)*1)+10)\t\t\t# [bar] - final pressure\n",
      "\n",
      "#By interpolation calculating internal energy at state 2\n",
      "#(P2-10)/(11-10)=(U2-Uv_2)/(Uv_3-Uv_2)\n",
      "U_2 = (((P_2-10)/(11-10))*(U_vap_3 - U_vap_2))+U_vap_2;\t\t\t#[kJ/kg]\n",
      "U_2t = U_2*M;\t\t\t#[kJ]\n",
      "H = U_2t - U_1t;\t\t\t#[kJ] - Heat supplied\n",
      "H = H/1000;\t\t\t#[MJ]\n",
      "\n",
      "# Results\n",
      "print \" Total heat supplied is %f MJ\"%H\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Total heat supplied is 104.381244 MJ\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example - 1.9 Page number - 26"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Variables\n",
      "#Antoine equation for water   ln(Psat)=16.262-(3799.89/(T_sat + 226.35))\n",
      "P = 2.;\t\t\t#[atm] - Pressure\n",
      "P = (2.*101325)/1000;\t\t\t#[kPa]\n",
      "\n",
      "# Calculations\n",
      "P_sat = P;\t\t\t# Saturation pressure\n",
      "T_sat = (3799.89/(16.262-math.log(P_sat)))-226.35;\t\t\t#[C] - Saturation temperature\n",
      "#Thus boiling at 2 atm occurs at Tsat = 120.66 C.\n",
      "\n",
      "#From steam tables%at 2 bar%Tsat = 120.23 C and at 2.25 bar%Tsat = 124.0 C\n",
      "#From interpolation for T_sat = 120.66 C%P = 2.0265 bar\n",
      "#For P_= 2.0265 bar%T_sat% from steam table by interpolation is given by\n",
      "#((2.0265-2)/(2.25-2))=((Tsat-120.23)/(124.0-120.23))\n",
      "T_sat_0 = (((2.0265-2)/(2.25-2))*(124.0-120.23))+120.23;\t\t\t#[C]\n",
      "\n",
      "# Results\n",
      "print \" Saturation temperature (Tsat) = %f C which is close \\\n",
      "to %f C as determined from Antoine equation\"%(T_sat_0,T_sat)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Saturation temperature (Tsat) = 120.629620 C which is close to 120.655450 C as determined from Antoine equation\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example - 1.10 Page number - 27"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Variables\n",
      "# math.log(P)=-(1640/T)+10.56 (solid)\n",
      "# math.log(P)=-(1159/T)+7.769 (liquid)%where T is in K\n",
      "# F+P=C+2% at triple point F+3=1+2 or%F=0 i.e%vapour pressure of liquid and solid at triple point are same%we get\n",
      "# -(1640/T)+10.56 = -(1159/T)+7.769\n",
      "\n",
      "# Calculations\n",
      "T = (1640-1159)/(10.56-7.769)\t\t\t#[K]\n",
      "P = 10**((-1640/T)+10.56)\t\t\t#[torr]\n",
      "\n",
      "# Results\n",
      "print \" The temperature is %f K\"%T\n",
      "print \" The pressure is %f torr (or mm Hg)\"%P\n",
      "\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The temperature is 172.339663 K\n",
        " The pressure is 11.063907 torr (or mm Hg)\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example - 1.11 Page number - 29"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Variables\n",
      "M_O2 = 31.999;\t\t\t#molecular weight of oxygen\n",
      "M_N2 = 28.014;\t\t\t#molecular weight of nitrogen\n",
      "Y = 1.4;\t\t\t#molar heat capacities ratio for air\n",
      "\n",
      "# Calculations and Results\n",
      "#Molecular weight of air(21 vol% O2 and 79 vol% N2)is given by\n",
      "M_air = (0.21*M_O2)+(0.79*M_N2)\t\t\t#(vol% = mol%)\n",
      "\n",
      "R = 8.314;\t\t\t#[J/mol*K] - Universal gas constant\n",
      "R = (R*1/M_air)\t\t\t#[kJ/kg*K]\n",
      "\n",
      "print \" The value of universal gas constant (R) = %f kJ/kg-K \"%R\n",
      "\n",
      "#Y=Cp0/Cv0 and Cp0-Cv0=R\n",
      "Cv_0 = R/(Y-1)\t\t\t#[kJ/kg*K] \n",
      "Cp_0 = Y*Cv_0;\t\t\t#[kJ/kg*K]\n",
      "print \" The value of Cp_0 for air is %f kJ/kg-K\"%Cp_0\n",
      "print \" The value of Cv_0 for air is %f kJ/kg-K\"%Cv_0\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The value of universal gas constant (R) = 0.288172 kJ/kg-K \n",
        " The value of Cp_0 for air is 1.008601 kJ/kg-K\n",
        " The value of Cv_0 for air is 0.720429 kJ/kg-K\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example - 1.12 Page number - 30"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Variables\n",
      "Y = 1.4;\t\t\t#molar heat capacities ratio for air\n",
      "R = 8.314;\t\t\t# [J/mol*K] - Universal gas constant\n",
      "\n",
      "# Calculations\n",
      "Cv_0 = R/(Y-1)\t\t\t# [J/mol*K]\n",
      "Cp_0 = Y*Cv_0;\t\t\t# [J/mol*K]\n",
      "\n",
      "# Results\n",
      "print \" The molar heat capacity at constant volume (Cv_0) is %f J/mol-K\"%Cv_0\n",
      "print \" The molar heat capacity at constant pressure (Cp_0) is %f J/mol-K\"%Cp_0\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The molar heat capacity at constant volume (Cv_0) is 20.785000 J/mol-K\n",
        " The molar heat capacity at constant pressure (Cp_0) is 29.099000 J/mol-K\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example - 1.13 Page number - 30"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "from scipy.integrate import quad\n",
      "\n",
      "# Variables\n",
      "# Cp0=7.7+(0.04594*10**(-2)*T)+(0.2521*10**(-5)*T**(2))-(0.8587*10**(-9)*T**(3))\n",
      "T_1 = 400.;\t\t\t#[K]\n",
      "T_2 = 500.;\t\t\t#[K]\n",
      "\n",
      "# Calculations\n",
      "def f(T):\n",
      "    return 7.7+(0.04594*10**(-2)*T)+(0.2521*10**(-5)*T**(2))-(0.8587*10**(-9)*T**(3))\n",
      "#(C)avg = q/(T_2 - T_1) = 1/(T_2 - T_1)*{(integrate('C'%'T'%T_1%T_2))}\n",
      "#(Cp0)avg = 1/(T_2 - T_1)*{(integrate('Cp0'%'T'%T_1%T_2))}\n",
      "Cp0_avg = (1/(T_2 - T_1))*quad(f,T_1,T_2)[0]\n",
      "\n",
      "# Results\n",
      "print \" The mean heat capacity (Cp0_avg) for temerature range of 400 to 500 K is %f cal/mol-K\"%Cp0_avg\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The mean heat capacity (Cp0_avg) for temerature range of 400 to 500 K is 8.340118 cal/mol-K\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example - 1.14 Page number - 31"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "# Variables\n",
      "#(a)\n",
      "P_1 = 0.2;\t\t\t# [MPa] - pressure\n",
      "x_1 = 0.59;\t\t\t# mole fraction\n",
      "\n",
      "# Calculations and Results\n",
      "#From saturated steam tables at 0.2 MPa\n",
      "H_liq_1 = 504.7;\t\t\t# [kJ/kg] - Enthalpy of saturated liquid\n",
      "H_vap_1 = 2706.7;\t\t\t# [kJ/kg]- Enthalpy of saturated vapour\n",
      "H_1 = (H_liq_1*(1-x_1))+(x_1*H_vap_1)\t\t\t# [kJ/kg]\n",
      "print \" (a).Enthalpy of 1 kg of water in tank is %f kJ/kg\"%H_1\n",
      "\n",
      "#(b)\n",
      "T_2 = 120.23;\t\t\t# [C] - temperature\n",
      "V_2 = 0.6;\t\t\t# [m**(3)/kg] - specific volume\n",
      "\n",
      "#From saturated steam tables at 120.23 C% as reported in the book\n",
      "V_liq_2=0.001061;\t\t\t# [m**(3)/kg]\n",
      "V_vap_2=0.8857;\t\t\t# [m**(3)/kg]\n",
      "#since V_2 < Vv_2%dryness factor will be given by% V = ((1-x)*V_liq)+(x*V_vap)\n",
      "x_2 = (V_2- V_liq_2)/(V_vap_2 - V_liq_2)\n",
      "\n",
      "#From steam table%at 120.2 C%the vapour pressure of water is 0.2 MPa.So%enthalpy is given by\n",
      "H_2 = (H_liq_1*(1-x_2))+(H_vap_1*x_2)\t\t\t#kJ/kg]\n",
      "print \" (b).Enthalpy of saturated steam is %f kJ/kg\"%H_2\n",
      "\n",
      "#(c)\n",
      "P_3 = 2.5;\t\t\t#[MPa]\n",
      "T_3 = 350;\t\t\t#[C]\n",
      "#From steam tables at 2.5 MPa%T_sat = 223.99 C%as reported in the book\n",
      "#since%T_3 > Tsat% steam is superheated\n",
      "print \" (c).As steam is superheated%from steam table%enthalpy (H) is 3126.3 kJ/kg\"\n",
      "\n",
      "#(d)\n",
      "T_4 = 350;\t\t\t#[C]\n",
      "V_4 = 0.13857;\t\t\t#[m**(3)/kg]\n",
      "#From steam table%at 350 C% V_liq = 0.001740 m**(3)/kg and V_vap = 0.008813 m**(3)/kg.Since%V > V_vap%therefore it is superheated.\n",
      "#From steam table at 350 C and 1.6 MPa% V = 0.17456 m**(3)/kg\n",
      "#At 350 C and 2.0 MPa% V = 0.13857 m**(3)/kg. So%\n",
      "print \" (d).The enthalpy of superheated steam (H) is 3137.0 kJ/kg\"\n",
      "\n",
      "#(e)\n",
      "P_4 = 2.0;\t\t\t#[MPa]\n",
      "U_4 = 2900;\t\t\t# [kJ/kg] - internal energy\n",
      "#From saturated table at 2.0 MPa% U_liq = 906.44kJ and U_vap = 2600.3 kJ/kg\n",
      "#scince%U_4 > Uv% it is saturated.\n",
      "#From superheated steam table at 2.0 MPa and 350 C% as reported in the book\n",
      "U_1 = 2859.8;\t\t\t#[kJ/kg]\n",
      "H_1 = 3137.0;\t\t\t#[kJ/kg]\n",
      "#At 2.0 MPa and 400 C%\n",
      "U_2 = 2945.2;\t\t\t#[kJ/kg]\n",
      "H_2 = 3247.6;\t\t\t#[kJ/kg]\n",
      "T = (((U_4 - U_1)/(U_2 - U_1))*(400 - 350)) + 350;\t\t\t#[C] - By interpolation\n",
      "H = (((T - 350)/(400 - 350))*(H_2 - H_1)) + H_1;\t\t\t#[kJ/kg]\n",
      "print \" (e).The enthalpy value (of superheated steam) obtained after interpolation is %f kJ/kg\"%H\n",
      "\n",
      "#(f)\n",
      "P_5 = 2.5;\t\t\t#[MPa]\n",
      "T_5 = 100;\t\t\t#[C]\n",
      "#At 100 C%P_sat=101350 N/m**(2). Since P_5 > P_sat%it is compressed liquid\n",
      "P_sat = 0.101350;\t\t\t#[MPa]\n",
      "H_liq = 419.04;\t\t\t#[kJ/kg] - At 100 C and 0.10135 MPa\n",
      "V_liq = 0.001044;\t\t\t#[m**(3)/kg] - At 100 C and 0.10135 MPa\n",
      "H_0 = H_liq + (V_liq*(P_5 - P_sat))*1000;\t\t\t#kJ/kg]\n",
      "print \" (f).The enthalpy of compressed liquid is %f kJ/kg\"%H_0\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " (a).Enthalpy of 1 kg of water in tank is 1803.880000 kJ/kg\n",
        " (b).Enthalpy of saturated steam is 1995.549576 kJ/kg\n",
        " (c).As steam is superheated%from steam table%enthalpy (H) is 3126.3 kJ/kg\n",
        " (d).The enthalpy of superheated steam (H) is 3137.0 kJ/kg\n",
        " (e).The enthalpy value (of superheated steam) obtained after interpolation is 3189.062295 kJ/kg\n",
        " (f).The enthalpy of compressed liquid is 421.544191 kJ/kg\n"
       ]
      }
     ],
     "prompt_number": 15
    }
   ],
   "metadata": {}
  }
 ]
}