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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
|
{
"metadata": {
"name": "",
"signature": "sha256:891c986a46f113e35878dc6d6a0b8d702286ad7b4ea91bae03f716286f9bdeaa"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h1>Chapter 4: Electrostatic Fields<h1>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 4.1, Page number: 107<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
" \n",
"import scipy\n",
"from numpy import *\n",
"\n",
"#Variable Declaration\n",
"\n",
"ax=array([1,0,0]) #Unit vector along x direction\n",
"ay=array([0,1,0]) #Unit vector along y direction\n",
"az=array([0,0,1]) #Unit vector along z direction\n",
"Q1=1*10**-3 #charge 1 at (-1,-1,4) in C\n",
"Q2=-2*10**-3 #charge 2 at (3,2,-1) in C\n",
"Q=10*10**-9 #charge 3 at (0,3,1) in C\n",
"P1=array([0,3,1])-array([3,2,-1]) #distance vector from charge 3 to 1\n",
"P2=array([0,3,1])-array([-1,-1,4]) #distance vector from charge 3 to 2\n",
"e=10**-9/(36*scipy.pi) #permittivity in Farad/m \n",
"\n",
"#Calculations\n",
"\n",
"modP1=scipy.sqrt(dot(P1,P1))\n",
"modP2=scipy.sqrt(dot(P2,P2))\n",
"F1=(Q*Q1)*P1*10**3/(4*scipy.pi*e*modP1**3) #force on charge 3 by 1 in mN\n",
"F2=(Q*Q2)*P2*10**3/(4*scipy.pi*e*modP2**3) #force on charge 3 by 2 in mN\n",
"\n",
" #Total force on charge 3\n",
" \n",
"Fx=round(dot(F1+F2,ax),3)\n",
"Fy=round(dot(F1+F2,ay),3)\n",
"Fz=round(dot(F1+F2,az),3)\n",
"F=array([Fx,Fy,Fz]) #Total force in mN\n",
"E=(10**-6)*(F/Q) #Electric field in kV/m\n",
"\n",
"#Results \n",
"\n",
"print 'Total force on charge at (0,3,1) =',F,'in mN'\n",
"print 'Electric field at (0,3,1) =',E,'kV/m'"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Total force on charge at (0,3,1) = [-6.512 -3.713 7.509] in mN\n",
"Electric field at (0,3,1) = [-651.2 -371.3 750.9] kV/m\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Example 4.3, Page number: 109"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
" \n",
"import scipy\n",
"#Variable Declaration\n",
"\n",
"E=500*10**3 #electric field in V/m\n",
"Qm=9*10**-6 #Q/m in C/kg\n",
"y=0.8 #distance fallen in m\n",
"g=9.8 #acceleration due to gravity in m/s^2\n",
"\n",
"#Calculations\n",
"\n",
"t=scipy.sqrt(2*y/g) #time taken to fall in seconds\n",
"x=Qm*E*t**2/2 #half the separation between particles in m\n",
"sep=2*x #separation between particles in m\n",
"\n",
"#Result\n",
"\n",
"print 'The separation between particles is',round(sep*100,2),'cm'\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The separation between particles is 73.47 cm\n"
]
}
],
"prompt_number": 2
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Example 4.5, Page number: 120"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
" \n",
"import scipy\n",
"import scipy.integrate\n",
"\n",
"#Variable Declaration\n",
"\n",
"Eo=10**-9/(36*scipy.pi) #permittivity of free space\n",
"ax=array([1,0,0]) #Unit vector along x direction\n",
"ay=array([0,1,0]) #Unit vector along y direction\n",
"az=array([0,0,1]) #Unit vector along z direction\n",
"q=-1 #charge in mC\n",
"\n",
"#Calculations\n",
"\n",
"def charge(x,y): \n",
" return x*y*(x**2+y**2+25)**(1.5)\n",
"Q, errq = scipy.integrate.dblquad(lambda y , x: charge(x,y), #total charge in nC\n",
" 0, 1, lambda y: 0, lambda y: 1) \n",
"\n",
"d=(4*scipy.pi*Eo*(x**2+y**2+25)**(1.5))\n",
"\n",
"def elecx(x,y): \n",
" return 10**-9*x*y*(x**2+y**2+25)**(1.5)*(-x)/d #x component of electric field\n",
"Ex, errx = scipy.integrate.dblquad(lambda y , x: elecx(x,y), \n",
" 0, 1, lambda y: 0, lambda y: 1) \n",
"\n",
"def elecy(x,y): \n",
" return 10**-9*x*y*(x**2+y**2+25)**(1.5)*(-y)/d #y component of electric field\n",
"Ey, erry = scipy.integrate.dblquad(lambda y , x: elecy(x,y), \n",
" 0, 1, lambda y: 0, lambda y: 1) \n",
"\n",
"def elecz(x,y): \n",
" return 10**-9*x*y*(5)/(4*scipy.pi*Eo) #z component of electric field\n",
"Ez, errz = scipy.integrate.dblquad(lambda y , x: elecz(x,y), \n",
" 0, 1, lambda y: 0, lambda y: 1) \n",
"\n",
"E=array([round(Ex,1),round(Ey,1),round(Ez,2)]) #electric field in V/m\n",
"\n",
"F=q*E #force in mN \n",
"\n",
"#Results\n",
"\n",
"print 'Total charge =',round(Q,2),'nC'\n",
"print 'Electric field at (0,0,5) =',E,'V/m'\n",
"print 'Force experienced by -1mC =',F,'mN'"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Total charge = 33.15 nC\n",
"Electric field at (0,0,5) = [ -1.5 -1.5 11.25] V/m\n",
"Force experienced by -1mC = [ 1.5 1.5 -11.25] mN\n"
]
}
],
"prompt_number": 10
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 4.6, Page number: 121<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
" \n",
"import scipy\n",
"from numpy import *\n",
"\n",
"#Variable Declaration\n",
"\n",
"ax=array([1,0,0]) #Unit vector along x direction\n",
"ay=array([0,1,0]) #Unit vector along y direction\n",
"az=array([0,0,1]) #Unit vector along z direction\n",
"ps1=10*10**-9 #Surface charge density of plane 1\n",
"ps2=15*10**-9 #Surface charge density of plane 2\n",
"pl=10*scipy.pi*10**-9 #charge density of line\n",
"e=(10**-9)/(36*scipy.pi) #permittivity of free space in Farad/m\n",
"\n",
"#Calculations\n",
"\n",
"E1=(ps1/(2*e))*-ax/scipy.pi #field due to plane 1 in multiples of pi in V/m\n",
"E2=(ps2/(2*e))*ay/scipy.pi #field due to plane 2 in multiples of pi in V/m\n",
"\n",
" #field due to line charge in multiples of pi in V/m\n",
" \n",
"a=(ax-3*az) \n",
"moda=scipy.sqrt(dot((ax-3*az),(ax-3*az)))\n",
"e3=(pl/(2*scipy.pi*e*moda**2))*a\n",
"E3=array([dot(e3,ax)/scipy.pi,0,dot(e3,az)/scipy.pi])\n",
"\n",
" #total field in multiples of pi in V/m\n",
" \n",
"E=E1+E2+E3 \n",
"\n",
"#Result\n",
"\n",
"print 'The total electric field at (1,1,-1) =',E,'Pi V/m'"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The total electric field at (1,1,-1) = [-162. 270. -54.] Pi V/m\n"
]
}
],
"prompt_number": 2
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 4.7, Page number: 123<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
" \n",
"import scipy\n",
"from numpy import *\n",
"\n",
"#Variable Declaration\n",
"\n",
"ax=array([1,0,0]) #Unit vector along x direction\n",
"ay=array([0,1,0]) #Unit vector along y direction\n",
"az=array([0,0,1]) #Unit vector along z direction\n",
"Q=-5*scipy.pi*10**-3 #charge at (4,0,0) in C\n",
"pl=3*scipy.pi*10**-3 #charge density of line charge in C/m\n",
"r=array([4,0,3]) #point where D is to be found \n",
"rp=array([4,0,0]) #position of point charge\n",
"\n",
"#Calculations \n",
"\n",
"R=r-rp \n",
"modR=scipy.sqrt(dot(R,R)) \n",
"Dq=(Q*R)/(4*scipy.pi*modR**3) #flux density due to point charge in C/m^2\n",
"p=scipy.sqrt(dot(r,r))\n",
"ap=r/p \n",
"Dl=(pl/(2*scipy.pi*p))*ap #flux density due to line charge in C/m^2\n",
"D=(Dq+Dl)*10**6 #total flux density in micro C/m^2\n",
"Dz=round(dot(D,az),0)\n",
"Dx=round(dot(D,ax),0)\n",
"Dy=round(dot(D,ay),0)\n",
"Dround=array([Dx,Dy,Dz]) #value of D rounded to 0 decimal points\n",
"\n",
"#Result\n",
"\n",
"print 'D at (4,0,0) due to point charge and line charge =',Dround,'micro C/m^2'\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"D at (4,0,0) due to point charge and line charge = [ 240. 0. 41.] micro C/m^2\n"
]
}
],
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 4.8, Page number: 130<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
" \n",
"\n",
"import scipy\n",
"from numpy import *\n",
"import scipy.integrate\n",
"from fractions import Fraction\n",
"\n",
"#Variable Declaration\n",
"\n",
"ap=array([1,0,0]) #Unit vector along rho direction\n",
"aph=array([0,1,0]) #Unit vector along phi direction\n",
"az=array([0,0,1]) #Unit vector along z direction\n",
"point=array([1,scipy.pi/4,3])\n",
"p1=0\n",
"p2=1\n",
"ph1=0\n",
"ph2=2*scipy.pi\n",
"\n",
"#Calculations\n",
"\n",
"pointp=dot(point,ap)\n",
"pointph=dot(point,aph)\n",
"pv=pointp*scipy.cos(pointph)**2 #charge density at (1,pi/4,3) in C/m^3\n",
"\n",
"def ctop(phi,p): \n",
" return 2*p**2*(scipy.cos(phi)**2)\n",
"psya, erra = scipy.integrate.dblquad(lambda p , phi: ctop(phi,p), \n",
" ph1, ph2, lambda p: p1, lambda p: p2)\n",
"\n",
"def cbot(phi,p): \n",
" return 2*p**2*(scipy.cos(phi)**2)\n",
"psyb, errb = scipy.integrate.dblquad(lambda p , phi: cbot(phi,p), \n",
" ph1, ph2, lambda p: p1, lambda p: p2)\n",
" \n",
"psy=psya+psyb #Charge in C\n",
"psyp=psy/scipy.pi #Charge in multiples of Pi in C\n",
"psyf=Fraction(psyp).limit_denominator(100) #converting to fraction\n",
"\n",
"\n",
"#Results\n",
"\n",
"print 'Charge density at (1,pi/4,3) =',pv,'C/m^3'\n",
"print 'Total charge enclosed by the cylinder =',psyf,'Pi C'"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Charge density at (1,pi/4,3) = 0.5 C/m^3\n",
"Total charge enclosed by the cylinder = 4/3 Pi C\n"
]
}
],
"prompt_number": 4
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 4.10, Page number: 136<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
" \n",
"\n",
"import scipy\n",
"from numpy import *\n",
"\n",
"#Variable Declaration\n",
"\n",
"Q1=-4 #charge 1 in micro C\n",
"Q2=5 #charge 2 in micro C\n",
"e=10**-9/(36*scipy.pi) #permittivity of free space in Farad/m \n",
"\n",
"#Calculations\n",
"\n",
"R1=array([1,0,1])-array([2,-1,3]) #distance vector from (1,0,1) to charge 1\n",
"R2=array([1,0,1])-array([0,4,-2]) #distance vector from (1,0,1) to charge 2\n",
"modR1=scipy.sqrt(dot(R1,R1))\n",
"modR2=scipy.sqrt(dot(R2,R2)) \n",
"V=10**-9*((Q1/modR1)+(Q2/modR2))/(4*scipy.pi*e) #potential in kV\n",
"\n",
"#Result\n",
"\n",
"print 'The potential at (1, 0, 1) =',round(V,3),'kV'\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The potential at (1, 0, 1) = -5.872 kV\n"
]
}
],
"prompt_number": 5
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Example 4.11, Page number: 136"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
" \n",
"import scipy\n",
"\n",
"#Variable Declaration\n",
"\n",
"Eo=10**-9/(36*scipy.pi) #permittivity of free space\n",
"Vo=0 #potential at O in V\n",
"Vb=100 #potential at B in V\n",
"po=scipy.sqrt(2)\n",
"ro=5\n",
"pa=1\n",
"ra=9\n",
"pb=1\n",
"rb=scipy.sqrt(21)\n",
"pc=scipy.sqrt(20)\n",
"rc=scipy.sqrt(11)\n",
"pl=2*10**-9 #charge density of the line in C/m\n",
"Q=5*10**-9 #point charge at (-3,4,0) in C\n",
"\n",
"#Calculations\n",
"\n",
"Va=Vo-(-pl*scipy.log(po/pa)/(2*scipy.pi*Eo)+Q*(ra-ro)/(4*scipy.pi*Eo*ra*ro))\n",
"Vc=Vb+(-pl*scipy.log(pc/pb)/(2*scipy.pi*Eo)+Q*(rb-rc)/(4*scipy.pi*Eo*rb*rc))\n",
"Vbc=Vc-Vb\n",
"\n",
"#Results\n",
"\n",
"print 'Va =',round(Va,3),'V'\n",
"print 'Vc =',round(Vc,3),'V'\n",
"print 'Vbc =',round(Vbc,3),'V'"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Va = 8.477 V\n",
"Vc = 49.825 V\n",
"Vbc = -50.175 V\n"
]
}
],
"prompt_number": 5
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 4.12, Page number: 140<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
" \n",
"\n",
"import scipy\n",
"from numpy import *\n",
"\n",
"#Variable Declaration\n",
"\n",
"ar=array([1,0,0]) #Unit vector along radial direction\n",
"ath=array([0,1,0]) #Unit vector along theta direction\n",
"aph=array([0,0,1]) #Unit vector along phi direction\n",
"e=(10**-9)/(36*scipy.pi) #permittivity of free space in Farad/m\n",
"\n",
" #The point (2, pi/2, 0)\n",
"r=2\n",
"th=scipy.pi/2\n",
"ph=0\n",
" #Point A\n",
"ra=1\n",
"tha=scipy.pi*30/180\n",
"pha=scipy.pi*120/180\n",
" #Point B\n",
"rb=4\n",
"thb=scipy.pi/2\n",
"phb=scipy.pi*60/180\n",
"\n",
"q=10*10**-6 \n",
"\n",
"#Calculations\n",
"\n",
"Er=(20.0/r**3)*scipy.sin(th)*scipy.cos(ph) #Radial component of E in V/m\n",
"Eth=-(10/r**3)*scipy.cos(th)*scipy.cos(ph) #Theta component of E in V/m\n",
"Eph=(10/r**3)*scipy.sin(ph) #Phi component of E in V/m\n",
"E=array([Er,Eth,Eph])\n",
"D=E*e*10**12 #Electric flux density D in pC/m^2\n",
"Dr=round(dot(D,ar),1) #Radial component of D in V/m rounded to 1 decimal\n",
"Dth=round(dot(D,ath),0) #Theta component of D in pC/m^2 rounded to 0 decimal\n",
"Dph=round(dot(D,aph),0) #Phi component of D in pC/m^2 rounded to 0 decimal\n",
"Dc=array([Dr,Dth,Dph]) #Rounded D in pC/m^2\n",
"\n",
"Va=10*scipy.sin(tha)*cos(pha)/ra**2 #potential at point A in V\n",
"Vb=10*scipy.sin(thb)*cos(phb)/rb**2 #potential at point B in V\n",
"W=q*(Vb-Va)*10**6 #work done in micro J\n",
"\n",
"#Results\n",
"\n",
"print 'The electric flux density D at (2, pi/2, 0) =',Dc,'pC/m^2'\n",
"print 'Work done in moving the charge =',W,'micro J'\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The electric flux density D at (2, pi/2, 0) = [ 22.1 -0. 0. ] pC/m^2\n",
"Work done in moving the charge = 28.125 micro J\n"
]
}
],
"prompt_number": 6
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 4.13, Page number: 145<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
" \n",
"\n",
"import scipy\n",
"from numpy import *\n",
"\n",
"#Variable Declaration\n",
"\n",
"p1=-5*10**-9 #dipole moment of dipole 1 in C/m\n",
"p2=9*10**-9 #dipole moment of dipole 2 in C/m\n",
"z1=2 #z component of position vector of dipole 1\n",
"z2=-3 #z component of position vector of dipole 2\n",
"e=10**-9/(36*scipy.pi) #permittivity of free space in Farad/m\n",
"\n",
"#Calculation\n",
"\n",
"V=(1/(4*scipy.pi*e))*((p1*abs(z1)/z1**3)+(p2*abs(z2)/z2**3))\n",
"\n",
"#Result\n",
"\n",
"print 'Potential at origin =',V, 'V'\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Potential at origin = -20.25 V\n"
]
}
],
"prompt_number": 7
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 4.14, Page number: 148<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
" \n",
"import scipy\n",
"from numpy import *\n",
"\n",
"#Variable Declaration\n",
"\n",
"Q1=-1*10**-9 #Charge 1 in C\n",
"Q2=4*10**-9 #Charge 2 in C\n",
"Q3=3*10**-9 #Charge 3 in C\n",
"e=10**-9/(36*scipy.pi) #permittivity of free space in farad/m\n",
"\n",
"#Calculations\n",
"\n",
"V1=(1/(4*scipy.pi*e)*(Q2+Q3))\n",
"V2=(1/(4*scipy.pi*e)*(Q1+Q3/(2**.5)))\n",
"V3=(1/(4*scipy.pi*e)*(Q1+Q2/(2**.5)))\n",
"W=0.5*((V1*Q1)+(V2*Q2)+(V3*Q3))*10**9 #Energy in nJ\n",
"\n",
"#Result\n",
"\n",
"print 'Energy in the system =',round(W,2),'nJ'"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Energy in the system = 13.37 nJ\n"
]
}
],
"prompt_number": 8
}
],
"metadata": {}
}
]
}
|