{
 "metadata": {
  "name": "",
  "signature": "sha256:6899d33957757e53b75082591aa468f495e3dee26f9772aa86059a86f9321499"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 2 : Work"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.1 Page No : 28"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "\t\t\t\n",
      "# Variables\n",
      "Force = 180 \t\t\t#in N \t\t\t#horizontal force\n",
      "theta = 30 \t\t\t#in degrees \t\t\t#angle of inclination\n",
      "distance = 12 \t\t\t#in m \t\t\t#distance moved by block along inclined plane.\n",
      " \n",
      "\t\t\t\n",
      "# Calculations and Results\n",
      "Work = Force * (distance * math.cos(math.radians(theta))) \t\t\t#in J \t\t\t# Work done\n",
      "Work = 0.001 * Work \t\t\t# Work done in KJ\n",
      "print \"Work done by block = %.4f KJ\"%(Work);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Work done by block = 1.8706 KJ\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.2 Page No : 31"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "mass_body = 2 \t\t\t#in kg \t\t\t#mass of body\n",
      "L = 5 \t\t\t#in m \t\t\t#vertical distance\n",
      "g = 9.8 \t\t\t#in m/s**2 \t\t\t#acceleration due to gravity\n",
      "\n",
      "\t\t\t\n",
      "# Calculations and Results\n",
      "Work_done_by_agent = mass_body * g * L \t\t\t#in Nm \t\t\t#work done by agent\n",
      "Work_done_by_body = -1*Work_done_by_agent\n",
      "print \"Work done by agent = %.0f Nm\"%(Work_done_by_agent);\n",
      "print \"Work done by body = %.0f Nm\"%(Work_done_by_body);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Work done by agent = 98 Nm\n",
        "Work done by body = -98 Nm\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.4 Page No : 39"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "from scipy.integrate import quad \n",
      "\t\t\t\n",
      "# Variables\n",
      "p1 = 1.5 * 10**(5) \t\t\t#N/m**2 \t\t\t#initial pressure in ballon\n",
      "d1 = 0.25 \t\t\t#m \t\t\t#initial diameter of balloon\n",
      "d2 = 0.3 \t\t\t#m \t\t\t#final diameter of balloon\n",
      "p_atm = 10**(5) \t\t\t#N/m**2 \t\t\t#atmospheric pressure\n",
      "\t\t\t\n",
      "# Calculations and Results\n",
      "\n",
      "#Part (a)\n",
      "print \"Part a\";\n",
      "print \"As p is proportional to d, p = k*d, where k is proportionality constant\"\n",
      "print \"Therefore,\";\n",
      "\n",
      "k = p1/d1;\n",
      "print \"p1 = k*d1 => k = p1/d1 = %.2f/%.2f) = %.1e N/m**3\"%(p1,d1,k);\n",
      "\n",
      "p2 = k*d2; \t\t\t#N/m**2 \t\t\t#final pressure in balloon\n",
      "print \"p2 = k*d2 = %.2f*%.2f) = %.1e N/m**2\"%(k,d2,p2);\n",
      "\n",
      "\n",
      "def f0(d): \n",
      "\t return k*(math.pi/2)*(d**3)\n",
      "\n",
      "W_air =  quad(f0,d1,d2)[0]\n",
      "\n",
      "print \"Work done by balloon on air = %.0f Nm\"%(W_air);\n",
      "\n",
      "\t\t\t#Part (b)\n",
      "print \"Part b\";\n",
      "\n",
      "def f1(d): \n",
      "\t return p_atm*(0.5*math.pi*(d**2))\n",
      "\n",
      "W_atm =  quad(f1,d2,d1)[0]\n",
      "\n",
      "print \"Work done by atmosphere on balloon = %.2f Nm\"%(W_atm);\n",
      "W_balloon = -1*(W_air+W_atm);\n",
      "print \"Work done by balloon = -Work done by air + Work done by atmosphere = -%.0f %.0f = %.0f Nm\"%(W_air,W_atm,W_balloon);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Part a\n",
        "As p is proportional to d, p = k*d, where k is proportionality constant\n",
        "Therefore,\n",
        "p1 = k*d1 => k = p1/d1 = 150000.00/0.25) = 6.0e+05 N/m**3\n",
        "p2 = k*d2 = 600000.00*0.30) = 1.8e+05 N/m**2\n",
        "Work done by balloon on air = 988 Nm\n",
        "Part b\n",
        "Work done by atmosphere on balloon = -595.59 Nm\n",
        "Work done by balloon = -Work done by air + Work done by atmosphere = -988 -596 = -393 Nm\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.5 Page No : 40"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "\n",
      "# Variables\n",
      "p1 = 10 \t\t\t#bar \t\t\t#initial pressure\n",
      "V1 = 0.1 \t\t\t#m**3 \t\t\t#initial volume\n",
      "p2 = 2 \t\t\t#bar \t\t\t#final pressure\n",
      "V2 = 0.35 \t\t\t#m**3 \t\t\t#final volume\n",
      "\n",
      "\t\t\t\n",
      "# Calculations and Results\n",
      "print \"Let the expansion process follow the path pV**n = constant\";\n",
      "print \"Therefore \"\n",
      "n = (math.log(p1/p2))/(math.log(V2/V1));\n",
      "print \"n = lnp1/p2/lnV2/V1 = ln%.2f/%.2f/ln %.2f/%.2f = %.4f\"%(p1,p2,V2,V1,n);\n",
      "W_d = (p1*V1 - p2*V2)*10**5/(n-1) \t\t\t#J \t\t\t#Work interaction for pure substance\n",
      "print \"Work interaction for pure substance = p1V1 - p2V2)/n-1) = %.2f kJ\"%(W_d*.001)\n",
      "\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Let the expansion process follow the path pV**n = constant\n",
        "Therefore \n",
        "n = lnp1/p2/lnV2/V1 = ln10.00/2.00/ln 0.35/0.10 = 1.2847\n",
        "Work interaction for pure substance = p1V1 - p2V2)/n-1) = 105.37 kJ\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.6 Page No : 41"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\t\t\n",
      "# Variables\n",
      "p1 = 1.0 \t\t\t#bar \t\t\t#initial pressure\n",
      "V1 = 0.1 \t\t\t#m**3 \t\t\t#initial volume\n",
      "p2 = 6   \t\t\t#bar \t\t\t#final pressure\n",
      "         \t\t\t#and p1*(V1**1.4) = p2*(V2**1.4)\n",
      "\n",
      "\t\t\t\n",
      "# Calculations and Results\n",
      "#Part (a)\n",
      "print \"Part a\";\n",
      "V2 = V1*(p1/p2)**(1/1.4) \t\t\t#m**3 \t\t\t#final volume\n",
      "print \"Final Volume = %.4f m**3\"%(V2);\n",
      "\n",
      "W_d = (10**5)*(p1*V1 - p2*V2)/(1.4-1); \t\t\t#J \t\t\t#Work of compression for air\n",
      "print \"Work of compression for air = %.1f KJ\"%(W_d*.001);\n",
      "\n",
      "#Part (b)\n",
      "print \"Part b\";\n",
      "V2 = (p1/p2)*V1; \t\t\t#m**3 \t\t\t#final volume\n",
      "print \"Final Volume = %.4f m**3\"%(V2);\n",
      "\n",
      "W_d = (10**5)*p1*V1*math.log(V2/V1); \t\t\t#J \t\t\t#Work done on air\n",
      "print \"Work done on air = %.1f KJ\"%(W_d*.001);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Part a\n",
        "Final Volume = 0.0278 m**3\n",
        "Work of compression for air = -16.7 KJ\n",
        "Part b\n",
        "Final Volume = 0.0167 m**3\n",
        "Work done on air = -17.9 KJ\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.7 Page No : 43"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\t\t\n",
      "# Variables\n",
      "#four-stroke engine\n",
      "x = 3. \t\t\t#number of cylinders\n",
      "y = 1. \t\t\t#engine is math.single-acting\n",
      "n = 500. \t\t\t#rev/min \n",
      "N = n/2 \t\t\t#cycles/min\n",
      "D = 0.075 \t\t\t#m \t\t\t#bore length\n",
      "L = 0.1 \t\t\t#m \t\t\t#stroke length\n",
      "a = 6.*10**(-4) \t\t\t#m**2 \t\t\t#area\n",
      "l = 0.05 \t\t\t#m \t\t\t#length\n",
      "S = 2.*10**8 \t\t\t#N/m**3 \t\t\t#spring constant\n",
      "\n",
      "\t\t\t\n",
      "# Calculations and Results\n",
      "p_m = (a/l)*S \t\t\t#Pa \t\t\t#mep\n",
      "\n",
      "print \"Mean effective pressure, mep{Pm} = %.2f kPa\"%(p_m*.001)\n",
      "A = (math.pi/4)*D**2 \t\t\t#m**2\n",
      "\n",
      "print \"Indicated power{P_ind} = %.2f kW\"%(x*y*p_m*L*A*N/60000)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Mean effective pressure, mep{Pm} = 2400.00 kPa\n",
        "Indicated power{P_ind} = 13.25 kW\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.8 Page No : 45"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "from numpy import *\n",
      "\t\t\t\n",
      "# Variables\n",
      "N = poly1d([.5,0]) \t\t\t#n is engine speed\n",
      "x = 6 \t\t\t#six cylinders\n",
      "y = 1 \t\t\t#assumed\n",
      "d = 0.1 \t\t\t#m \t\t\t#bore length\n",
      "A = math.pi*(0.1)**2/4 \t\t\t#m**2 \t\t\t#Area\n",
      "L = 0.15 \t\t\t#m \t\t\t#stroke length\n",
      "P_shaft = 24.78 \t\t\t#KW \t\t\t#Power of shaft\n",
      "T = 474.9 \t\t\t#Nm \t\t\t#Torque in the crank shaft\n",
      "l = 0.05 \t\t\t#m \t\t\t#length of indicator diagram\n",
      "a = 9.37*10**(-4) \t\t\t#cm**2 \t\t\t#area of indicator diagram\n",
      "S = 0.5*(10**8) \t\t\t#N/m**3 \t\t\t#spring constant\n",
      "\n",
      "\t\t\t\n",
      "# Calculations and Results\n",
      "p_m = a*S/l \t\t\t#mean pressure difference\n",
      "print \"Mean pressure difference = %.2f N/m**2\"%(p_m);\n",
      "\n",
      "P_ind = (x*y)*p_m*(L*A*N/60000) \t\t\t#indicated power\n",
      "#C = coeff(P_ind)\n",
      "C = poly(P_ind)\n",
      "print \"Indicated Power = %.6f n kW\"%(C[1])\n",
      "\n",
      "P_shaft = 2*math.pi*poly([1,0])*T/60000 \t\t\t#shaft power output\n",
      "print \"Shaft power output in KW)= %.5f n kW\"%(P_shaft[0])\n",
      "\n",
      "#Mechanical_efficiency = poly(P_shaft,1)/coeff(P_ind,1)*100\n",
      "Mechanical_efficiency = poly(P_shaft[1])/poly(P_ind[1])*100\n",
      "print \"Mechanical Efficiency = %.0f %%\"%(-Mechanical_efficiency[1])\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Mean pressure difference = 937000.00 N/m**2\n",
        "Indicated Power = -0.055194 n kW\n",
        "Shaft power output in KW)= 0.04973 n kW\n",
        "Mechanical Efficiency = 90 %\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.9 Page No : 46"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\t\t\n",
      "# Variables\n",
      "d = 0.4 \t\t\t#m \t\t\t#cylinder diameter\n",
      "t = 10. \t\t\t#min \t\t\t#Time taken for stirring\n",
      "L = 0.49 \t\t\t#m \t\t\t#distance moved by the piston\n",
      "p_atm = 1. \t\t\t#bar \t\t\t#atmospheric pressure\n",
      "W_net = -1965. \t\t\t#Nm \t\t\t#net work done\n",
      "n = 750. \t\t\t#rev/min \t\t\t#rotational velocity of electric motor\n",
      "I = 0.9 \t\t\t#A \t\t\t#current\n",
      "V = 24. \t\t\t#V \t\t\t#voltage\n",
      "\n",
      "\t\t\t\n",
      "# Calculations and Results\n",
      "#Part(a)\n",
      "print \"Part a\";\n",
      "W_d = 10**5*p_atm * (math.pi/4) * d**2 * L; \t\t\t#Nm \t\t\t#work done by fluid on piston\n",
      "print \"Work done by fluid on the piston = %.1f Nm\"%(W_d);\n",
      "W_str = W_net - W_d; \t\t\t#Nm \t\t\t#Work done by stirrer\n",
      "print \"Work done by stirrer on the fluid = %.1f Nm\"%(W_str);\n",
      "P_shaft = abs(W_str)/(t*60); \t\t\t#W \t\t\t#shaft power output\n",
      "print \"Shaft power output = %.2f W\"%(P_shaft);\n",
      "T = (P_shaft*60)/(2*math.pi*n); \t\t\t#Nm \t\t\t#Torque in the driving shaft\n",
      "print \"Torque in the driving shaft = %.3f Nm\"%( T);\n",
      "\n",
      "#Part(b)\n",
      "print \"Part b\";\n",
      "W_bat = I*V*t*60; \t\t\t#Nm \t\t\t#work done by battery\n",
      "print \"Work done by battery = %.1f Nm\"%(W_bat);\n",
      "W_motor = -1*(W_bat+W_str) \t\t\t#Nm \t\t\t#work done by motor\n",
      "print \"Work done by motor = %.1f Nm\"%(W_motor);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Part a\n",
        "Work done by fluid on the piston = 6157.5 Nm\n",
        "Work done by stirrer on the fluid = -8122.5 Nm\n",
        "Shaft power output = 13.54 W\n",
        "Torque in the driving shaft = 0.172 Nm\n",
        "Part b\n",
        "Work done by battery = 12960.0 Nm\n",
        "Work done by motor = -4837.5 Nm\n"
       ]
      }
     ],
     "prompt_number": 9
    }
   ],
   "metadata": {}
  }
 ]
}