{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter No - 3 : Thermodynamic Processes\n",
      "    "
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.1 - Page No :  66"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "# Given data\n",
      "P = 2.15 * 10**5 # in N/m**2\n",
      "T = 20 # in degree C \n",
      "T = T + 273 # in K\n",
      "V = 0.20 # in m**3\n",
      "R = 0.2927 # in kJ/kg-K\n",
      "R = R * 10**3 # in J/kg-K\n",
      "m = (P*V)/(T*R) # in kg\n",
      "Q = 20*10**3 # in J\n",
      "C_v = 0.706*10**3 # in J/kg-K\n",
      "theta = Q/(m*C_v) # in degree C\n",
      "T = T - 273 # in degree C\n",
      "T1 = theta + T # new temp. in degree C\n",
      "print \"New temperature = %0.1f degree C \" %T1\n",
      "T1 = T1 + 273 # in K\n",
      "T = T + 273 # in K\n",
      "P2 = P * (T1/T) # in N/m**2\n",
      "P2 = P2 * 10**-3# in kN/m**2\n",
      "print \"New pressure = %0.3f kN/m**2 \" %P2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "New temperature = 76.5 degree C \n",
        "New pressure = 256.459 kN/m**2 \n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.2 - Page No :  66"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "P = 350# in kN/m**2\n",
      "P = P * 10**3# in N/m**2\n",
      "m = 1# in kg\n",
      "m = m * 10**3# in gram\n",
      "V = 0.35# in m**3\n",
      "C_p = 1.005# in kJ/kg-K\n",
      "C_v = 0.710# in kJ/kg-K\n",
      "R = C_p - C_v# in kJ/kg-K\n",
      "T = (P*V)/(m*R) # in K\n",
      "T = T - 273# in degree C\n",
      "print \"The intial temperature = %0.0f K \" %(T+273)\n",
      "T = T + 273# in K\n",
      "T1 = 316# in degree C\n",
      "T1 = T1 + 273# in K\n",
      "P2 = P * (T1/T) # in N/m**2\n",
      "P2 = P2 * 10**-3# in kN/m**2\n",
      "print \"The final pressure of air = %0.1f kN/m**2 \" %P2\n",
      "T = T - 273# in degree C\n",
      "T1 = T1 - 273# in degree C\n",
      "m = m * 10**-3# in kg\n",
      "Q = m * C_v * (T1-T) # in kJ\n",
      "print \"Heat added = %0.2f kJ \" %Q\n",
      "G = m*C_v * (T1-T) # Gain of internal energy # in kJ\n",
      "print \"Gain of internal energy = %0.2f kJ \" %G\n",
      "G_enthalpy = m*C_p*(T1-T) # Gain of enthalpy  in kJ\n",
      "print \"Gain of enthalpy = %0.2f kJ \" %G_enthalpy"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The intial temperature = 415 K \n",
        "The final pressure of air = 496.4 kN/m**2 \n",
        "Heat added = 123.36 kJ \n",
        "Gain of internal energy = 123.36 kJ \n",
        "Gain of enthalpy = 174.61 kJ \n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.3 - Page No :  67"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "P = 3.2# in bar\n",
      "P = P * 10**5# in N/m**2\n",
      "R = 292.7# in kJ/kg-K\n",
      "C_p = 1.003# in kJ/kg-K\n",
      "m = 1#\n",
      "V1 = 0.3# in m**3\n",
      "V2 = 2*V1# in m**3\n",
      "W = P*(V2-V1) # in J\n",
      "W =  W * 10**-3 # in kJ\n",
      "print \"The work done = %0.0f kJ \" %W\n",
      "T1 = (P*V1)/(m*R) # in K\n",
      "print \"The intail Temperature = %0.0f \u00b0C \" %(T1-273)\n",
      "T2 = T1*(V2/V1) # in K\n",
      "print \"The final temperature = %0.0f \u00b0C \" %(T2-273)\n",
      "Q = m*C_p*(T2-T1) # in kJ\n",
      "print \"The Heat added = %0.0f kJ \" %(Q)\n",
      "\n",
      "# Note: To evaluate the value of Heat added, \n",
      "#       wrong value of T1 is putted (i.e 273 k  at place of 328 K), so the answer of Heat added is wrong in the book."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The work done = 96 kJ \n",
        "The intail Temperature = 55 \u00b0C \n",
        "The final temperature = 383 \u00b0C \n",
        "The Heat added = 329 kJ \n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.4 - Page No : 67"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "R = 0.29# in kJ/kg-K\n",
      "R = R * 10**3# in J/kg-K\n",
      "C_p = 1.005# in kJ/kg-K\n",
      "T = 185# in degree C\n",
      "T = T + 273# in K\n",
      "T2 = 70+273# in K\n",
      "V1 = 0.23# in m**3\n",
      "P = 500# in kN/m**2\n",
      "P = P * 10**3# in N/m**2\n",
      "m = (P*V1)/(R*T) # in kg\n",
      "Q = m*C_p*(T2-T) # in kJ\n",
      "print \"Heat transferred = %0.2f kJ \" %Q\n",
      "print \"i.e. %0.2f kJ heat has been abstracted from the gas\" %(abs(Q))\n",
      "V2 = V1*(T2/T) # in m**3\n",
      "W = P * (V2-V1) # in J\n",
      "W= W*10**-3#in kJ\n",
      "print \"The work done = %0.0f kJ \" %W\n",
      "print \"i.e.\",round(abs(W),0),\"kJ work has been done on the gas \"\n",
      "R= R*10**-3# in kJ/kg-K\n",
      "C_v = C_p - R# in kJ/kg-K\n",
      "I_E = m*C_v*(T2-T) # Change in internal energy in kJ\n",
      "print \"Change in internal energy = %0.3f kJ \" %I_E\n",
      "print \"i.e.\",round(abs(I_E),3),\"kJ energy is decrease in internal energy\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Heat transferred = -100.07 kJ \n",
        "i.e. 100.07 kJ heat has been abstracted from the gas\n",
        "The work done = -29 kJ \n",
        "i.e. 29.0 kJ work has been done on the gas \n",
        "Change in internal energy = -71.193 kJ \n",
        "i.e. 71.193 kJ energy is decrease in internal energy\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.5 - Page No :  71"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import log\n",
      "# Given data\n",
      "P1 = 1.1# in MN/m**2\n",
      "P1 = P1 * 10**6# in N/m**2\n",
      "V1 = 1.5# in m**3\n",
      "V2 = 7.5# in m**3\n",
      "P2 = (P1*V1)/V2# in kN/m**2\n",
      "P2 = P2 * 10**-6# in MN/m**2\n",
      "P2 = P2 * 10**3# in kN/m**2\n",
      "print \"The final pressure = %0.0f kN/m**2 \" %P2\n",
      "W = P1*V1*log(V2/V1) # in J\n",
      "W = W * 10**-4# in kJ\n",
      "print \"The work done = %0.0f kJ \" %int(W)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The final pressure = 220 kN/m**2 \n",
        "The work done = 265 kJ \n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.6 - Page No :  75"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "P1 = 2800000# in N/m**2\n",
      "P1 = P1 * 10**-6# in MN/m**2\n",
      "C_p = 1.024# in kJ/kg-K\n",
      "C_v = 0.7135# in kJ/kg-K\n",
      "V1 = 1# in m**3. (asuumed )\n",
      "V2 = 5*V1# in m**3\n",
      "T1 = 220# in degree C\n",
      "T1 = T1 + 273# in K\n",
      "Gamma = C_p/C_v#\n",
      "P2 = (P1*(V1)**Gamma)/((V2)**Gamma) # in MN/m**2\n",
      "print \"The final pressure = %0.3f MN/m**2 \" %P2\n",
      "T2 = (P2/P1)*V2*T1 # in K\n",
      "print \"The final temperature = %0.1f degree C \" %(T2-273)\n",
      "R = C_p-C_v# in kJ/kg-K\n",
      "W = (R*(T1-T2))/(Gamma - 1) # in kJ\n",
      "print \"Work done = %0.1f kJ \" %W"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The final pressure = 0.278 MN/m**2 \n",
        "The final temperature = -28.3 degree C \n",
        "Work done = 177.1 kJ \n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.7 - Page No :  76"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import log10\n",
      "# Given data\n",
      "W = 89.947# in kJ\n",
      "T1 = 240# in degree C\n",
      "T1=T1+273# in K\n",
      "T2 = 115# in degree C\n",
      "T2=T2+273# in K\n",
      "C_v = W/(T1-T2) # in kJ/kg-K\n",
      "print \"The value of Cv = %0.3f kJ/kg-K \" %C_v\n",
      "V1 = 1# in m**3 (assumed)\n",
      "V2 = 2*V1# in m**3\n",
      "# (T1/T2) = (V2/V1)**(Gamma - 1)\n",
      "Gamma=log10(T1/T2)/log10(V2/V1)+1#\n",
      "Gamma = 1.4#\n",
      "C_p = Gamma * C_v# in kJ/kg-K\n",
      "print \"The value Cp = %0.3f kJ/kg-K \" %C_p"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of Cv = 0.720 kJ/kg-K \n",
        "The value Cp = 1.007 kJ/kg-K \n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.8 - Page No :   77"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "P = 7# in bar\n",
      "P = P *10**5# in N/m**2\n",
      "R = 0.287# in kJ/kg-K\n",
      "R=R*10**3# in J/kg-K\n",
      "Gamma = 1.4#\n",
      "T = 100# in degree C\n",
      "T = T + 273# in K\n",
      "V = (R*T)/P# in m**3\n",
      "print \"The volume of one kg of air = %0.3f m**3\" %V\n",
      "C_v = 0.718# in kJ/kg\n",
      "T=T-273# in degree C\n",
      "InternalEnergy= C_v*T# in kJ/kg\n",
      "print \"Internal energy of 1 kg air = %0.1f kJ/kg\" %InternalEnergy\n",
      "P1= P# in bar\n",
      "V1 = 1# in m**3 (assumed)\n",
      "V2 = 4 * V1# in m**3\n",
      "T1= T# in degree C\n",
      "T1=T1+273# in K\n",
      "P2 = (P * (V1)**Gamma)/((V2)**Gamma) # in N/m**2\n",
      "print \"The final pressure = %0.3f bar \" %(P2*10**-5)\n",
      "T2 = (P2*V2)/(P1*V1)*T1# in K\n",
      "T2 = T2 - 273# in degree \n",
      "print \"The final temperature = %0.1f degree C \" %T2\n",
      "I_E = C_v * T2# in kJ/kg\n",
      "print \"Internal energy = %0.2f kJ/kg \" %I_E"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The volume of one kg of air = 0.153 m**3\n",
        "Internal energy of 1 kg air = 71.8 kJ/kg\n",
        "The final pressure = 1.005 bar \n",
        "The final temperature = -58.8 degree C \n",
        "Internal energy = -42.20 kJ/kg \n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.9 - Page No :   78"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "Gamma = 1.41#\n",
      "C_v = 0.703# in kJ/kg-K\n",
      "P1 = 105# in kN/m**2\n",
      "P2 = 2835# in kN/m**2\n",
      "T1 = 15# in degree C\n",
      "T1 = T1 + 273# in K\n",
      "m = 0.2# in kg\n",
      "# Formula T2/T1 = (P2/P1)**((Gamma-1)/Gamma)\n",
      "T2 = T1*(P2/P1)**((Gamma-1)/Gamma) # in K\n",
      "T2 = T2 - 273# in degree C\n",
      "print \"The final temperature = %0.0f degree C \" %T2\n",
      "T2 = T2+273# in K\n",
      "I_E = m*C_v*(T2-T1) # in kJ\n",
      "print \"Change in internal energy = %0.3f kJ \" %I_E\n",
      "W = I_E# in kJ\n",
      "print \"Work done = %0.3f kJ \" %W\n",
      "\n",
      "# Note: There is an error to calculate the value of T2, and this wrong value is putted to evaluate \n",
      "#       the value of Change in internal energy but the value of Change in internal energy is calculated correct."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The final temperature = 478 degree C \n",
        "Change in internal energy = 65.089 kJ \n",
        "Work done = 65.089 kJ \n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.10 - Page No :   - Page No :   86"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from numpy import pi\n",
      "# Given data\n",
      "P1= 100# in N/m**2\n",
      "T1 = 30# in degree C\n",
      "T1 = T1 + 273# in K\n",
      "C_v = 0.718# in kJ/kg-K\n",
      "#C_v= C_v*10**3# in J/kg-K\n",
      "R = 287.1# in J/kg-K\n",
      "d = 15# in cm\n",
      "l = 20# in cm\n",
      "V = (pi/4)*(d)**2*l# in cm**3\n",
      "V = V * 10**-3# in litre\n",
      "Clear_V = 1.147# clearance volume \n",
      "Vol = V+Clear_V#volume of air at beginning of compression in litre\n",
      "ROC = Vol/Clear_V# Ratio of compression\n",
      "P2 = P1*(Vol/Clear_V)**1.2# in kN/m**2\n",
      "print \"The pressure at the end of compression = %0.1f kN/m**2 \" %P2\n",
      "T2 = (P2*Clear_V*T1)/(P1*Vol) # in K\n",
      "T2 = T2 - 273# in degree C\n",
      "T1 = T1 - 273# in degree C\n",
      "T = T2-T1# in degree C\n",
      "print \"The temperature at the end of compression = %0.1f degree C \" %T\n",
      "T1 = T1 + 273# in K\n",
      "m = (P1*Vol)/(R*T1) # in kg\n",
      "I_E = m*C_v*T# in kJ\n",
      "print \"The change in internal energy = %0.3f kJ \" %I_E"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The pressure at the end of compression = 540.7 kN/m**2 \n",
        "The temperature at the end of compression = 98.4 degree C \n",
        "The change in internal energy = 0.380 kJ \n"
       ]
      }
     ],
     "prompt_number": 32
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.11 - Page No :  87"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "V1 = 2.5 # in litre\n",
      "P1  = 1400 # kN/m**2\n",
      "P2 = 280 # in kN/m**2\n",
      "T1 = 1100 # in \u00b0C\n",
      "T1 = T1 + 273 # in K\n",
      "n = 1.28\n",
      "V2 = V1*(P1/P2)**(1/1.28) # in litres\n",
      "print \"Final volume = %0.1f litres \" %V2\n",
      "T2 = T1*((P2*V2)/(P1*V1)) # in K\n",
      "T2 = T2  - 273# in degree C\n",
      "print \"Final temperature = %0.0f degree C \" %T2\n",
      "W = (P1* V1 - P2*V2)/(n-1) # in Joules\n",
      "print \"Work done = %0.2f kJ \" %(W*10**-3)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Final volume = 8.8 litres \n",
        "Final temperature = 693 degree C \n",
        "Work done = 3.71 kJ \n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.12 - Page No :   87"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import log\n",
      "# Given data\n",
      "Gamma = 1.4#\n",
      "P1 = 780# in kN/m**2\n",
      "P2 = 100# in kN/m**2\n",
      "V1 = 750# in cm**3\n",
      "V1= V1*10**-6# in m**3\n",
      "V2 = (1/5)*V1# in m**3\n",
      "n = (log(P1/P2))/(log(V1/V2))\n",
      "print \"The value of index = %0.3f\" %n\n",
      "W = (P1*V2-P2*V1)/(1-n) # in kJ\n",
      "print \"Work done = %0.3f kJ \" %W\n",
      "print \"i.e.\",round(abs(W),4),\"kJ work is done on the gas\"\n",
      "Q = ((Gamma - n)/(Gamma-1)) * (-W) # in kJ\n",
      "print \"Heat rejected during Compression is :\",round(Q,4),\"kJ or\",round(Q*10**3),\"joules.\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of index = 1.276\n",
        "Work done = -0.152 kJ \n",
        "i.e. 0.152 kJ work is done on the gas\n",
        "Heat rejected during Compression is : 0.047 kJ or 47.0 joules.\n"
       ]
      }
     ],
     "prompt_number": 33
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.13 - Page No :  90"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import log\n",
      "# Given data\n",
      "T1 = 40# in degree C\n",
      "T1 = T1  +273# in K\n",
      "P2 = 50# in bar\n",
      "P1 = 1# in bar\n",
      "Gamma = 1.4#\n",
      "C_v = 0.718# in kJ/kg-K\n",
      "SpeHeat = 1.005# in kJ/kg-K\n",
      "HeatSupply= 125.6# in kJ/kg\n",
      "T2 = T1 * (P2/P1)**((Gamma-1)/Gamma) # in K\n",
      "C_p = C_v * (T2-T1) # in kJ/kg\n",
      "del_T = HeatSupply/SpeHeat# in degree C\n",
      "del_U = C_v * del_T# in kJ/kg\n",
      "print \"Change in internal energy = %0.1f kJ/kg \" %del_U\n",
      "T3 = T2  + del_T# in K\n",
      "del_Phi = SpeHeat * log(T3/T2) # in kJ/kg-K\n",
      "print \"Change in entropy during constant pressure = %0.3f kJ/kg-K \" %del_Phi"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in internal energy = 89.7 kJ/kg \n",
        "Change in entropy during constant pressure = 0.123 kJ/kg-K \n"
       ]
      }
     ],
     "prompt_number": 34
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.14 - Page No :  91"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import log\n",
      "# Given data\n",
      "P1 = 30# in bar\n",
      "P1= P1*10**5# in N/m**2\n",
      "V1 = 0.85# in m**3\n",
      "V2 = 4.25# in m**3\n",
      "W = P1 *V1 * log(V2/V1) # in Joules\n",
      "W = W * 10**-3# in kJ\n",
      "T = 400# in K\n",
      "del_U = W/T# in kJ/K\n",
      "print \"Change in entropy = %0.3f kJ/K \" %del_U"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in entropy = 10.260 kJ/K \n"
       ]
      }
     ],
     "prompt_number": 35
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.15 - Page No :   91"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import log\n",
      "# Given data\n",
      "C_P = 1.041# in kJ/kg-K\n",
      "C_V = 0.743# in kJ/kg-K\n",
      "R = C_P - C_V# in kJ/kg-K\n",
      "P1 = 140# in kN/m**2\n",
      "P2 = 1400# in kN/m**2\n",
      "V1 = 0.14# in m**3\n",
      "T1 = 25# in degree C\n",
      "T1 = T1 + 273# in K\n",
      "Gamma = 1.4#\n",
      "n = 1.25#\n",
      "m = (P1 *  10**3 *V1)/(R * 10**3 * T1) # in kg\n",
      "V2 = V1 * (P1/P2)**(1/n) # in m**3\n",
      "del_U = C_P * (log(V2/V1))  + C_V * (log(P2/P1)) # in kJ/kg-K\n",
      "del_U = m * del_U # in kJ/K\n",
      "print \"Part (i)\"\n",
      "print \"Change in entropy = %0.4f kJ/K \" %del_U\n",
      "T2 = T1 * (V1/V2)**(n-1) # in K\n",
      "del_U1 = C_P * (log(T2/T1)) - R*(log(P2/P1)) # in kJ/kg-K\n",
      "print \"Part (ii)\"\n",
      "print \"Change in entropy = %0.3f kJ/kg-K \" %del_U1\n",
      "del_U2 = C_V * (log(T2/T1)) + R*(log(V2/V1)) # in kJ/kg-K\n",
      "print \"Part (iii)\"\n",
      "print \"Change in entropy = %0.3f kJ/kg-K \" %del_U2\n",
      "del_U3 = C_V * (Gamma-n) * (log(V2/V1)) # in kJ/kg-K\n",
      "print \"Part (iv)\"\n",
      "print \"Change in entropy = %0.3f kJ/kg-K \" %del_U3\n",
      "del_U4 = C_V * ((Gamma-n)/(n-1)) * (log(T1/T2)) # in kJ/kg-K\n",
      "print \"Part (v)\"\n",
      "print \"change in entropy = %0.3f kJ/kg \" %del_U4\n",
      "del_U5 = C_V * ((Gamma-n)/n) * (log(P1/P2)) # in kJ/kg-K\n",
      "print \"Part (vi)\"\n",
      "print \"Change in entropy = %0.3f kJ/kg-k \" %del_U5"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Part (i)\n",
        "Change in entropy = -0.0456 kJ/K \n",
        "Part (ii)\n",
        "Change in entropy = -0.207 kJ/kg-K \n",
        "Part (iii)\n",
        "Change in entropy = -0.207 kJ/kg-K \n",
        "Part (iv)\n",
        "Change in entropy = -0.205 kJ/kg-K \n",
        "Part (v)\n",
        "change in entropy = -0.205 kJ/kg \n",
        "Part (vi)\n",
        "Change in entropy = -0.205 kJ/kg-k \n"
       ]
      }
     ],
     "prompt_number": 36
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.16 - Page No :  93 "
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import log\n",
      "# Given data\n",
      "P1 = 1# in bar\n",
      "P2 = 15# in bar\n",
      "T1 = 0# in degree C\n",
      "T1 = T1 + 273# in K\n",
      "T2 = 200# in degree C\n",
      "T2 = T2 + 273# in K\n",
      "C_P = 1.005# in kJ/kg-K\n",
      "C_V = 0.718# in kJ/kg-K\n",
      "R = C_P-C_V# in kJ/kg-K\n",
      "del_U = C_P * (log(T2/T1)) - R*(log(P2/P1)) # in kJ/kg-K\n",
      "print \"Change in entropy = %0.3f kJ/kg-K \"  %del_U"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in entropy = -0.225 kJ/kg-K \n"
       ]
      }
     ],
     "prompt_number": 37
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.17 - Page No :  94"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import log\n",
      "# Given data\n",
      "C_V = 2.174# in kJ/kg-K\n",
      "R = 0.5196# in kJ/kg-K\n",
      "C_P = C_V+R# in kJ/kg-K\n",
      "V2 = 1# in m**3\n",
      "V1 = 8# in m**3\n",
      "P1 = 0.7# in bar\n",
      "P2 = 7# in bar\n",
      "del_U = C_P * (log(V2/V1)) + C_V * (log(P2/P1)) # in kJ/kg-K\n",
      "m = 0.9# in kg\n",
      "del_U = m * del_U# in kJ/K\n",
      "print \"Change in entropy = %0.3f kJ/K \" %del_U\n",
      "print \"It is a loss of entropy\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in entropy = -0.536 kJ/K \n",
        "It is a loss of entropy\n"
       ]
      }
     ],
     "prompt_number": 38
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.18 - Page No :   95 "
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "C_P = 1.005# in kJ/kg-K\n",
      "C_V = 0.718# in kJ/kg-K\n",
      "R = C_P - C_V# in kJ/kg-K\n",
      "R= R*10**3#in J/kg-K\n",
      "P1 = 3*10**5#in N/m**2\n",
      "V1 = 1.5# m**3\n",
      "T1 = 15# in degree C\n",
      "T1 = T1  +273# in K\n",
      "m1 = (P1*V1)/(R* T1) # in kg\n",
      "m2 = m1+2#final mass of air in kg\n",
      "P2 = P1 * (m2/m1) # in kN/m**2\n",
      "T1 = T1 - 273# in degree C\n",
      "T2 = 0# in degree C\n",
      "m = 1# in kg\n",
      "del_U = m * C_P * (T1-T2) # in kJ\n",
      "print \"Total enthapy of air = %0.3f kJ \" %del_U"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Total enthapy of air = 15.075 kJ \n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.19 - Page No :   96"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "R = 0.287# in kJ/kg-K\n",
      "P1 = 30# in bar\n",
      "V1 = 0.12# in m**3\n",
      "m = 1.8# in kg\n",
      "U= 8.3143# in kJ/kg-mol-K\n",
      "T1 = (P1 * 10**5 * V1)/(m*R*10**3) # in K\n",
      "T1 = T1 - 273# in degree C\n",
      "print \"The temperature = %0.0f degree C \" %int(T1)\n",
      "m_m = U/R# in kg\n",
      "print \"The molecular mass = %0.2f kg \" %m_m\n",
      "V_s = V1/m# in m**3\n",
      "print \"The Specific volume = %0.4f m**3 \" %V_s\n",
      "V_m = V_s * m_m# in m**3\n",
      "print \"Molecular volume = %0.2f m**3 \" %V_m"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The temperature = 423 degree C \n",
        "The molecular mass = 28.97 kg \n",
        "The Specific volume = 0.0667 m**3 \n",
        "Molecular volume = 1.93 m**3 \n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.20 - Page No :  96"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "T=15+273#in K\n",
      "U= 8.3143# in kJ/kg-mol-K\n",
      "GasConstant = 0.618# in kJ/kg-K\n",
      "GasVolume= 1# in m**3 (assume)\n",
      "AirVolume= 1.5*GasVolume# in m**3\n",
      "P=760# in mm\n",
      "P= P/750# in bar\n",
      "P= P*10**5#in N/m**2\n",
      "MixtureVolume= GasVolume+AirVolume#in m**3\n",
      "PGM= GasVolume/MixtureVolume*100# in %\n",
      "print \"Percentage of gas by volume in the mixture = %0.0f %%\" %PGM\n",
      "PAM= AirVolume/MixtureVolume*100# in %\n",
      "print \"Percentage of air by volume in the mixture = %0.0f %%\" %PAM\n",
      "M1= U/0.287# in mol\n",
      "M2= U/0.618# in mol\n",
      "M= PAM/100*M1+PGM/100*M2# mass of mixture in mol\n",
      "R= U/M# gas constant in kJ/kg-K\n",
      "R= R*10**3#in J/kg-K\n",
      "print \"The gas constant = %0.3f kJ/kg-K\" %(R*10**-3)\n",
      "PAM1= PAM*M1/M# in %\n",
      "print \"Percentage of air by mass in the mixture = %0.2f %%\" %PAM1\n",
      "PGM1= PGM*M2/M# in %\n",
      "print \"Percentage of gas by mass in the mixture = %0.2f %%\" %PGM1\n",
      "Rho= P/(R*T) # kg/m**3\n",
      "print \"The density of the gas = %0.3f kg/m**3\" %Rho"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Percentage of gas by volume in the mixture = 40 %\n",
        "Percentage of air by volume in the mixture = 60 %\n",
        "The gas constant = 0.365 kJ/kg-K\n",
        "Percentage of air by mass in the mixture = 76.36 %\n",
        "Percentage of gas by mass in the mixture = 23.64 %\n",
        "The density of the gas = 0.963 kg/m**3\n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.21 - Page No :  97"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "from math import log\n",
      "# Given data\n",
      "Gamma = 1.4#\n",
      "P1 = 7# in bar\n",
      "P1= P1*10**5# in N/m**2\n",
      "V1 = 1.6# in m**3\n",
      "V2 = 8# in m**3\n",
      "P2 = (P1 * (V1)**(Gamma))/((V2)**(Gamma)) # in bar\n",
      "W1 = (P1*V1-P2*V2)/(Gamma-1) # work done by the gas during isentropic expansion in J\n",
      "Rho = V2/V1#\n",
      "W2 = P1*V1*(log(Rho)) # work done by the gas during isothermal expansion in J\n",
      "del_W = W2-W1# in J\n",
      "del_W = del_W*10**-3 # in kJ\n",
      "print \"Difference between the work done during isentropic and isothemal expansion = %0.0f kJ \" %del_W"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Difference between the work done during isentropic and isothemal expansion = 473 kJ \n"
       ]
      }
     ],
     "prompt_number": 39
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.22 - Page No :  98"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "P1 = 1# in  bar\n",
      "V1 = 400# in  cm**3\n",
      "V2 = 80# in Cm**3\n",
      "T1 = 110# in degree C\n",
      "T1  = T1 + 273# in K\n",
      "Gamma = 1.3#\n",
      "P2 = P1*((V1/V2)**(Gamma)) # in bar\n",
      "print \"The pressure = %0.1f bar \" %P2\n",
      "T2 = T1 * ((P2*V2)/(P1*V1)) # in K\n",
      "T2 = int(T2-273)#in degree C\n",
      "print \"The temperature = %0.0f degree C \" %T2\n",
      "T2 = T2 + 273# in K\n",
      "m = 1#\n",
      "C_V = 0.75#\n",
      "del_U = m*C_V*(T2-T1) # in kJ\n",
      "print \"Change in internal energy = %0.2f kJ \" %del_U\n",
      "P1= P1*10**5# in N/m**2\n",
      "P2= P2*10**5# in N/m**2\n",
      "V1= V1*10**-3# in litre\n",
      "V2= V2*10**-3# in litre\n",
      "W = (P1*V1-P2*V2)/(Gamma-1) # in J\n",
      "W = abs(W * 10**-3) # in kJ\n",
      "print \"Work done = %0.2f kJ \" %W\n",
      "P3 = 40*10**5# in N/m**2\n",
      "T3 = (P3/P2) * T2# in K\n",
      "T3 = T3 - 273# in degree C\n",
      "print \"Temperature of gas = %0.0f degree C \" %T3"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The pressure = 8.1 bar \n",
        "The temperature = 347 degree C \n",
        "Change in internal energy = 177.75 kJ \n",
        "Work done = 82.75 kJ \n",
        "Temperature of gas = 2787 degree C \n"
       ]
      }
     ],
     "prompt_number": 21
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.23 - Page No :  99"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "C_P = 1.068# in kJ/kg-K\n",
      "C_V = 0.775#in kJ/kg-K\n",
      "R = C_P-C_V# in kJ/kg-K\n",
      "R= R*10**3# in J/kg-K\n",
      "P1 = 12# in bar\n",
      "P1= P1*10**5# in N/m**2\n",
      "V1 = 0.15#in m**3\n",
      "V2= 0.28# in m**3\n",
      "m = 1# in kg\n",
      "T1 = (P1*V1)/(R* m) # in K\n",
      "T2 = (T1 * (V2/V1)) # in K\n",
      "print \"Temperature at the end of Constant pressure = %0.3f \u00b0C \" %(T2-273)\n",
      "W = P1* (V2-V1) # in J\n",
      "W = W * 10**-3# in kJ\n",
      "Gamma = 1.38\n",
      "V3 = 1.5# in m**3\n",
      "T3 = T2/((V3/V2)**(Gamma-1)) # in K\n",
      "T3 = (T3 - 273)# in degree C\n",
      "print \"Temperature at the end of Isentropic = %0.0f \u00b0C \" %T3\n",
      "T3 = T3 + 273# in K\n",
      "W1 = m *C_V*(T2-T3) # work done during isentropic expansion in kJ\n",
      "W2 = W+W1# in kJ\n",
      "print \"Total Work done = %0.2f kJ \" %W2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Temperature at the end of Constant pressure = 873.758 \u00b0C \n",
        "Temperature at the end of Isentropic = 333 \u00b0C \n",
        "Total Work done = 575.08 kJ \n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.24 - Page No :  100"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from scipy.integrate import quad\n",
      "# Given data\n",
      "C_P = 1.005# in kJ/kg-K\n",
      "C_V = 0.718# in kJ/kg-K\n",
      "R = C_P-C_V# in kJ/kg-K\n",
      "P1 = 20#in bar\n",
      "P2 = 12# in bar\n",
      "T1 = 200#in degree C\n",
      "T1 = T1 + 273# in K\n",
      "T2 = 125#in degree c\n",
      "T2 = T2 + 273# in K\n",
      "V1 = (R*10**3*T1)/(P1*10**5) # in m**3\n",
      "V2 = (R*10**3*T2)/(P2*10**5) # in m**3\n",
      "def integrand(V):\n",
      "    return -293*V+40\n",
      "ans, err = quad(integrand, 0.0679,0.0952)\n",
      "W = 10**5 * ans# in Joules\n",
      "W = round(W * 10**-3)  # in  kJ\n",
      "print \"Work done = %0.0f kJ \" %W\n",
      "m = 1# in kg\n",
      "del_U = m*C_V*(T2-T1) # change in internal energy in kJ\n",
      "print \"Change in internal energy = %0.2f kJ \" %del_U\n",
      "print \"Negative sign indicates that there is decrease in internal energy of the gas. \"\n",
      "C_Enthalpy = m*C_P*(T2-T1) # change  in enthalpy in kJ\n",
      "print \"The change in enthalpy = %0.1f kJ\" %C_Enthalpy\n",
      "print \"Negative sign indicates that there is decrease in enthalpy of the gas\"\n",
      "Q = W+ del_U# in kJ\n",
      "print \"Heat transfer = %0.2f kJ \" %Q\n",
      "print \"Negative sign indicates that the heat is rejected by the air\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Work done = 44 kJ \n",
        "Change in internal energy = -53.85 kJ \n",
        "Negative sign indicates that there is decrease in internal energy of the gas. \n",
        "The change in enthalpy = -75.4 kJ\n",
        "Negative sign indicates that there is decrease in enthalpy of the gas\n",
        "Heat transfer = -9.85 kJ \n",
        "Negative sign indicates that the heat is rejected by the air\n"
       ]
      }
     ],
     "prompt_number": 23
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.25 - Page No :  101"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import log\n",
      "import math\n",
      "# Given data\n",
      "P1 = 14# in bar\n",
      "P3 = 2.222# in bar\n",
      "V3byV1 = P1/P3#\n",
      "P2 = 1.05# in bar\n",
      "Gamma = log(P1/P2)/log(V3byV1)\n",
      "C_P = 1.005# in kJ/kg-K\n",
      "C_V = C_P/Gamma# in kJ/kg-K\n",
      "T3 = 343# in degree C\n",
      "T3 = T3 + 273# in K\n",
      "T2 = math.ceil(T3*P2)/P3# in K\n",
      "m = 0.5# in kg \n",
      "del_U = m*C_V*(T2-T3) # in kJ\n",
      "print \"Change in internal energy = %0.3f kJ \" %del_U\n",
      "print \"i.e. there is a loss of\",round(abs(del_U),3),\"kJ of internal energy\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in internal energy = -115.986 kJ \n",
        "i.e. there is a loss of 115.986 kJ of internal energy\n"
       ]
      }
     ],
     "prompt_number": 40
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.26 - Page No :  102"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "R = 0.26# in kJ/kg-K\n",
      "R = R * 10**3# in J/kg-K\n",
      "Gamma = 1.4#\n",
      "P1 = 3.1# MN/m**2\n",
      "P1 = P1 * 10**6# N/m**2\n",
      "P2 = 1.7# in  MN/m**2\n",
      "P2 = P2 * 10**6# in N/m**2\n",
      "V1 = 500# in cm**3\n",
      "T = 18# in degree C\n",
      "T = T + 273# in K\n",
      "T2 = 15# in degree C\n",
      "T2 = T2 + 273# in K\n",
      "m = (P1*V1)/(R*T)*10**-3# in kg\n",
      "m_desh = (P2*V1)/(R*T2)*10**-3#in kg\n",
      "M = m-m_desh# in kg\n",
      "print \"The mass of oxygen = %0.2f kg \" %M\n",
      "R = R * 10**-3# in kJ/kg-K\n",
      "C_v = R/(Gamma-1) # in kJ/kg-K\n",
      "Q = m_desh*C_v * (T-T2) # in kJ\n",
      "print \"Heat transfered = %0.3f kJ \" %Q"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The mass of oxygen = 9.13 kg \n",
        "Heat transfered = 22.135 kJ \n"
       ]
      }
     ],
     "prompt_number": 25
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.27 - Page No :  103"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "P1 = 1 * 10**5# in N/m**2\n",
      "V1 = 0.1# in m**3\n",
      "V2 = 0.01# in m**3\n",
      "T1 = 90# in degree C\n",
      "T1 = T1  +273# in K\n",
      "R = 0.287# in kJ/kg-K\n",
      "R = R  *10**3#\n",
      "C_v = 0.717# in kJ/kg-K\n",
      "C_P = 1.005# in kJ/kg-K\n",
      "m = (P1 * V1)/(R*T1) # in kg\n",
      "Gamma = 1.4#\n",
      "T2 = T1 * ((V1/V2)**(Gamma - 1))  # in K\n",
      "del_U = m*C_v*(T1-T2) # in kJ\n",
      "print \"The change in internal energy = %0.2f kJ\" %del_U\n",
      "del_E = m * C_P*(T2-T1) # in kJ\n",
      "print \"The change in enthalpy = %0.2f kJ\" %del_E\n",
      "U2 = m*C_v*T2#Internal energy at 2 in kJ\n",
      "T= 473# temp. of entering air\n",
      "E = V1*C_P*T#Enthalpy of entering air in kJ\n",
      "# U3= (m+V1)*C_v*T3 # (internal energy at 3)\n",
      "# U3= U2+E\n",
      "T3 = (E+U2)/( (m+V1)*C_v ) # in K\n",
      "print \"Temperature = %0.0f K\" %T3\n",
      "m=m+.1#\n",
      "P3 =m* R*T3/V2# in N/m**2\n",
      "print \"The pressure = %0.3f MN/m**2 \" %(P3*10**-6)\n",
      "\n",
      "# Note: There is a calculation error to evaluating the value of P3. So the answer in the book of P3 is wrong."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The change in internal energy = -37.77 kJ\n",
        "The change in enthalpy = 52.94 kJ\n",
        "Temperature = 785 K\n",
        "The pressure = 4.415 MN/m**2 \n"
       ]
      }
     ],
     "prompt_number": 26
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.28 - Page No :  104"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "T= 60+273# in K\n",
      "T2= 25+273# in K\n",
      "P1=3.5*10**6# in Pa\n",
      "P2=1.7*10**6# in Pa\n",
      "Gamma=0.4# value of Cp-Cv\n",
      "m1=1# (assumed value)\n",
      "# R= P1*V/(m*T)             (i)\n",
      "# R= P2*V/((m-m1)*T2) (ii)\n",
      "# From eq(i) and (ii)\n",
      "m= m1*P1*T2/(P1*T2-P2*T)\n",
      "# U= m*Cv*T and U1= (m-m1)*Cv*T2+m1*Cv*T1\n",
      "# U-U1= P1*V1= m1*R*T1 or\n",
      "# m1*R*T1= m*Cv*T-[(m-m1)*Cv*T2+m1*Cv*T1]\n",
      "T1= (m*T-(m-m1)*T2)/(m1*Gamma+m1) # in K\n",
      "print \"The temperature of gas in the cylinder = %0.2f \u00b0C\" %(T1-273)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The temperature of gas in the cylinder = -5.47 \u00b0C\n"
       ]
      }
     ],
     "prompt_number": 27
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.29 - Page No : 105"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "U=180# energy received by system in kJ\n",
      "RH= 200# rejected heat by system in kJ\n",
      "RcHeat= 50# received heat by system in kJ\n",
      "W= U-RH+RcHeat# in kJ\n",
      "U1 = 0# in kJ\n",
      "U2= U+U1# in kJ\n",
      "U3 = RcHeat-RH+U2# in kJ\n",
      "print \"Internal energy = %0.0f kJ \" %U3"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Internal energy = 30 kJ \n"
       ]
      }
     ],
     "prompt_number": 28
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example  3.30 - Page No :  105"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import log\n",
      "# Given data\n",
      "C_P = 1.045# in kJ/kg-K\n",
      "Q = 100# in kJ\n",
      "del_T = Q/C_P# in degree C\n",
      "T1 = 25# in degree C\n",
      "T1 = T1 + 273# in K\n",
      "T = 0# in degree C\n",
      "T = T + 273# in K\n",
      "T2 = T1 + del_T# in K\n",
      "del_Phi = C_P * (log(T2/T1)) # in kJ/kg-K\n",
      "print \"The change in entropy in the process = %0.3f kJ/kg-K \" %del_Phi\n",
      "ini_entropy = C_P * (log(T1/T)) # initial entropy in kJ/kg-K\n",
      "print \"The initial entropy = %0.3f kJ/kg-K \" %ini_entropy"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The change in entropy in the process = 0.291 kJ/kg-K \n",
        "The initial entropy = 0.092 kJ/kg-K \n"
       ]
      }
     ],
     "prompt_number": 41
    }
   ],
   "metadata": {}
  }
 ]
}