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
|
{
"metadata": {
"name": "",
"signature": "sha256:d78c85d754b20d2817dcaff01d1e4d9adbe09676da8e1b1ab97dcc0ae047a88a"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h1>Chapter 2: Coordinate Systems and Transformation<h1>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 2.1, Page number: 36<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
" \n",
"import scipy\n",
"from numpy import *\n",
"\n",
"#Variable Declaration\n",
"\n",
"x=-2\n",
"y=6\n",
"z=3 \n",
"\n",
"#Calculations\n",
"\n",
"r=scipy.sqrt(x**2+y**2)\n",
"phi=scipy.arctan(-y/x) #phi in radians in 1st quadrant\n",
"phid=180-(phi*180/scipy.pi) #phi in degrees in second quadrant\n",
"phic=scipy.pi*phid/180.0 #phi in radians in second quadrant\n",
"R=scipy.sqrt(x**2+y**2+z**2) \n",
"theta=scipy.arctan(r/z) \n",
"\n",
" #P in cylindrical coordinates\n",
" \n",
"Pcyl=array([round(r,2),round(phid,2),z]) \n",
"\n",
" #P in spherical coordinates\n",
" \n",
"Psph=array([round(R,2),round(theta*180/scipy.pi,2),\n",
" round(phid,2)]) \n",
"\n",
" #Vector A in cylindrical coordinate system\n",
"\n",
"Xc=r*scipy.cos(phic)\n",
"Yc=r*scipy.sin(phic)\n",
"Zc=z \n",
"Ar=Yc*scipy.cos(phic)+(Xc+Zc)*scipy.sin(phic)\n",
"Aphi=-Yc*scipy.sin(phic)+(Xc+Zc)*scipy.cos(phic)\n",
"Az=0\n",
"Acyl=array([round(Ar,4),round(Aphi,3),Az])\n",
"\n",
" #Vector A in spherical coordinate system\n",
"\n",
"Xs=R*scipy.cos(phic)*scipy.sin(theta)\n",
"Ys=R*scipy.sin(phic)*scipy.sin(theta)\n",
"Zs=R*scipy.cos(theta)\n",
"AR=Ys*scipy.sin(theta)*scipy.cos(phic)+(Xs+Zs)*scipy.sin(theta)*scipy.sin(phic) \n",
"Ath=Ys*scipy.cos(theta)*scipy.cos(phic)+(Xs+Zs)*scipy.cos(theta)*scipy.sin(phic) \n",
"Aph=-Ys*scipy.sin(phic)+(Xs+Zs)*scipy.cos(phic)\n",
"Asph=array([round(AR,4),round(Ath,4),round(Aph,3)])\n",
"\n",
"#Results\n",
"\n",
"print 'P in cylindrical coordinates =',Pcyl\n",
"print 'P in spherical coordinates =',Psph\n",
"print 'A in cylindrical coordinates =',Acyl\n",
"print 'A in spherical coordinates =',Asph"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"P in cylindrical coordinates = [ 6.32 108.43 3. ]\n",
"P in spherical coordinates = [ 7. 64.62 108.43]\n",
"A in cylindrical coordinates = [-0.9487 -6.008 0. ]\n",
"A in spherical coordinates = [-0.8571 -0.4066 -6.008 ]\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 2.2, Page number: 39<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
" \n",
"import scipy\n",
"from numpy import *\n",
" \n",
"#Variable Declaration\n",
"\n",
"x=-3\n",
"y=4\n",
"z=0\n",
"p=5\n",
"phi=scipy.pi/2 \n",
"Zc=-2\n",
"\n",
"#Calculations\n",
"\n",
" #B in cartesian coordinates\n",
"\n",
"R=scipy.sqrt(x**2+y**2+z**2)\n",
"r=scipy.sqrt(x**2+y**2) \n",
"P=scipy.arcsin(r/R) #in radians\n",
"Q=scipy.arccos(x/r) #in radians \n",
"f=10/R \n",
"Bx=f*scipy.sin(P)*scipy.cos(Q)+R*(scipy.cos(P))**2*scipy.cos(Q)-scipy.sin(Q) \n",
"By=f*scipy.sin(P)*scipy.sin(Q)+R*(scipy.cos(P))**2*scipy.sin(Q)+scipy.cos(Q) \n",
"Bz=f*scipy.cos(P)-R*scipy.cos(P)*scipy.sin(P) \n",
"Bcart=array([round(Bx,0),round(By,0),round(-Bz,0)])\n",
"\n",
" #B in cylindrical coordinates\n",
" \n",
"Rc=sqrt(p**2+Zc**2) \n",
"Pc=scipy.arccos(Zc/Rc) #in radians\n",
"Br=(10/Rc)*scipy.sin(Pc)+Rc*(scipy.cos(Pc))**2 \n",
"Bp=1 \n",
"Bzc=(10/Rc)*scipy.cos(Pc)-Rc*scipy.cos(Pc)*scipy.sin(Pc) \n",
"Bcyl=array([round(Br,3),Bp,round(Bzc,3)])\n",
"\n",
"#Results\n",
"\n",
"print 'B(-3,4,0) in cartesian coordinates is',Bcart\n",
"print 'B(5,pi/2,-2) in cylindrical coordinates is',Bcyl"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"B(-3,4,0) in cartesian coordinates is [-2. 1. 0.]\n",
"B(5,pi/2,-2) in cylindrical coordinates is [ 2.467 1. 1.167]\n"
]
}
],
"prompt_number": 2
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 2.3, Page number: 44<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
" \n",
"import scipy\n",
"from numpy import *\n",
"\n",
"#Variable Declaration\n",
"\n",
"E=array([-5,10,3]) #in cylindrical coordinates\n",
"F=array([1,2,-6]) #in cylindrical coordinates\n",
"P=array([5,scipy.pi/2,3]) #in cylindrical coordinates\n",
"\n",
"#Calculations\n",
"\n",
"exf=cross(E,F)\n",
"ansa=scipy.sqrt(dot(exf,exf)) #|EXF|\n",
"ay=array([round(scipy.sin(scipy.pi/2),0),\n",
" round(scipy.cos(scipy.pi/2),0),0])\n",
"ansb=dot(E,ay)*ay\n",
"modE=scipy.sqrt(dot(E,E))\n",
"az=array([0,0,1])\n",
"thetaEz=(180/scipy.pi)*arccos(dot(E,az)/modE) #in degrees\n",
"ansc=90-thetaEz #in degrees\n",
"\n",
"#Results\n",
"\n",
"print '|EXF| =',round(ansa,2)\n",
"print 'The vector component of E at P parallel to the line x=2,z=3 =',ansb,','\n",
"print 'in spherical coordinates'\n",
"print 'The angle E makes with the surface z = 3 at P =',round(ansc,2),'degrees'"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"|EXF| = 74.06\n",
"The vector component of E at P parallel to the line x=2,z=3 = [-5. -0. -0.] ,\n",
"in spherical coordinates\n",
"The angle E makes with the surface z = 3 at P = 15.02 degrees\n"
]
}
],
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 2.4, Page number: 45<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
" \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",
"P=array([10,scipy.pi*150/180,scipy.pi*330/180])\n",
"\n",
"#Calculations\n",
"\n",
"r=dot(P,aR)\n",
"q=dot(P,aph)\n",
"p=dot(P,ath)\n",
"R=r*scipy.sin(q)\n",
"Ph=-scipy.sin(p)*scipy.cos(q)/r\n",
"Q=r*r\n",
"D=array([R,Ph,Q]) #D at P(10,150\u00b0,330\u00b0)\n",
"rDr=round(dot(aR,D),0) #radial component of D\n",
"rDth=round(dot(-ath,D),3) #theta component of D\n",
"rDph=round(dot(aph,D),0) #phi component of D\n",
"\n",
"Dn=array([r*scipy.sin(q),0,0]) #Component of D normal to surface r=10\n",
"Dt=D-Dn #Component of D tangential to surface r=10\n",
"Dtr=round(dot(aR,Dt),0) #radial component of Dt\n",
"Dtth=round(dot(-ath,Dt),3) #theta component of Dt\n",
"Dtph=round(dot(aph,Dt),0) #phi component of Dt\n",
"rDt=array([Dtr,Dtth,Dtph])\n",
"\n",
" #Unit vector normal to D and tangential to cone theta=45 degrees\n",
"\n",
"U=cross(D,ath)\n",
"u=U/scipy.sqrt(dot(U,U)) \n",
"ru=array([round(dot(aR,u),4),round(dot(ath,u),4),round(dot(aph,u),4)])\n",
"\n",
"#Results\n",
"\n",
"print 'D at P(10,150\u00b0,330\u00b0) = [',rDr,' ',rDth,' ',rDph,']'\n",
"print 'The component of D tangential to the spherical surface r = 10 at P ='\n",
"print '[',Dtr,' ',Dtth,' ',Dtph,']'\n",
"print 'A unit vector at P perpendicular to D and tangential to cone 0 = 150\u00b0 ='\n",
"print ru"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"D at P(10,150\u00b0,330\u00b0) = [ -5.0 0.043 100.0 ]\n",
"The component of D tangential to the spherical surface r = 10 at P =\n",
"[ 0.0 0.043 100.0 ]\n",
"A unit vector at P perpendicular to D and tangential to cone 0 = 150\u00b0 =\n",
"[-0.9988 0. -0.0499]\n"
]
}
],
"prompt_number": 10
}
],
"metadata": {}
}
]
}
|