{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 8 - Measurement of Resistance, Inductance & Capacitance"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1 - pg 8_6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "R1 (ohm) =  983.33\n",
      "R2 (ohm) =  25.0\n",
      "change in value R2 (ohm) =  27.027\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_1,pg 8_6\n",
    "#calculate the values of resistances and change in R2\n",
    "#given\n",
    "Rh=1000.\n",
    "Rm=50.\n",
    "V=3.\n",
    "Ifsd=1*10**-3\n",
    "#calculations\n",
    "R1=Rh-(Ifsd*Rm*Rh)/V\n",
    "R2=(Ifsd*Rm*Rh)/(V-Ifsd*Rh)\n",
    "#results\n",
    "print\"R1 (ohm) = \",round(R1,2)\n",
    "print\"R2 (ohm) = \",R2\n",
    "#due to 5% voltage drop\n",
    "V=V-0.05*V\n",
    "R2=(Ifsd*Rm*Rh)/(V-Ifsd*Rh)\n",
    "print\"change in value R2 (ohm) = \",round(R2,3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2 - pg 8_18"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "unknown resistance (kohm) =  25.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_2,pg 8_18\n",
    "#calculate the unknown resistance\n",
    "#given\n",
    "R1=10.*10**3\n",
    "R2=2.*10**3\n",
    "R3=5.*10**3\n",
    "#R4=Rx\n",
    "#calculations\n",
    "R4=(R1*R3)/R2\n",
    "#results\n",
    "print\"unknown resistance (kohm) = \",R4/1000.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3 - pg 8_18"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "current through galvanometer (muA) =  85.65\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_3,pg 8_18\n",
    "#calculate the current\n",
    "#given\n",
    "R1=7.*10**3\n",
    "R2=2.*10**3\n",
    "R3=4.*10**3\n",
    "R4=20.*10**3\n",
    "E=8.\n",
    "Rg=300.\n",
    "#calculations\n",
    "Vth=(E*R4/(R3+R4))-(E*R1 /(R1+R2))#voltage divider rule\n",
    "Req=(R1*R2/(R1+R2))+(R3*R4/(R3+R4))\n",
    "Ig=Vth/(Req+Rg)\n",
    "#results\n",
    "print\"current through galvanometer (muA) = \",round(Ig*10**6,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4 - pg 8_25"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "unknown resistance (muohm) =  199.907\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_4,pg 8_25\n",
    "#calculate the unknown resistance\n",
    "#given\n",
    "R3=100.03*10**-6\n",
    "R2=100.24\n",
    "R1=200.\n",
    "b=100.31\n",
    "a=200.\n",
    "Ry=700*10**-6\n",
    "#calculations\n",
    "Rx=R1*R3/R2\n",
    "Rx=Rx+(b*Ry/(Ry+a+b))*((R1/R2)-(a/b))\n",
    "#results\n",
    "print\"unknown resistance (muohm) = \",round(Rx*10**6,3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5 - pg 8_35"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "unknown impedance (ohm) =  (642.787609687-766.044443119j)\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_5,pg 8_35\n",
    "#calculate the unknown impedance\n",
    "#given\n",
    "import math,cmath\n",
    "Z2=250.\n",
    "Z3=200.\n",
    "Z1=50.\n",
    "theta1=80.\n",
    "theta2=0.\n",
    "theta3=30.\n",
    "#calculations\n",
    "Z4=Z2*Z3/Z1#magnitude condition\n",
    "theta4=theta2+theta3-theta1#angle condition\n",
    "theta4=theta4*math.pi/180#in radians\n",
    "Rx=Z4*math.cos(theta4)#real part\n",
    "Ry=Z4*math.sin(theta4)#imag. part\n",
    "Z4=Rx+1j*Ry\n",
    "#results\n",
    "print\"unknown impedance (ohm) = \",Z4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6 - pg 8_35"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "magl=  1500.0\n",
      "magr=  1500.0\n",
      "lhs=rhs hence,magnitude condition is satisfied \n",
      "thetal=  70.0\n",
      "thetar=  -45.0\n",
      "angle condition is not satisfied \n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_6,pg 8_35\n",
    "#calculate the angles and find if magnitude and angle conditions are satisfied\n",
    "import math\n",
    "from math import sin,cos,sqrt\n",
    "#given\n",
    "Z1=sqrt(((50*cos(40*math.pi/180))**2)+(50*sin(40*math.pi/180))**2)#angle in radians\n",
    "Z2=sqrt(((100*cos(-90*math.pi/180))**2)+(100*sin(-90*math.pi/180))**2)\n",
    "Z3=sqrt(((15*cos(45*math.pi/180))**2)+(15*sin(45*math.pi/180))**2)\n",
    "Z4=sqrt(((30*cos(30*math.pi/180))**2)+(30*sin(30*math.pi/180))**2)\n",
    "#mag(Z1*Z4)=mag(Z2*Z3)....magnitude condition\n",
    "#calculations and results\n",
    "magl=Z1*Z4#lhs\n",
    "magr=Z2*Z3#rhs\n",
    "print\"magl= \",magl\n",
    "print\"magr= \",magr\n",
    "print\"lhs=rhs hence,magnitude condition is satisfied \"\n",
    "theta1=40.\n",
    "theta2=-90.\n",
    "theta3=45.\n",
    "theta4=30.\n",
    "#theta1+theta4=theta2+theta3.......angle condition\n",
    "thetal=theta1+theta4#lhs\n",
    "thetar=theta2+theta3#rhs\n",
    "print\"thetal= \",thetal\n",
    "print\"thetar= \",thetar\n",
    "print\"angle condition is not satisfied \"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7 - pg 8_37"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "equivalent series circuit \n",
      "Rx (Mohm) =  10.0\n",
      "Cx (muF) =  0.12\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_7,pg 8_37\n",
    "#calculate the equivalent series circuit\n",
    "#given\n",
    "C3=10.*10**-6\n",
    "R1=1.2*10**3\n",
    "R2=100.*10**3\n",
    "R3=120.*10**3\n",
    "#calculations\n",
    "Rx=R2*R3/R1\n",
    "Cx=R1*C3/R2\n",
    "#results\n",
    "print\"equivalent series circuit \"\n",
    "print\"Rx (Mohm) = \",Rx/10**6\n",
    "print\"Cx (muF) = \",Cx*10**6\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 8 - pg 8_39"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "equivalent series circuit\n",
      "Rx (Mohm) =  1.25\n",
      "Lx (mH) =  200.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_8,pg 8_39\n",
    "#calculate the equivalent series circuit\n",
    "#given\n",
    "L3=8.*10**-3\n",
    "R1=1.*10**3\n",
    "R2=25.*10**3\n",
    "R3=50.*10**3\n",
    "#calculations\n",
    "Rx=R2*R3/R1\n",
    "Lx=R2*L3/R1\n",
    "#results\n",
    "print\"equivalent series circuit\"\n",
    "print\"Rx (Mohm) = \",Rx/10**6\n",
    "print\"Lx (mH) = \",Lx*1000.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 9 - pg 8_44"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "components of branch RC\n",
      "Rx (ohm) =  175.0\n",
      "Lx (mH) =  105.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_9,pg 8_44\n",
    "#calculate the components of branch\n",
    "#from the bridge\n",
    "#given\n",
    "C1=0.5*10**-6\n",
    "R1=1200.\n",
    "R2=700.\n",
    "R3=300.\n",
    "#calculations\n",
    "Rx=R2*R3/R1\n",
    "Lx=R2*R3*C1\n",
    "#results\n",
    "print\"components of branch RC\"\n",
    "print\"Rx (ohm) = \",Rx\n",
    "print\"Lx (mH) = \",Lx*1000.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10 - pg 8_49"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "unknown inductance and resistance\n",
      "Rx (kohm) =  1.212\n",
      "Lx (mH) =  118.83\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_10,pg 8_49\n",
    "#from hay's balance bridge \n",
    "#given\n",
    "w=1000.\n",
    "R1=5.1*10**3\n",
    "C1=2*10**-6\n",
    "R2=7.9*10**3\n",
    "R3=790.\n",
    "#calculations\n",
    "Rx=((w**2)*R1*(C1**2)*R2*R3)/(1+((w**2)*(R1**2)*(C1**2)))\n",
    "Lx=R2*R3*C1/(1+((w**2)*(R1**2)*(C1**2)))\n",
    "#results\n",
    "print\"unknown inductance and resistance\"\n",
    "print\"Rx (kohm) = \",round(Rx/1000.,3)\n",
    "print\"Lx (mH) = \",round(Lx*1000.,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11 - pg 8_56"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "unknown capacitance and resistance\n",
      "Rx (kohm) =  4.7\n",
      "Cx (muF) =  0.255\n",
      "dissipation factor  3.77\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_11,pg 8_56\n",
    "#calculate the unknown capacitance and resistance\n",
    "#given\n",
    "import math\n",
    "R1=1.2*10**3\n",
    "R2=4.7*10**3\n",
    "C1=1.*10**-6\n",
    "C3=1.*10**-6\n",
    "f=0.5*10**3\n",
    "#calculations\n",
    "w=2*math.pi*f\n",
    "Rx=R2*C1/C3\n",
    "Cx=R1*C3/R2\n",
    "D=w*Cx*Rx\n",
    "#results\n",
    "print\"unknown capacitance and resistance\"\n",
    "print\"Rx (kohm) = \",Rx/1000.\n",
    "print\"Cx (muF) = \",round(Cx*10**6,3)\n",
    "print\"dissipation factor \",round(D,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 12 - pg 8_58"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "deflection of galvanometer (mm) =  71.2674\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_12,pg 58\n",
    "#calculate the deflection of galvanometer\n",
    "#given\n",
    "R1=200.\n",
    "R2=100.\n",
    "R3=1000.\n",
    "R4=200\n",
    "Rg=200.\n",
    "R41=2005.#changed by delR\n",
    "Si=12.#senstivity\n",
    "E=10.\n",
    "#calculations\n",
    "Vth=E*((R41/(R3+R41))-(R1/(R1+R2)))\n",
    "Req=(R1*R2/(R1+R2))+(R3*R41/(R3+R41))\n",
    "Ig=Vth/(Rg+Req)\n",
    "theta=Si*Ig*10**6#deflection of galvanometer(mm)\n",
    "#results\n",
    "print\"deflection of galvanometer (mm) = \",round(theta,4)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 13 - pg 8_59"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "deflection of galvanometer (mm) =  27.412\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_13,pg 59\n",
    "#calculate the deflection of galvanometer\n",
    "#given\n",
    "R1=1000.\n",
    "R2=1000.\n",
    "R3=119.\n",
    "R4=121.\n",
    "Rg=200.\n",
    "S1=1.\n",
    "E=5.\n",
    "#calculations\n",
    "Vth=E*((R4/(R3+R4))-(R1/(R1+R2)))\n",
    "Req=(R1*R2/(R1+R2))+(R3*R4/(R3+R4))\n",
    "Ig=Vth/(Rg+Req)\n",
    "theta=S1*Ig*10**6#deflection of galvanometer(mm)\n",
    "#results\n",
    "print\"deflection of galvanometer (mm) = \",round(theta,3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 14 - pg 8_59"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "current through galvanometer (muA) =  160.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_14,pg 59\n",
    "#calculate the current through galvanometer\n",
    "#given\n",
    "R=500.\n",
    "delR=20.\n",
    "E=10.\n",
    "#calculations\n",
    "Vth=E*delR/(4*R)\n",
    "Req=R\n",
    "Rg=125.\n",
    "Ig=Vth/(Req+Rg)\n",
    "#results\n",
    "print\"current through galvanometer (muA) = \",Ig*10**6\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 15 - pg 8_60"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "change in resistance (muohm) =  200.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_15,pg 60\n",
    "#calculate the change in resistance\n",
    "#given\n",
    "R=1000.\n",
    "E=20.\n",
    "Ig=1*10**-9\n",
    "#calculations\n",
    "Req=R\n",
    "#Ig=Vth/Req......Rg=0\n",
    "delR=Ig*4*R**2/E\n",
    "#results\n",
    "print\"change in resistance (muohm) = \",delR*10**6\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 16 - pg 8_61"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bridge is balanced at 80deg. from graph when Rv=10k\n",
      "\n",
      "error voltage (V) =  -0.2632\n",
      "negative sign indicates opposite polarity of error voltage\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_16,pg 61\n",
    "#calculate the error voltage\n",
    "#R4=Rv\n",
    "#given\n",
    "R1=10.*10**3\n",
    "R2=10.*10**3\n",
    "R3=10.*10**3\n",
    "R4=R1*R3/R2\n",
    "E=10.\n",
    "print\"bridge is balanced at 80deg. from graph when Rv=10k\\n\"\n",
    "#at 60deg bridge is unbalanced \n",
    "R4=9.*10**3\n",
    "#calculations\n",
    "e=E*((R4/(R3+R4))-(R1/(R1+R2)))#thevenin's voltage\n",
    "#results\n",
    "print\"error voltage (V) = \",round(e,4)\n",
    "print\"negative sign indicates opposite polarity of error voltage\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 17 - pg 8_62"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "unbalanced current in galvanometer (mA) =  5.1335\n",
      "resistance for null deflection (ohm) =  40.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_17,pg 8_62\n",
    "#calculate the unbalanced current and resistance\n",
    "#given\n",
    "R1=100.\n",
    "R2=10.\n",
    "R3=4.\n",
    "R4=50.\n",
    "E=10.\n",
    "Rg=20.\n",
    "#calculations\n",
    "Vth=E*((R4/(R3+R4))-(R1/(R1+R2)))\n",
    "Req=(R1*R2/(R1+R2))+(R3*R4/(R3+R4))\n",
    "Ig=Vth/(Rg+Req)\n",
    "#for null deflection\n",
    "R4=R3*R1/R2\n",
    "#results\n",
    "print\"unbalanced current in galvanometer (mA) = \",round(Ig*1000.,4)\n",
    "print\"resistance for null deflection (ohm) = \",R4\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 18 - pg 8_62"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Max. Unknown resistance which can be measured (kohm) = 40.0\n",
      "change in resistance (ohm) =  7.8974\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_18,pg 8_62\n",
    "#calculate the change in resistance\n",
    "#given\n",
    "R1=1000.\n",
    "R2=100.\n",
    "R3=4.*10**3\n",
    "Si=70\n",
    "theta=3*10**-6#deflection\n",
    "E=10\n",
    "Rg=80\n",
    "#calculations\n",
    "R4=R1*R3/R2\n",
    "Rth=(R1*R2/(R1+R2))+(R3*R4/(R3+R4))\n",
    "delR=(theta*(Rth+Rg)*((R3+R4)**2))/(Si*E*R3)\n",
    "#results\n",
    "print\"Max. Unknown resistance which can be measured (kohm) =\",R4/1000. \n",
    "print\"change in resistance (ohm) = \",round(delR,4)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 19 - pg 8_63"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "series resistance (ohm) =  91.0615\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_19,pg 8_63\n",
    "#calculate the series resistance\n",
    "#given\n",
    "import math\n",
    "P=0.4\n",
    "Rarm=150.#resistance in each arm\n",
    "I=math.sqrt(P/Rarm)#P=(I**2)*R\n",
    "#applying KVL to loop ABCEFA\n",
    "r=1.\n",
    "E=25.\n",
    "R=(-I*Rarm-I*Rarm+E-2*I*r)/(2*I)\n",
    "#results\n",
    "print\"series resistance (ohm) = \",round(R,4)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 20 - pg 8_63"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "unknown resistance (ohm) =  0.0167\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_20,pg 8_63\n",
    "#calculate the unknown resistance\n",
    "#given\n",
    "R1=10.\n",
    "R2=R1/0.5#given\n",
    "Rba=1./1200#Rb/Ra\n",
    "#calculations\n",
    "Rx=R2*Rba\n",
    "#results\n",
    "print\"unknown resistance (ohm) = \",round(Rx,4)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 21 - pg 8_64"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "unknown resistance (ohm) =  34.31\n",
      "unknown inductance (mH) =  29.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_21,pg 8_64\n",
    "#calculate the unknown resistance and inductance\n",
    "import math\n",
    "import cmath\n",
    "#given\n",
    "w=2*math.pi*1000.\n",
    "C1=0.2*10**-6\n",
    "R2=500.\n",
    "R3=300.\n",
    "C3=0.1*10**-6\n",
    "#calculations\n",
    "Z4=(1j*w*C1*R2)/((1/R3)+(1j*w*C3))#from basic balance equaton\n",
    "Zx=Z4#unknown impedance\n",
    "Rx=Zx.real\n",
    "Xl=Zx.imag\n",
    "Lx=Xl/w#Xl=w*Lx\n",
    "#results\n",
    "print\"unknown resistance (ohm) = \",round(Rx,2)\n",
    "print\"unknown inductance (mH) = \",round(Lx*1000.,0)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 22 - pg 8_67"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "unknown impedance (ohm) =  (248.899013631-583.56812467j)\n",
      "The answer given in textbook is wrong\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_22,pg 8_67\n",
    "#calculate the unknown impedance\n",
    "import math,cmath\n",
    "#given\n",
    "Z1=300.\n",
    "R2=200.\n",
    "w=2*math.pi*10**3\n",
    "C2=5.*10**-6\n",
    "#calculations\n",
    "Z2=R2-1j*(1./(w*C2))\n",
    "R3=500.\n",
    "C3=0.2*10**-6\n",
    "Z3=R3-1j*(1./(w*C3))\n",
    "Z4=Z2*Z3/Z1#balance equation\n",
    "Zx=Z4\n",
    "#results\n",
    "print \"unknown impedance (ohm) = \",Z4\n",
    "print \"The answer given in textbook is wrong\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 23 - pg 8_67"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "unknown resistance (kohm) =  500.0\n",
      "unknown capacitance (muF) =  20.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_23,pg 8_67\n",
    "#calculate the unknown resistance and capacitance\n",
    "#given\n",
    "import math,cmath\n",
    "Z1=10.*10**3\n",
    "Z2=50.*10**3\n",
    "w=2*math.pi*2*10**3\n",
    "C3=100.*10**-6\n",
    "R3=100.*10**3\n",
    "#calculations\n",
    "Z3=R3-1j*(1/(w*C3))\n",
    "Z4=Z2*Z3/Z1\n",
    "Zx=Z4\n",
    "Rx=Zx.real\n",
    "Xc=-Zx.imag\n",
    "Cx=1./(Xc*w)\n",
    "#results\n",
    "print\"unknown resistance (kohm) = \",Rx/1000.\n",
    "print\"unknown capacitance (muF) = \",Cx*10**6\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 24 - pg 8_68"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "arm-1 resistance (ohm) =  0.3649\n",
      "arm-1 capacitance (muF) =  7.125\n",
      "dissipation factor =  0.007351\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_24,pg 8_68\n",
    "#calculate the resistance,capacitance and dissipation factor\n",
    "#given\n",
    "import math,cmath\n",
    "R2=4.8\n",
    "r2=0.4\n",
    "w=2*math.pi*450\n",
    "C2=0.5*10**-6\n",
    "#calculations\n",
    "Z2=R2+r2-1j*(1/(w*C2))\n",
    "Z3=200.\n",
    "Z4=2850.\n",
    "#I1*Z1=I2*Z2........null deflection detector\n",
    "Z1=Z2*Z3/Z4\n",
    "R1=Z1.real\n",
    "Xc1=-Z1.imag\n",
    "C1=1./(w*Xc1)\n",
    "D=w*R1*C1#dissipation factor\n",
    "#results\n",
    "print\"arm-1 resistance (ohm) = \",round(R1,4)\n",
    "print\"arm-1 capacitance (muF) = \",round(C1*10**6,3)\n",
    "print\"dissipation factor = \",round(D,6)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 25 - pg 8_70"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "resistance of arm AB (ohm) =  74.074\n",
      "inductance of arm AB (mH) =  8.42\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_25,pg 8_70\n",
    "#calculate the resistance and inductance\n",
    "#given\n",
    "import math,cmath\n",
    "R2=842.\n",
    "w=2*math.pi*10**3\n",
    "C2=0.135*10**-6\n",
    "Z2=R2-1j*(1/(w*C2))\n",
    "Z3=10\n",
    "C4=10**-6\n",
    "#calculations\n",
    "Z4=-1j*(1/(w*C4))\n",
    "Z1=Z2*Z3/Z4\n",
    "R1=Z1.real\n",
    "Xl1=Z1.imag\n",
    "L1=Xl1/w\n",
    "#results\n",
    "print\"resistance of arm AB (ohm) = \",round(R1,3)\n",
    "print\"inductance of arm AB (mH) = \",round(L1*1000.,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 8_26 - pg 8_71"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "inductance of branch-CD (mH) =  47.8\n",
      "resistance of branch-CD (ohm) =  31.34\n",
      "The value of L2 is wrong in textbook\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_26,pg 8_71\n",
    "#calculate the inductance and resistance\n",
    "#given\n",
    "#balance is obtained when\n",
    "L1=47.8*10**-3\n",
    "R1=1.36\n",
    "#calculations\n",
    "#at balance 100(r1+jwL1)=100((R2+r2)+jwL2)\n",
    "L2=L1\n",
    "r1=32.7\n",
    "r2=r1-R1\n",
    "#results\n",
    "print\"inductance of branch-CD (mH) = \",L2*1000.\n",
    "print\"resistance of branch-CD (ohm) = \",r2\n",
    "print \"The value of L2 is wrong in textbook\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 8_27 - pg 8_72"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "limiting range of R4\n",
      "upper limit (ohm) =  230.115\n",
      "lower limit (ohm) =  229.885\n"
     ]
    }
   ],
   "source": [
    "#Chapter-8,Example8_27,pg 8_72\n",
    "#calculate the upper and lower limits of R4\n",
    "#given\n",
    "R1=100.\n",
    "R2=100.\n",
    "R3=230.\n",
    "#calculations\n",
    "R4=R1*R3/R2\n",
    "lerrR1=0.02/100\n",
    "lerrR3=0.01/100\n",
    "lerrR2=0.02/100#lerrR........limiting error in R\n",
    "lerrR4=lerrR1+lerrR3+lerrR2\n",
    "R4u=R4+lerrR4*R4\n",
    "R4l=R4-lerrR4*R4#limiting ranges of R4\n",
    "#results\n",
    "print\"limiting range of R4\"\n",
    "print\"upper limit (ohm) = \",R4u\n",
    "print\"lower limit (ohm) = \",R4l\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
}