<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Matrix-Multiplication on avni.sh</title>
    <link>http://www.avni.sh/tags/matrix-multiplication/</link>
    <description>Recent content in Matrix-Multiplication on avni.sh</description>
    <image>
      <title>avni.sh</title>
      <url>http://www.avni.sh/cover.webp</url>
      <link>http://www.avni.sh/cover.webp</link>
    </image>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Tue, 16 Jul 2024 00:00:00 +0000</lastBuildDate>
    <atom:link href="http://www.avni.sh/tags/matrix-multiplication/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Gaussian Elimination</title>
      <link>http://www.avni.sh/posts/linear-algebra/gaussian-elimination/</link>
      <pubDate>Tue, 16 Jul 2024 00:00:00 +0000</pubDate>
      <guid>http://www.avni.sh/posts/linear-algebra/gaussian-elimination/</guid>
      <description>The Gaussian Elimination algorithm is used to find the solution of a system of linear equations by performing row-wise operations on its matrix.</description>
      <content:encoded><![CDATA[<p>Let&rsquo;s consider a problem where we have to buy oranges and apples but under the following conditions.</p>
<ul>
<li>The difference between 2X the number of oranges and the number of apples should be 3.</li>
<li>The sum of 4X the number of oranges and the number of apples should be 9.</li>
<li>The difference between 5X the number of oranges and 3X the number of apples should be 7.</li>
</ul>
<h1 id="system-of-linear-equations">System of Linear Equations</h1>
<p>These conditions could be modeled using the following equations</p>
<p>$$2x-y=3\tag{1}$$</p>
<p>$$4x+y=9\tag{2}$$</p>
<p>$$5x-3y=7\tag{3}$$</p>
<p>where $x$ and $y$ are the number of oranges and apples respectively. Collectively, these equations would be called a <strong>system of linear equations</strong> of variables $x$ and $y$.</p>
<p>We can also represent this system of linear equations using matrices as follows.</p>
<p>$$\begin{bmatrix} 2x - y \\ 4x+y \\ 5x-3y \end{bmatrix} = \begin{bmatrix} 3 \\ 9  \\ 7\end{bmatrix}$$</p>
<h1 id="row-picture">Row Picture</h1>
<p>The representation of a system of linear equations as a <a href="/posts/math/linear-algebra/matrices/#multiplication-of-matrices" target="_blank">matrix multiplication</a> product of the coefficients and the variable matrix is called the <strong>row picture</strong>. Each row represents a different linear equation.</p>
<p>$$\begin{bmatrix} 2 &amp; -1 \\ 4 &amp; 1 \\ 5 &amp; -3 \end{bmatrix} \times \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} 3 \\ 9  \\ 7\end{bmatrix}$$</p>
<p>As a linear algebra equation, this could be written as $\textbf{Ax=b}$. Where $\textbf{A}$ is the matrix of coefficients, $\textbf{x}$ is the vector of variables, and $\textbf{b}$ is the vector of constants.</p>
<h1 id="column-picture">Column Picture</h1>
<p>Alternatively, the coefficients of the variable $x$ and $y$ could be separated into two matrices as follows.</p>
<p>$$\begin{bmatrix} 2 \\ 4 \\ 5 \end{bmatrix} x \ + \begin{bmatrix} -1 \\ 1 \\ -3 \end{bmatrix}y = \begin{bmatrix} 3 \\ 9  \\ 7\end{bmatrix}$$</p>
<p>this is the <strong>column picture</strong> of the system of linear equations.</p>
<h1 id="solution-of-linear-equations">Solution of Linear Equations</h1>
<p>The value of variables that satisfies all equations is called the <strong>solution</strong> (or solutions if there are multiple) of the system of linear equations.</p>
<h2 id="one-solution">One Solution</h2>
<p>If we plot equations $(1)$, $(2)$, and $(3)$ on a 2D graph</p>
<p align="center"><img src="one_solution.png" alt="System of linear equations with one solution on a 2D graph"></p>
<p>The point at which all three lines intersect will be the solution of the linear equations i.e. $(2, 1)$.</p>
<h2 id="infinitely-many-solutions">Infinitely Many Solutions</h2>
<p>Consider the following system of linear equations.</p>
<p>$$x+3y=9 \tag{4}$$</p>
<p>$$2x+6y=18\tag{5}$$</p>
<p>If we plot them on a 2D graph, both lines overlap over each other.</p>
<p align="center"><img src="infinitely_many_solutions.png" alt="System of linear equations with infinitely many solutions on a 2D graph"></p>
<p>The set of values for $x$ and $y$ for which both equations are satisfied is infinitely large.
We can also observe this from the fact that if we multiply the equation $(4)$ by $2$ we get the equation $(5)$.</p>
<p>$$2 \times (x+3y = 9)$$</p>
<p>$$2x + 2\cdot3y = 2\cdot 9$$</p>
<p>$$2x+6y=18$$</p>
<p>Thus, the equation $(5)$ is just the equation $(4)$ scaled up by 2.</p>
<h2 id="no-solution">No Solution</h2>
<p>It is also possible for a system of linear equations that none of the variable values satisfy all the equations, like the following.</p>
<p>$$x+y=4 \tag{6}$$</p>
<p>$$x+y=8\tag{7}$$$$x-y=0 \tag{8}$$</p>
<p align="center"><img src="no_solution.png" alt="System of linear equations with no solution on a 2D graph"></p>
<p>Although we have multiple points of intersection between the lines, there is no single point where all three lines intersect. Thus, for no common values of $x$ and $y$ equations $(6)$, $(7)$, and $(8)$ are satisfied.</p>
<h1 id="elimination-method">Elimination Method</h1>
<p>To find the values of $x$ and $y$ in the system of linear equations $(1)$, $(2)$, and $(3)$, we can start by eliminating one of the variables from any of the equations.</p>
<p>If we multiply the equation $(2)$ by $3$</p>
<p>$$3 \times (4x+y=9) $$</p>
<p>$$12x + 3y = 27 \tag{9}$$</p>
<p>and add it to the equation $(3)$</p>
<p>$$(5x - 3y)+(12x+3y) = 7+27$$</p>
<p>$$5x+12x-3y+3y=34$$</p>
<p>$$17x=34$$</p>
<p>$$x=2$$</p>
<p>Now that we know the value of $x$ we can substitute it into any equation (like equation $(2)$) to find the value of $y$.</p>
<p>$$4 \times 2 + y = 9$$</p>
<p>$$8 + y = 9$$</p>
<p>$$y=9-8$$</p>
<p>$$y=1$$</p>
<p>To verify if $(2, 1)$ is indeed the solution of the system of linear equations $(1)$, $(2)$, and $(3)$ we can test the values in the equation $(1)$.</p>
<p>$$2x-y=3$$</p>
<p>$$2 \times 2 - 1 = 3$$</p>
<p>$$4-1 = 3$$</p>
<p>$$3=3$$</p>
<p>Thus, we can confirm that $(2, 1)$ is the solution.</p>
<h1 id="gaussian-elimination">Gaussian Elimination</h1>
<p>The <strong>Gaussian Elimination</strong> is an algorithm for finding the solution of a system of linear equations by performing row-wise operation on the matrix of coefficients and constants. It is named after Carl Friedrich Gauss.</p>
<p>It is similar to the <em>elimination method</em> discussed above, the difference is that the operations are performed collectively on the matrix. It involves the following steps.</p>
<ol>
<li>Expressing the system of linear equations with matrices, in the row picture form.</li>
<li>Creating an augmented matrices of coefficients and constants.</li>
<li>Reducing the augmented matrix to its row echelon form.</li>
<li>Breaking the row echelon form of the augmented matrix back to its row picture form.</li>
<li>Solving the reduced equations to find the values of variables.</li>
</ol>
<p>Let&rsquo;s apply the Gaussian Elimination on the row picture of equations $(1)$, $(2)$, and $(3)$</p>
<p>$$\begin{bmatrix} 2 &amp; -1 \\ 4 &amp; 1 \\ 5 &amp; -3 \end{bmatrix} \times \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} 3 \\ 9  \\ 7\end{bmatrix}$$</p>
<h2 id="augmented-matrix-of-coefficients-and-constants">Augmented Matrix of Coefficients and Constants</h2>
<p>First, we have to create an augmented matrix from the coefficient and constants matrix of the row picture.</p>
<p>$$\begin{bmatrix} 2 &amp; -1 &amp; | &amp; 3 \\ 4 &amp; 1 &amp; | &amp; 9 \\ 5 &amp; -3 &amp; | &amp; 7\end{bmatrix}$$</p>
<p>Then, we reduce this augmented matrix to its row echelon form.</p>
<h2 id="row-echelon-form">Row Echelon Form</h2>
<p>The <strong>row echelon form</strong> of a matrix is an <a href="/posts/math/linear-algebra/matrices/#triangular-matrix" target="_blank">upper-triangular matrix</a> representation (the last row of the matrix could be just $0$s) of the augmented matrix.</p>
<p>To obtain the row echelon form, we can perform <a href="/posts/math/linear-algebra/matrices/#addition-and-subtraction-of-matrices" target="_blank">matrix addition</a>, <a href="/posts/math/linear-algebra/matrices/#multiplication-and-division-with-a-scalar-value" target="_blank">scalar multiplication</a> (with values other than $0$) and swaps between the rows of the augmented matrix.</p>
<p>Initially, the first element in the <a href="/posts/math/linear-algebra/matrices/#diagonal-of-a-matrix" target="_blank">diagonal</a> of the matrix is the <strong>pivot</strong>. All the elements below the pivot have to be reduced to $0$s by performing scalar multiplication and matrix addition/subtraction between the pivot row and the rows below it.</p>
<p>$$\begin{bmatrix} {\color{blue} 2} &amp; -1 &amp; | &amp; 3 \\ 4 &amp; 1 &amp; | &amp; 9 \\ 5 &amp; -3 &amp; | &amp; 7\end{bmatrix}$$</p>
<p>After that, we move on to the next pivot (next element in the diagonal) and repeat the process until we obtain the row echelon form.
If the next pivot element candidate is zero then we won&rsquo;t be able to reduce the elements below it to zero by just scalar multiplication and matrix addition/subtraction. In such cases, we perform a swap between the next row and any other row below it to obtain a non-zero element as the pivot.</p>
<p>If we multiply row 1 of the augmented matrix with the scalar value ${5 \over 2}$</p>
<p>$${5 \over 2} \times \begin{bmatrix} 2 &amp; -1 &amp; | &amp; 3\end{bmatrix} = \begin{bmatrix} 5 &amp; {-5 \over 2} &amp; | &amp; {15 \over 2}\end{bmatrix}$$</p>
<p>and subtract it from row 3 we will obtain the following matrix.</p>
<p>$$\begin{bmatrix} 2 &amp; -1 &amp; | &amp; 3 \\ 4 &amp; 1 &amp; | &amp; 9 \\ 5-5 &amp; -3+{5 \over 2} &amp; | &amp; 7-{15 \over 2}\end{bmatrix}$$</p>
<p>$$\begin{bmatrix} 2 &amp; -1 &amp; | &amp; 3 \\ 4 &amp; 1 &amp; | &amp; 9 \\ 0 &amp; {-1 \over 2} &amp; | &amp; {-1 \over 2}\end{bmatrix}$$</p>
<p>Next, to reduce the last element under the pivot to $0$, we can multiply row 1 with the scalar value $2$</p>
<p>$$2 \times \begin{bmatrix} 2 &amp; -1 &amp; | &amp; 3 \end{bmatrix} = \begin{bmatrix} 4 &amp; -2 &amp; | &amp; 6\end{bmatrix}$$</p>
<p>and subtract it from row 2.</p>
<p>$$\begin{bmatrix} 2 &amp; -1 &amp; | &amp; 3 \\ 4-4 &amp; 1+2 &amp; | &amp; 9-6 \\ 0 &amp; {-1 \over 2} &amp; | &amp; {-1 \over 2}\end{bmatrix}$$</p>
<p>$$\begin{bmatrix} 2 &amp; -1 &amp; | &amp; 3 \\ 0 &amp; 3 &amp; | &amp; 3 \\ 0 &amp; {-1 \over 2} &amp; | &amp; {-1 \over 2}\end{bmatrix}$$</p>
<p>Now, we move on to the next pivot.</p>
<p>$$\begin{bmatrix} 2 &amp; -1 &amp; | &amp; 3 \\ 0 &amp; {\color{blue} 3} &amp; | &amp; 3 \\ 0 &amp; {-1 \over 2} &amp; | &amp; {-1 \over 2}\end{bmatrix}$$</p>
<p>To reduce the element below the pivot to zeros we can multiply row 2 with the scalar value $1 \over 6$</p>
<p>$${1 \over 6} \times \begin{bmatrix} 0 &amp; 3 &amp; | &amp; 3 \end{bmatrix} = \begin{bmatrix} 0 &amp; {1 \over 2} &amp; | &amp; {1 \over 2} \end{bmatrix}$$</p>
<p>and add it to row 3</p>
<p>$$\begin{bmatrix} 2 &amp; -1 &amp; | &amp; 3 \\ 0 &amp; 3 &amp; | &amp; 3 \\ 0+0 &amp; {-1 \over 2}+{1 \over 2} &amp; | &amp; {-1 \over 2}+{1 \over 2}\end{bmatrix}$$</p>
<p>$$\begin{bmatrix} 2 &amp; -1 &amp; | &amp; 3 \\ 0 &amp; 3 &amp; | &amp; 3 \\ 0 &amp; 0 &amp; | &amp; 0\end{bmatrix}$$</p>
<p>This is the row echelon form the augmented matrix created by equation $(1)$, $(2)$, and $(3)$. Notice that the number of non-zero elements in the diagonal ($2$ and $3$) equals to the number of variables in the equations ($x$ and $y$).</p>
<h2 id="back-substitution">Back Substitution</h2>
<p>If we break the row echelon form of the augmented matrix back into the row picture we will obtain the reduced linear equations.</p>
<p>$$\begin{bmatrix} 2 &amp; -1 \\ 0 &amp; 3 \end{bmatrix} \times \begin{bmatrix} x \\ y\end{bmatrix} = \begin{bmatrix} 3 \\ 3\end{bmatrix}$$</p>
<p>$$\begin{bmatrix} 2x-y \\ 3y \end{bmatrix} = \begin{bmatrix} 3 \\ 3\end{bmatrix}$$</p>
<p>By solving these equations for the values of $y$</p>
<p>$$3y=y$$</p>
<p>$$y=1$$</p>
<p>and $x$</p>
<p>$$2x-y=3$$</p>
<p>$$2x - 1 = 3$$</p>
<p>$$2x = 3+1$$</p>
<p>$$2x=4$$</p>
<p>$$x=2$$</p>
<p>we have obtained the solution of the system of linear equations i.e. $(2, 1)$ which is the same solution that we got from the elimination method and the graph.</p>
<h2 id="infinitely-many-solutions-1">Infinitely many solutions</h2>
<p>Applying Gaussian Elimination to the system of linear equations $(4)$ and $(5)$.</p>
<ul>
<li>Creating the augmented matrix</li>
</ul>
<p>$$\begin{bmatrix} 1 &amp; 3 &amp; | &amp; 9 \\ 2 &amp; 6 &amp; | &amp; 18 \end{bmatrix}$$</p>
<ul>
<li>Selecting the pivot element.</li>
</ul>
<p>$$\begin{bmatrix} {\color{blue} 1} &amp; 3 &amp; | &amp; 9 \\ 2 &amp; 6 &amp; | &amp; 18 \end{bmatrix}$$</p>
<ul>
<li>Calculating the row echelon form by multiplying row 1 by the scalar value $2$ and subtracting it from row 2.</li>
</ul>
<p>$$\begin{bmatrix} 1 &amp; 3 &amp; | &amp; 9 \\ 0 &amp; 0 &amp; | &amp; 0\end{bmatrix}$$</p>
<p>The number of non-zero elements in the diagonal ($1$) is lower than the number of variables in the equation ($x$ and $y$).</p>
<p>After converting the row echelon form back to the row picture we get back the equation $(4)$ which can have infinitely many solutions like $(1, 2)$, $(0, 3)$, $(9, 0)$, etc.</p>
<h2 id="no-solution-1">No Solution</h2>
<p>Following is the application of Gaussian elimination on the system of linear equations $(6)$, $(7)$, and $(8)$</p>
<ul>
<li>Creating the augmented matrix.</li>
</ul>
<p>$$\begin{bmatrix} 1 &amp; 1 &amp; | &amp; 4 \\ 1 &amp; 1 &amp; | &amp; 8 \\ 1 &amp; -1 &amp; | &amp; 0\end{bmatrix}$$</p>
<ul>
<li>Selecting the pivot element.</li>
</ul>
<p>$$\begin{bmatrix} {\color{blue} 1} &amp; 1 &amp; | &amp; 4 \\ 1 &amp; 1 &amp; | &amp; 8 \\ 1 &amp; -1 &amp; | &amp; 0\end{bmatrix}$$</p>
<ul>
<li>Subtracting row 1 from row 2</li>
</ul>
<p>$$\begin{bmatrix} 1 &amp; 1 &amp; | &amp; 4 \\ 0 &amp; 0 &amp; | &amp; -4 \\ 1 &amp; -1 &amp; | &amp; 0\end{bmatrix}$$</p>
<ul>
<li>Subtracting row 1 from row 3</li>
</ul>
<p>$$\begin{bmatrix} 1 &amp; 1 &amp; | &amp; 4 \\ 0 &amp; 0 &amp; | &amp; -4 \\ 0 &amp; -2 &amp; | &amp; -4\end{bmatrix}$$</p>
<ul>
<li>Since the next pivot candidate is $0$, we&rsquo;ll have to swap rows 2 and 3 and make $-2$ the new pivot element.</li>
</ul>
<p>$$\begin{bmatrix} 1 &amp; 1 &amp; | &amp; 4 \\ 0 &amp; {\color{blue} -2} &amp; | &amp; -4 \\ 0 &amp; 0 &amp; | &amp; -4 \end{bmatrix}$$</p>
<p>We can&rsquo;t reduce this further without disrupting the row echelon form. The number of non-zero elements in the diagonal ($1$, $-2$, and $-4$) is higher than the number of variables in the equations ($x$ and $y$).</p>
<p>The reduced equations obtained after converting this back to row picture are:</p>
<p>$$x+y=4 \tag{10}$$</p>
<p>$$-2y=-4 \tag{11}$$</p>
<p>$$0=-4 \tag{12}$$</p>
<p>The equation $(12)$ is a fallacy. Thus, we can confirm that there is no solution for the system of linear equations $(10)$, $(11)$, and $(12)$.</p>
<h1 id="resources">Resources</h1>
<p><a href="https://youtu.be/QVKj3LADCnA?si=CXmVqn42IgpG8lwO" target="_blank">2. Elimination with Matrices.</a><br>
<a href="https://medium.com/linear-algebra/part-1-linear-equation-of-two-variables-and-matrices-d8de21eb8d51" target="_blank">Part 1 : Linear equation of two variables and Matrices</a><br>
<a href="https://medium.com/linear-algebra/part-5-row-picture-and-column-picture-899e6d834564" target="_blank">Part 5 : Row Picture and Column Picture</a><br>
<a href="https://medium.com/linear-algebra/part-6-gaussian-elimination-b1ad4a279a74" target="_blank">Part 6 : Gaussian Elimination</a></p>
]]></content:encoded>
    </item>
    <item>
      <title>Matrices</title>
      <link>http://www.avni.sh/posts/linear-algebra/matrices/</link>
      <pubDate>Fri, 12 Jul 2024 00:00:00 +0000</pubDate>
      <guid>http://www.avni.sh/posts/linear-algebra/matrices/</guid>
      <description>A matrix is a two dimensional array of data.</description>
      <content:encoded><![CDATA[<p>A matrix is a rank 2 <a href="/posts/math/linear-algebra/tensors/" target="_blank">tensor</a> i.e. an array expanding in a maximum of two independent dimensions.</p>
<p>Multiple <a href="/posts/math/linear-algebra/vectors/" target="_blank">vectors</a> could be arranged in rows or columns to create a matrix.</p>
<p>$$\vec{a} = \begin{bmatrix} 5 \\ 6 \\ 7 \end{bmatrix}\ \ \vec{b} = \begin{bmatrix} 7 \\ 9 \\ 10 \end{bmatrix}$$</p>
<p>$$\textbf{A} = \begin{bmatrix} \vec{a} &amp; \vec{b} \end{bmatrix} = \begin{bmatrix} 5 &amp; 7 \\ 6 &amp; 9 \\ 7 &amp; 10 \end{bmatrix}$$</p>
<p>$$\textbf{B} = \begin{bmatrix} \vec{a} \\ \vec{b} \end{bmatrix} = \begin{bmatrix} 5 &amp; 6 &amp; 7 \\ 7 &amp; 9 &amp; 10 \end{bmatrix}$$</p>
<p>The term <em>matrix</em> encompasses all vectors so $\vec{a}$ and $\vec{b}$ could be called matrices or vectors interchangeably.</p>
<h1 id="order-of-a-matrix">Order of a matrix</h1>
<p>The notation of the number of $rows \times columns$ of a matrix is called its <strong>order</strong>. For example, the following matrix has order $3 \times 4$.</p>
<p>$$\begin{bmatrix} 1 &amp; 8 &amp; 99 &amp; 0 \\ 56 &amp; 43 &amp; 91 &amp; 2 \\ 9 &amp; 5 &amp; 33 &amp; 1 \end{bmatrix}$$</p>
<p>Vectors are matrices with an order of either $n \times 1$ or $1 \times n$.</p>
<h1 id="diagonal-of-a-matrix">Diagonal of a matrix</h1>
<p>The <strong>diagonal</strong> of the matrix refers to the elements from the top left corner to the bottom right corner of the matrix (highlighted below).</p>
<p>$$\begin{bmatrix}  {\color {red} 4} &amp; 9 &amp; 5 \\ 9 &amp; {\color{red} 3} &amp; 1 \\ 90 &amp; 2 &amp; {\color{red} 8}\end{bmatrix} \ \ \ \begin{bmatrix}  {\color {red} 5} &amp; 9 &amp; 5 &amp; 98 \\ 9 &amp; {\color{red} 43} &amp; 1 &amp; 1 \\ 90 &amp; 2 &amp; {\color{red} 9} &amp; 52\end{bmatrix}$$</p>
<h1 id="square-matrix">Square Matrix</h1>
<p>A matrix with an equal number of rows and columns is called a <strong>square matrix</strong>. For example:</p>
<p>$$\begin{bmatrix} 1 &amp; 8 &amp; 9 \\ 2 &amp; 0 &amp; 11 \\ 9 &amp; 7 &amp; 1\end{bmatrix}$$</p>
<h2 id="triangular-matrix">Triangular Matrix</h2>
<p>A <strong>triangular matrix</strong> is a type of square matrix where either the elements above or below the diagonal are all $0$s.</p>
<p>Here is an example of an <strong>upper triangular matrix</strong></p>
<p>$$\begin{bmatrix} \color{red} 6 &amp; \color{red} 21 &amp; \color{red} 6 &amp; \color{red} 88 \\ 0 &amp; \color{red} 71 &amp; \color{red} 90 &amp; \color{red} 8 \\ 0 &amp; 0 &amp; \color{red} 1 &amp; \color{red} 71 \\ 0 &amp; 0 &amp; 0 &amp; \color{red} 4 \end{bmatrix}$$</p>
<p>Following is an example of a <strong>lower triangular matrix</strong></p>
<p>$$\begin{bmatrix} \color{red} 6 &amp;  0 &amp;  0 &amp;  0 \\ \color{red} 7 &amp; \color{red} 71 &amp; 0 &amp; 0 \\ \color{red} 12 &amp; \color{red} 61 &amp; \color{red} 1 &amp; 0 \\ \color{red} 4 &amp; \color{red} 6 &amp; \color{red} 5 &amp; \color{red} 4 \end{bmatrix}$$</p>
<h1 id="matrix-operations">Matrix Operations</h1>
<h2 id="equality-of-matrices">Equality of Matrices</h2>
<p>Two matrices are equal if</p>
<ol>
<li>They have the same order.</li>
<li>The values of the corresponding elements are the same.</li>
</ol>
<p>Given a matrix $\textbf{A} = \begin{bmatrix} 1 &amp; 2 \\ 3 &amp; 4 \end{bmatrix}$ and a matrix $\textbf{B} = \begin{bmatrix} 1 &amp; 2 \\ 3 &amp; 4 \end{bmatrix}$ we can say that $\textbf{A} = \textbf{B}$ because the order of both matrices is $2 \times 2$ and the elements corresponding to same position are also equal.</p>
<h2 id="addition-and-subtraction-of-matrices">Addition and Subtraction of Matrices</h2>
<p>To add two matrices we just have to sum the elements at corresponding positions. The order of both matrices should be the same for addition (and subtraction).</p>
<p>$$\begin{bmatrix} 4 &amp; 5 &amp; 9 \\ 89 &amp; 5 &amp; 91 \end{bmatrix} + \begin{bmatrix} 9 &amp; 4 &amp; 8 \\ 9 &amp; 1 &amp; 85 \end{bmatrix} = \begin{bmatrix} 4+9 &amp; 5+4 &amp; 9+8 \\ 89+9 &amp; 5+1 &amp; 91+85  \end{bmatrix} = \begin{bmatrix} 13 &amp; 9 &amp; 17 \\ 98 &amp; 6 &amp; 176 \end{bmatrix}$$</p>
<p>The subtraction operation is similar to the addition.</p>
<p>$$\begin{bmatrix} 9 &amp; 4 &amp; 8 \\ 9 &amp; 1 &amp; 85 \end{bmatrix} - \begin{bmatrix} 4 &amp; 5 &amp; 9 \\ 89 &amp; 5 &amp; 91 \end{bmatrix}  = \begin{bmatrix} 9-4 &amp; 4-5 &amp; 8-9 \\ 9-89 &amp; 1-5 &amp; 85-91  \end{bmatrix} = \begin{bmatrix} 5 &amp; -1 &amp; -1 \\ -80 &amp; -4 &amp; -6 \end{bmatrix}$$</p>
<h2 id="multiplication-and-division-with-a-scalar-value">Multiplication and Division with a Scalar Value</h2>
<p>If we want to multiply a matrix with a <a href="/posts/math/linear-algebra/tensors/#scalar-rank-0-tensor" target="_blank">scalar</a> value, we just have to multiply the scalar with each element individually.</p>
<p>$$5 \times \begin{bmatrix} 7 &amp; 6 \\ 8 &amp; 4 \end{bmatrix} = \begin{bmatrix} 7 \times 5 &amp; 6 \times 5 \\ 8 \times 5 &amp; 4 \times 5 \end{bmatrix} = \begin{bmatrix} 35 &amp; 30 \\ 40 &amp; 20 \end{bmatrix}$$</p>
<p>Division operation with a scalar value is also applied similarly on the matrix.</p>
<p>$$\begin{bmatrix} 9 &amp; 6 \\ 12 &amp; 36 \end{bmatrix} \div 3 = \begin{bmatrix} 9 &amp; 6 \\ 12 &amp; 36 \end{bmatrix} \times {1 \over 3} = \begin{bmatrix} {9 \over 3} &amp; {6 \over 3} \\ {12 \over 3} &amp; {36 \over 3} \end{bmatrix} = \begin{bmatrix} 3 &amp; 2 \\ 4 &amp; 12 \end{bmatrix}$$</p>
<h2 id="transpose-of-a-matrix">Transpose of a Matrix</h2>
<p>The <strong>transpose</strong> operation on a matrix swaps the elements in its rows and columns. For example, if we apply the transpose operation on the matrix $\textbf{C} = \begin{bmatrix} 4 &amp; 5 &amp; 8 \\ 6 &amp; 7 &amp; 9 \end{bmatrix}$ the result would be $\textbf{C}^T = \begin{bmatrix} 4 &amp; 6 \\ 5 &amp; 7 \\ 8 &amp; 9 \end{bmatrix}$.</p>
<p>Notice that the order of the matrix is also changed from $2 \times 3$ to $3 \times 2$.</p>
<h3 id="symmetric-matrix">Symmetric Matrix</h3>
<p>A matrix is <strong>symmetric</strong> if it remains unchanged after the transpose operation is applied i.e. $\textbf{C}^T = \textbf{C}$. The following matrix is an example of a symmetric matrix:</p>
<p>$$\left(\begin{bmatrix} 9 &amp; 5 &amp; 89 \\ 5 &amp; 8 &amp; 67 \\ 89 &amp; 67 &amp; 34\end{bmatrix}\right)^T = \begin{bmatrix} 9 &amp; 5 &amp; 89 \\ 5 &amp; 8 &amp; 67 \\ 89 &amp; 67 &amp; 34\end{bmatrix}$$</p>
<h3 id="skew-symmetric-matrix">Skew-Symmetric Matrix</h3>
<p>If we perform the transpose operation on a skew-symmetric matrix the result will be the original matrix multiplied by the scalar value $(-1)$ i.e. $\textbf{C}^T = (-1) \times \textbf{C}$.</p>
<p>$$\left(\begin{bmatrix} 9 &amp; 5 &amp; 89 \\ -5 &amp; 8 &amp; 67 \\ -89 &amp; -67 &amp; 34\end{bmatrix}\right)^T = \begin{bmatrix} 9 &amp; -5 &amp; -89 \\ 5 &amp; 8 &amp; -67 \\ 89 &amp; 67 &amp; 34\end{bmatrix}$$</p>
<h2 id="multiplication-of-matrices">Multiplication of Matrices</h2>
<p>To calculate the product of two matrices we have to take the <a href="/posts/math/linear-algebra/vectors/#dot-product" target="_blank">dot product</a> of each row from the first matrix with every column of the second matrix.</p>
<p>$$\textbf{A} \times \textbf{B} = \begin{bmatrix} a_{11} &amp; a_{12} \\ a_{21} &amp; a_{22} \\ a_{31} &amp; a_{32} \end{bmatrix} \times \begin{bmatrix} b_{11} &amp; b_{12} \\ b_{21} &amp; b_{22}  \end{bmatrix} = \begin{bmatrix} a_{11}b_{11} +a_{12}b_{21} &amp; a_{11}b_{12} +a_{12}b_{22} \\ a_{21}b_{11} +a_{22}b_{21} &amp; a_{21}b_{12} +a_{22}b_{22} \\ a_{31}b_{11} +a_{32}b_{21} &amp; a_{31}b_{12} +a_{32}b_{22}\end{bmatrix}$$</p>
<p>Because the dot product could only be calculated between the vectors with identical number of elements, to multiply two matrices the number of columns in the first matrix should be equal to the number of rows in the second matrix.</p>
<p align="center"><img src="order_of_matrices.png" alt="Order of product matrix"></p>
<p>If we switch the matrix $\textbf{A}$ and $\textbf{B}$ while performing multiplication the resulting product matrix will have different dimensions (and elements). Thus,  <em>matrix multiplication is not commutative</em>.
$$\textbf{A} \times \textbf{B} \neq \textbf{B} \times \textbf{A}$$</p>
<h3 id="identity-matrix">Identity Matrix</h3>
<p>A square matrix with $1$s on its diagonal (and $0$s as non-diagonal elements) is called an <strong>identity matrix</strong>. Multiplying any matrix with an identity matrix (of valid order) is analogous to multiplying a number with $1$.</p>
<p>In equations, the identity matrix is represented with $\textbf{I}$</p>
<p>$$\textbf{A} \times \textbf{I} = \textbf{A}$$
$$\begin{bmatrix} 7 &amp; 1 &amp; 8 \\ 4 &amp; 5 &amp; 3 \\ 1 &amp; 2 &amp; 6 \end{bmatrix} \times \begin{bmatrix} 1 &amp; 0 &amp; 0 \\ 0 &amp; 1 &amp; 0 \\ 0 &amp; 0 &amp; 1 \end{bmatrix} = \begin{bmatrix} 7 &amp; 1 &amp; 8 \\ 4 &amp; 5 &amp; 3 \\ 1 &amp; 2 &amp; 6 \end{bmatrix}$$</p>
<h3 id="null-matrix">Null Matrix</h3>
<p>If multiplication with identity matrix is analogous to multiplication with $1$ then multiplication with null matrix will be analogous to multiplication of a number with $0$.
A null matrix has only $0$s as elements and doesn&rsquo;t have to be a square matrix. It is represented as $\textbf{0}$ in equations.</p>
<p>$$\textbf{A} \times \textbf{0} = \textbf{0}$$
$$\begin{bmatrix} 7 &amp; 1 &amp; 8 \\ 4 &amp; 5 &amp; 3 \\ 1 &amp; 2 &amp; 6 \end{bmatrix} \times \begin{bmatrix} 0 &amp; 0 &amp; 0 \\ 0 &amp; 0 &amp; 0 \\ 0 &amp; 0 &amp; 0 \end{bmatrix} = \begin{bmatrix} 0 &amp; 0 &amp; 0 \\ 0 &amp; 0 &amp; 0 \\ 0 &amp; 0 &amp; 0 \end{bmatrix}$$</p>
<h3 id="idempotent-matrix">Idempotent Matrix</h3>
<p>A matrix when multiplied by itself remains unchanged, is called an <strong>idempotent matrix</strong>.
$$\textbf{A} \times \textbf{A} = \textbf{A}^{2} = \textbf{A}$$
Since the order of the product matrix has to be the same as the original matrix, an idempotent matrix must always be a square matrix.
All identity matrices are idempotent.</p>
<h2 id="division-of-matrices">Division of Matrices</h2>
<p>If we have to divide a matrix with another matrix</p>
<p>$$\textbf{A} \div \textbf{B} = {\textbf{A} \over \textbf{B}}$$</p>
<p>we can rephrase it as</p>
<p>$$\textbf{A} \times {\textbf{I} \over \textbf{B}} = \textbf{A} \times \textbf{B}^{-1}$$</p>
<h3 id="inverse-of-a-matrix">Inverse of a Matrix</h3>
<p>The matrix $\textbf{B}^{-1}$ will be called the <strong>inverse</strong> of the matrix $\textbf{B}$.
$$\textbf{B} \times \textbf{B}^{-1} = \textbf{I}$$
The inverse matrix has the same order as the original matrix.
We can find the inverse of any square matrix using the process of <a href="/posts/math/linear-algebra/gauss-jordan-elimitation/" target="_blank">Gauss-Jordan Elimination</a>.</p>
<h1 id="resources">Resources</h1>
<p><a href="https://www.khanacademy.org/math/precalculus/x9e81a4f98389efdf:matrices/x9e81a4f98389efdf:properties-of-matrix-multiplication/a/matrix-multiplication-dimensions" target="_blank">Matrix multiplication dimensions</a><br>
<a href="https://medium.com/linear-algebra/part-2-operations-on-matrices-3caab542aebd" target="_blank">Part 2 : Operations on Matrices</a><br>
<a href="https://medium.com/linear-algebra/part-3-types-of-matrices-diagonal-and-transpose-151418a47c06" target="_blank">Part 3 : Types of Matrices, Diagonal, and Transpose</a></p>
]]></content:encoded>
    </item>
  </channel>
</rss>
