Dot product of two vectors and the (cosine of the) angle between them === ======= == === ======= === === ====== == === ===== ======= ==== Suppose given two vectors v and w , neither of them the zero vector. In fact, suppose each of v and w has length 1 . (At the very very end, we'll see what happens when this restriction is lifted.) To come to grips with the significance of the dot product of v with w let's try to find out for which number(s) k (non-zero, if possible) the vector (from the origin to) w is the hypotenuse of a right triangle whose other two legs are the vector (from the origin to) kv and the vector from kv to w . (Draw two pictures, one with angle between v and w acute, and k > 0 , and one with angle in question obtuse, and k < 0 .) In particular, k should be so chosen that the last two legs mentioned really are perpendicular to each other. But then the Pythagorean Theorem would let us expect that the sum of the squares of their two lengths is just equal to the square of the length of the hypotenuse, i.e., || kv ||^2 + || w - kv ||^2 = || w ||^2 . Remembering that we're supposing || v || = 1 and || w || = 1 , this equation simplifies (why?) to k^2 + || w - kv ||^2 = 1 . Now to come to grips with the expression || w - kv ||^2 , let's say v = (v_1, v_2, ..., v_i, ..., v_n) and w = (w_1, w_2, ..., w_i, ..., w_n) . Then, still remembering that || v || = 1 and || w || = 1 , || w - kv ||^2 = ∑_i=1...n (w_i - kv_i)^2 = = ∑_i=1...n ( (w_i)^2 - 2kv_iw_i + (kv_i)^2 ) = = ∑_i=1...n (w_i)^2 - ∑_i=1...n 2k(v_i)(w_i) + ∑_i=1...n k^2 (v_i)^2 = = || w ||^2 - 2k(v • w) + k^2 || v ||^2 = = 1 - 2k(v • w) + k^2 ; so the simplified equation simplifies further to k^2 + 1 - 2k(v • w) + k^2 = 1 , or, rebalancing by leaving only the "k^2" terms on the LHS, 2 k^2 = 2k(v • w) , or, if you prefer, 2k(k - (v • w) ) = 0 . Clearly, the only solutions k to this equation have form k = 0 (which, as we said at the outset, we'd prefer to avoid, if possible), and k = v • w (which, when v • w = 0 , will be the only solution). Thus the number k we are seeking has the uniform expression k = v • w , and this is the significance of the dot product of the (unit) vectors v and w . Trigonometrically, of course, when the angle between v and w is acute, the length k of kv is the cosine (why?) of that angle, while when that angle is obtuse, it's the negative -|k| (= k) of the length |k| of kv that is that cosine, whence, at least for unit vectors v and w , cos ( ∠ between v and w ) = k = v • w . Finally, let's drop the requirements that v and w be unit vectors. But let's at least assume they're each non-zero, so that they have non-zero lengths. Well, then (1/||v||)v and (1/||w||)w are unit vectors. And the angle between the vectors from the origin to v and from the origin to w is certainly the same as the angle between those two unit vectors (1/||v||)v and (1/||w||)w . So: cos ( ∠ between v and w ) = = cos ( ∠ between (1/||v||)v and (1/||w||)w ) = = ((1/||v||)v) &bul; ((1/||w||)w) = = (1/||v||)(1/||w||)( v &bul; w ) = v &bul; w = ----------- . ||v|| ||w|| (When at least one of v and w -- v , say -- is the zero vector, the above procedure can't be carried out. On the other hand, it's hard to come up with a number you'd really like to think of as measuring any "angle" between the zero vector and the vector from the origin to w . But the dot product of zero with w still makes sense, as zero. And the "cross-multiplied" form of the above equation, ||v|| ||w|| cos ( ∠ between v and w ) = v • w , remains valid (after all, it becomes 0 = 0 ) no matter what number you might chose to play the role of cos ( ∠ between v and w ) .) [NB: HTML version in preparation. Prepared 18 Feb 2004. Questions, broken typography, and other errata, please, to me at FLinton@Wesleyan.edu . Many thanks. -- FEJ]
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "http://tlvp.net/~fej.math.wes/spr-2004/DotProd.txt", "fetch_time": 1558408143000000000, "content_mime_type": "text/plain", "warc_filename": "crawl-data/CC-MAIN-2019-22/segments/1558232256215.47/warc/CC-MAIN-20190521022141-20190521044141-00249.warc.gz", "warc_record_offset": 204586627, "warc_record_length": 2300, "token_count": 1207, "char_count": 3817, "score": 4.28125, "int_score": 4, "crawl": "CC-MAIN-2019-22", "snapshot_type": "latest", "language": "en", "language_score": 0.9230362772941589, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00039-of-00064.parquet"}