{
 "metadata": {
  "name": "",
  "signature": "sha256:b9d1caf08ce2c756df19d01d96849c688c97e2ec4dcb3d504ac57e0fbe14e7ea"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 9 : Higher order circuits and Complex frequency"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.6  Page No : 151"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "#Example 9.6\")\n",
      "\n",
      "# Given\n",
      "#resistance is 10ohm and inducmath.tance is 2H\")\n",
      "#Applied voltage is 10*exp(-2*t)*math.cos(10*t+30)\")\n",
      "#s = %s;\n",
      "#For a RL circuit\n",
      "#Applying KVL equation \n",
      "#v = i*R+L*d/dt(i)    (1)\n",
      "#As v = 10(30 deg)    (2)\n",
      "#Equating (1) and (2) \n",
      "# Let i = I*exp(s*t)    (3)\n",
      "# 10(30 deg)*exp(s*t) = 10*I*exp(s*t)+2*s*I*exp(s*t)\")\n",
      "#Solving for I\n",
      "#I = 10(30 deg)/10+2*s\")\n",
      "s = -2+1j*10\n",
      "a = 10+2*s\n",
      "x = 10*math.cos((30*math.pi)/180);\n",
      "y = 10*math.sin((30*math.pi)/180);\n",
      "z = complex(x,y)\n",
      "I = z/a\n",
      "b = I.real\n",
      "c = I.imag\n",
      "magn = math.sqrt(b**2+c**2)\n",
      "ph = (math.atan(c/b)*180)/math.pi\n",
      "#From (3)\n",
      "print \"i = %0.2f*exp-2*t)*math.cos10t%3.1f deg) A)\"%(magn,ph);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "i = 0.48*exp-2*t)*math.cos10t-43.3 deg) A)\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.7  Page No : 156"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "#Example 9.7\")\n",
      "\n",
      "# Given\n",
      "#resistance is 10ohm and capacitance is 0.2F\")\n",
      "#Applied voltage is 10*exp(-2*t)*math.cos(10*t+30)\")\n",
      "#s = %s;\n",
      "#For a RC circuit\n",
      "#Applying KVL equation \n",
      "#v = i*R+(1/C)*integrate(i*dt)    (1)\n",
      "#As v = 10(30 deg)    (2)\n",
      "#Equating (1) and (2) \n",
      "# Let i = I*exp(s*t)    (3)\n",
      "# 10(30 deg)*exp(s*t) = 10*I*exp(s*t)+(5/s)*I*exp(s*t)\")\n",
      "#Solving for I\n",
      "#I = 10(30 deg)/10+(5/s)\")\n",
      "s = -2+1j*10\n",
      "a = 10+(5/s)\n",
      "x = 10*math.cos((30*math.pi)/180);\n",
      "y = 10*math.sin((30*math.pi)/180);\n",
      "z = complex(x,y)\n",
      "I = z/a\n",
      "b = I.real\n",
      "c = I.imag\n",
      "magn = math.sqrt(b**2+c**2)\n",
      "ph = (math.atan(c/b)*180)/math.pi\n",
      "#From (3)\n",
      "print \"i = %0.2f*exp-2*t)*math.cos10t+%3.1f deg) A)\"%(magn,ph);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "i = 1.01*exp-2*t)*math.cos10t+32.8 deg) A)\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.8  Page No : 161"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "from numpy import roots\n",
      "from numpy.linalg import solve\n",
      "#Example 9.8\")\n",
      "\n",
      "#s = %s ;\n",
      "\n",
      "#From figure 9.13\n",
      "#Z(s) = (2.5+((5*s/3)*(20/s))/(5*s/3+20/s))\")\n",
      "#On solving\n",
      "z1 = roots([12, 8, 1])\n",
      "z2 = roots([12 ,0, 1])\n",
      "\n",
      "Z = 2.5*(z1/z2)\n",
      "print \"Z(s)\",Z\n",
      "#H(s) = I(s)/Z(s)\n",
      "#Let I(s) = 1 the H(s) = 1/Z(s)\n",
      "H = (1/2.5)*(z2/z1)\n",
      "print \"H(s)\", H"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Z(s) [ 0.+4.33012702j  0.-1.44337567j]\n",
        "H(s) [ 0.-0.23094011j -0.+0.69282032j]\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.9  Page No : 163"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "#Example 9.9\")\n",
      "\n",
      "# Calculation\n",
      "#If s = 1Np/s\n",
      "H1 = 0.4*(1.+12)/((1.+2)*(1+6))\n",
      "\n",
      "# Results\n",
      "print \"H1) = %0.3f\"%(H1)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "H1) = 0.248\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.11  Page No : 166"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "from numpy import roots\n",
      "\n",
      "#From figure 9.16\n",
      "#H(s) = V(s)/I(s) = Z(s)\n",
      "#Let V(s) = 1 the H(s) = Z(s)\n",
      "Z = [(1/2.5),(3/(5)),(s/20)]\n",
      "#Dem = Z('den')\n",
      "#The roots are\n",
      "q = roots(Z)\n",
      "print \"Poles are\", q\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Poles are [ 0.87314228-0.71580545j -0.87314228+0.71580545j]\n"
       ]
      }
     ],
     "prompt_number": 19
    }
   ],
   "metadata": {}
  }
 ]
}