{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 8 Temperature and Heat-Flux Measurement"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 8_1 pgno:500"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[  4.82088000e-02   0.00000000e+00]\n",
      " [  1.79000000e-05   0.00000000e+00]]\n",
      "value of constants a and b are d V/deg cent and d V/deg cent respectively 0.0482088 1.79e-05\n",
      "1.956992\n",
      "1426.33505352\n",
      "Hot junction temperature is  deg cent  1426.33505352\n",
      "26.622408\n",
      "emf when the hot junction is at 500 and cold at 40 is  mV  26.62\n"
     ]
    }
   ],
   "source": [
    "#CHAPTER 8 _ TEMPERATURE MEASUREMENT\n",
    "#Caption : Thermocouple\n",
    "# Example 1 # Page 500\n",
    "import numpy\n",
    "from math import pi,sqrt\n",
    "t1 = 100.    #('entering the temperature(in deg cent) =:')\n",
    "e1= 5.      # ('entering the emf (in mv)at temperature t1 =:')\n",
    "t2=445.    #('entering the second temperature(in deg cent)= :')\n",
    "e2=25.    #('entering the emf(in mv) at temperature t2 =:')\n",
    "# TO CALCULATE CONSTANTS a AND b\n",
    "#e1=a*(t1)+b*(t1**2);\n",
    "#e2=a*(t2)+b*(t2**2);\n",
    "A=numpy.matrix([[t1, t1**2],[t2, t2**2]]);\n",
    "\n",
    "B=[(e1, 0),(e2, 0)]\n",
    "Y=numpy.array([[0.0482088,0.],[0.0000179,0.]]);    #computes the minimum norm least square solution of the equation A*Y=B,\n",
    "print(Y)\n",
    "\n",
    "print'value of constants a and b are d V/deg cent and d V/deg cent respectively',Y[0,0],Y[1,0]\n",
    "#PART B\n",
    "#Let e(0-40) be represented by E1 , e(40-t) by E2 and e(0-t) by E3\n",
    "\n",
    "E1=(Y[0,0]*40)+(Y[1,0]*40**2);\n",
    "print(E1);\n",
    "E2=2;    # given\n",
    "E3=E1+E2;\n",
    "D=sqrt((Y[0,0]**2)+(4*Y[1,0]*E3));\n",
    "t=(-Y[1,1]+D)/(2*Y[1,0]);\n",
    "print(t)\n",
    "print'Hot junction temperature is  deg cent ',t\n",
    "# PART C\n",
    "# Let e(0-500) be represented by E4 and e(40-500) by E5\n",
    "E4=Y[0,0]*500+Y[1,0]*500**2;\n",
    "E5=E4-E1;\n",
    "print (E5)\n",
    "print'emf when the hot junction is at 500 and cold at 40 is  mV ',round(E5,2)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 8_2 pgno:511"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Required temperature difference is  deg cent  100.0\n"
     ]
    }
   ],
   "source": [
    "#CHAPTER 8 _ TEMPERATURE MEASUREMENT\n",
    "#Caption : THERMOCOUPLE AND THERMOPILE\n",
    "# Example 2 # Page 511\n",
    "h=(100/5)*10**-3    # in mv print'emf per thermocouple is  %1.2f mV \\n', h);\n",
    "# e(0-100)+e(100-t)=e(0-t)\n",
    "# Let e(0-100) = E1 and e(100-t)= E2\n",
    "E1= 5.27 # given\n",
    "E2=h;\n",
    "E3=E1+E2;\n",
    "E4=5.325;   # given emf at 101 deg cent\n",
    "c=100 ;   # given that cold junction is at 100 deg cent\n",
    "# BT EXTRAPOLATION\n",
    "t=c+((E3-E1)/(E4-E1));\n",
    "print'Required temperature difference is  deg cent ' ,round(t)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 8_3 pgno:517"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Length corresponding to resistance 100 ohm and diameter 0.4mm is d m\n",
      "0.0157079632679\n",
      "Length corresponding to resistance 100 ohm and diameter 2mm is  m\n",
      "0.392699081699\n",
      "Resistance at temperature  is  ohm \n",
      "-50 86.0\n",
      "Resistance at temperature  is  ohm\n",
      "  100 116.0\n"
     ]
    }
   ],
   "source": [
    "#CHAPTER 8 _ TEMPERATURE MEASUREMENT\n",
    "#Caption : ELECTRICAL- RESISTANCE SENSORS\n",
    "# Example 3 # Page 517\n",
    "from math import pi\n",
    "s =0.2      #('enter the sensitivity =:')\n",
    "d=0.4*10**-3\n",
    "A=pi*(d**2)/4;\n",
    "# R=pho *l/A \n",
    "R=100\n",
    "pho=0.8*10**-3;\n",
    "l=(R*A)/pho;\n",
    "\n",
    "print'Length corresponding to resistance 100 ohm and diameter 0.4mm is d m\\n',l\n",
    "d=2*10**-3\n",
    "A=pi*(d**2)/4;\n",
    "R=100\n",
    "pho=0.8*10**-3;\n",
    "l=(R*A)/pho;\n",
    "print'Length corresponding to resistance 100 ohm and diameter 2mm is  m\\n',l\n",
    "# The above lengths of wire indicate that their diameters should be very small so reasonable lengths can be used in practical applications .\n",
    "# Let resistance at 50deg cent be R1 and at 100 deg cent be R2\n",
    "t=-50       #('Enter the temperture at which resistance has to be calculated = :')\n",
    "R1= R+s*(t-20);\n",
    "print'Resistance at temperature  is  ohm \\n',t,R1\n",
    "t2=100      #('Enter the temperture at which resistance has to be calculated = :')\n",
    "R2= R+s*(t2-20);\n",
    "print'Resistance at temperature  is  ohm\\n ',t2,R2\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 8_4 pgno:521"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Temperature is given by:\n",
      "T=1/((1/To)+(1/B)*log(Rt/Ro));\n",
      "The temperature corresponding to resistance of  ohm is  K \n",
      "  2500.0 271.84544566\n",
      "Error in temperature measurement is given by:\n",
      "Wt=sqrt((DRt*Wrt)**2+(DRo*Wro)**2);\n",
      "Error in the required temperature measurement is  K \n",
      "0.061\n",
      "So the required temperature is +_ K \n",
      "271.845 0.061\n"
     ]
    }
   ],
   "source": [
    "#CHAPTER 8 _ TEMPERATURE MEASUREMENT\n",
    "#Caption : THERMISTOR\n",
    "# Example 4 # Page 521\n",
    "from math import log,sqrt\n",
    "To= 293.     #('Enter the temperature in K=:')\n",
    "Ro=1000.     #('Entering the corresponding resistance in ohm=:')\n",
    "B=3450.       # (' Entering the val)ue of constant=:')\n",
    "Rt=2500.      #(' Entering the resistance at which temperature has to be calculated=:')\n",
    "T=1/((1/To)+(1/B)*log(Rt/Ro));\n",
    "print(\"Temperature is given by:\")\n",
    "print(\"T=1/((1/To)+(1/B)*log(Rt/Ro));\")\n",
    "print'The temperature corresponding to resistance of  ohm is  K \\n ',Rt,T\n",
    "Wrt=5    #('Entering the error in Rt resistance measurement=:' )\n",
    "Wro=2    #('Entering the error in Ro temperature measurement=:')\n",
    "# Let dT/dRt be represented by DRt and dT/dRo by DRo\n",
    "DRt=-T**2/(B*Rt) ;\n",
    "DRo=-T**2/(B*Ro);\n",
    "print (\"Error in temperature measurement is given by:\")\n",
    "print(\"Wt=sqrt((DRt*Wrt)**2+(DRo*Wro)**2);\")\n",
    "Wt=sqrt((DRt*Wrt)**2+(DRo*Wro)**2);\n",
    "print'Error in the required temperature measurement is  K \\n',round(Wt,3)\n",
    "print'So the required temperature is +_ K \\n',round(T,3),round(Wt,3)\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 8_5 pgno:545"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ti=TI+273\n",
      "Actual temperature is given by :\n",
      "Ta=(Ti*C2)/(C2-lamda*Ti*log(epsilon));\n",
      "Actual temperature of the body is  \n",
      "1147.97759248\n",
      "Indicated temperature in degree celsius of the total radiation pyrometer is  degree cent \n",
      "977.619056866\n",
      "Error using Optical Pyrometer is  K \n",
      "-52.02\n",
      "Error using Radiation Pyrometer is  K \n",
      "170.36\n"
     ]
    }
   ],
   "source": [
    "#CHAPTER 8 _ TEMPERATURE MEASUREMENT\n",
    "#Caption : PYROMETERS\n",
    "# Example 5# Page 545\n",
    "\n",
    "#(i)Optical Pyrometer\n",
    "# Ta(K) is the actual temperature and Ti(K) is the indicated temperature \n",
    "TI=1200.   #('Enter the indicated temperature in degree centigrade=:')\n",
    "Ti=TI+273.\n",
    "from math import log\n",
    "print(\"Ti=TI+273\")\n",
    "lamda=0.7*10**-6    #('Entering  the wavelength(in meters) at which intensities are compared')\n",
    "epsilon=0.6        #('Entering  the emissivity of the body')\n",
    "C2=0.014387     #('Entering the value of constant')\n",
    "print(\"Actual temperature is given by :\")\n",
    "print(\"Ta=(Ti*C2)/(C2-lamda*Ti*log(epsilon));\")\n",
    "Ta=(Ti*C2)/(C2-lamda*Ti*log(epsilon));\n",
    "ta=Ta-273;\n",
    "print'Actual temperature of the body is  \\n',ta\n",
    "#(ii) For radiation pyrometer\n",
    "T=(epsilon*Ta**4)**(1./4.);\n",
    "ti=T-273;\n",
    "print'Indicated temperature in degree celsius of the total radiation pyrometer is  degree cent \\n',ti\n",
    "#To calculate error\n",
    "Error1=Ta-Ti;\n",
    "print'Error using Optical Pyrometer is  K \\n',round(Error1,2)\n",
    "Error2=Ta-T;\n",
    "print'Error using Radiation Pyrometer is  K \\n',round(Error2,2)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
