{"id":31692,"date":"2017-06-12T14:57:29","date_gmt":"2017-06-12T19:57:29","guid":{"rendered":"http:\/\/blogs.ams.org\/mathgradblog\/?p=31692"},"modified":"2017-06-19T16:52:34","modified_gmt":"2017-06-19T21:52:34","slug":"matrix-multiplication-human-way","status":"publish","type":"post","link":"https:\/\/blogs.ams.org\/mathgradblog\/2017\/06\/12\/matrix-multiplication-human-way\/","title":{"rendered":"Matrix Multiplication, the human way!"},"content":{"rendered":"<p>Having to do copious calculations by hand when preparing for an exam, I came to realize that there was an alternative way of interpreting a matrix multiplication. This new insight would allow me to instantly guess the following product <em>without ever doing any numerical multiplication<\/em>:<br \/>\n\\[\\begin{bmatrix}<br \/>\n1 &amp; 2 &amp; 3 \\\\<br \/>\n4 &amp; 5 &amp; 6 \\\\<br \/>\n7 &amp; -8 &amp; 0<br \/>\n\\end{bmatrix}<br \/>\n\\begin{bmatrix}<br \/>\n0 &amp; 0 &amp; 0 \\\\<br \/>\n0&amp; 1 &amp; 0 \\\\<br \/>\n1&amp; 0 &amp; 0<br \/>\n\\end{bmatrix}<br \/>\n=<br \/>\n\\begin{bmatrix}<br \/>\n3 &amp; 2 &amp; 0 \\\\<br \/>\n6 &amp; 5 &amp; 0 \\\\<br \/>\n0 &amp; -8 &amp; 0<br \/>\n\\end{bmatrix}\\]<\/p>\n<p>Was there a way to have known that the first column of the product would be the third column of the first matrix?<\/p>\n<p><!--more--><\/p>\n<p><strong>MATRIX TIMES VECTOR<\/strong><\/p>\n<p><strong>Observation:<\/strong> If <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=A&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"A\" class=\"latex\" \/> has $n$ columns and $v$ is an <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=n&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"n\" class=\"latex\" \/>-vector, then<\/p>\n<p>\\[Av=\\begin{bmatrix}<br \/>\nc &amp; c &amp; c &amp; \\cdots \\\\<br \/>\no &amp; o &amp; o &amp; \\cdots \\\\<br \/>\nl &amp; l &amp; l &amp; \\cdots \\\\<br \/>\nu &amp; u &amp; u &amp; \\cdots \\\\<br \/>\nm &amp; m &amp; m &amp; \\cdots \\\\<br \/>\nn &amp; n &amp; n &amp; \\cdots \\\\<br \/>\n\\end{bmatrix}<br \/>\n\\begin{bmatrix}<br \/>\na\u00a0 \\\\<br \/>\nb \\\\<br \/>\nc \\\\<br \/>\n\\vdots<br \/>\n\\end{bmatrix}<br \/>\n=<br \/>\na* \\begin{bmatrix}<br \/>\n1^{st}\u00a0 \\\\<br \/>\nc \\\\<br \/>\no \\\\<br \/>\nl \\\\<br \/>\nu \\\\<br \/>\nm \\\\<br \/>\nn<br \/>\n\\end{bmatrix}<br \/>\n+b*\u00a0 \\begin{bmatrix}<br \/>\n2^{nd}\u00a0 \\\\<br \/>\nc \\\\<br \/>\no \\\\<br \/>\nl \\\\<br \/>\nu \\\\<br \/>\nm \\\\<br \/>\nn<br \/>\n\\end{bmatrix}<br \/>\n+c* \\begin{bmatrix}<br \/>\n3^{rd}\u00a0 \\\\<br \/>\nc \\\\<br \/>\no \\\\<br \/>\nl \\\\<br \/>\nu \\\\<br \/>\nm \\\\<br \/>\nn<br \/>\n\\end{bmatrix}+ \\cdots \\]<\/p>\n<p>That is, the product is a linear combination of the columns with coefficients coming from the vector.<\/p>\n<p>Examples:<\/p>\n<p>1.<\/p>\n<p>\\[\\begin{bmatrix}<br \/>\n1 &amp; -5 &amp; 3 \\\\<br \/>\n0 &amp; 0.5 &amp; 2\\\\<br \/>\n1 &amp; -8 &amp; 0<br \/>\n\\end{bmatrix}<br \/>\n\\begin{bmatrix}<br \/>\n2\\\\<br \/>\n-1 \\\\<br \/>\n0<br \/>\n\\end{bmatrix}<br \/>\n= 2* \\begin{bmatrix} 1st\\\\ col \\end{bmatrix} + (-1)*\\begin{bmatrix} 2nd\\\\ col \\end{bmatrix} + 0\u00a0\u00a0 \\\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\\u00a0 \\ \\ \\ \\ \\ \\\u00a0 \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\\u00a0 =<br \/>\n2 \\begin{bmatrix}<br \/>\n1 \\\\<br \/>\n0 \\\\<br \/>\n1<br \/>\n\\end{bmatrix} -\\begin{bmatrix}<br \/>\n-5 \\\\<br \/>\n0.5 \\\\<br \/>\n-8<br \/>\n\\end{bmatrix}+0 = \\begin{bmatrix}<br \/>\n7 \\\\<br \/>\n-0.5 \\\\<br \/>\n10<br \/>\n\\end{bmatrix}\\]<\/p>\n<p>2. What vector to multiply a matrix <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=A&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"A\" class=\"latex\" \/> into, so that we get the second column of <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=A&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"A\" class=\"latex\" \/> as the product?<\/p>\n<p>Answer: \\[ \\begin{bmatrix}<br \/>\n0 \\\\<br \/>\n1 \\\\<br \/>\n0 \\\\<br \/>\n\\vdots<br \/>\n\\end{bmatrix}. \\]<\/p>\n<p>It is not only the practical calculations that benefit from this new method. Some lemmas and theorems of linear algebra become more obvious and accessible. For example:<\/p>\n<p>Ax=0 has a nontrivial solution iff the columns of A are linearly dependent (as vectors).<\/p>\n<p>dimension of {Ax: x ranging over all column vectors} = number of independent columns of A<\/p>\n<p>Given <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=A&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"A\" class=\"latex\" \/> and <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=b&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"b\" class=\"latex\" \/>, <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=Av%3Db&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"Av=b\" class=\"latex\" \/> has a solution iff <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=b&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"b\" class=\"latex\" \/> can be written as a linear combination of columns of <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=A&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"A\" class=\"latex\" \/>.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>MATRIX TIMES MATRIX<\/strong><\/p>\n<p>In computing<\/p>\n<p>\\[AB=\\begin{bmatrix}<br \/>\nc &amp; c &amp; c &amp; \\cdots \\\\<br \/>\no &amp; o &amp; o &amp; \\cdots \\\\<br \/>\nl &amp; l &amp; l &amp; \\cdots \\\\<br \/>\nu &amp; u &amp; u &amp; \\cdots \\\\<br \/>\nm &amp; m &amp; m &amp; \\cdots \\\\<br \/>\nn &amp; n &amp; n &amp; \\cdots \\\\<br \/>\n\\end{bmatrix}<br \/>\n\\begin{bmatrix}<br \/>\nc &amp; c &amp; c &amp; \\cdots \\\\<br \/>\no &amp; o &amp; o &amp; \\cdots \\\\<br \/>\nl &amp; l &amp; l &amp; \\cdots \\\\<br \/>\nu &amp; u &amp; u &amp; \\cdots \\\\<br \/>\nm &amp; m &amp; m &amp; \\cdots \\\\<br \/>\nn &amp; n &amp; n &amp; \\cdots \\\\<br \/>\n\\end{bmatrix}<br \/>\n, \\ \\]<\/p>\n<p>To get the\u00a0 j&#8217;th\u00a0column of the product, ignore all other columns of B except the\u00a0 j\u2019th, and then do A*[column j of B], using the above method. Do this for all columns and you will have the product <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=AB&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"AB\" class=\"latex\" \/>.<\/p>\n<p>Examples:<\/p>\n<p>1.<\/p>\n<p>\\[\\begin{bmatrix}<br \/>\n1 &amp; 2 &amp; 3 \\\\<br \/>\n4 &amp; 5 &amp; -2 \\\\<br \/>\n7 &amp; -4 &amp; 0<br \/>\n\\end{bmatrix}<br \/>\n\\begin{bmatrix}<br \/>\n1 &amp; 0 &amp; 1 \\\\<br \/>\n0&amp; 1 &amp; 1 \\\\<br \/>\n2&amp; 3 &amp; 0<br \/>\n\\end{bmatrix} \\]<\/p>\n<p>The <strong><span style=\"text-decoration: underline\">first<\/span> <\/strong>column will be<\/p>\n<p>\\[ \\begin{bmatrix}<br \/>\n1 &amp; 2 &amp; 3 \\\\<br \/>\n4 &amp; 5 &amp; -2 \\\\<br \/>\n7 &amp; -4 &amp; 0<br \/>\n\\end{bmatrix}<br \/>\n\\begin{bmatrix}<br \/>\n1\u00a0 \\\\<br \/>\n0 \\\\<br \/>\n2<br \/>\n\\end{bmatrix} =<br \/>\n1*\\begin{bmatrix}<br \/>\n1\u00a0 \\\\<br \/>\n4 \\\\<br \/>\n7<br \/>\n\\end{bmatrix} + 2* \\begin{bmatrix}<br \/>\n3\u00a0 \\\\<br \/>\n-2 \\\\<br \/>\n0<br \/>\n\\end{bmatrix} = \\begin{bmatrix}<br \/>\n7\\\\<br \/>\n0 \\\\<br \/>\n7<br \/>\n\\end{bmatrix} \\]<\/p>\n<p>The <span style=\"text-decoration: underline\"><strong>second<\/strong><\/span> column will be<\/p>\n<p>\\[ \\begin{bmatrix}<br \/>\n1 &amp; 2 &amp; 3 \\\\<br \/>\n4 &amp; 5 &amp; -2 \\\\<br \/>\n7 &amp; -4 &amp; 0<br \/>\n\\end{bmatrix}<br \/>\n\\begin{bmatrix}<br \/>\n0\u00a0 \\\\<br \/>\n1 \\\\<br \/>\n3<br \/>\n\\end{bmatrix} =<br \/>\n1*\\begin{bmatrix}<br \/>\n2\u00a0 \\\\<br \/>\n5 \\\\<br \/>\n-4<br \/>\n\\end{bmatrix} + 3* \\begin{bmatrix}<br \/>\n3\u00a0 \\\\<br \/>\n-2 \\\\<br \/>\n0<br \/>\n\\end{bmatrix} = \\begin{bmatrix}<br \/>\n11 \\\\<br \/>\n-1 \\\\<br \/>\n-4<br \/>\n\\end{bmatrix} \\]<\/p>\n<p>Column 3 is computed similarly, and the full result is:<\/p>\n<p>\\[\\begin{bmatrix}<br \/>\n1 &amp; 2 &amp; 3 \\\\<br \/>\n4 &amp; 5 &amp; -2 \\\\<br \/>\n7 &amp; -4 &amp; 0<br \/>\n\\end{bmatrix}<br \/>\n\\begin{bmatrix}<br \/>\n1 &amp; 0 &amp; 1 \\\\<br \/>\n0&amp; 1 &amp; 1 \\\\<br \/>\n2&amp; 3 &amp; 0<br \/>\n\\end{bmatrix} = \\begin{bmatrix}<br \/>\n7 &amp; 11\u00a0 &amp; 3 \\\\<br \/>\n0 &amp; -1 &amp; 9 \\\\<br \/>\n7 &amp; -4 &amp; 3<br \/>\n\\end{bmatrix} \\]<\/p>\n<p>Note: Most of the calculations above are doable in mind, and I have written them out to explain the procedure only.<\/p>\n<p>2. Multiply\u00a0 \\[A= \\begin{bmatrix}<br \/>\n2 &amp; 33\u00a0 &amp; 0 \\\\<br \/>\n0 &amp; -1 &amp; 9 \\\\<br \/>\n4\u00a0 &amp; -14 &amp; 13<br \/>\n\\end{bmatrix} \\]\u00a0 into a matrix <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=B&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"B\" class=\"latex\" \/> so that the columns 2 and 3 of A are interchanged.<\/p>\n<p>Answer:\u00a0 \\[ B=\\begin{bmatrix}<br \/>\n1 &amp; 0 &amp;\u00a0 0 \\\\<br \/>\n0 &amp; 0 &amp; 1 \\\\<br \/>\n0 &amp; 1 &amp;\u00a0\u00a0 0<br \/>\n\\end{bmatrix} \\]<\/p>\n<p>3. Find the 3rd column of the product<\/p>\n<p>\\[\\begin{bmatrix}<br \/>\n10 &amp; 2 &amp; 3 \\\\<br \/>\n4 &amp; 0 &amp; -2 \\\\<br \/>\n7 &amp; -4 &amp; 0<br \/>\n\\end{bmatrix}<br \/>\n\\begin{bmatrix}<br \/>\n1 &amp; 0 &amp; 1 \\\\<br \/>\n0&amp; 1 &amp; 1 \\\\<br \/>\n-2&amp; 0 &amp; -1<br \/>\n\\end{bmatrix} \\]<\/p>\n<p>Answer:<\/p>\n<p>thrid column of AB = A * third column of B. So<\/p>\n<p>\\[ \\begin{bmatrix}<br \/>\n10 &amp; 2 &amp; 3 \\\\<br \/>\n4 &amp; 0 &amp; -2 \\\\<br \/>\n7 &amp; -4 &amp; 0<br \/>\n\\end{bmatrix}<br \/>\n\\begin{bmatrix} 1 \\\\ 1 \\\\ -1 \\end{bmatrix}= \\begin{bmatrix} 9 \\\\ 6 \\\\ 3 \\end{bmatrix} \\]<\/p>\n<p>(Please verify!)<\/p>\n<p>&nbsp;<\/p>\n<p>4. Is the following true or false? <em>&#8220;If we change arrays in the second column of B, then in the product AB only the arrays in the second column may change &#8212; all other arrays on other columns will remain the same.&#8221;<\/em><\/p>\n<p>Answer: True.<\/p>\n<p>&nbsp;<\/p>\n<p>Whether you are convinced that computing AB one column at a time is more practical than the conventional array-by-array multiplication or not, one cannot ignore its usefulness in helping one to &#8220;see&#8221; the linear algebra behind matrices and their multiplication. So, next time you encounter a sparse matrix save yourself tens of multiplications by zero!<\/p>\n<p><strong>HOMEWORK<\/strong><\/p>\n<p>Can you guess and prove a row-wise version of the above?<\/p>\n<p>&nbsp;<\/p>\n<div style=\"margin-top: 0px; margin-bottom: 0px;\" class=\"sharethis-inline-share-buttons\" ><\/div>","protected":false},"excerpt":{"rendered":"<p>Having to do copious calculations by hand when preparing for an exam, I came to realize that there was an alternative way of interpreting a matrix multiplication. This new insight would allow me to instantly guess the following product without &hellip; <a href=\"https:\/\/blogs.ams.org\/mathgradblog\/2017\/06\/12\/matrix-multiplication-human-way\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n<div style=\"margin-top: 0px; margin-bottom: 0px;\" class=\"sharethis-inline-share-buttons\" data-url=https:\/\/blogs.ams.org\/mathgradblog\/2017\/06\/12\/matrix-multiplication-human-way\/><\/div>\n","protected":false},"author":118,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[12],"tags":[67,300,301],"class_list":["post-31692","post","type-post","status-publish","format-standard","hentry","category-math","tag-mathematics","tag-matrix-multiplication","tag-tips-and-tricks"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3gbww-8fa","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blogs.ams.org\/mathgradblog\/wp-json\/wp\/v2\/posts\/31692","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.ams.org\/mathgradblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.ams.org\/mathgradblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.ams.org\/mathgradblog\/wp-json\/wp\/v2\/users\/118"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.ams.org\/mathgradblog\/wp-json\/wp\/v2\/comments?post=31692"}],"version-history":[{"count":26,"href":"https:\/\/blogs.ams.org\/mathgradblog\/wp-json\/wp\/v2\/posts\/31692\/revisions"}],"predecessor-version":[{"id":31725,"href":"https:\/\/blogs.ams.org\/mathgradblog\/wp-json\/wp\/v2\/posts\/31692\/revisions\/31725"}],"wp:attachment":[{"href":"https:\/\/blogs.ams.org\/mathgradblog\/wp-json\/wp\/v2\/media?parent=31692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.ams.org\/mathgradblog\/wp-json\/wp\/v2\/categories?post=31692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.ams.org\/mathgradblog\/wp-json\/wp\/v2\/tags?post=31692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}