{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 7 - Basic Measuring Instruments"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1 - pg 7-13"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "deflection theta (deg) =  30.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_1,pg 7-13\n",
    "#calculate the deflection angle\n",
    "#given\n",
    "N=100.\n",
    "B=0.15\n",
    "A=10*8*10**-6\n",
    "I=5*10**-3\n",
    "K=0.2*10**-6#spring const.\n",
    "#calculations\n",
    "Td=N*B*A*I#deflecting torque\n",
    "theta=Td/K#deflecting angle\n",
    "#results\n",
    "print\"deflection theta (deg) = \",theta"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2 - pg 7_21"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "deflection for given current (degrees) =  144.75\n",
      "inductance for given deflection (muH) =  2.53\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_2,pg 7-21\n",
    "#given\n",
    "#calculate the deflection\n",
    "import math\n",
    "from sympy import *\n",
    "x=Symbol('x')\n",
    "L=(12+6*x-(x**2))#x is deflection in rad from zero\n",
    "dl=L.diff(x)\n",
    "K=12.\n",
    "I=8.\n",
    "#calculations\n",
    "x=6./(((2*K)/(I**2))+2)#x=((I**2)dl)/(2*k)\n",
    "z=x*(180./math.pi)\n",
    "y=horner(x,L)\n",
    "#results\n",
    "print\"deflection for given current (degrees) = \",round(z,2)\n",
    "print\"inductance for given deflection (muH) = \",round(y,2)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3 - pg 7_23"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "value of shunt resistance (ohm) =  1.351\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_3,pg 7-23\n",
    "#calculate the value of shunt resistance\n",
    "#given\n",
    "Rm=100.\n",
    "Im=2.*10**-3\n",
    "I=150.*10**-3\n",
    "#calculations\n",
    "Rsh=(Im*Rm)/(I-Im)\n",
    "#results\n",
    "print\"value of shunt resistance (ohm) = \",round(Rsh,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4 - pg 7_23"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "current through shunt (A) =  40.0\n",
      "voltage through shunt (V) =  0.5\n",
      "meter resistance (ohm) =  937.5\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_4,pg 7-23\n",
    "#calculate the current, voltage and meter resistance\n",
    "#given\n",
    "Vsh1=400.*10**-3\n",
    "Rsh=0.01\n",
    "Ish1=50.\n",
    "Rm=750.#coil resistance\n",
    "#calculations\n",
    "Ish=Vsh1/Rsh\n",
    "Vsh=Ish1*Rsh\n",
    "Im=Vsh1/Rm\n",
    "Rm1=Vsh/Im#meter resistance\n",
    "#results\n",
    "print\"current through shunt (A) = \",Ish\n",
    "print\"voltage through shunt (V) = \",Vsh\n",
    "print\"meter resistance (ohm) = \",Rm1\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5 - pg 7_25"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "designed multi-range ammeter\n",
      "full scale deflection Im (mA) =  2.0\n",
      "meter resistance Rm (ohm) =  75\n",
      "R1(ohm) =  18.75\n",
      "R2(ohm) =  3.125\n",
      "R3(ohm) =  1.53\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_5,pg 7-25\n",
    "#calculate the full scale deflection and meter resistance\n",
    "#given\n",
    "I1=10*10**-3\n",
    "Im=2*10**-3\n",
    "Rm=75\n",
    "I2=50*10**-3\n",
    "I3=100*10**-3\n",
    "#calculations\n",
    "R1=(Im*Rm)/(I1-Im)\n",
    "R2=(Im*Rm)/(I2-Im)\n",
    "R3=(Im*Rm)/(I3-Im)\n",
    "#results\n",
    "print\"designed multi-range ammeter\"\n",
    "print\"full scale deflection Im (mA) = \",Im*1000.\n",
    "print\"meter resistance Rm (ohm) = \",Rm\n",
    "print\"R1(ohm) = \",R1\n",
    "print\"R2(ohm) = \",R2\n",
    "print\"R3(ohm) = \",round(R3,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6 - pg 7_27"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "various sections of aryton shunt are\n",
      "\n",
      "full scale deflection Im (mA) =  1.0\n",
      "meter resistance Rm (ohm) =  50.0\n",
      "R1 (ohm) =  0.005\n",
      "R2 (ohm) =  0.005\n",
      "R3 (ohm) =  0.03999\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_6,pg 7-27\n",
    "#calculate the meter resistance and full scale deflection\n",
    "#given\n",
    "I1=10.\n",
    "Im=1*10**-3\n",
    "Rm=50.\n",
    "#in position-1 R1 is in shunt with R2+R3+Rm\n",
    "#R1=10**-4(R2+R3+50)......(1)\n",
    "#in position-2 (R1+R2) is in shunt with R3+Rm\n",
    "#R1+R2=2*10**-4(R3+50).....(2)\n",
    "#in position-3 R1+R2+R3 is in shunt with Rm\n",
    "#R1+R2+R3=0.05............(3)\n",
    "#from.....(3)\n",
    "#R1+R2=0.05-R3\n",
    "#substituting in........(2)\n",
    "#calculations\n",
    "R3=0.04/1.0002\n",
    "#R2=0.01-R1........(4)\n",
    "#substituing in (1)\n",
    "R1=5.00139*10**-3/1.0001\n",
    "R2=0.01-R1#from........(4)\n",
    "#results\n",
    "print\"various sections of aryton shunt are\\n\"\n",
    "print\"full scale deflection Im (mA) = \",Im*1000.\n",
    "print\"meter resistance Rm (ohm) = \",Rm\n",
    "print\"R1 (ohm) = \",round(R1,3)\n",
    "print\"R2 (ohm) = \",round(R2,3)\n",
    "print\"R3 (ohm) = \",round(R3,5)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7 - pg 7_30"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "multiplier resistance (kohm) =  249.5\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_7,pg 7-30\n",
    "#calculate the multiplier resistance\n",
    "#given\n",
    "Rm=500.\n",
    "Im=40*10**-6\n",
    "V=10\n",
    "#calculations\n",
    "Rs=(V/Im)-Rm\n",
    "#results\n",
    "print\"multiplier resistance (kohm) = \",Rs/1000.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 8 - pg 7_30"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "required shunt resistance (ohm) =  0.001\n",
      "required multipler resistance (kohm) =  24.99\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_8,pg 7-30\n",
    "#calculate the required shunt and multipler resistances\n",
    "#given\n",
    "Im=20*10**-3\n",
    "Vm=200*10**-3\n",
    "I=200\n",
    "#calculations\n",
    "Rm=(Vm/Im)\n",
    "Rsh=(Im*Rm)/(I-Im)\n",
    "V=500.\n",
    "Rs=(V/Im)-Rm\n",
    "#results\n",
    "print\"required shunt resistance (ohm) = \",round(Rsh,3)\n",
    "print\"required multipler resistance (kohm) = \",Rs/1000.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 9 - pg 7_33"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "series string of multipliers\n",
      "R1 (kohm) =  200.0\n",
      "R2 (kohm) =  25.0\n",
      "R3 (kohm) =  20.0\n",
      "R4 (kohm) =  4.95\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_9,pg 7-33\n",
    "#calculate the series string of multiplers\n",
    "#given\n",
    "Rm=50\n",
    "Im=2*10**-3\n",
    "#calculations\n",
    "#for position V4 multipler is R4\n",
    "V4=10.\n",
    "R4=(V4/Im)-Rm#Rs=(V/Im)-RmV3 m\n",
    "#for position V3 multipler is R3+R4\n",
    "V3=50.\n",
    "R3=(V3/Im)-Rm-R4\n",
    "#for position V2 multiplier is R2+R3+R4\n",
    "V2=100.\n",
    "R2=(V2/Im)-Rm-R3-R4\n",
    "#for position V1 multiplier is R1+R2+R3+R4\n",
    "V1=500.\n",
    "R1=(V1/Im)-Rm-R3-R4-R2\n",
    "#results\n",
    "print\"series string of multipliers\"\n",
    "print\"R1 (kohm) = \",R1/1000.\n",
    "print\"R2 (kohm) = \",R2/1000.\n",
    "print\"R3 (kohm) = \",R3/1000.\n",
    "print\"R4 (kohm) = \",R4/1000.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10 - pg 7_35"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "series string of multipliers\n",
      "R1 (ohm) =  200.0\n",
      "R2 (ohm) =  25.0\n",
      "R3 (ohm) =  20.0\n",
      "R4 (ohm) =  4.95\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_10,pg 7-35\n",
    "#calculate the series string of multipliers\n",
    "#given\n",
    "Rm=50\n",
    "Im=2*10**-3\n",
    "V1=500.\n",
    "V2=100.\n",
    "V3=50.\n",
    "V4=10.\n",
    "#calculations\n",
    "S=1/Im#senstivity\n",
    "R4=S*V4-Rm\n",
    "R3=S*V3-(R4+Rm)\n",
    "R2=S*V2-(R4+Rm+R3)\n",
    "R1=S*V1-(R4+Rm+R3+R2)\n",
    "#results\n",
    "print\"series string of multipliers\"\n",
    "print\"R1 (ohm) = \",R1/1000.\n",
    "print\"R2 (ohm) = \",R2/1000.\n",
    "print\"R3 (ohm) = \",R3/1000.\n",
    "print\"R4 (ohm) = \",R4/1000.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11 - pg 7_36"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "multipler resistance (Mohm) =  9.9998\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_11,pg 7-36\n",
    "#calculate the multipler resistance\n",
    "#given\n",
    "Im=50*10**-6\n",
    "Rm=200.\n",
    "V=500.#V is voltage range\n",
    "#calculations\n",
    "S=1/Im\n",
    "Rs=S*V-Rm\n",
    "#results\n",
    "print\"multipler resistance (Mohm) = \",round(Rs/10**6,4)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 12 - pg 7_36"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "senstivity of meter A (ohm/volt) =  260.0\n",
      "senstivity of meter B (ohm/volt) =  151.0\n",
      "Meter A is more sensitive than meter B\n"
     ]
    }
   ],
   "source": [
    "#calculate the senstivity of meters A and B\n",
    "#Chapter-7,Example7_12,pg 7-36\n",
    "#given\n",
    "#for meter A\n",
    "Rs=25.*10**3\n",
    "Rm=1.*10**3\n",
    "V=100.\n",
    "#calculations\n",
    "S=(Rs+Rm)/V\n",
    "#for meter B\n",
    "Rs=150.*10**3\n",
    "Rm=1.*10**3\n",
    "V=1000.\n",
    "S2=(Rs+Rm)/V\n",
    "#results\n",
    "print\"senstivity of meter A (ohm/volt) = \",S\n",
    "print\"senstivity of meter B (ohm/volt) = \",S2\n",
    "print 'Meter A is more sensitive than meter B'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 13 - pg 7-37"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "first voltmeter reading (V) =  120.97\n",
      "second voltmeter reading (V) =  137.87\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_13,pg 7-37\n",
    "#calculate the voltmeter readings\n",
    "#given\n",
    "R1=20.*10**3\n",
    "R2=25.*10**3\n",
    "V=250#voltage supply\n",
    "#calculations and results\n",
    "VR2=R2*V/(R1+R2)#voltage across R2\n",
    "#case-1\n",
    "S=500\n",
    "Vr=150#voltage range of resistor\n",
    "Rv=S*Vr\n",
    "Req=R2*Rv/(R2+Rv)\n",
    "VReq=Req*V/(Req+R1)#voltage across Req\n",
    "print\"first voltmeter reading (V) = \",round(VReq,2)\n",
    "#case-2\n",
    "S=10*10**3\n",
    "Rv=S*Vr\n",
    "Req=R2*Rv/(R2+Rv)\n",
    "VReq=Req*V/(Req+R1)\n",
    "print\"second voltmeter reading (V) = \",round(VReq,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 14 - pg 7_38"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "true voltage (V) =  4.167\n",
      "voltmeter reading case-1 (V) =  3.571\n",
      "percentage error (percent) =  14.3\n",
      "percentage accuracy =  85.7\n",
      "voltmeter reading case-2 (V) =  4.132\n",
      "percentage error (percent) =  0.83\n",
      "percentage accuracy =  99.17\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_14,pg 7-38\n",
    "#calculate the voltmeter reading case and percentage error,accuracy\n",
    "#given\n",
    "Rb=1.*10**3\n",
    "Ra=5.*10**3\n",
    "V=25.\n",
    "#calculations and results\n",
    "VRb=Rb*V/(Ra+Rb)#voltage across Rb\n",
    "Vr=5.\n",
    "#case-1\n",
    "S=1.*10**3\n",
    "Rv=S*Vr\n",
    "Req=Rb*Rv/(Rb+Rv)\n",
    "VReq=Req*V/(Req+Ra)\n",
    "err=(VRb-VReq)*100/VRb\n",
    "acc=100-err\n",
    "print \"true voltage (V) = \",round(VRb,3)\n",
    "print\"voltmeter reading case-1 (V) = \",round(VReq,3)\n",
    "print\"percentage error (percent) = \",round(err,1)\n",
    "print\"percentage accuracy = \",round(acc,1)\n",
    "#case-2\n",
    "S=20*10**3\n",
    "Rv=S*Vr\n",
    "Req=Rb*Rv/(Rb+Rv)\n",
    "VReq=Req*V/(Req+Ra)\n",
    "err=(VRb-VReq)*100/VRb\n",
    "acc=100-err\n",
    "print\"voltmeter reading case-2 (V) = \",round(VReq,3)\n",
    "print\"percentage error (percent) = \",round(err,2)\n",
    "print\"percentage accuracy = \",round(acc,2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 15 - pg 7_41"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "shunt resistance for I=10A (ohm) =  0.1002\n",
      "shunt resistance for I=20A (ohm) =  0.05\n",
      "series resistance for V=150V (kohm) =  7.45\n",
      "series resistance for V=300V (kohm) =  14.95\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_15,pg 7-41\n",
    "#calculate the shunt and series resistances\n",
    "#given\n",
    "Rm=50.\n",
    "Im=20.*10**-3\n",
    "I=10.\n",
    "#calculatiosn and results\n",
    "Rsh=(Im*Rm)/(I-Im)\n",
    "print\"shunt resistance for I=10A (ohm) = \",round(Rsh,4)\n",
    "\n",
    "I=20\n",
    "Rsh=(Im*Rm)/(I-Im)\n",
    "print\"shunt resistance for I=20A (ohm) = \",round(Rsh,2)\n",
    "\n",
    "V=150\n",
    "Rs=(V/Im)-Rm\n",
    "print\"series resistance for V=150V (kohm) = \",round(Rs/1000.,2)\n",
    "\n",
    "V=300\n",
    "Rs=(V/Im)-Rm\n",
    "print\"series resistance for V=300V (kohm) = \",round(Rs/1000.,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 16 - pg 7_42"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "shunt current (A) =  25.0\n",
      "resistance for Ish=10A (ohm) =  400.0\n",
      "resistance for Ish=75A (ohm) =  3000.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_16,pg 7-42\n",
    "#calculate the shunt current,resistance\n",
    "#given\n",
    "Rsh=0.02\n",
    "R=1000.\n",
    "Vm=500.*10**-3\n",
    "#calculations and results\n",
    "Im=Vm/R\n",
    "Ish=Vm/Rsh\n",
    "print\"shunt current (A) = \",Ish\n",
    "Ish1=10.\n",
    "V=Ish1*Rsh\n",
    "R=V/Im\n",
    "print\"resistance for Ish=10A (ohm) = \",R\n",
    "Ish2=75.\n",
    "V=Ish2*Rsh\n",
    "R=V/Im\n",
    "print\"resistance for Ish=75A (ohm) = \",R"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 17 - pg 7_50"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "final inductance (muH) =  4.0528\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_17,pg 7-50\n",
    "#calculate the final inductance\n",
    "#given\n",
    "import math\n",
    "K=5.73*10**-6\n",
    "I=20.\n",
    "theta=110*(math.pi/180)#full scale deflection\n",
    "L=4*10**-6\n",
    "#calculations\n",
    "dtheta=theta#change in theta\n",
    "dm=(theta*K/(I**2))*dtheta#change in inductance\n",
    "Lf=L+dm\n",
    "#results\n",
    "print\"final inductance (muH) = \",round(Lf*10**6,4)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 18 - pg 7_50"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "deflecting torque (muNm) =  0.48296\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_18,pg 7-50\n",
    "#calculate the deflecting torque\n",
    "import math\n",
    "#given\n",
    "I=10*10**-3\n",
    "x=30#deflection\n",
    "#calculations\n",
    "dM=5*math.sin((x+45)*(math.pi/180))*10**-3#diffrentiate M w.r.t x\n",
    "Td=(I**2)*dM#deflecting torque\n",
    "#results\n",
    "print\"deflecting torque (muNm) = \",round(Td*10**6,5)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 19 - pg 7_51"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "difference in readings Vdc=100V (V) =  1.2718\n",
      "difference in readings Vdc=50V (V) =  0.6132\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_19,pg 7-51\n",
    "#calculate the difference in readings\n",
    "import cmath\n",
    "import math\n",
    "#given\n",
    "I=100*10**-3\n",
    "Td=0.8*10**-4\n",
    "dtheta=90*math.pi/180#in radians\n",
    "theta=90#deflection\n",
    "#calculations\n",
    "dM=Td*dtheta/(I**2)\n",
    "Mo=0.5#original M\n",
    "M=Mo+dM#total M\n",
    "#case-1 \n",
    "Vdc=100\n",
    "R=Vdc/I\n",
    "w=2*math.pi*50\n",
    "Z=R+(1j*w*M)\n",
    "Z=abs(Z)\n",
    "Vac=R*Vdc/Z\n",
    "dif=Vdc-Vac#difference between readings\n",
    "#case-2\n",
    "Vdc1=50\n",
    "I1=Vdc1/R\n",
    "theta1=theta*((I1/I)**2)#theta=kI**2\n",
    "theta1=theta1*math.pi/180#in radians\n",
    "dM1=Td*theta1/(I**2)\n",
    "M1=dM1+Mo\n",
    "Z1=R+(1j*w*M1)\n",
    "Z1=abs(Z1)\n",
    "Vac1=R*Vdc1/Z1\n",
    "dif1=Vdc1-Vac1\n",
    "#results\n",
    "print\"difference in readings Vdc=100V (V) = \",round(dif,4)\n",
    "print\"difference in readings Vdc=50V (V) = \",round(dif1,4)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 20 - pg 7_65"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "percentage error =  -2.174\n",
      "negative sign shows that meter is slow and Er<Et\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_20,pg 7-65\n",
    "#calculate the percentage error\n",
    "#given\n",
    "I=20.\n",
    "V=230.\n",
    "Pf=0.8#power factor\n",
    "t=3600.\n",
    "K=100.\n",
    "#calculations\n",
    "Et=V*I*Pf*t\n",
    "Et=Et/(3600*10**3)#in kWh\n",
    "N=360.\n",
    "Er=3.6#in kWh\n",
    "err=(Er-Et)/Et\n",
    "err=err*100\n",
    "#results\n",
    "print\"percentage error = \",round(err,3)\n",
    "print\"negative sign shows that meter is slow and Er<Et\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exampe 21 - pg 7_65"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "percentage error =  0.819\n",
      "positive sign shows that meter is fast and Er>Et\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_21,pg 7-65\n",
    "#calculate the percentage error\n",
    "#given\n",
    "K=1800.\n",
    "V=230.\n",
    "I=10.\n",
    "Pf=1.#half load\n",
    "Ihl=I/2.#half load current\n",
    "t=138.\n",
    "#calculations\n",
    "Et=V*Ihl*Pf*t\n",
    "Et=Et/(3600*10**3)\n",
    "N=80#no. of revolutions\n",
    "Er=N/K#in kWh\n",
    "err=(Er-Et)/Et\n",
    "err=err*100\n",
    "#results\n",
    "print\"percentage error = \",round(err,3)\n",
    "print\"positive sign shows that meter is fast and Er>Et\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 22 - pg 7_66"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "meter constant (rev/kWh) =  400.0\n",
      "power factor (lagging) =  0.8\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_22,pg 7-66\n",
    "#calculate the meter constant and power factor\n",
    "#given\n",
    "V=230.\n",
    "I=4.\n",
    "t=6.\n",
    "Pf=1.\n",
    "N=2208.\n",
    "#calculations\n",
    "Et=V*I*Pf*t\n",
    "K=N/Et\n",
    "V=230\n",
    "I=5\n",
    "t=4\n",
    "N=1472\n",
    "Et=V*I*Pf*t\n",
    "Er=N/K\n",
    "Pf=(Er/Et)\n",
    "#results\n",
    "print\"meter constant (rev/kWh) = \",K*1000\n",
    "print\"power factor (lagging) = \",Pf\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 23 - pg 7_66"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "speed of disc (rpm) =  60.04\n",
      "percentage error =  0.77\n",
      "Er>Et meter is fast\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_23,pg 7-66\n",
    "#calculate the speed of disc and percentage error\n",
    "#given\n",
    "I=5.\n",
    "V=220.\n",
    "Pf=1.\n",
    "K=3275.\n",
    "t=1/60.#in hr\n",
    "#calculations\n",
    "E=V*I*Pf*t\n",
    "E=E/10**3#in kWh\n",
    "Rev=E*K#no. of revolutions\n",
    "#at half load\n",
    "I=I/2\n",
    "t=59.5\n",
    "Et=V*I*Pf*t\n",
    "Et=Et/(3600*10**3)#in kWh\n",
    "N=30\n",
    "Er=N/K\n",
    "err=(Er-Et)/Et\n",
    "err=err*100.\n",
    "print\"speed of disc (rpm) = \",round(Rev,2)\n",
    "print\"percentage error = \",round(err,2)\n",
    "print\"Er>Et meter is fast\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 24 - pg 7_67"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in case 1, percentage error in case-1 =  -0.2436\n",
      "speed of disc (rpm) =  19.2\n",
      "in case 2, percentage error in case-2 =  -12.326\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_24,pg 7-67\n",
    "#calculate the speed and percentage error\n",
    "import math\n",
    "from math import cos,sin\n",
    "#given\n",
    "V=240.\n",
    "I=10.\n",
    "Pf=0.8\n",
    "t=1/60.\n",
    "K=600.\n",
    "#calculations\n",
    "E=V*I*Pf*t\n",
    "E=E/10**3#in kWh\n",
    "Rev=E*K#no. of revolutions \n",
    "dela=90#for correct lag adjustment\n",
    "dela1=86*math.pi/180#given in radian\n",
    "phi=0#case-1 unity power factor\n",
    "err=(sin(dela1-phi)-cos(phi))/cos(phi)\n",
    "err=err*100\n",
    "print\"in case 1, percentage error in case-1 = \",round(err,4)\n",
    "Pf=0.5#case-2\n",
    "phi=60*math.pi/180#in radians\n",
    "err=(sin(dela1-phi)-cos(phi))/cos(phi)\n",
    "err=err*100\n",
    "print\"speed of disc (rpm) = \",Rev\n",
    "print\"in case 2, percentage error in case-2 = \",round(err,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 25 - pg 7_67"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "percentage error upperlimt =  0.07\n",
      "percentage error lowerlimt =  0.331\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_25,pg 7-67\n",
    "#calculate the percentage error upperlimt and lowerlimt\n",
    "#given\n",
    "V=240.\n",
    "I=5.\n",
    "K=1200.\n",
    "N=40.\n",
    "t=99.8\n",
    "Td=500#total divisions\n",
    "#calculations\n",
    "Er=N/K\n",
    "W=V*I\n",
    "div=K/Td#1 division\n",
    "We=0.1*div#wattmeter error\n",
    "Ce=0.05*K/100#construction wattmeter error\n",
    "Te=We+Ce#total error\n",
    "Wru=K+Te\n",
    "Wrl=K-Te#wattmeter reading limits\n",
    "He=0.05#human error\n",
    "Se=0.01#stopwatch error\n",
    "Tte=He+Se#total timing error\n",
    "Sru=t+Tte#stopwatch reading limits\n",
    "Srl=t-Tte\n",
    "Eu=Wru*Sru*1/(3600*10**3)#energy obtained limits\n",
    "El=Wrl*Srl*1/(3600*10**3)\n",
    "errl=(Er-El)/El\n",
    "errl=errl*100\n",
    "erru=(Er-Eu)/Eu#error limits\n",
    "erru=erru*100\n",
    "#results\n",
    "print\"percentage error upperlimt = \",round(erru,3)\n",
    "print\"percentage error lowerlimt = \",round(errl,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 26 - pg 7_79"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "line current (A) =  135.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_26,pg 7-79\n",
    "#calculate the line current\n",
    "#given\n",
    "I1=250.\n",
    "I2=5.\n",
    "#calculations\n",
    "I=I1/I2\n",
    "#as ammeter is in secondary I2=2.7\n",
    "I1=I*2.7#line current\n",
    "#results\n",
    "print\"line current (A) = \",I1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 27 - pg 7_82"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "line voltage (V) =  8750.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_27,pg 7-82\n",
    "#calculate the line voltage\n",
    "#given\n",
    "V1=11000.\n",
    "V2=110.\n",
    "#calculations\n",
    "V=V1/V2\n",
    "V2=87.5\n",
    "V1=87.5*V#line voltage\n",
    "#results\n",
    "print\"line voltage (V) = \",V1\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 28 - pg 7_88"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "percentage ratio error =  -3.66\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_28,pg 7-88\n",
    "#calculate the percentage ratio error\n",
    "#given\n",
    "Im=120.\n",
    "Ic=38.\n",
    "Kn=1000./5 #at full load\n",
    "Is=5.\n",
    "Ns=1000.\n",
    "Np=5.\n",
    "#calculations\n",
    "n=Ns/Np#turns ratio\n",
    "R=n+(Ic/Is)\n",
    "err=(Kn-R)/R#ratio error\n",
    "err=err*100.\n",
    "#results\n",
    "print\"percentage ratio error = \",round(err,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 29 - pg 7_88"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "percentage ratio error =  -3.734\n"
     ]
    }
   ],
   "source": [
    "#Chapter-7,Example7_29,pg 7-88\n",
    "#calculate the percentage ratio error\n",
    "#given\n",
    "import math\n",
    "Im=90.\n",
    "Ic=40.\n",
    "delta=28*(math.pi/180)#in radians\n",
    "Is=5.\n",
    "Ns=400.\n",
    "Np=1.\n",
    "#calculations\n",
    "n=Ns/Np\n",
    "Kn=n\n",
    "R=n+((Im*math.sin(delta)+Ic*math.cos(delta))/Is)\n",
    "Ip=R*Is#actual primary current\n",
    "err=(Kn-R)/R\n",
    "err=err*100\n",
    "#results\n",
    "print\"percentage ratio error = \",round(err,3)\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
}