diff options
Diffstat (limited to 'Elements_of_Electromagnetics/chapter_1.ipynb')
-rw-r--r-- | Elements_of_Electromagnetics/chapter_1.ipynb | 420 |
1 files changed, 420 insertions, 0 deletions
diff --git a/Elements_of_Electromagnetics/chapter_1.ipynb b/Elements_of_Electromagnetics/chapter_1.ipynb new file mode 100644 index 00000000..ae4e75b3 --- /dev/null +++ b/Elements_of_Electromagnetics/chapter_1.ipynb @@ -0,0 +1,420 @@ +{
+ "metadata": {
+ "name": "chapter_1.ipynb"
+ },
+ "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",
+ "If A= 1Oa_x - 4a_y + 6a_z and B == 2a_x + a_y, find: \n",
+ "(a) the component of A along a_y ,\n",
+ "(b) the magnitude of 3A - B,\n",
+ "(c) a unit vector along A + 2B. '''\n",
+ "\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",
+ "Points P and Q are located at (0, 2, 4) and (- 3, 1, 5). Calculate \n",
+ "(a) The position vector P \n",
+ "(b) The distance vector from P to Q \n",
+ "(c) The distance between P and Q \n",
+ "(d) A vector parallel to PQ with magntude of 10 '''\n",
+ "\n",
+ "\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",
+ "A river flows southeast at 10 km/hr and a boat flows upon it \n",
+ "with its bow pointed in the direction of travel. A man walks upon\n",
+ "the deck at 2 km/hr in a direction to the right and perpendicular\n",
+ "to the direction of the boat's movement. \n",
+ "Find the velocity of the man with respect to the earth. '''\n",
+ "\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",
+ "Given vectors A = 3a_x + 4a_y + a_z and B = 2a_y - 5a_z , \n",
+ "find the angle between A and B. '''\n",
+ " \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",
+ "Three field quantities are given by \n",
+ "P = 2a_x - a_z \n",
+ "Q = 2a_x - a_y + 2a_z \n",
+ "R = 2a_x - 3a_y + a_z\n",
+ "\n",
+ "Determine \n",
+ "\n",
+ "(a) (P + Q) X (P - Q) \n",
+ "(b) Q.(R X P)\n",
+ "(c) P.(Q X R)\n",
+ "(d) Sin(theta_QR) \n",
+ "(e) P X (Q X R) \n",
+ "(f) A unit vector perpendicular to both Q and R \n",
+ "(g) The component of P along Q '''\n",
+ "\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",
+ "Show that points P1(5,2,-4), P2(1,1,2), and P3( -3,0,8) all \n",
+ "lie on a straight line. Determine the shortest distance between \n",
+ "the line and point P4(3,- 1,0). '''\n",
+ "\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": {}
+ }
+ ]
+}
\ No newline at end of file |