Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

203 lines (190 sloc) 9.548 kB
<!DOCTYPE html>
<html data-require="math kmatrix qhints">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Defined and undefined matrix operations</title>
<script data-main="../local-only/main.js" src="../local-only/require.js"></script>
</head>
<body>
<div class="exercise">
<div class="vars" data-ensure="!(DIM_1 === 1 &amp;&amp; DIM_2 === 1) &amp;&amp; !(DIM_3 === 1 &amp;&amp; DIM_4 === 1) &amp;&amp; (PRETTY_MAT_1_ID !== PRETTY_MAT_2_ID)">
<var id="YES,NO">[$._("Yes"), $._("No")]</var>
<var id="ANSWER">DEFINED ? YES : NO</var>
<var id="MAT_1">makeMatrix(randRange(-2, 4, DIM_1, DIM_2))</var>
<var id="MAT_2">makeMatrix(randRange(-2, 4, DIM_3, DIM_4))</var>
<var id="PRETTY_MAT_1_ID">"\\textbf " + randFromArray("ABCDEF")</var>
<var id="PRETTY_MAT_2_ID">"\\textbf " + randFromArray("ABCDEF")</var>
<var id="PRETTY_MAT_1">
printSimpleMatrix(MAT_1)
</var>
<var id="PRETTY_MAT_2">
printSimpleMatrix(MAT_2)
</var>
</div>
<div class="problem">
<p>
<code><var>PRETTY_MAT_1_ID</var> = <var>PRETTY_MAT_1</var></code>
</p>
<p>
<code><var>PRETTY_MAT_2_ID</var> = <var>PRETTY_MAT_2</var></code>
</p>
</div>
<p class="question">
Is <code><var>PRETTY_MAT_1_ID + OPERATION + PRETTY_MAT_2_ID</var></code> defined?
</p>
<p class="solution"><var>ANSWER</var></p>
<ul class="choices" data-category="true">
<li><var>YES</var></li>
<li><var>NO</var></li>
</ul>
<div class="problems">
<div id="addition-subtraction">
<div class="vars" data-apply="prependVars">
<var id="DEFINED">randRange(0, 1)</var>
<var id="DIM_1">randRange(1, 3)</var>
<var id="DIM_2">randRange(1, 3)</var>
<var id="DIM_3">DIM_1</var>
<var id="DIM_4">
DEFINED ? DIM_2 : randRangeExclude(1, 3, [DIM_2])
</var>
<var id="OPERATION">randFromArray("+-")</var>
</div>
<div class="hints">
<div>
<span data-if="OPERATION === '+'">
<p>
In order for addition of two matrices to be
defined, the matrices must have the same
dimensions.
</p>
<p>
If <code><var>PRETTY_MAT_1_ID</var></code> is of
dimension <code>(\blue m \times \red n)</code> and
<code><var>PRETTY_MAT_2_ID</var></code> is of
dimension <code>(\blue p \times \red q)</code>,
then for their sum to be defined:
</p>
</span><span data-else>
<p>
In order for subtraction of two matrices to be
defined, the matrices must have the same
dimensions.
</p>
<p>
If <code><var>PRETTY_MAT_1_ID</var></code> is of
dimension <code>(\blue m \times \red n)</code> and
<code><var>PRETTY_MAT_2_ID</var></code> is of
dimension <code>(\blue p \times \red q)</code>,
then for their difference to be defined:
</p>
</span>
<p>
1. <code>\blue m</code> (number of rows in <code><var>PRETTY_MAT_1_ID</var></code>) must equal <code>\blue p</code> (number of rows in <code><var>PRETTY_MAT_2_ID</var></code>) and
</p>
<p>
2. <code>\red n</code> (number of columns in <code><var>PRETTY_MAT_1_ID</var></code>) must equal <code>\red q</code> (number of columns in <code><var>PRETTY_MAT_2_ID</var></code>)
</p>
</div>
<div class="qhint">
<p>
Do <code><var>PRETTY_MAT_1_ID</var></code> and <code><var>PRETTY_MAT_2_ID</var></code> have the same number of rows?
</p>
<span class="qhint-answer"><var>DIM_1 === DIM_3 ? YES : NO</var></span>
<p class="qhint-input">
<a href="javascript:void(0)" class="qhint-button simple-button"><var>YES</var></a>
<a href="javascript:void(0)" class="qhint-button simple-button"><var>NO</var></a>
</p>
</div>
<div class="qhint">
<p>
Do <code><var>PRETTY_MAT_1_ID</var></code> and <code><var>PRETTY_MAT_2_ID</var></code> have the same number of columns?
</p>
<span class="qhint-answer"><var>DIM_2 === DIM_4 ? YES : NO</var></span>
<p class="qhint-input">
<a href="javascript:void(0)" class="qhint-button simple-button"><var>YES</var></a>
<a href="javascript:void(0)" class="qhint-button simple-button"><var>NO</var></a>
</p>
</div>
<div>
<p data-if="DEFINED">
Since <code><var>PRETTY_MAT_1_ID</var></code> has
the same dimensions
<code>(<var>DIM_1 + "\\times" + DIM_2</var>)</code> as
<code><var>PRETTY_MAT_2_ID</var></code> <code>(<var>DIM_3 + "\\times" + DIM_4</var>)</code>,
<code><var>PRETTY_MAT_1_ID + OPERATION + PRETTY_MAT_2_ID</var></code>
is defined.
</p><p data-else>
Since <code><var>PRETTY_MAT_1_ID</var></code> has
different dimensions
<code>(<var>DIM_1 + "\\times" + DIM_2</var>)</code> from
<code><var>PRETTY_MAT_2_ID</var></code> <code>(<var>DIM_3 + "\\times" + DIM_4</var>)</code>,
<code><var>PRETTY_MAT_1_ID + OPERATION + PRETTY_MAT_2_ID</var></code>
is not defined.
</p>
</div>
</div>
</div>
<div id="multiplication">
<div class="vars" data-apply="prependVars">
<var id="DEFINED">randRange(0, 1)</var>
<var id="DIM_1">randRange(1, 3)</var>
<var id="DIM_2">randRange(1, 3)</var>
<var id="DIM_3">
DEFINED ? DIM_2 : randRangeExclude(1, 3, [DIM_2])
</var>
<var id="DIM_4">randRange(1, 3)</var>
<var id="OPERATION">""</var>
</div>
<div class="hints">
<div>
<p>
In order for multiplication of two matrices to be defined, the two inner dimensions must be equal.
</p>
</div>
<div>
<p>
If the two matrices have dimensions <code>(\blue m \times \red n)</code> and <code>(\red p \times \green q)</code>, then <code>\red n</code> (number of columns in the first matrix) must equal <code>\red p</code> (number of rows in the second matrix) for their product to be defined.
</p>
</div>
<div class="qhint">
<p>
How many columns does the first matrix, <code><var>PRETTY_MAT_1_ID</var></code>, have?
</p>
<span class="qhint-answer"><var>DIM_2</var></span>
<p class="qhint-input">
<input type="text" value="">
<input type="submit" value="Check">
</p>
</div>
<div class="qhint">
<p>
How many rows does the second matrix, <code><var>PRETTY_MAT_2_ID</var></code>, have?
</p>
<span class="qhint-answer"><var>DIM_3</var></span>
<p class="qhint-input">
<input type="text" value="">
<input type="submit" value="Check">
</p>
</div>
<div data-if="DEFINED">
Since <code><var>PRETTY_MAT_1_ID</var></code> has the same
number of columns (<var>DIM_2</var>) as
<code><var>PRETTY_MAT_2_ID</var></code> has rows
(<var>DIM_3</var>),
<code><var>PRETTY_MAT_1_ID + PRETTY_MAT_2_ID</var></code>
is defined.
</div><div data-else>
Since <code><var>PRETTY_MAT_1_ID</var></code> has a
different number of columns
(<var>DIM_2</var>) than
<code><var>PRETTY_MAT_2_ID</var></code> has rows
(<var>DIM_3</var>),
<code><var>PRETTY_MAT_1_ID + PRETTY_MAT_2_ID</var></code>
is not defined.
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.