# calculate dot product of two vectors implemented as lists import math def calcX(A,B): AdotB=0 for i in range (len(A)): AdotB = AdotB + (A[i] * B[i]) return AdotB #check if two vectors are orthogonal def orthogonal(A,B): if calcX(A,B) ==0: result = True else: result = False return result #endsub # normalise a vector def normalise (A): normalA = [0,0] print('normalA and A',normalA, ' ',A) length = math.sqrt(A[0]**2 + A[1]**2) print('length =',length) normalA[0] = round(A[0]/length,2) normalA[1] =round(A[1]/length,2) print('normalA',normalA, A) return normalA #endsub #main A =[3,4] B =[2,1] x = calcX(A,B) print('Dot product',x) RightAngle = orthogonal(A,B) print(RightAngle) B = [2,-1.5] RightAngle = orthogonal(A,B) print('Right angle', RightAngle) X = [3,4] Y = normalise(X) print ('vector',X,'normalised is ',Y)