{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 2: Energy Conversion and General Energy Analysis"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "    Example 2-1 ,Page No.57"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#there is a 0.00490% error as the answer in textbook is expressed in multiple of 10\n",
      "#Constants used\n",
      "Hu=6.73*10**10;#Energy liberated by 1 kg of uranium\n",
      "\n",
      "# Given values\n",
      "p=0.75;# assuming the avg density of gasoline in kg/L\n",
      "V=5;# consumption per day of gasoline in L\n",
      "Hv=44000; #heat value in kJ/kg\n",
      "mu=0.1;# mass of uranium used\n",
      "\n",
      "#Calculation\n",
      "mgas=p*V;#mass of gasoline required per day\n",
      "Egas=mgas*Hv;\n",
      "Eu=mu*Hu;\n",
      "d=Eu/Egas;\n",
      "print'%i number of days the car can run with uranium' %round(d,0)\n",
      "print'equivalent to %i years' %round(d/365,0)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "40788 number of days the car can run with uranium\n",
        "equivalent to 112 years\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2-2 ,Page No.59"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given values\n",
      "v=8.5;# wind speed in m/s\n",
      "m=10;# given mass for part - b \n",
      "mf=1154;# given flowrate for part - c\n",
      "\n",
      "#Calculations\n",
      "e=(v**2)/2;\n",
      "print'wind energy per unit mass %f J/kg' %round(e,1);\n",
      "E=m*e;\n",
      "print'wind energy for 10 kg mass %i J' %E;\n",
      "E=mf*e/1000;\n",
      "print'wind energy for mass flow rate of 1154kg/s %f kW'%round(E,1)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "wind energy per unit mass 36.100000 J/kg\n",
        "wind energy for 10 kg mass 361 J\n",
        "wind energy for mass flow rate of 1154kg/s 41.700000 kW\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2-7 ,Page No.67"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# Given values\n",
      "T=200;# applied torque in N\n",
      "n=4000;# shaft rotation rate in revolutions per minute\n",
      "\n",
      "#Calculation\n",
      "Wsh=(2*math.pi*n*T)/1000/60;#factor of 1000 to convert to kW and 60 to convert to sec\n",
      "print'Power transmitted %f kW'%round(Wsh,1)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Power transmitted 83.800000 kW\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2-8 ,Page No.69"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Constants used\n",
      "g=9.81;#acceleration due to gravity in m/s^2;\n",
      "\n",
      "#Given values\n",
      "m=1200;#mass of car in kg\n",
      "V=90/3.6;#velocity ; converting km/h into m/s\n",
      "d=30*math.pi/180;#angle of slope ; converting into radians\n",
      "\n",
      "#Calculation\n",
      "Vver=V*math.sin(d);#velocity in vertical direction\n",
      "Wg=m*g*Vver/1000;\n",
      "print'the addtional power %i kW'%Wg"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "the addtional power 147 kW\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2-9 ,Page No.69"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Given values\n",
      "m=900;#mass of car in kg\n",
      "v1=0;# intial velocity\n",
      "v2=80/3.6;# final velocity; converting km/h into m/s\n",
      "t=20;# time taken1\n",
      "\n",
      "#Calculation\n",
      "Wa=m*(v2**2-v1**2)/2/1000;\n",
      "Wavg=Wa/t;\n",
      "print'the average power %f kW'%round(Wavg,1)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "the average power 11.100000 kW\n"
       ]
      }
     ],
     "prompt_number": 21
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2-10 ,Page No.74"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Given values\n",
      "Win=100;# work done in the process in kJ\n",
      "Qout=500;# heat lost in kJ\n",
      "U1=800;# internal energy of the fluid in kJ\n",
      "\n",
      "#Calculations\n",
      "# Win - Qout = U2- U1 i.e change in internal energy \n",
      "U2=U1-Qout+Win;\n",
      "print'final internal of the system %i kJ'%U2\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "final internal of the system 400 kJ\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2-11 ,Page No.75"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#given values\n",
      "Win=20;# power consumption in W\n",
      "mair=0.25;# rate of air discharge in kg/sec\n",
      "\n",
      "#calculation\n",
      "v=math.sqrt(Win/2/mair)#Win = 1/2*m*v^2\n",
      "if v >=8:\n",
      "    print('True');\n",
      "else:\n",
      "    print('False')\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "False\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2-12 ,Page No.76"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Given values\n",
      "Win=200.0;#Power of fan in W\n",
      "U=6.0;#Overall heat transfer coefficient in W/m^2 C\n",
      "A=30;#Surface area in m^2\n",
      "To=25;#Outdoor temperature in C\n",
      "\n",
      "#Calculations\n",
      "Ti= (Win/U/A)+To;# Win = Qout = U*A*(Ti - To)\n",
      "print'the indoor air temperature %f Celcius'%Ti\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "the indoor air temperature 26.111111 Celcius\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2-13 ,Page No.76"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Given values\n",
      "Plamp=80.0;#Power of lamp in W\n",
      "N=30;#no of lamps\n",
      "t=12;#time period the light is in use in hours/day\n",
      "y=250;#days in a year light is in function \n",
      "UC=0.07;#unit cost in $\n",
      "\n",
      "#Calculation\n",
      "LP=Plamp*N/1000;#Lighting power in kW\n",
      "OpHrs=t*y;#Operating hours\n",
      "LE=LP*OpHrs;#Lighting energy in kW\n",
      "LC=LE*UC;#Lighting cost\n",
      "print'the annual energy cost $%i'%LC\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "the annual energy cost $504\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2-15 ,Page No.82"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Given values\n",
      "Ein=2.0;#Power of electric burner in kW\n",
      "n1=0.73;#Efficiency of open burners\n",
      "n2=0.38;#efficency of gas units\n",
      "CinH=0.09;#Unit cost of electricity in $\n",
      "CinB=0.55;#Unit cost of natural gas in $\n",
      "\n",
      "#Calculations\n",
      "QutH= Ein * n1;\n",
      "print'rate of energy consumption by the heater %f kW'%round(QutH,2);\n",
      "CutH= CinH / n1;\n",
      "print'the unit cost of utilized energy for heater $%f/kWh'%round(CutH,3);\n",
      "QutB= QutH / n2 ;\n",
      "print'rate of energy consumption by the burner %f kW'%round(QutB,2);\n",
      "CutB= CinB / n2 / 29.3; # 1 therm = 29.3 kWh\n",
      "print'the unit cost of utilized energy for burner %f kWh'%round(CutB,3);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "rate of energy consumption by the heater 1.460000 kW\n",
        "the unit cost of utilized energy for heater $0.123000/kWh\n",
        "rate of energy consumption by the burner 3.840000 kW\n",
        "the unit cost of utilized energy for burner 0.049000 kWh\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2-16 ,Page No.84"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#there is a 0.204% error in the last part of the question due to rounding off the intermidiate steps in the solution\n",
      "\n",
      "#Constants used\n",
      "g=9.81;#acceleration due to gravity in m/s^2;\n",
      "\n",
      "#Given values\n",
      "h=50.0;#Depth of water in m\n",
      "m=5000.0;#mass flow rate of water in kg/sec\n",
      "Wout=1862.0;#generated electric power in kW\n",
      "ngen=0.95;#efficiency of turbine\n",
      "\n",
      "#calculation\n",
      "X=g*h/1000.0;# X stands for the differnce b/w change in mechanical energy per unit mass\n",
      "R=m*X;#rate at which mech. energy is supplied to turbine in kW\n",
      "nov=Wout/R;#overall efficiency i.e turbine and generator\n",
      "print'overall efficiency is %f'%round(nov,2);\n",
      "ntu=nov/ngen;#efficiency of turbine\n",
      "print'efficiency of turbine is %f'%round(ntu,2);\n",
      "Wsh=ntu*R;#shaft output work\n",
      "print'shaft power output %i kW'%round(Wsh,0)\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "overall efficiency is 0.760000\n",
        "efficiency of turbine is 0.800000\n",
        "shaft power output 1960 kW\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2-17 ,Page No.85"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Given values\n",
      "Pstd=4520.0;\n",
      "Phem=5160.0;#prices of std and high eff motor in USD\n",
      "R=60*0.7457;#rated power in kW from hp\n",
      "OpHrs=3500.0;#Operating hours\n",
      "Lf=1.0;#Load Factor\n",
      "nsh=0.89;#efficiency of shaft\n",
      "nhem=0.932;#efficiency of high eff. motor\n",
      "CU=0.08;#per unit cost in $\n",
      "\n",
      "#calculation\n",
      "PS=R*Lf*(1/nsh-1/nhem);#Power savings = W electric in,standard -   W electric in,efficient\n",
      "ES=PS*OpHrs;#Energy savings = Power savings * Operating hours\n",
      "print'Energy savings %i kWh/year'%ES;\n",
      "CS=ES*CU;\n",
      "print'Cost savings per year $%i'%CS;\n",
      "EIC=Phem-Pstd;#excess intial cost\n",
      "Y=EIC/CS;\n",
      "print'simple payback period %f years'%round(Y,1)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Energy savings 7929 kWh/year\n",
        "Cost savings per year $634\n",
        "simple payback period 1.000000 years\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2-18 ,Page No.91"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Given values\n",
      "#NOx details\n",
      "m1=0.0047;#emissions of gas furnaces of NOx in kg/therm\n",
      "N1=18*10**6;#no. of therms per year \n",
      "#CO2 details\n",
      "m2=6.4;#emissions of gas furnaces of CO2 in kg/therm\n",
      "N2=18*10**6;#no. of therms per year \n",
      "\n",
      "#Calculation\n",
      "NOxSav=m1*N1;\n",
      "print'NOx savings %f kg/year'%round(NOxSav,1);\n",
      "CO2Sav=m2*N2;\n",
      "print'CO2 savings %f kg/year'%round(CO2Sav,1)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "NOx savings 84600.000000 kg/year\n",
        "CO2 savings 115200000.000000 kg/year\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2-19 ,Page No.95"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Constants used\n",
      "e=0.95;#Emissivity\n",
      "tc=5.67*10**-8;#thermal conductivity in W/m^2 K^4\n",
      "\n",
      "#Given values\n",
      "h=6;#convection heat transfer coefficient in W/m^2 C\n",
      "A=1.6;#cross-sectional area in m^2\n",
      "Ts=29;#average surface temperature in C\n",
      "Tf=20;#room temperature in C\n",
      "\n",
      "#Calculation\n",
      "#convection rate\n",
      "Q1=h*A*(Ts-Tf);\n",
      "#radiation rate\n",
      "Q2=e*tc*A*((Ts+273)**4-(Tf+273)**4);\n",
      "Qt=Q1+Q2;\n",
      "print'the total rate of heat transfer %f W'%round(Qt,1)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "the total rate of heat transfer 168.100000 W\n"
       ]
      }
     ],
     "prompt_number": 7
    }
   ],
   "metadata": {}
  }
 ]
}