{
 "metadata": {
  "name": "",
  "signature": "sha256:f74164c35ff607aa01d36f8c7437d6d39765d83d37afb55e71acad01e24d293a"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h1>Chapter 23: Revision of complex numbers</h1>"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 1, page no. 418</h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from __future__ import division\n",
      "import math\n",
      "import cmath\n",
      "#initializing  the  variables:\n",
      "Z1  =  5  -  3j;\n",
      "Z2  =  4  +  7j;\n",
      "Z3  =  3.9  -  6.7j;\n",
      "\n",
      " #calculation:\n",
      "ZT  =  (Z1*Z2/(Z1  +  Z2))+  Z3\n",
      "y  =  ZT.imag\n",
      "x  =  ZT.real\n",
      "\n",
      "\n",
      "#Results\n",
      "print  \"\\n\\n  Result  \\n\\n\"\n",
      "print  \"\\n  ZT  is  \",round(x,2),\"  +  (\",round(y,2),\")i\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "\n",
        "  Result  \n",
        "\n",
        "\n",
        "\n",
        "  ZT  is   8.65   +  ( -6.26 )i"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 2, page no. 418</h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from __future__ import division\n",
      "import math\n",
      "import cmath\n",
      "#initializing  the  variables:\n",
      "Z1  =  3  +  4j;\n",
      "Z2  =  2  -  5j;\n",
      "\n",
      "#calculation:\n",
      "za  =  1/Z1\n",
      "zb  =  1/Z2\n",
      "zc  =  za  +  zb\n",
      "zd  =  1/zc\n",
      "zax  =  za.real\n",
      "zay  =  za.imag\n",
      "zbx  =  zb.real\n",
      "zby  =  zb.imag\n",
      "zcx  =  zc.real\n",
      "zcy  =  zc.imag\n",
      "zdx  =  zd.real\n",
      "zdy  =  zd.imag\n",
      "\n",
      "\n",
      "#Results\n",
      "print  \"\\n\\n  Result  \\n\\n\"\n",
      "print  \"\\n  (a)1/Z1  is  \",round(  zax,2),\"  +  (\",round(zay,2),\")i\"\n",
      "print  \"\\n  (b)1/Z2  is  \",round(  zbx,2),\"  +  (\",round(zby,2),\")i\"\n",
      "print  \"\\n  (c)1/Z1  +  1/Z2  is  \",round(  zcx,2),\"  +  (\",round(zcy,2),\")i\"\n",
      "print  \"\\n  (d)1/(1/Z1  +  1/Z2)  is  \",round(  zdx,2),\"  +  (\",round(zdy,2),\")i\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "\n",
        "  Result  \n",
        "\n",
        "\n",
        "\n",
        "  (a)1/Z1  is   0.12   +  ( -0.16 )i\n",
        "\n",
        "  (b)1/Z2  is   0.07   +  ( 0.17 )i\n",
        "\n",
        "  (c)1/Z1  +  1/Z2  is   0.19   +  ( 0.01 )i\n",
        "\n",
        "  (d)1/(1/Z1  +  1/Z2)  is   5.27   +  ( -0.35 )i"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 3, page no. 419</h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from __future__ import division\n",
      "import math\n",
      "import cmath\n",
      "#initializing  the  variables:\n",
      "Z1  =  9  -  2j;\n",
      "Z2  =  2  +  1j;\n",
      "Z3  =  -2  +  1j;\n",
      "Z4  =  5  +  2j;\n",
      "\n",
      "#calculation:\n",
      "za  =  Z1/3\n",
      "zb  =  Z2*Z3\n",
      "zca  =  (2*Z4.real  +  Z4.imag)/-1\n",
      "zcb  =  Z4.real  -  zca\n",
      "zaa  =  za.real\n",
      "zab  =  za.imag\n",
      "zbx  =  zb.real\n",
      "zby  =  zb.imag\n",
      "\n",
      "\n",
      "#Results\n",
      "print  \"\\n\\n  Result  \\n\\n\"\n",
      "print  \"\\n  (a)a  and  b  are  \",  zaa,\"  and  \",round(zab,2),\"  resp.\"\n",
      "print  \"\\n  (b)x  and  y  are  \",  zbx,\"  and  \",zby,\"  resp.\"\n",
      "print  \"\\n  (c)a  and  b  are  \",  zca,\"  and  \",zcb,\"  resp.\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "\n",
        "  Result  \n",
        "\n",
        "\n",
        "\n",
        "  (a)a  and  b  are   3.0   and   -0.67   resp.\n",
        "\n",
        "  (b)x  and  y  are   -5.0   and   0.0   resp.\n",
        "\n",
        "  (c)a  and  b  are   -12.0   and   17.0   resp."
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 5, page no. 422</h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from __future__ import division\n",
      "import math\n",
      "import cmath\n",
      "#initializing  the  variables:\n",
      "r  =  5;#  magnitude\n",
      "theta  =  -132;#  in  degree\n",
      "\n",
      "#calculation:\n",
      "x  =  r*math.sin(theta*math.pi/180)\n",
      "y  =  r*math.cos(theta*math.pi/180)\n",
      "z  =  x + y*1j\n",
      "\n",
      "\n",
      "#Results\n",
      "print  \"\\n\\n  Result  \\n\\n\"\n",
      "print  \"\\n  Z  is  \",round(x,2),\"  +  (\",round(y,2),\")i\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "\n",
        "  Result  \n",
        "\n",
        "\n",
        "\n",
        "  Z  is   -3.72   +  ( -3.35 )i"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 6, page no. 422</h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from __future__ import division\n",
      "import math\n",
      "import cmath\n",
      "#initializing  the  variables:\n",
      "r1  =  4.76;#  magnitude\n",
      "theta1  =  35;#  in  degree\n",
      "r2  =  7.36;#  magnitude\n",
      "theta2  =  -48;#  in  degree\n",
      "\n",
      "#calculation:\n",
      "x1  =  r1*cmath.cos(theta1*math.pi/180)\n",
      "y1  =  r1*cmath.sin(theta1*math.pi/180)\n",
      "z1  =  x1 + y1*1j\n",
      "x2  =  r2*cmath.cos(theta2*math.pi/180)\n",
      "y2  =  r2*cmath.sin(theta2*math.pi/180)\n",
      "z2  =  x2 + y2*1j\n",
      "z3  =  z1*z2/(z1  +  z2)\n",
      "x3  =  z3.real\n",
      "y3  =  z3.imag\n",
      "r3  =  (x3**2  +  y3**2)**0.5\n",
      "theta3  =  cmath.phase(complex(x3,y3))*180/math.pi\n",
      "\n",
      "\n",
      "#Results\n",
      "print  \"\\n\\n  Result  \\n\\n\"\n",
      "print  \"\\n  ZT  is  (\",round( r3,2),\",round(/_\",round(theta3,2),\"deg)\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "\n",
        "  Result  \n",
        "\n",
        "\n",
        "\n",
        "  ZT  is  ( 3.79 ,round(/_ 4.25 deg)"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 7, page no. 423</h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from __future__ import division\n",
      "import math\n",
      "import cmath\n",
      "#initializing  the  variables:\n",
      "z  =  -2  +  3j;\n",
      "\n",
      "#calculation:\n",
      "zc  =  z**5\n",
      "x  =  zc.real\n",
      "y  =  zc.imag\n",
      "r  =  (x**2  +  y**2)**0.5\n",
      "theta  =  cmath.phase(complex(x,y))*180/math.pi\n",
      "\n",
      "#Results\n",
      "print  \"\\n\\n  Result  \\n\\n\"\n",
      "print  \"\\n  Z  is  \",round(  x,2),\"  +  (\",round(y,2),\")i\"\n",
      "print  \"\\n  ZT  is  (\",round(  r,2),\"round/_\",round(theta,2),\"deg)\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "\n",
        "  Result  \n",
        "\n",
        "\n",
        "\n",
        "  Z  is   -122.0   +  ( -597.0 )i\n",
        "\n",
        "  ZT  is  ( 609.34 round/_ -101.55 deg)"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 8, page no. 423</h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from __future__ import division\n",
      "import math\n",
      "import cmath\n",
      "#initializing  the  variables:\n",
      "z  =  12  +  5j;\n",
      "\n",
      "#calculation:\n",
      "x  =  z.real\n",
      "y  =  z.imag\n",
      "r  =  (x**2  +  y**2)**0.5\n",
      "theta1  =  cmath.atan(y/x)*180/math.pi\n",
      "'''\n",
      "if  ((x<0)&(y<0))\n",
      "         theta1  =  theta1  -180;\n",
      "elif  ((x<0)&(y>0))\n",
      "         theta1  =  theta1  +180;\n",
      "'''\n",
      "theta2  =  theta1  +  360\n",
      "rtheta1  =  theta1/2\n",
      "rtheta2  =  theta2/2\n",
      "'''\n",
      "if  (rtheta2  >  180)\n",
      "         rtheta2  =  rtheta2  -360;\n",
      "elif  ((x<0)&(y>0))\n",
      "         rtheta2  =  rtheta2  +360;\n",
      "'''\n",
      "rr  =  r**0.5\n",
      "x1  =  rr*cmath.cos(rtheta1*math.pi/180)\n",
      "y1  =  rr*cmath.sin(rtheta1*math.pi/180)\n",
      "z1  =  x1  +  y1*1j\n",
      "\n",
      "x2  =  rr*cmath.cos(rtheta2*math.pi/180)\n",
      "y2  =  rr*cmath.sin(rtheta2*math.pi/180)\n",
      "z2  =  x2  +  y2*1j\n",
      "\n",
      "\n",
      "#Results\n",
      "print  \"\\n\\n  Result  \\n\\n\"\n",
      "print  \"\\n  two  roots  are  (\",round(z1.real,2),\"  +  (\",round(z1.imag,2),\")i) \"\n",
      "print   \" and  (\",round(z2.real,2),\"  +  (\",round(z2.imag,2),\")i)\"\n",
      "print  \"\\n  two  roots  are  (\",round(  rr,2),\"/_\",round((cmath.phase(complex(z1.real,z1.imag)))*180/math.pi,2),\"deg) \"\n",
      "print   \" and  (\",round(  rr,2),\"/_\",round((cmath.phase(complex(z2.real,z2.imag)))*180/math.pi,2),\"deg)\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "\n",
        "  Result  \n",
        "\n",
        "\n",
        "\n",
        "  two  roots  are  ( 3.54   +  ( 0.71 )i) \n",
        " and  ( -3.54   +  ( -0.71 )i)\n",
        "\n",
        "  two  roots  are  ( 3.61 /_ 11.31 deg) \n",
        " and  ( 3.61 /_ -168.69 deg)\n"
       ]
      }
     ],
     "prompt_number": 1
    }
   ],
   "metadata": {}
  }
 ]
}