{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 15: Alternating Voltages and Currents"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 15.1, Page 305"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reactance, Xl = 1 Ohm\n"
     ]
    }
   ],
   "source": [
    "#Initialisation\n",
    "w=1000                 #Angular Frequency       \n",
    "L=10**-3               #Inductance\n",
    "\n",
    "#Calculation\n",
    "Xl=w*L                 #Reactance\n",
    "\n",
    "#Result\n",
    "print'Reactance, Xl = %d Ohm'%Xl"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 15.2, Page 305"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reactance, Xl = 1.59 KOhm\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Initialisation\n",
    "f=50                   #frequency\n",
    "C=2*10**-6             #Capacitance\n",
    "\n",
    "#Calculation\n",
    "w=2*math.pi*f                 #Angular Frequency  \n",
    "Xc=1/(w*C)                 #Reactance\n",
    "\n",
    "#Result\n",
    "print'Reactance, Xl = %.2f KOhm'%(Xc/1000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 15.3, Page 306"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Peak Current, IL = 318 mA\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Initialisation\n",
    "f=100                  #frequency\n",
    "l=25*10**-3               #Inductance\n",
    "Vl=5                    #AC Voltage (Sine)\n",
    "\n",
    "#Calculation\n",
    "w=2*math.pi*f                 #Angular Frequency  \n",
    "Xl=w*l                 #Reactance\n",
    "Il=Vl*Xl**-1\n",
    "\n",
    "#Result\n",
    "print'Peak Current, IL = %d mA'%(Il*10**3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 15.4, Page 306"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Voltage appear across the capacitor, V = 8 V r.m.s\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Initialisation\n",
    "Ic=2                 #sinusoidal Current\n",
    "C=10*10**-3          #Capacitance\n",
    "w=25                 #Angular Frequency  \n",
    "\n",
    "\n",
    "\n",
    "#Calculation \n",
    "Xc=1/(w*C)                 #Reactance\n",
    "Vc= Ic*Xc                   #Voltage\n",
    "\n",
    "#Result\n",
    "print'Voltage appear across the capacitor, V = %d V r.m.s'%(Vc)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 15.5, Page 309"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(a) V = 63.6 V\n",
      "(b) V = 38.15 V\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Initialisation\n",
    "I=5                   #sinusoidal Current\n",
    "R=10                  #Resistance in Ohm\n",
    "f=50                  #Frequency in Hertz\n",
    "L=0.025               #Inductancec in Henry\n",
    " \n",
    "\n",
    "#Calculation \n",
    "Vr=I*R                         #Voltage across resistor\n",
    "Xl=2*math.pi*f*L               #Reactance\n",
    "VL= I*Xl                       #Voltage across inductor\n",
    "V=math.sqrt((Vr**2)+(VL**2))   #total voltage\n",
    "phi=math.atan(VL*Vr**-1)       #Phase Angle in radians\n",
    "\n",
    "#Result\n",
    "print'(a) V = %.1f V'%(V)\n",
    "print'(b) V = %.2f V'%(phi*180/math.pi)         #phase angle in degree"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 15.6, Page 311"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(a) Current, I = 884 uA\n",
      "(b) V = -27.95 V\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Initialisation\n",
    "R=10**4                  #Resistance in Ohm\n",
    "f=10**3                  #Frequency in Hertz\n",
    "C=3*10**-8               #Capacitance in Farad\n",
    "V=10                     #Voltage\n",
    "\n",
    "#Calculation \n",
    "Xc=1/(2*math.pi*f*C)                #Reactance\n",
    "a=((10**4)**2)+(5.3*10**3)**2\n",
    "I=math.sqrt((V**2)/a)               #Current in Amp\n",
    "Vr=I*R                            #Voltage\n",
    "Vc=Xc*I                            #Voltage\n",
    "phi=math.atan(Vc/Vr)       #Phase Angle in radians\n",
    "\n",
    "#Result\n",
    "print'(a) Current, I = %d uA'%round(I*10**6)\n",
    "print'(b) V = %.2f V'%(-phi*180/math.pi)         #phase angle in degree"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 15.7, Page 317"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Z = 200 + j 62 Ohms\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Initialisation\n",
    "I=5                   #sinusoidal Current\n",
    "R=200                  #Resistance in Ohm\n",
    "f=50                  #Frequency in Hertz\n",
    "L=400*10**-3               #Inductancec in Henry\n",
    "C=50*10**-6               #Capacitance in Henry \n",
    "\n",
    "#Calculation \n",
    "Vr=I*R                         #Voltage across resistor\n",
    "Xl=2*math.pi*f*L               #Reactance\n",
    "Xc=1/(2*math.pi*f*C)                #Reactance\n",
    "i=Xl-Xc\n",
    "\n",
    "#Result\n",
    "print'Z = %d + j %d Ohms'%(R,i)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 15.8, Page 320"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "vo = 12.4 < 29.7\n",
      "Therefore\n",
      "vo = 12.4 sin(500 t + 29.7)\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from numpy import ones\n",
    "\n",
    "#Initialisation\n",
    "R1=5                  #Resistance in Ohm\n",
    "R2=50                  #Resistance in Ohm\n",
    "w=500                  #rad/s\n",
    "L=50*10**-3               #Inductancec in Henry\n",
    "C=200*10**-6               #Capacitance in Henry \n",
    "v=10\n",
    "\n",
    "#Calculation\n",
    "Xc=1/(w*C)                              #Reactance\n",
    "Z1=complex(R1,-Xc)                      #taking in complex form\n",
    "a=(R2*w**2*L**2)/(R2**2+(w**2*L**2))\n",
    "b=(R2**2*w*L)/(R2**2+(w**2*L**2))\n",
    "Z2=complex(a,b)                         #taking in complex form\n",
    "Z3=(Z1+Z2)\n",
    "Z=Z2/Z3\n",
    "r=math.sqrt((Z.real)**2 + (Z.imag)**2)   #converting in polar (absolute)\n",
    "r1=v*r \n",
    "phi=math.atan(Z.imag/Z.real)             #converting in polar (phase)\n",
    "\n",
    "#Result\n",
    "print'vo = %.1f < %.1f'%(r1,(phi*180/math.pi))\n",
    "print'Therefore'\n",
    "print'vo = %.1f sin(%d t + %.1f)'%(r1,w,(phi*180/math.pi))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [Root]",
   "language": "python",
   "name": "Python [Root]"
  },
  "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.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}