{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapater 2 - Ohm's Law "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.3,Page number: 19"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The voltage across resistor 1 is: 12 V.\n",
      "The voltage across resistor 2 is: 12 V.\n",
      "The voltage across resistor 3 is: 16 V.\n",
      "The voltage across resistor 4 is: 8 V.\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "#Variable Declaration:\n",
    "Req=(8.0*12)/(8+12) #Equivalent Resistance of the circuit(in Ohms)\n",
    "I=5                 #Current in the circuit(in Amperes) \n",
    "\n",
    "\n",
    "#Calculations:\n",
    "V=I*Req\n",
    "V1=(4.0*V)/(4+4)\n",
    "V2=(4.0*V)/(4+4)\n",
    "V3=(8.0*V)/(8+4)\n",
    "V4=(4.0*V)/(8+4)\n",
    "\n",
    "\n",
    "#Result:\n",
    "print \"The voltage across resistor 1 is: %d V.\" % (V1)\n",
    "print \"The voltage across resistor 2 is: %d V.\" % (V2)\n",
    "print \"The voltage across resistor 3 is: %d V.\" % (V3)\n",
    "print \"The voltage across resistor 4 is: %d V.\" % (V4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.4,Page number:20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The current i1= 2.00 A.\n",
      "The current i2= 1.20 A.\n",
      "The current i3= 0.80 A.\n",
      "The voltage v1= 4.00 V.\n",
      "The voltage v2= 4.80 V.\n",
      "The voltage v3= 4.80 V.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "#Variable Declaration:\n",
    "I=2.0                 #Current in Circuit(in Amperes)\n",
    "R1=2.0                #Resistance of resistor 1(in Ohms) \n",
    "R2=4.0                #Resistance of resistor 2(in Ohms)\n",
    "R3=6.0                #Resistance of resistor 3(in Ohms)\n",
    "\n",
    "\n",
    "#Calculations:\n",
    "Rp=1/((1/R2)+(1/R3))\n",
    "Req=R1+Rp\n",
    "Vs=I*Req\n",
    "v1=Vs*(R1/(R1+Rp))\n",
    "v2=Vs*(Rp/(R1+Rp))\n",
    "v3=v2\n",
    "i1=I\n",
    "i2=v2/R2\n",
    "i3=v3/R3\n",
    "\n",
    "\n",
    "#Result:\n",
    "print \"The current i1= %.2f A.\\nThe current i2= %.2f A.\\nThe current i3= %.2f A.\" %(i1,i2,i3)\n",
    "print \"The voltage v1= %.2f V.\\nThe voltage v2= %.2f V.\\nThe voltage v3= %.2f V.\\n\" %(v1,v2,v3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.5,Page number: 23"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(a)The effective resistance between points A and B for the combination of resistances is R_AB = 20.00 Ohms.\n",
      "(b)The effective resistance between points A and B for the combination of resistances is R_AB = 0.4545*R Ohms.\n",
      "(c)The effective resistance between points A and B for the combination of resistances is R_AB = 15.00 Ohms.\n"
     ]
    }
   ],
   "source": [
    "from sympy import symbols\n",
    "from __future__ import division\n",
    "#Calculations:\n",
    "Rp=1.0/((1.0/20)+(1.0/10)+(1.0/20))\n",
    "R_AB_1=15+Rp\n",
    "R = symbols('R')\n",
    "R1=1.0/((1.0/2.0)+1.0)+ 1.0\n",
    "R2=R1\n",
    "R_AB_2= 1.0/((1/R1)+(1/R2)+(1))\n",
    "R_AB_b=round(R_AB_2,4)*R\n",
    "R3=1.0/((1.0/3)+(1.0/6)) + 18\n",
    "R_AB_3= 1.0/((1.0/20)+(1/R3)) + 5\n",
    "\n",
    "\n",
    "#Result:\n",
    "print \"(a)The effective resistance between points A and B for the combination of resistances is R_AB = %.2f Ohms.\" %(R_AB_1)\n",
    "print \"(b)The effective resistance between points A and B for the combination of resistances is R_AB = %s Ohms.\" %(R_AB_b)\n",
    "print \"(c)The effective resistance between points A and B for the combination of resistances is R_AB = %.2f Ohms.\" %(R_AB_3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.6,Page number: 24"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The current I1= 5.00 A.\n",
      "The current I2= 3.00 A.\n",
      "The current I3= 2.00 A.\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "#Variable Declaration:\n",
    "V=100                 #Voltage of the DC source(in Volts) \n",
    "\n",
    "\n",
    "#Calculations:\n",
    "Reff= 2+ (1.0/((1.0/12)+(1.0/20)+(1.0/30)))+2\n",
    "I=V/Reff\n",
    "\n",
    "#Applying Ohm's Law, we have 12*I1=20*I2=30*I3;\n",
    "    \n",
    "#I2=0.6*I1; I3=0.4*I1 \"\"\"\n",
    "\n",
    "I1=I/(0.6+0.4+1)\n",
    "I2=0.6*I1\n",
    "I3=0.4*I1\n",
    "\n",
    "\n",
    "#Result:\n",
    "\n",
    "print \"The current I1= %.2f A.\\nThe current I2= %.2f A.\\nThe current I3= %.2f A.\" %(I1,I2,I3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.7,Page number: 25"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The supply current( I ) is 3 A.\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt\n",
    "from __future__ import division\n",
    "#Variable Declaration:\n",
    "P=20.0                #Power dissipated by resistor(in Watts)\n",
    "RL=5.0                #Resistance of the load resistor(in Ohms)\n",
    "R=10.0                #Resistance of resistor(in Ohms)\n",
    "\n",
    "\n",
    "#Calculations:\n",
    "I1=sqrt(P/RL)\n",
    "I=(I1*(R+RL))/R\n",
    "\n",
    "\n",
    "#Result:\n",
    "\n",
    "print \"The supply current( I ) is %d A.\"%(I)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.8,Page number:25"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The voltage across bulb A is 80.00 V. \n",
      "The voltage across bulb B is 40.00 V. \n",
      "The voltage across bulb C is 40.00 V.\n",
      "The total power dissipated in the three bulbs is 40.00 W.\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "#Variable Declaration:\n",
    "V=120.0               #Voltage of the power line(in Volts)\n",
    "P_bulb=60.0           #Power rating of the bulb(in Watts)\n",
    "V_bulb=120.0          #Voltage rating of the bulb(in Volts)\n",
    "\n",
    "\n",
    "#Calculations:\n",
    "R=(V_bulb*V_bulb)/P_bulb\n",
    "R_A=R\n",
    "R_B=R\n",
    "R_C=R\n",
    "R_BC=1.0/((1.0/R)+(1.0/R))\n",
    "V_B=V*(R_BC/(R_BC+R_A)) \n",
    "V_C=V*(R_BC/(R_BC+R_A))\n",
    "V_A=V-V_B\n",
    "P_A=(V_A*V_A)/R_A \n",
    "P_B=(V_B*V_B)/R_B\n",
    "P_C=(V_C*V_C)/R_C\n",
    "P=P_A+P_B+P_C\n",
    "\n",
    "\n",
    "#Result:\n",
    "print \"The voltage across bulb A is %.2f V. \\nThe voltage across bulb B is %.2f V. \\nThe voltage across bulb C is %.2f V.\" %(V_A,V_B,V_C)\n",
    "print \"The total power dissipated in the three bulbs is %.2f W.\" %(P)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.9,Page number: 26"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(a)Minimum value of Req is obtained when R=0(i.e.,a short circuit,because the parallel combination of R2 and R is reduced to 0).\n",
      "   Maximum value of Req is obtained when R is an open ciruit.\n",
      "   Hence,  R1 = 30.00 Ohms and R2 = 45.00 Ohms. \n",
      " \n",
      "(b)The resistance R to give Req=(30+75)/2 ohm is R = 45.00 Ohms.\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "#Variable Declaration:\n",
    "R1=30.0               #Resistance of the resistor(in Ohms)\n",
    "\n",
    "\n",
    "#Calculations:\n",
    "R2=75-R1\n",
    "Req=(30+75)/2.0\n",
    "Rp=Req-R1\n",
    "R=1/((1/Rp)-(1/R2))\n",
    "\n",
    "#Result:\n",
    "print \"(a)Minimum value of Req is obtained when R=0(i.e.,a short circuit,because the parallel combination of R2 and R is reduced to 0).\"    \n",
    "print \"   Maximum value of Req is obtained when R is an open ciruit.\\n   Hence,  R1 = %.2f Ohms and R2 = %.2f Ohms. \\n \" %(R1,R2)\n",
    "print \"(b)The resistance R to give Req=(30+75)/2 ohm is R = %.2f Ohms.\" %(R)"
   ]
  }
 ],
 "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
}