Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok, a quick course in Matrix/Vector calculation:</p> <p>A matrix is a collection of numbers ordered in a rectangular grid like:</p> <pre><code>[ 0, 1, 2 ] [ 2, 3, 5 ] [ 2, 1, 3 ] [ 0, 0, 1 ] </code></pre> <p>The above matrix has 4 rows and 3 columns and as such is a 4 x 3 matrix. A vector is a matrix with 1 row (a row vector) or 1 column (a column vector). Normal numbers are called scalars to contrast with matrices.</p> <p>It is also common to use capital letters for matrices and lowercase letters for scalars.</p> <p>We can do basic calculation with matrices but there are some conditions.</p> <p><strong>Addition</strong></p> <p>Matrices can be added if they have the same dimensions. So a 2x2 matrix can be added to a 2x2 matrix but not to a 3x5 matrix.</p> <pre><code>[ 1, 2 ] + [ 2, 5 ] = [ 3, 7 ] [ 2, 4 ] [ 0, 3 ] [ 2, 7 ] </code></pre> <p>You see that by addition each number at each cell is added to the number on the same position in the other matrix.</p> <p><strong>Matrix multiplication</strong></p> <p>Matrices can be multiplied, but this is a bit more complex. In order to multiply matrix A with matrix B, you need to multiply the numbers in each row if matrix A with each column in matrix B. This means that if you multiply an a x b matrix with a c x d matrix, b and c must be equal and the resulting matrix is a x d:</p> <pre><code>[1,2,3] x [4,6] = [1x4+2x2+3x2, 1x6+2x1+3x3 ] = [4+4+6, 6+2+9 ] = [14, 20] [1,4,5] [2,1] [1x4+4x2+5x2, 1x6+4x1+5x3 ] [4+8+10, 6+4+15 ] [22, 25] [2,3] </code></pre> <p>As you can see, with matrixes, A x B differs from B x A. </p> <p><strong>Matrix scalar multiplication</strong></p> <p>You can multiply a matrix with a scalar. In that case, each cell is multiplied with that number:</p> <pre><code>3 x [1,2] = [ 3, 6] [4,7] [12,21] </code></pre> <p><strong>Inverting a matrix</strong> Matrix division is not possible, but you can create an inversion of a matrix such that A x A-inv is a matrix with all zero's except for that main diagonal:</p> <pre><code>[ 1, 0, 0 ] [ 0, 1, 0 ] [ 0, 0, 1 ] </code></pre> <p>Inverting a matrix can only be done with square matrices and it is a complex job that does not neccesary have a result. </p> <p>Start with matrix A:</p> <pre><code> [ 1, 2, 3 ] A = [ 1, 3, 4 ] [ 2, 5, 1 ] </code></pre> <p>We add 3 extra columns and fill them with the unit matrix:</p> <pre><code>[ 1, 2, 3, 1, 0, 0 ] [ 1, 3, 4, 0, 1, 0 ] [ 2, 5, 1, 0, 0, 1 ] </code></pre> <p>Now we start with the first column. We need to subtract the first row from each other row such that the first column contains only zeroes except for the first row. In order to do that we subtract the first row once from the second and twice from the third:</p> <pre><code>[ 1, 2, 3, 1, 0, 0 ] [ 0, 1, 1,-1, 1, 0 ] [ 0, 1,-5,-2, 0, 1 ] </code></pre> <p>Now we repeat this with the second column (twice from the first row and once from the third)</p> <pre><code>[ 1, 0, 1, 3,-2, 0 ] [ 0, 1, 1,-1, 1, 0 ] [ 0, 0,-6,-1,-1, 1 ] </code></pre> <p>For the third column, we have a slight problem. The pivot number is -6 and not 1. But we can solve this by multiplying the entire row with -1/6:</p> <pre><code>[ 1, 0, 1, 3, -2, 0 ] [ 0, 1, 1, -1, 1, 0 ] [ 0, 0, 1, 1/6, 1/6, -1/6 ] </code></pre> <p>And now we can subtract the third row from the first and the second:</p> <pre><code>[ 1, 0, 0, 17/6,-13/6, 1/6 ] [ 0, 1, 0, -7/6, 5/6, 1/6 ] [ 0, 0, 1, 1/6, 1/6, -1/6 ] </code></pre> <p>Ok now we have the inverse of A:</p> <pre><code>[ 17/6,-13/6, 1/6 ] [ -7/6, 5/6, 1/6 ] [ 1/6, 1/6, -1/6 ] </code></pre> <p>We can write this as:</p> <pre><code> [ 17,-13, 1 ] 1/6 * [ -7, 5, 1 ] [ 1, 1, -1 ] [ 1, 2, 3 ] [ 17,-13, 1 ] [ 6, 0, 0 ] [ 1, 0, 0 ] A = [ 1, 3, 4 ] x [ -7, 5, 1 ] x 1/6 = 1/6 x [ 0, 6, 0 ] = [ 0, 1, 0 ] [ 2, 5, 1 ] [ 1, 1, -1 ] [ 0, 0, 6 ] [ 0, 0, 1 ] </code></pre> <p>Hope this helps a bit.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload