# Khan/khan-exercises

Switch branches/tags
Nothing to show
Fetching contributors…
Cannot retrieve contributors at this time
182 lines (172 sloc) 7.24 KB
 Inverse of a 3x3 matrix
3 makeMatrix([["a","b","c"],["d","e","f"],["g","h","i"]]) makeMatrix(randRange(0, 2, DIM, DIM)) matrixDet(MAT) matrixMinors(MAT) matrixMap(function(elem) { return matrixDet(elem); }, MAT_MINORS) matrixMap(function(elem, row, col) { var sign = (row + col) % 2 ? -1 : 1; return sign * elem; }, MAT_MINORS_DET) printSimpleMatrix(matrixMap(function(elem) { return printSimpleMatrixDet(elem); }, MAT_MINORS)) matrixTranspose(MAT_MINORS_DET_SIGNS)
matrixInverse(MAT) matrixPad(SOLN_MAT, 3, 3) printMatrix(function(a) { var sign = (a < 0) ? "-" : ""; var frac = toFraction(abs(a)); // omit denominator when it's equal to 1 if (frac[1] === 1) { return sign + frac[0]; } return sign + "\\frac{" + frac[0] + "}{" + frac[1] + "}"; }, SOLN_MAT) "\\textbf " + randFromArray("ABCDEF")

PRETTY_MAT_ID = printSimpleMatrix(MAT)

What is PRETTY_MAT_ID^{-1}?

elem elem

The inverse of a matrix is equal to the adjugate of the matrix divided by the determinant of the matrix.

Step 1: Find the adjugate

First, compute the matrix of minors of PRETTY_MAT_ID.

MAT_MINORS_FORMAT = printSimpleMatrix(MAT_MINORS_DET)

Next, multiply the elements of the matrix of minors by the following pattern:

printSimpleMatrix([["+","-","+"],["-","+","-"],["+","-","+"]])

This gives us what is called the matrix of cofactors:

printSimpleMatrix(MAT_MINORS_DET_SIGNS)

Next, transpose the matrix of cofactors to get the adjugate.

Step 2: Find the determinant

Compute the determinant of the original matrix. [Show me how]

The determinant of any 3x3 matrix can be computed the following way:

printSimpleMatrixDet(HINT_MAT) = matrix3x3DetHint(HINT_MAT, true)

= matrix3x3DetHint(HINT_MAT)

In this specific case,

printSimpleMatrixDet(MAT) = matrix3x3DetHint(MAT, true)

= matrix3x3DetHint(MAT)

= DET

det(PRETTY_MAT_ID) = printSimpleMatrixDet(MAT)= expr(["color", KhanUtil.RED, DET])

Step 3: Put it all together

Now that we have both the determinant and the adjugate, we can compute the inverse.

PRETTY_MAT_ID^{-1} = \frac{1}{expr(["color", KhanUtil.RED, DET])} printSimpleMatrix(MAT_ADJ, KhanUtil.BLUE)

= PRETTY_SOLN_MAT