{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 1 - Electronic Voltmeters"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1 - pg 1_17"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "required multiplier resistance (kohm) =  4.3\n"
     ]
    }
   ],
   "source": [
    "#Chapter-1,Example1_1,pg 1_17\n",
    "#calculate the required multiplier resistance\n",
    "import math\n",
    "#given\n",
    "Erms=10.\n",
    "Rm=200\n",
    "#calculations\n",
    "Ep=math.sqrt(2)*Erms\n",
    "Eav=0.6*Ep\n",
    "E=Eav/2.\n",
    "Edc=0.45*Erms\n",
    "Idc=1*10**-3\n",
    "Rs=(Edc/Idc)-Rm\n",
    "#results\n",
    "print\"required multiplier resistance (kohm) = \",Rs/1000."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2 - pg 1_18"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "required multiplier resistance(kohm) =  4.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-1,Example1_2,pg 1_18\n",
    "#calculate the required multiplier resistance\n",
    "#given\n",
    "Eav=9.\n",
    "Erms=10.\n",
    "Rm=500.\n",
    "Idc=2*10**-3\n",
    "#calculations\n",
    "Edc=0.9*Erms\n",
    "Rs=(Edc/Idc)-Rm\n",
    "#results\n",
    "print \"required multiplier resistance(kohm) = \",Rs/1000.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3 - pg 1_20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "percentage error =  -11.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-1,Example1_3,pg 1_20\n",
    "#calculate the percentage error\n",
    "#given\n",
    "Kf=1#Erms=Em for 1 time period\n",
    "Kf1=1.11#Kf(sine)/Kf(square)\n",
    "#calculations\n",
    "pere=(Kf-Kf1)/Kf*100.#percentage error\n",
    "#results\n",
    "print\"percentage error = \",pere\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4 - pg 1_20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "percentage error (percent) =  3.87\n"
     ]
    }
   ],
   "source": [
    "#Chapter-1,Example1_4,pg 1_20\n",
    "#calculate the percentage error\n",
    "import math\n",
    "import scipy\n",
    "from scipy import integrate\n",
    "#given\n",
    "A=50.\n",
    "T=2.\n",
    "Kf2=1.11\n",
    "#calculations\n",
    "def f(t):\n",
    "\tE=(50*t)**2#e=At(ramp function)\n",
    "\treturn E\n",
    "\n",
    "\n",
    "I=scipy.integrate.quad(f,0,T)\n",
    "\n",
    "Erms=math.sqrt((1./T)*I[0])\n",
    "def f1(t):\n",
    "\te=50*t#e=At(ramp function)\n",
    "\treturn e\n",
    "\n",
    "\n",
    "I1=scipy.integrate.quad(f1,0,T)\n",
    "Eav=(1./T)*I1[0]\n",
    "Kf=Erms/Eav\n",
    "kfr=Kf2/Kf #Kf(sine)/Kf(sawtooth)\n",
    "pere=(1-kfr)/1*100#percentage error\n",
    "#results\n",
    "print\"percentage error (percent) = \",round(pere,2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5 - pg 1_27"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total meter resistance (ohm) =  6100.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-1,Example1_5,pg 1_27\n",
    "#calculate the total meter resistance\n",
    "#given\n",
    "Idc=25*10**-3\n",
    "Erms=200.\n",
    "Rm=100.\n",
    "Rf=500.\n",
    "#calculations\n",
    "Rd=2*Rf\n",
    "Rm1=Rm+Rd#total meter resistance\n",
    "Rs=(0.9*Erms)/Idc-Rm1\n",
    "#results\n",
    "print \"total meter resistance (ohm) = \",Rs\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6 - pg 1_38"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "meter current (mA) =  5.99\n"
     ]
    }
   ],
   "source": [
    "#Chapter-1,Example1_6,pg 1_38\n",
    "#calculate the meter current\n",
    "#given\n",
    "V1=2.\n",
    "Rm=50.\n",
    "Rd=15.*10**3\n",
    "gm=0.006\n",
    "rd=100*10**3\n",
    "#calculations\n",
    "Im=(gm*rd*Rd/(rd+Rd)*V1)/((2*(rd*Rd/(rd+Rd))+Rm))\n",
    "#results\n",
    "print \"meter current (mA) = \",round(Im*1000.,2)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7 - pg 1_38"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "meter current (mA) =  3.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-1,Example1_7,pg 1_38\n",
    "#calculate the meter current\n",
    "#given\n",
    "V1=1\n",
    "Rm=50\n",
    "Rd=15*10**3\n",
    "gm=0.006\n",
    "rd=100*10**3\n",
    "#calculations\n",
    "Im=(gm*rd*Rd/(rd+Rd)*V1)/((2*(rd*Rd/(rd+Rd))+Rm))\n",
    "#results\n",
    "print \"meter current (mA) = \",round(Im*1000.,1)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 8 - pg 1_39"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "resistance values are\n",
      "R1 (Mohm) =  8.7\n",
      "R2 (kohm) =  120.0\n",
      "R3 (kohm) =  90.0\n",
      "R4 (kohm) =  90.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-1,Example1_8,pg 1_39\n",
    "#calculate the resistance values\n",
    "#given\n",
    "V1=1.\n",
    "Vin=30.\n",
    "Rin=9.*10**6\n",
    "#calcuations\n",
    "R4=Rin/100.#for Vin=100V\n",
    "R3=(Rin-50*R4)/50#for Vin=50V\n",
    "R2=(Rin-30*R3-30*R4)/30#for Vin=30V\n",
    "R1=Rin-R2-R3-R4\n",
    "#results\n",
    "print \"resistance values are\"\n",
    "print \"R1 (Mohm) = \",round(R1/10**6,1)\n",
    "print \"R2 (kohm) = \",round(R2/10**3,1)\n",
    "print \"R3 (kohm) = \",round(R3/10**3,1)\n",
    "print \"R4 (kohm) = \",round(R4/10**3,1)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 9 - pg 1_40"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "current Im (mA) =  0.3896\n",
      "series resistance (kohm) =  7.042\n"
     ]
    }
   ],
   "source": [
    "#Chapter-1,Example1_9,pg 1_40\n",
    "#calculate the current, series resistance\n",
    "#given\n",
    "rd=10*10**3\n",
    "gm=0.003\n",
    "Rs=15*10**3\n",
    "V1=1#input voltage\n",
    "Rm=1800.\n",
    "Img=0.1*10**-3#meter current given\n",
    "#calculations\n",
    "rdf=rd/(1+gm*rd)#actual rd\n",
    "Vo=(gm*rdf*Rs)*V1/(rdf+Rs)\n",
    "Rth=(2*Rs*rdf/(Rs+rdf))\n",
    "Im=Vo/(Rth+Rm)\n",
    "Rf=(Vo/Img)-Rth-Rm#series resistance\n",
    "#results\n",
    "print \"current Im (mA) = \",round(Im*1000.,4)\n",
    "print \"series resistance (kohm) = \",round(Rf/10**3,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10 - pg 1_41"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "calibration resistance (kohm) =  18.4\n"
     ]
    }
   ],
   "source": [
    "#Chapter-1,Example1_10,pg 1_41\n",
    "#calculate the calibration resistance\n",
    "#given\n",
    "rd=200.*10**3\n",
    "gm=0.004\n",
    "Rs=40.*10**3\n",
    "Rm=1000.\n",
    "V1=1\n",
    "#calculations\n",
    "rdf=rd/(1+gm*rd)#actual rd\n",
    "Rth=(2*Rs*rdf/(Rs+rdf))\n",
    "Vo=(gm*rdf*Rs)*V1/(rdf+Rs)\n",
    "Im=50*10**-6\n",
    "Rcal=(Vo/Im)-Rth-Rm#calibration resistance\n",
    "#results\n",
    "print \"calibration resistance (kohm) = \",round(Rcal/1000.,1)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11 - pg 1_42"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Resistances are \n",
      "R1(kohm) =  666.67\n",
      "R2(kohm) =  300.0\n",
      "R3(kohm) =  23.33\n",
      "R4(kohm) =  10.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-1,Example1_11,pg 1_42\n",
    "#calculate the resistances\n",
    "#given\n",
    "Vin=3.\n",
    "V1=1.\n",
    "Rin=1.*10**6#input resistance of FET\n",
    "#calculations\n",
    "R4=Rin/100.#for Vin=100V\n",
    "R3=(Rin-30*R4)/30.#for Vin=30V\n",
    "R2=(Rin-3*R3-3*R4)/3.#for Vin=3V\n",
    "R1=Rin-R2-R3-R4\n",
    "#results\n",
    "print \"Resistances are \"\n",
    "print \"R1(kohm) = \",round(R1/1000.,2)\n",
    "print \"R2(kohm) = \",round(R2/1000.,0)\n",
    "print \"R3(kohm) = \",round(R3/1000.,2)\n",
    "print \"R4(kohm) = \",round(R4/1000.,0)\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
}