"
]
},
{
"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": [
"
Example 2.4, Page number: 45
"
]
},
{
"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": {}
}
]
}