Fetching contributors…
Cannot retrieve contributors at this time
163 lines (149 sloc) 6.32 KB
<!DOCTYPE html>
<html data-require="math kmatrix matrix-input">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Multiplying a matrix by a vector</title>
<script data-main="../local-only/main.js" src="../local-only/require.js"></script>
</head>
<body>
<div class="exercise">
<div class="vars">
<var id="DIM_3">DIM_2</var>
<var id="DIM_4">1</var>
<var id="MAT_1">makeMatrix(randRange(-2, 5, DIM_1, DIM_2))</var>
<var id="MAT_2">makeMatrix(randRange(-2, 5, DIM_3, DIM_4))</var>
<var id="SOLN_MAT">
matrixMult(MAT_1, MAT_2)
</var>
<var id="PADDED_SOLN_MAT">matrixPad(SOLN_MAT, 3, 3)</var>
<var id="PRETTY_MAT_1_ID">"\\textbf " + randFromArray("ABCDEF")</var>
<var id="PRETTY_MAT_2_ID">"\\textbf " + randFromArray("vw")</var>
<!-- For generating hint matrices-->
<var id="ROW_COLORS">[GREEN, BLUE, GRAY]</var>
<var id="COL_COLORS">[ORANGE]</var>
<var id="FINAL_HINT_MAT">
makeMultHintMatrix(MAT_1, MAT_2, ROW_COLORS, COL_COLORS)
</var>
<var id="ROW">i18n._("row")</var>
<var id="COLUMN">i18n._("column")</var>
</div>
<div class="problem">
<p>
<code><var>PRETTY_MAT_1_ID</var> = <var>printSimpleMatrix(MAT_1)</var></code>
</p>
<p>
<code><var>PRETTY_MAT_2_ID</var> = <var>printSimpleMatrix(MAT_2)</var></code>
</p>
</div>
<p class="question">
What is <code><var>PRETTY_MAT_1_ID + PRETTY_MAT_2_ID</var></code>?
</p>
<div class="hints">
<div>
<p>
Because <code><var>PRETTY_MAT_1_ID</var></code> has dimensions <code>(<var>DIM_1 + "\\times" + DIM_2</var>)</code> and <code><var>PRETTY_MAT_2_ID</var></code> has dimensions <code>(<var>DIM_3 + "\\times" + DIM_4</var>)</code>, the answer matrix will have dimensions <code>(<var>DIM_1 + "\\times" + DIM_4</var>)</code>.
</p>
<p>
<code>
<var>PRETTY_MAT_1_ID + PRETTY_MAT_2_ID</var>
=
<var>printColoredDimMatrix(MAT_1, ROW_COLORS, true)</var>
<var>printColoredDimMatrix(MAT_2, COL_COLORS, false)</var>
=
<var>
printSimpleMatrix(maskMatrix(FINAL_HINT_MAT, []))
</var>
</code>
</p>
</div>
<div>
<p>
To find the element at any row <code>i</code>, column <code>j</code> of the answer matrix, multiply the elements in row <code>i</code> of the first matrix, <code><var>PRETTY_MAT_1_ID</var></code>, with the corresponding elements in column <code>j</code> of the second matrix, <code><var>PRETTY_MAT_2_ID</var></code>, and add the products together.
</p>
</div>
<div>
<p>
So, to find the element at row 1, column 1 of the answer matrix, multiply the first element in <code><var>colorMarkup("\\text{" + ROW + " }1", ROW_COLORS[0])</var></code> of <code><var>PRETTY_MAT_1_ID</var></code> with the first element in <code><var>colorMarkup("\\text{" + COLUMN + " }1", COL_COLORS[0])</var></code> of <code><var>PRETTY_MAT_2_ID</var></code>, then multiply the second element in <code><var>colorMarkup("\\text{" + ROW + " }1", ROW_COLORS[0])</var></code> of <code><var>PRETTY_MAT_1_ID</var></code> with the second element in <code><var>colorMarkup("\\text{" + COLUMN + " }1", COL_COLORS[0])</var></code> of <code><var>PRETTY_MAT_2_ID</var></code>, and so on. Add the products together.
</p>
<p>
<code>
<var>
printSimpleMatrix(
maskMatrix(FINAL_HINT_MAT, [[1, 1]])
)
</var>
</code>
</p>
</div>
<div>
<p>
Likewise, to find the element at row 2, column 1 of the answer matrix, multiply the elements in <code><var>colorMarkup("\\text{" + ROW + " }2", ROW_COLORS[1])</var></code> of <code><var>PRETTY_MAT_1_ID</var></code> with the corresponding elements in <code><var>colorMarkup("\\text{" + COLUMN + " }1", COL_COLORS[0])</var></code> of <code><var>PRETTY_MAT_2_ID</var></code> and add the products together.
</p>
<p>
<code>
<var>
printSimpleMatrix(
maskMatrix(FINAL_HINT_MAT, [[1, 1], [2, 1]])
)
</var>
</code>
</p>
</div>
<div>
<p>
Fill out the rest:
</p>
<p>
<code>
<var>
printSimpleMatrix(FINAL_HINT_MAT)
</var>
</code>
</p>
</div>
<div>
<p>After simplifying, we end up with:</p>
<div>
<code>
<var>printSimpleMatrix(SOLN_MAT)</var>
</code>
</div>
</div>
</div>
<div class="solution" data-type="multiple">
<div class="matrix-row" data-each="PADDED_SOLN_MAT as row">
<span data-each="row as elem">
<span class="sol" data-forms="integer" data-if="elem !== ''">
<var>elem</var>
</span>
<span class="sol" data-else="" data-type="text">
<var>elem</var>
</span>
</span>
</div>
</div>
<div class="problems">
<!-- 2x1 solution dimensions -->
<div id="2x2-2x1">
<div class="vars" data-apply="prependVars">
<var id="DIM_1">2</var>
<var id="DIM_2">2</var>
</div>
</div>
<div id="2x3-3x1">
<div class="vars" data-apply="prependVars">
<var id="DIM_1">2</var>
<var id="DIM_2">3</var>
</div>
</div>
<!-- 3x1 solution dimensions -->
<div id="3x2-2x1">
<div class="vars" data-apply="prependVars">
<var id="DIM_1">3</var>
<var id="DIM_2">2</var>
</div>
</div>
</div>
</div>
</body>
</html>