Task

Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors.

If possible, make the vectors of arbitrary length.



As an example, compute the dot product of the vectors:

     [1,  3, -5]       and 
     [4, -2, -1]   


If implementing the dot product of two vectors directly:

   each vector must be the same length
   multiply corresponding terms from each vector
   sum the products   (to produce the answer)


Related task

   Vector products


 
 100 :
 110  REM  DOT PRODUCT
 120 :
 130  REM  INITIALIZE VECTORS OF LENGTH N
 140  N = 3
 150  DIM V1(N): DIM V2(N)
 160  FOR I = 1 TO N
 170  V1(I) =  INT ( RND (1) * 20 - 9.5)
 180  V2(I) =  INT ( RND (1) * 20 - 9.5)
 190  NEXT I
 300 :
 310  REM  CALCULATE THE DOT PRODUCT
 320 :
 330  FOR I = 1 TO N:DP = DP + V1(I) * V2(I): NEXT I
 400 :
 410  REM  DISPLAY RESULT
 420 :
 430  PRINT "[";: FOR I = 1 TO N: PRINT " ";V1(I);: NEXT I
 440  PRINT "] . [";: FOR I = 1 TO N: PRINT " ";V2(I);: NEXT I
 450  PRINT "] = ";DP
 