summaryrefslogtreecommitdiff
path: root/sample_notebooks/MohdRizwan/Chapter2.ipynb
blob: 39ad283ec8188b11bba1217c1da01d433df702a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
{
 "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
}