Chapter 1: Vector Analysis

Example 1.1, Page number: 8

In [1]:
 

import scipy
from numpy import *

#Variable Declaration

A=array([10,-4,6])            
B=array([2,1,0])
ax=array([1,0,0])                #Unit vector along x direction
ay=array([0,1,0])                #Unit vector along y direction
az=array([0,0,1])                #Unit vector along z direction

#Calculations

Ay=dot(A,ay)                     #Component of A along y direction
l=scipy.sqrt(dot(3*A-B,3*A-B))   #Magnitude of the vector 3A-B

 #Defining the x,y and z components of the unit vector along A+2B
 
ux=round(dot(A+2*B,ax)/scipy.sqrt(dot(A+2*B,A+2*B)),4)
uy=round(dot(A+2*B,ay)/scipy.sqrt(dot(A+2*B,A+2*B)),4)
uz=round(dot(A+2*B,az)/scipy.sqrt(dot(A+2*B,A+2*B)),4)

u=array([ux,uy,uz])

#Results

print 'The component of A along y direction is',Ay
print 'Magnitude of 3A-B =',round(l,2)
print 'Unit vector along A+2B is',u
The component of A along y direction is -4
Magnitude of 3A-B = 35.74
Unit vector along A+2B is [ 0.9113 -0.1302  0.3906]

Example 1.2, Page number: 9

In [2]:
 
import scipy
from numpy import *

#Variable Declaration

P=array([0,2,4])            
Q=array([-3,1,5])
ax=array([1,0,0])                #Unit vector along x direction
ay=array([0,1,0])                #Unit vector along y direction
az=array([0,0,1])                #Unit vector along z direction
origin=array([0,0,0])            #Defining the origin

#Calculations

PosP=P-origin                    #The position vector P
Dpq=Q-P                          #The distance vector from P to Q
l=scipy.sqrt(dot(Dpq,Dpq))       #Magnitude of the distance vector from P to Q

 #Defining the x,y and z components of the unit vector along Dpq
 
ux=round(dot(Dpq,ax)/l,4)
uy=round(dot(Dpq,ay)/l,4)
uz=round(dot(Dpq,az)/l,4)

vect=array([ux*10,uy*10,uz*10])  #Vector parallel to PQ with magntude of 10

#Results

print 'The position vector P is',PosP
print 'The distance vector from P to Q is',Dpq
print 'The distance between P and Q is',round(l,3)
print 'Vector parallel to PQ with magntude of 10 is',vect
The position vector P is [0 2 4]
The distance vector from P to Q is [-3 -1  1]
The distance between P and Q is 3.317
Vector parallel to PQ with magntude of 10 is [-9.045 -3.015  3.015]

Example 1.3, Page number: 10

In [3]:
 
import scipy
from numpy import *

#Variable Declaration

vriver=10              #Speed of river in km/hr
vman=2                 #Speed of man relative to boat in km/hr
ax=array([1,0,0])      #Unit vector along x direction
ay=array([0,1,0])      #Unit vector along y direction
az=array([0,0,1])      #Unit vector along z direction

#Calculations

 #Velocity of boat

Vboat=vriver*(scipy.cos(scipy.pi/4)*ax-       
 scipy.sin(scipy.pi/4)*ay) 
 
 #Relative velocity of man with respect to boat

Vrelman=vman*(-scipy.cos(scipy.pi/4)*ax-      
 scipy.sin(scipy.pi/4)*ay) 
 
 #Absolute velocity of man
 
Vabs=Vboat+Vrelman
 
mag=scipy.sqrt(dot(Vabs,Vabs))               #Magnitude of the velocity of man
Vabsx=dot(Vabs,ax)                           #X component of absolute velocity
Vabsy=dot(Vabs,ay)                           #Y component of absolute velocity
angle=scipy.arctan(Vabsy/Vabsx)*180/scipy.pi #Angle made with east in degrees

#Result

print 'The velocity of the man is',round(mag,1),'km/hr at an angle of'
print -round(angle,1),'degrees south of east'
The velocity of the man is 10.2 km/hr at an angle of
56.3 degrees south of east

Example 1.4, Page number: 17

In [4]:
 

import scipy
from numpy import *

#Variable Declaration

A=array([3,4,1])
B=array([0,2,-5])
ax=array([1,0,0])          #Unit vector along x direction
ay=array([0,1,0])          #Unit vector along y direction
az=array([0,0,1])          #Unit vector along z direction

#Calculations

magA=scipy.sqrt(dot(A,A))                  #Magnitude of A
magB=scipy.sqrt(dot(B,B))                  #Magnitude of B
angle=scipy.arccos(dot(A,B)/(magA*magB))   #Angle between A and B in radians
angled=angle*180/scipy.pi                  #Angle between A and B in degrees


#Result

print 'The angle between A and B =',round(angled,2),'degrees'
The angle between A and B = 83.73 degrees

Example 1.5, Page number: 17

In [5]:
 

import scipy
from numpy import *

#Variable Declaration

P=array([2,0,-1])
Q=array([2,-1,2])
R=array([2,-3,1])
ax=array([1,0,0])             #Unit vector along x direction
ay=array([0,1,0])             #Unit vector along y direction
az=array([0,0,1])             #Unit vector along z direction

#Calculations

ansa=cross((P+Q),(P-Q))
ansb=dot(Q,cross(R,P))
ansc=dot(P,cross(Q,R))
lqxr=scipy.sqrt(dot(cross(Q,R),cross(Q,R)))   #Magnitude of QXR
lq=scipy.sqrt(dot(Q,Q))                       #Magnitude of Q
lr=scipy.sqrt(dot(R,R))                       #Magnitude of R
ansd=lqxr/(lq*lr)
anse=cross(P,cross(Q,R))

#Finding unit vector perpendicular to Q and R

ux=dot(cross(Q,R),ax)/lqxr    #X component of the unit vector
uy=dot(cross(Q,R),ay)/lqxr    #Y component of the unit vector
uz=dot(cross(Q,R),az)/lqxr    #Z component of the unit vector

ansf=array([round(ux,3),round(uy,3),round(uz,3)])

ansg=round((float(dot(P,Q))/dot(Q,Q)),4)*Q


#Results

print '(P+Q)X(P-Q) =',ansa
print 'Q.(R X P) =',ansb
print 'P.(Q X R) =',ansc
print 'Sin(theta_QR) =',round(ansd,4)
print 'P X (Q X R) =',anse
print 'A unit vector perpendicular to both Q and R =',ansf
print 'The component of P along Q =',ansg
(P+Q)X(P-Q) = [ 2 12  4]
Q.(R X P) = 14
P.(Q X R) = 14
Sin(theta_QR) = 0.5976
P X (Q X R) = [2 3 4]
A unit vector perpendicular to both Q and R = [ 0.745  0.298 -0.596]
The component of P along Q = [ 0.4444 -0.2222  0.4444]

Example 1.7, Page number: 21

In [6]:
 
import scipy
from numpy import *

#Variable Declaration

P1=array([5,2,-4])
P2=array([1,1,2])
P3=array([-3,0,8])
P4=array([3,-1,0])

#Calculations

R12=P2-P1;                                      #Distance vector from P1 to P2
R13=P3-P1;                                      #Distance vector from P1 to P3
R14=P4-P1;                                      #Distance vector from P1 to P4
s=cross(R12,R13)
x=cross(R14,R12)
d=scipy.sqrt(dot(x,x))/scipy.sqrt(dot(R12,R12)) #Distance from line to P4 

#Results

print 'The cross product of the distance vectors R12 and R14 =',s
print 'So they are along same direction and hence P1, P2 and P3 are collinear.'
print 'The shortest distance from the line to point P4 =',round(d,3)
The cross product of the distance vectors R12 and R14 = [0 0 0]
So they are along same direction and hence P1, P2 and P3 are collinear.
The shortest distance from the line to point P4 = 2.426