summaryrefslogtreecommitdiff
path: root/Elements_of_Electromagnetics/chapter_1.ipynb
blob: d44c3a90e923fabb10ef59ffae0f216ba3768da9 (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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
{
 "metadata": {
  "name": "",
  "signature": "sha256:eb36bd65b4a83ec123fa29550d3c2d667495d3d3383848faa667d8b6a5548ac3"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h1>Chapter 1: Vector Analysis<h1>"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 1.1, Page number: 8<h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "\n",
      "import scipy\n",
      "from numpy import *\n",
      "\n",
      "#Variable Declaration\n",
      "\n",
      "A=array([10,-4,6])            \n",
      "B=array([2,1,0])\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",
      "\n",
      "#Calculations\n",
      "\n",
      "Ay=dot(A,ay)                     #Component of A along y direction\n",
      "l=scipy.sqrt(dot(3*A-B,3*A-B))   #Magnitude of the vector 3A-B\n",
      "\n",
      " #Defining the x,y and z components of the unit vector along A+2B\n",
      " \n",
      "ux=round(dot(A+2*B,ax)/scipy.sqrt(dot(A+2*B,A+2*B)),4)\n",
      "uy=round(dot(A+2*B,ay)/scipy.sqrt(dot(A+2*B,A+2*B)),4)\n",
      "uz=round(dot(A+2*B,az)/scipy.sqrt(dot(A+2*B,A+2*B)),4)\n",
      "\n",
      "u=array([ux,uy,uz])\n",
      "\n",
      "#Results\n",
      "\n",
      "print 'The component of A along y direction is',Ay\n",
      "print 'Magnitude of 3A-B =',round(l,2)\n",
      "print 'Unit vector along A+2B is',u"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The component of A along y direction is -4\n",
        "Magnitude of 3A-B = 35.74\n",
        "Unit vector along A+2B is [ 0.9113 -0.1302  0.3906]\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 1.2, Page number: 9<h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "import scipy\n",
      "from numpy import *\n",
      "\n",
      "#Variable Declaration\n",
      "\n",
      "P=array([0,2,4])            \n",
      "Q=array([-3,1,5])\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",
      "origin=array([0,0,0])            #Defining the origin\n",
      "\n",
      "#Calculations\n",
      "\n",
      "PosP=P-origin                    #The position vector P\n",
      "Dpq=Q-P                          #The distance vector from P to Q\n",
      "l=scipy.sqrt(dot(Dpq,Dpq))       #Magnitude of the distance vector from P to Q\n",
      "\n",
      " #Defining the x,y and z components of the unit vector along Dpq\n",
      " \n",
      "ux=round(dot(Dpq,ax)/l,4)\n",
      "uy=round(dot(Dpq,ay)/l,4)\n",
      "uz=round(dot(Dpq,az)/l,4)\n",
      "\n",
      "vect=array([ux*10,uy*10,uz*10])  #Vector parallel to PQ with magntude of 10\n",
      "\n",
      "#Results\n",
      "\n",
      "print 'The position vector P is',PosP\n",
      "print 'The distance vector from P to Q is',Dpq\n",
      "print 'The distance between P and Q is',round(l,3)\n",
      "print 'Vector parallel to PQ with magntude of 10 is',vect"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The position vector P is [0 2 4]\n",
        "The distance vector from P to Q is [-3 -1  1]\n",
        "The distance between P and Q is 3.317\n",
        "Vector parallel to PQ with magntude of 10 is [-9.045 -3.015  3.015]\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 1.3, Page number: 10<h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "import scipy\n",
      "from numpy import *\n",
      "\n",
      "#Variable Declaration\n",
      "\n",
      "vriver=10              #Speed of river in km/hr\n",
      "vman=2                 #Speed of man relative to boat in km/hr\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",
      "\n",
      "#Calculations\n",
      "\n",
      " #Velocity of boat\n",
      "\n",
      "Vboat=vriver*(scipy.cos(scipy.pi/4)*ax-       \n",
      " scipy.sin(scipy.pi/4)*ay) \n",
      " \n",
      " #Relative velocity of man with respect to boat\n",
      "\n",
      "Vrelman=vman*(-scipy.cos(scipy.pi/4)*ax-      \n",
      " scipy.sin(scipy.pi/4)*ay) \n",
      " \n",
      " #Absolute velocity of man\n",
      " \n",
      "Vabs=Vboat+Vrelman\n",
      " \n",
      "mag=scipy.sqrt(dot(Vabs,Vabs))               #Magnitude of the velocity of man\n",
      "Vabsx=dot(Vabs,ax)                           #X component of absolute velocity\n",
      "Vabsy=dot(Vabs,ay)                           #Y component of absolute velocity\n",
      "angle=scipy.arctan(Vabsy/Vabsx)*180/scipy.pi #Angle made with east in degrees\n",
      "\n",
      "#Result\n",
      "\n",
      "print 'The velocity of the man is',round(mag,1),'km/hr at an angle of'\n",
      "print -round(angle,1),'degrees south of east'\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The velocity of the man is 10.2 km/hr at an angle of\n",
        "56.3 degrees south of east\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 1.4, Page number: 17<h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "\n",
      "import scipy\n",
      "from numpy import *\n",
      "\n",
      "#Variable Declaration\n",
      "\n",
      "A=array([3,4,1])\n",
      "B=array([0,2,-5])\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",
      "\n",
      "#Calculations\n",
      "\n",
      "magA=scipy.sqrt(dot(A,A))                  #Magnitude of A\n",
      "magB=scipy.sqrt(dot(B,B))                  #Magnitude of B\n",
      "angle=scipy.arccos(dot(A,B)/(magA*magB))   #Angle between A and B in radians\n",
      "angled=angle*180/scipy.pi                  #Angle between A and B in degrees\n",
      "\n",
      "\n",
      "#Result\n",
      "\n",
      "print 'The angle between A and B =',round(angled,2),'degrees'\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The angle between A and B = 83.73 degrees\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 1.5, Page number: 17<h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "\n",
      "import scipy\n",
      "from numpy import *\n",
      "\n",
      "#Variable Declaration\n",
      "\n",
      "P=array([2,0,-1])\n",
      "Q=array([2,-1,2])\n",
      "R=array([2,-3,1])\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",
      "\n",
      "#Calculations\n",
      "\n",
      "ansa=cross((P+Q),(P-Q))\n",
      "ansb=dot(Q,cross(R,P))\n",
      "ansc=dot(P,cross(Q,R))\n",
      "lqxr=scipy.sqrt(dot(cross(Q,R),cross(Q,R)))   #Magnitude of QXR\n",
      "lq=scipy.sqrt(dot(Q,Q))                       #Magnitude of Q\n",
      "lr=scipy.sqrt(dot(R,R))                       #Magnitude of R\n",
      "ansd=lqxr/(lq*lr)\n",
      "anse=cross(P,cross(Q,R))\n",
      "\n",
      "#Finding unit vector perpendicular to Q and R\n",
      "\n",
      "ux=dot(cross(Q,R),ax)/lqxr    #X component of the unit vector\n",
      "uy=dot(cross(Q,R),ay)/lqxr    #Y component of the unit vector\n",
      "uz=dot(cross(Q,R),az)/lqxr    #Z component of the unit vector\n",
      "\n",
      "ansf=array([round(ux,3),round(uy,3),round(uz,3)])\n",
      "\n",
      "ansg=round((float(dot(P,Q))/dot(Q,Q)),4)*Q\n",
      "\n",
      "\n",
      "#Results\n",
      "\n",
      "print '(P+Q)X(P-Q) =',ansa\n",
      "print 'Q.(R X P) =',ansb\n",
      "print 'P.(Q X R) =',ansc\n",
      "print 'Sin(theta_QR) =',round(ansd,4)\n",
      "print 'P X (Q X R) =',anse\n",
      "print 'A unit vector perpendicular to both Q and R =',ansf\n",
      "print 'The component of P along Q =',ansg\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(P+Q)X(P-Q) = [ 2 12  4]\n",
        "Q.(R X P) = 14\n",
        "P.(Q X R) = 14\n",
        "Sin(theta_QR) = 0.5976\n",
        "P X (Q X R) = [2 3 4]\n",
        "A unit vector perpendicular to both Q and R = [ 0.745  0.298 -0.596]\n",
        "The component of P along Q = [ 0.4444 -0.2222  0.4444]\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 1.7, Page number: 21<h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "import scipy\n",
      "from numpy import *\n",
      "\n",
      "#Variable Declaration\n",
      "\n",
      "P1=array([5,2,-4])\n",
      "P2=array([1,1,2])\n",
      "P3=array([-3,0,8])\n",
      "P4=array([3,-1,0])\n",
      "\n",
      "#Calculations\n",
      "\n",
      "R12=P2-P1;                                      #Distance vector from P1 to P2\n",
      "R13=P3-P1;                                      #Distance vector from P1 to P3\n",
      "R14=P4-P1;                                      #Distance vector from P1 to P4\n",
      "s=cross(R12,R13)\n",
      "x=cross(R14,R12)\n",
      "d=scipy.sqrt(dot(x,x))/scipy.sqrt(dot(R12,R12)) #Distance from line to P4 \n",
      "\n",
      "#Results\n",
      "\n",
      "print 'The cross product of the distance vectors R12 and R14 =',s\n",
      "print 'So they are along same direction and hence P1, P2 and P3 are collinear.'\n",
      "print 'The shortest distance from the line to point P4 =',round(d,3)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The cross product of the distance vectors R12 and R14 = [0 0 0]\n",
        "So they are along same direction and hence P1, P2 and P3 are collinear.\n",
        "The shortest distance from the line to point P4 = 2.426\n"
       ]
      }
     ],
     "prompt_number": 6
    }
   ],
   "metadata": {}
  }
 ]
}