notes

Log | Files | Refs

dot_product.txt (2608B)


      1 ===============================================================================
      2 DOT PRODUCT
      3 ===============================================================================
      4 
      5 The dot product is an operation that takes two vectors of the same dimension and
      6 returns a single real number (a scalar), often written as a . b.
      7 
      8 
      9 -------------------------------------------------------------------------------
     10 1. ALGEBRAIC DEFINITION
     11 -------------------------------------------------------------------------------
     12 
     13 For vectors in R^n:
     14 
     15        | a1 |         | b1 |
     16        | a2 |         | b2 |
     17   a =  | .. |    b =  | .. |
     18        | an |         | bn |
     19 
     20 their dot product is:
     21 
     22   a . b = a1*b1 + a2*b2 + ... + an*bn
     23 
     24 Example in R^3:
     25 
     26   |  1 |   |  4 |
     27   |  3 | . | -2 | = 1*4 + 3*(-2) + (-5)*(-1) = 4 - 6 + 5 = 3
     28   | -5 |   | -1 |
     29 
     30 
     31 -------------------------------------------------------------------------------
     32 2. GEOMETRIC DEFINITION
     33 -------------------------------------------------------------------------------
     34 
     35 If a, b in R^n and theta is the angle between them, then:
     36 
     37   a . b = ||a|| * ||b|| * cos(theta)
     38 
     39 where ||a|| is the Euclidean length (norm) of a.
     40 
     41 From this, you also get:
     42 
     43   a . a = ||a||^2
     44   ||a|| = sqrt(a . a)
     45 
     46 
     47 -------------------------------------------------------------------------------
     48 3. BASIC CALCULATION RULES
     49 -------------------------------------------------------------------------------
     50 
     51 Let a, b, c in R^n and lambda in R. Then:
     52 
     53 Commutativity:
     54 
     55   a . b = b . a
     56 
     57 Distributivity over addition:
     58 
     59   a . (b + c) = a . b + a . c
     60 
     61 Homogeneity (scalar multiplication in one slot):
     62 
     63   (lambda*a) . b = lambda * (a . b)
     64   a . (lambda*b) = lambda * (a . b)
     65 
     66 Positivity:
     67 
     68   a . a >= 0
     69   a . a = 0  if and only if  a = 0
     70 
     71 
     72 -------------------------------------------------------------------------------
     73 4. WORKED EXAMPLES
     74 -------------------------------------------------------------------------------
     75 
     76 4.1 Simple 2D example
     77 
     78        | 2 |
     79   u =  | -1 |       v = | 3 |
     80                         | 4 |
     81 
     82   u . v = 2*3 + (-1)*4 = 6 - 4 = 2
     83 
     84 
     85 4.2 4D example
     86 
     87        |  2 |         | -1 |
     88        |  0 |         |  3 |
     89   x =  | -3 |    y =  |  1 |
     90        |  1 |         |  2 |
     91 
     92   x . y = 2*(-1) + 0*3 + (-3)*1 + 1*2 = -2 + 0 - 3 + 2 = -3
     93 
     94 
     95 4.3 Using the geometric form to find an angle
     96 
     97        | 1 |         | 2 |
     98   a =  | 2 |    b =  | 1 |
     99 
    100   a . b = 1*2 + 2*1 = 4
    101 
    102   ||a|| = sqrt(1^2 + 2^2) = sqrt(5)
    103   ||b|| = sqrt(2^2 + 1^2) = sqrt(5)
    104 
    105   cos(θ) = (a . b) / (||a|| * ||b||)
    106          = 4 / (sqrt(5) * sqrt(5))
    107          = 4/5
    108 
    109   θ = arccos(4/5)
    110 
    111   Reference read for arccos: https://www.math.net/arccos