p1_mrg_vector1

2894 days ago by LAC2011

#initialize vectors in R^3 a=vector([1,2,3]) a 
       
b=vector([-1,0,5]) b 
       
#vector sums c=a+b show(c) d=a-b show(d) 
       

#vector plots a.plot(rgbcolor='red')+b.plot(rgbcolor='blue')+c.plot(rgbcolor='green') 
       
#vector magnitudes lenA=norm(a) lenB=norm(b) lenC=norm(c) lenD=norm(d) show(lenA) show(lenB) show(lenC) show(lenD) 
       



#scalar product e=a*b e 
       
f=sum(ai*bi for ai,bi in zip(a,b)) f 
       
g=a.dot_product(b) g 
       
#find theta between vector a and b using dot product theta1=arccos(e/(lenA*lenB)) show(n(theta1)) theta2=theta1*180/pi show(n(theta2))