This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 863
/
scalar_matrix_multiplication.html
113 lines (101 loc) · 3.35 KB
/
scalar_matrix_multiplication.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<html data-require="math math-format kmatrix matrix-input">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Scalar matrix multiplication</title>
<script data-main="../local-only/main.js" src="../local-only/require.js"></script>
</head>
<body>
<div class="exercise">
<div class="vars">
<var id="MAT_A">randRange(-2, 4, ROWS, COLS)</var>
<var id="SCALAR">randFromArray([-1, 1]) * (rand(4) === 0 ? randRange(1, 3) / 4 : randRange(2, 5))</var>
<var id="SCALAR_TEXT">decimalFraction(SCALAR, true)</var>
<var id="OPERATION">"\\times"</var>
<var id="SOLN_MAT">
deepZipWith(2, function(a) {
return a * SCALAR;
}, MAT_A)
</var>
<var id="PADDED_SOLN_MAT">matrixPad(SOLN_MAT, 3, 3)</var>
<var id="MAT_A_COLOR">BLUE</var>
<var id="SCALAR_COLOR">GREEN</var>
<var id="SOLN_MAT_COLOR">PINK</var>
<var id="PRETTY_MAT_A">
printSimpleMatrix(MAT_A, MAT_A_COLOR)
</var>
<var id="PRETTY_HINT_MAT">
printMatrix(function(a) {
var s = colorMarkup(SCALAR_TEXT, SCALAR_COLOR);
var b = colorMarkup(a, MAT_A_COLOR);
return s + OPERATION + b;
}, MAT_A)
</var>
<var id="PRETTY_SOLN_MAT">
printFractionMatrix(SOLN_MAT, SOLN_MAT_COLOR)
</var>
</div>
<div class="question">
<code>
\Large{
\color{<var>SCALAR_COLOR</var>}{<var>SCALAR_TEXT</var>}
<var>OPERATION</var>
<var>PRETTY_MAT_A</var> = {?}
}
</code>
</div>
<div class="hints">
<div>
<p>To multiply a matrix by a number, multiply each item of the matrix by the number.</p>
<div>
<code>\Large{<var>PRETTY_HINT_MAT</var>}</code>
</div>
</div>
<div>
<p>Now, simplify:</p>
<div>
<code>\Large{<var>PRETTY_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-if="elem !== ''">
<var>elem</var>
</span>
<span class="sol" data-else="" data-type="text">
<var>elem</var>
</span>
</span>
</div>
</div>
<div class="problems">
<div id="2x2">
<div class="vars" data-apply="prependVars">
<var id="ROWS">2</var>
<var id="COLS">2</var>
</div>
</div>
<div id="2x3">
<div class="vars" data-apply="prependVars">
<var id="ROWS">2</var>
<var id="COLS">3</var>
</div>
</div>
<div id="3x1">
<div class="vars" data-apply="prependVars">
<var id="ROWS">3</var>
<var id="COLS">1</var>
</div>
</div>
<div id="3x2">
<div class="vars" data-apply="prependVars">
<var id="ROWS">3</var>
<var id="COLS">2</var>
</div>
</div>
</div>
</div>
</body>
</html>