Skip to content

An AI skill that turns books into animated, narrated, interactive web experiences

feat(linear-algebra): chapters 4-7 reviewed, with playgrounds

yzr009e2636c836
diff --git a/site/linear-algebra/ch04/audio/en/every.mp3 b/site/linear-algebra/ch04/audio/en/every.mp3
index e16327b..17b7645 100644
Binary files a/site/linear-algebra/ch04/audio/en/every.mp3 and b/site/linear-algebra/ch04/audio/en/every.mp3 differ
diff --git a/site/linear-algebra/ch04/audio/en/play.mp3 b/site/linear-algebra/ch04/audio/en/play.mp3
new file mode 100644
index 0000000..4c07394
Binary files /dev/null and b/site/linear-algebra/ch04/audio/en/play.mp3 differ
diff --git a/site/linear-algebra/ch04/audio/en/same.mp3 b/site/linear-algebra/ch04/audio/en/same.mp3
index eea5389..6ba5a42 100644
Binary files a/site/linear-algebra/ch04/audio/en/same.mp3 and b/site/linear-algebra/ch04/audio/en/same.mp3 differ
diff --git a/site/linear-algebra/ch04/audio/en/timings.js b/site/linear-algebra/ch04/audio/en/timings.js
index e4082da..63c25e7 100644
--- a/site/linear-algebra/ch04/audio/en/timings.js
+++ b/site/linear-algebra/ch04/audio/en/timings.js
@@ -34,6 +34,8 @@ window.TIMINGS = {
"top": 16.224,
"bot": 18.984,
"apples": 21.172,
+ "east": 25.0,
+ "north": 26.771,
"more": 28.737,
"more2": 33.125,
"order": 35.69,
@@ -274,37 +276,46 @@ window.TIMINGS = {
]
},
"every": {
- "dur": 22.896,
+ "dur": 31.992,
"marks": {
- "pts": 1.51,
- "fan": 3.086,
- "back": 8.685,
- "so": 12.018,
- "diff": 14.883
+ "pts": 1.484,
+ "vec": 4.635,
+ "fan": 12.331,
+ "back": 17.747,
+ "so": 20.99,
+ "diff": 23.802
},
"cues": [
[
- 0.104,
+ 0.117,
"Here's a neat fact."
],
[
- 1.51,
- "Pick any point of the plane."
+ 1.484,
+ "Pick any point of the plane, say minus five, two."
+ ],
+ [
+ 4.635,
+ "There's exactly one arrow from the origin to it: the vector minus five, two."
],
[
- 3.086,
- "There's exactly one arrow from the origin to it, so exactly one vector."
+ 10.365,
+ "Same numbers, standing up."
],
[
- 8.685,
+ 12.331,
+ "The same goes for every other point: one point, one arrow, one vector."
+ ],
+ [
+ 17.747,
"And every vector ends at exactly one point."
],
[
- 12.018,
+ 20.99,
"Points and vectors match up, one to one."
],
[
- 14.883,
+ 23.802,
"The difference is only how we think of them: a point is a place, and a vector is the trip from the origin to that place."
]
]
@@ -462,17 +473,19 @@ window.TIMINGS = {
]
},
"same": {
- "dur": 33.24,
+ "dur": 45.84,
"marks": {
- "v": 2.383,
- "w": 6.784,
- "u": 8.19,
- "eq": 9.362,
- "ex1": 15.312,
- "ex2": 17.161,
- "one": 22.096,
- "ex3": 26.458,
- "mirror": 29.609
+ "v": 2.422,
+ "w": 6.641,
+ "u": 7.956,
+ "eq": 9.167,
+ "ex1": 15.013,
+ "ex2": 16.576,
+ "one": 21.367,
+ "ex3": 25.898,
+ "mirror": 29.049,
+ "half": 32.773,
+ "half2": 40.547
},
"cues": [
[
@@ -480,36 +493,52 @@ window.TIMINGS = {
"We can have several vectors at once."
],
[
- 2.383,
+ 2.422,
"Each one gets its own letter and its own colour: v in green, w in violet, u in pink."
],
[
- 9.362,
+ 9.167,
"When are two vectors equal?"
],
[
- 11.12,
+ 10.872,
"When the top numbers match, and the bottom numbers match."
],
[
- 14.44,
+ 14.193,
"Both."
],
[
- 15.312,
+ 15.013,
"Say v is two, one."
],
[
- 17.161,
+ 16.576,
"If w is also two, one, then w equals v: the same two numbers, the same arrow, one exactly on top of the other."
],
[
- 26.458,
+ 25.898,
"But one, two is not equal to v."
],
[
- 29.609,
+ 29.049,
"The numbers are swapped, and the arrow is a different arrow."
+ ],
+ [
+ 32.773,
+ "And two, minus one?"
+ ],
+ [
+ 34.818,
+ "The tops match, but the bottoms do not: one is one, the other is minus one."
+ ],
+ [
+ 40.547,
+ "So it is not equal either."
+ ],
+ [
+ 42.331,
+ "One matching number is not enough; both must match."
]
]
},
@@ -619,6 +648,30 @@ window.TIMINGS = {
]
]
},
+ "play": {
+ "dur": 11.712,
+ "marks": {
+ "go": 3.698
+ },
+ "cues": [
+ [
+ 0.104,
+ "Playground."
+ ],
+ [
+ 1.042,
+ "Nothing here is marked right or wrong."
+ ],
+ [
+ 3.698,
+ "Change the numbers, drag the tips of the arrows, draw on the board if you like, and see what moves."
+ ],
+ [
+ 10.026,
+ "Press continue when you're done."
+ ]
+ ]
+ },
"finish": {
"dur": 9.456,
"marks": {},
diff --git a/site/linear-algebra/ch04/index.html b/site/linear-algebra/ch04/index.html
index 407ba47..8d3dc3b 100644
--- a/site/linear-algebra/ch04/index.html
+++ b/site/linear-algebra/ch04/index.html
@@ -12,6 +12,7 @@
<script src="../lib/math.js"></script>
<script src="../lib/linsys.js"></script>
<script src="../lib/vecs.js"></script>
+<script src="../lib/play.js"></script>
<script src="audio/en/timings.js"></script>
<script>
'use strict';
@@ -47,13 +48,14 @@ const walk = (vs, x, y, color, t0, into) => {
return g;
};
// A step-by-step walk along one axis direction: the line grows and each step's count pops up as it passes.
-const countWalk = (P, [xa, ya], [xb, yb], color, t0, dur, into, below = false) => {
+// Up/down counts sit inside the corner (towards the y-axis) unless out: then beyond the leg, clear of a steep arrow.
+const countWalk = (P, [xa, ya], [xb, yb], color, t0, dur, into, below = false, out = false) => {
const g = G(into, {}); g.below = below;
const n = Math.abs(xb - xa) + Math.abs(yb - ya), ln = path(g, '', { stroke: color, 'stroke-width': 5, 'stroke-linecap': 'round' });
const vert = xa === xb;
const marks = Array.from({ length: n }, (_, k) => {
const q = (k + 1) / n, x = xa + (xb - xa) * q, y = ya + (yb - ya) * q;
- const t = T(g, String(k + 1), { x: P.PX(x) + (vert ? (xb < 0 ? 22 : -22) : 0), y: P.PY(y) + (vert ? 8 : (g.below ? 48 : -16)), size: 24, fill: color, anchor: 'middle', weight: 700, o: 0 });
+ const t = T(g, String(k + 1), { x: P.PX(x) + (vert ? ((xb < 0) === out ? -22 : 22) : 0), y: P.PY(y) + (vert ? 8 : (g.below ? 48 : -16)), size: 24, fill: color, anchor: 'middle', weight: 700, o: 0 });
tw(t, { o: 1 }, t0 + dur * q - .1, .2);
return t;
});
@@ -61,6 +63,11 @@ const countWalk = (P, [xa, ya], [xb, yb], color, t0, dur, into, below = false) =
g.marks = marks;
return g;
};
+// Move vector n to (x, y) on the beat clock in whole steps, one grid point per `gap` seconds, like a reader's drag.
+const stepTo = (vs, n, [x0, y0], [x1, y1], t0, gap = .3) => {
+ const k = Math.max(Math.abs(x1 - x0), Math.abs(y1 - y0));
+ for (let i = 1; i <= k; i++) vs.to({ [n + '0']: Math.round(x0 + (x1 - x0) * i / k), [n + '1']: Math.round(y0 + (y1 - y0) * i / k) }, t0 + (i - 1) * gap, .01);
+};
const across = (x, y) => [x ? `${Math.abs(x)} ${x > 0 ? 'right' : 'left'}` : '', y ? `${Math.abs(y)} ${y > 0 ? 'up' : 'down'}` : ''].filter(Boolean).join(' and ') || 'nowhere';
/* ---------- practice data ---------- */
@@ -121,11 +128,11 @@ const BEATS = [
// the point (3, 2): its two numbers stand up into a column
const y = 330, sz = 54, mid = y - sz * .32;
const paren = G(p, { o: 0 });
- M(paren, ['( )'], { x: 300, y, size: sz, anchor: 'middle' });
- M(paren, [','], { x: 298, y, size: sz, anchor: 'middle' });
+ M(paren, ['( )'], { x: 300, y, size: sz, anchor: 'middle' });
+ M(paren, [','], { x: 300, y, size: sz, anchor: 'middle' });
show(paren, .4);
const three = inkM(p, ['3'], { x: 0, y: 0, size: sz, o: 0 }), two = inkM(p, ['2'], { x: 0, y: 0, size: sz, o: 0 });
- put(three, { x: 262, y }); put(two, { x: 336, y });
+ put(three, { x: 268, y }); put(two, { x: 332, y });
show(three, .4); show(two, .4);
const pt = text(p, 'a point', 300, y + 60, .6, { size: 28, fill: COL.dim, anchor: 'middle' });
hide(paren, m('stand'), .4); hide(pt, m('stand'), .4);
@@ -142,14 +149,24 @@ const BEATS = [
lightUp(three, m('top'), GREEN);
text(p, '← bottom: the second number', 400, mid + sz * .99 - 8, m('bot'), { size: 28, fill: COL.dim });
lightUp(two, m('bot'), GREEN);
- text(p, 'like 3 steps east and 2 steps north on a map', 90, 505, m('apples'), { size: 28, fill: COL.dim });
- const mp = G(p, {}), mx = 640, my = 470; // a little map walk: 3 east, then 2 north
- const e1 = path(mp, `M${mx} ${my}H${mx + 90}`, { stroke: GREEN, 'stroke-width': 4, 'stroke-linecap': 'round' }, { d: 0 });
- const e2 = path(mp, `M${mx + 90} ${my}V${my - 60}M${mx + 82} ${my - 48}L${mx + 90} ${my - 62}L${mx + 98} ${my - 48}`, { stroke: GREEN, 'stroke-width': 4, 'stroke-linecap': 'round', fill: 'none' }, { d: 0 });
- draw(e1, m('apples') + 2.4, 1.4, lin); draw(e2, m('apples') + 4.4, 1, lin);
- text(mp, 'E', mx + 104, my + 8, m('apples') + 3.6, { size: 22, fill: COL.dim });
- text(mp, 'N', mx + 82, my - 74, m('apples') + 5.2, { size: 22, fill: COL.dim });
- hide(mp, m('more') - .3, .4);
+ // a map on the right: 3 steps east, then 2 steps north, each step counted as it is said
+ const cap = text(p, 'like 3 steps east and 2 steps north on a map', 90, 505, m('apples'), { size: 28, fill: COL.dim });
+ const mp = G(p, { o: 0 }), MP = { PX: x => 1000 + 80 * x, PY: y => 600 - 80 * y };
+ let gd = '';
+ for (let i = 0; i <= 4; i++) gd += `M${MP.PX(i)} ${MP.PY(0)}V${MP.PY(3)}`;
+ for (let j = 0; j <= 3; j++) gd += `M${MP.PX(0)} ${MP.PY(j)}H${MP.PX(4)}`;
+ path(mp, gd, { stroke: COL.faint, 'stroke-width': 1.5, fill: 'none' });
+ mk('circle', { cx: MP.PX(0), cy: MP.PY(0), r: 9, fill: COL.chalk }, mp);
+ T(mp, 'start', { x: MP.PX(0), y: MP.PY(0) + 40, size: 24, fill: COL.dim, anchor: 'middle' });
+ const rose = G(mp, { x: 1400, y: 420 }); // the compass: north up, east right
+ path(rose, 'M0 30V-30M-8 -18L0 -32L8 -18M-30 0H30M18 -8L32 0L18 8', { stroke: COL.dim, 'stroke-width': 3, fill: 'none', 'stroke-linecap': 'round' });
+ T(rose, 'N', { x: 0, y: -42, size: 24, fill: COL.dim, anchor: 'middle', weight: 600 });
+ T(rose, 'E', { x: 46, y: 8, size: 24, fill: COL.dim, anchor: 'middle', weight: 600 });
+ show(mp, m('apples') + .4, .5);
+ countWalk(MP, [0, 0], [3, 0], GREEN, m('east') + .2, 1.5, mp, true);
+ countWalk(MP, [3, 0], [3, 2], GREEN, m('north') + .2, 1.1, mp, false, true);
+ lightUp(three, m('east'), GREEN); lightUp(two, m('north'), GREEN);
+ hide(mp, m('more') - .3, .4); hide(cap, m('more') - .3, .4);
// more vectors, and the order
const r2 = 610;
show(colm(p, -1, 5, 150, r2, { o: 0 }), m('more'));
@@ -170,7 +187,7 @@ const BEATS = [
M(pv, [r], { x: px + 250, y: yy, size: 46, anchor: 'start' });
});
mk('rect', { x: px + 22, y: 290, width: 82, height: 150, rx: 12, fill: 'none', stroke: GREEN, 'stroke-width': 3 }, pv);
- mk('rect', { x: px + 160, y: 290, width: 84, height: 150, rx: 12, fill: 'none', stroke: VIOLET, 'stroke-width': 3 }, pv);
+ mk('rect', { x: px + 112, y: 290, width: 132, height: 150, rx: 12, fill: 'none', stroke: VIOLET, 'stroke-width': 3 }, pv);
colm(pv, 2, -1, px + 63, 620, { fill: GREEN });
colm(pv, -1, 2, px + 202, 620, { fill: VIOLET });
path(pv, `M${px + 63} 450V520M${px + 55} 508L${px + 63} 522L${px + 71} 508M${px + 202} 450V520M${px + 194} 508L${px + 202} 522L${px + 210} 508`, { stroke: COL.dim, 'stroke-width': 3, fill: 'none' });
@@ -190,8 +207,8 @@ const BEATS = [
showRow(r1, .4);
show(vs.stage, m('axes') - .3, .6);
const wv = G(p, {});
- countWalk(vs.P, [0, 0], [3, 0], GREEN, m('right') + 1.4, 2.4, wv);
- countWalk(vs.P, [3, 0], [3, 2], GREEN, m('up') + 1.4, 1.6, wv);
+ countWalk(vs.P, [0, 0], [3, 0], GREEN, m('right') + .8, 2.4, wv);
+ countWalk(vs.P, [3, 0], [3, 2], GREEN, m('up') + .8, 1.6, wv);
const trav = G(p, { o: 0 });
mk('circle', { r: 9, fill: COL.task }, trav);
show(trav, m('tip') + 1.2, .3);
@@ -200,19 +217,20 @@ const BEATS = [
vs.flash('v0', m('right')); vs.flash('v1', m('up') - .4);
vs.P.dot(0, 0, COL.task, m('tip'), { r: 8, label: '(0, 0)', dx: -84, dy: -14 });
vs.show('v', m('tip') + 4.4, .6);
- const pd = vs.P.dot(3, 2, COL.chalk, m('same'), { r: 8, label: '(3, 2)', dx: 16, dy: 36 });
+ const pd = G(p, {}); vs.P.dot(3, 2, COL.chalk, m('same'), { r: 8, label: '(3, 2)', dx: 16, dy: 36, into: pd });
const note = G(p, { o: 0 });
T(note, 'the point (3, 2) is where the arrow ends', { x: 90, y: 720, size: 28, fill: COL.dim });
show(note, m('same') + .4);
hide(wv, m('w') - .3, .4); hide(note, m('w') - .3, .4);
const r2 = vs.row([{ t: 'w', fill: VIOLET }, '=', { col: 'w' }], { x: 90, y: 430, o: 0 });
showRow(r2, m('w'));
- const ww = walk(vs, 1, 0, VIOLET, m('w1'), p), ww2 = G(p, {});
- vs.P.arrow(1, 0, 1, 4, VIOLET, m('w4'), { label: '4', into: ww2 });
+ const ww = G(p, {}), ww2 = G(p, {});
+ countWalk(vs.P, [0, 0], [1, 0], VIOLET, m('w1'), .5, ww, true);
+ countWalk(vs.P, [1, 0], [1, 4], VIOLET, m('w4'), 1.2, ww2);
vs.flash('w0', m('w1')); vs.flash('w1', m('w4'));
vs.show('w', m('wtip'), .6);
- vs.P.dot(1, 4, COL.chalk, m('wtip') + .3, { r: 7, label: '(1, 4)', dx: 16, dy: 14 });
- hide(ww, m('swap') - .3, .4); hide(ww2, m('swap') - .3, .4); hide(pd, m('swap') - .3, .4);
+ const pw = G(p, {}); vs.P.dot(1, 4, COL.chalk, m('wtip') + .3, { r: 7, label: '(1, 4)', dx: 16, dy: 14, into: pw });
+ hide(ww, m('swap') - .3, .4); hide(ww2, m('swap') - .3, .4); hide(pd, m('swap') - .3, .4); hide(pw, m('swap') - .3, .4);
const r3 = vs.row([{ t: 'u', fill: PINK }, '=', { col: 'u' }], { x: 90, y: 610, o: 0 });
showRow(r3, m('swap'));
vs.show('u', m('swap') + 1, .6);
@@ -236,21 +254,24 @@ const BEATS = [
countWalk(vs.P, [-2, 0], [-2, 3], GREEN, m('up') + .2, 1.4, wv);
vs.flash('v0', m('left')); vs.flash('v1', m('up'));
vs.show('v', m('up') + .9, .6);
- text(p, '−2: two steps left', 330, 230, m('left') + .3, { size: 28, fill: COL.dim });
+ text(p, '−2: 2 left', 330, 230, m('left') + .3, { size: 28, fill: COL.dim });
+ text(p, '3: 3 up', 330, 272, m('up') + .2, { size: 28, fill: COL.dim });
hide(wv, m('n2'), .4);
const ww = G(p, {});
countWalk(vs.P, [0, 0], [4, 0], VIOLET, m('four'), 1.2, ww);
countWalk(vs.P, [4, 0], [4, -1], VIOLET, m('down') + .2, .6, ww);
vs.flash('w0', m('four')); vs.flash('w1', m('down'));
vs.show('w', m('down') + .8, .6);
- text(p, '−1: one step down', 330, 450, m('down') + .3, { size: 28, fill: COL.dim });
+ text(p, '4: 4 right', 330, 410, m('four'), { size: 28, fill: COL.dim });
+ text(p, '−1: 1 down', 330, 452, m('down') + .3, { size: 28, fill: COL.dim });
hide(ww, m('n3'), .4);
const wu = G(p, {});
countWalk(vs.P, [0, 0], [-3, 0], PINK, m('ld'), 1.2, wu);
countWalk(vs.P, [-3, 0], [-3, -2], PINK, m('ld') + 1.3, 1, wu);
vs.flash('u0', m('ld')); vs.flash('u1', m('ld') + 1.2);
vs.show('u', m('ld') + 2.2, .6);
- text(p, 'left and down', 330, 630, m('ld') + 2, { size: 28, fill: COL.dim });
+ text(p, '−3: 3 left', 330, 590, m('ld'), { size: 28, fill: COL.dim });
+ text(p, '−2: 2 down', 330, 632, m('ld') + 1.2, { size: 28, fill: COL.dim });
hide(wu, m('sum') - .2, .4);
const s = G(p, { o: 0 });
T(s, 'top number: − left, + right', { x: 90, y: 740, size: 30, weight: 600, fill: COL.task });
@@ -281,11 +302,13 @@ const BEATS = [
vs.label('w', ['w']);
const r2 = vs.row([{ t: 'w', fill: VIOLET }, '=', { col: 'w' }], { x: 90, y: 450, o: 0 });
showRow(r2, m('one'));
- vs.show('w', m('one') + 1.5, .6);
+ const zw = G(p, {}); countWalk(vs.P, [0, 0], [0, 3], VIOLET, m('one') + 1.8, 1.4, zw, false, true); hide(zw, m('flat'), .4);
+ vs.show('w', m('one') + 3.4, .6);
text(p, 'straight up, on the y-axis', 330, 450, m('yaxis'), { size: 28, fill: VIOLET, weight: 600 });
const r3 = vs.row([{ t: 'u', fill: PINK }, '=', { col: 'u' }], { x: 90, y: 640, o: 0 });
showRow(r3, m('flat'));
- vs.show('u', m('flat') + .8, .6);
+ const zu = G(p, {}); countWalk(vs.P, [0, 0], [4, 0], PINK, m('flat') + .4, 1.4, zu, true); hide(zu, m('flat') + 3, .4);
+ vs.show('u', m('flat') + 1.9, .6);
text(p, 'flat, on the x-axis', 330, 640, m('flat') + 1.2, { size: 28, fill: PINK, weight: 600 });
}],
@@ -296,7 +319,17 @@ const BEATS = [
vs.label('v', []);
const P2 = vs.P;
P2.dot(-5, 2, COL.task, m('pts'), { r: 10, label: '(−5, 2)', dx: -40, dy: -24 });
- vs.show('v', m('fan'), .6);
+ vs.show('v', m('vec'), .6);
+ const ex = G(p, { o: 0 });
+ M(ex, ['(−5, 2)'], { x: 90, y: 330, size: 44, anchor: 'start', fill: COL.task });
+ M(ex, ['↔'], { x: 290, y: 330, size: 44, fill: COL.task, anchor: 'middle' });
+ colm(ex, -5, 2, 400, 330, { fill: GREEN });
+ show(ex, m('vec') + .6, .6); hide(ex, m('so') - .3, .4);
+ // "same numbers": the trip to (−5, 2) counted, 5 left and 2 up
+ const ew = G(p, {});
+ countWalk(P2, [0, 0], [-5, 0], GREEN, m('vec') + 2.4, 2, ew, true);
+ countWalk(P2, [-5, 0], [-5, 2], GREEN, m('vec') + 4.6, 1, ew, false, true);
+ hide(ew, m('fan') - .3, .4);
const fanPts = [[4, 1], [2, -3], [-3, -4], [-1, 5], [5, 4], [-6, -1], [3, 6], [-4, 3], [0, -5], [6, -2], [-2, -2], [1, 3]];
const fan = G(p, {});
fanPts.forEach(([x, y], i) => {
@@ -337,17 +370,21 @@ const BEATS = [
text(p, '4 steps left → −4', 260, 300, m('top1') + .4, { size: 28, fill: COL.dim });
show(c1.bot, m('bot1')); lightUp(c1.bot, m('bot1') + .2, GREEN);
text(p, '1 step up → 1', 260, 380, m('bot1'), { size: 28, fill: COL.dim });
+ const b1 = G(p, {}); mk('rect', { x: 94, y: 244, width: 112, height: 144, rx: 12, fill: 'none', stroke: COL.task, 'stroke-width': 3 }, b1);
+ put(b1, { o: 0 }); show(b1, m('col1'), .4); hide(b1, m('a2'), .4);
hide(w1, m('a2'), .4);
vs.to({ v0: 2, v1: -5 }, m('a2') + .2, 1.4);
const w2 = G(p, {});
countWalk(vs.P, [0, 0], [2, 0], GREEN, m('count3'), 1, w2);
- countWalk(vs.P, [2, 0], [2, -5], GREEN, m('count4') + .2, 1.8, w2);
+ countWalk(vs.P, [2, 0], [2, -5], GREEN, m('count4') + .2, 1.8, w2, false, true);
const c2 = colm(p, 2, -5, 150, 620, { fill: GREEN, o: 0 });
put(c2.bot, { o: 0 });
show(c2, m('count3') + .8); lightUp(c2.top, m('count3') + 1, GREEN);
text(p, '2 steps right → 2', 260, 590, m('count3') + 1, { size: 28, fill: COL.dim });
show(c2.bot, m('bot2')); lightUp(c2.bot, m('bot2') + .2, GREEN);
text(p, '5 steps down → −5', 260, 670, m('bot2'), { size: 28, fill: COL.dim });
+ const b2 = G(p, {}); mk('rect', { x: 94, y: 534, width: 112, height: 144, rx: 12, fill: 'none', stroke: COL.task, 'stroke-width': 3 }, b2);
+ put(b2, { o: 0 }); show(b2, m('col2'), .4);
tw(vs.A.v.path, { 'a_stroke-width': 9 }, m('col2'), .3); tw(vs.A.v.path, { 'a_stroke-width': 5 }, m('col2') + .8, .5);
}],
@@ -358,9 +395,9 @@ const BEATS = [
}, { ask: done => quiz(CARD, [{
id: 'c-read', prompt: ['Write the arrow ', $m('v'), ' as a column of two numbers.'],
build: blanks([
- { parts: ['top number (how far right): ', { box: '-3' }], why: 'The tip is 3 steps left of the origin: −3.', hint: 'Count across from the origin to the tip. Steps to the left count as negative.',
+ { parts: ['top number (right +, left −): ', { box: '-3' }], why: 'The tip is 3 steps left of the origin: −3.', hint: 'Count across from the origin to the tip. Steps to the left count as negative.',
fx: () => fx(S.vs.A.v.leg, { o: 1 }, 0, .6) },
- { parts: ['bottom number (how far up): ', { box: '2' }], why: 'The tip is 2 steps above the x-axis: 2. So v = [−3, 2] as a column.', hint: 'Count up from the x-axis to the tip.' },
+ { parts: ['bottom number (up +, down −): ', { box: '2' }], why: 'The tip is 2 steps above the x-axis: 2. So v = [−3, 2] as a column.', hint: 'Count up from the x-axis to the tip.' },
]),
}], done) }],
@@ -372,8 +409,8 @@ const BEATS = [
vs.legs('v', .6);
tw(vs.A.v.path, { 'a_stroke-width': 8 }, m('nums'), .3); tw(vs.A.v.path, { 'a_stroke-width': 5 }, m('nums') + .8, .5);
vs.flash('v0', m('nums')); vs.flash('v1', m('nums'));
- vs.to({ v0: 5 }, m('five') + .4, 1.4); vs.flash('v0', m('five') + .4);
- vs.to({ v1: -1 }, m('minus') + .9, 1.4); vs.flash('v1', m('minus') + .9);
+ stepTo(vs, 'v', [3, 2], [5, 2], m('five') + .6, .5); vs.flash('v0', m('five') + .6);
+ stepTo(vs, 'v', [5, 2], [5, -1], m('minus') + .9, .5); vs.flash('v1', m('minus') + .9);
// a hand takes the tip and pulls it; the tip jumps from grid point to grid point, as it does for the reader
const hand = G(p, { o: 0 }), { PX, PY } = vs.P;
mk('circle', { r: 20, fill: COL.task, 'fill-opacity': .25, stroke: COL.task, 'stroke-width': 3 }, hand);
@@ -429,11 +466,16 @@ const BEATS = [
['v0', 'w0', 'u0'].forEach(k => vs.flash(k, m('eq') + 2));
['v1', 'w1', 'u1'].forEach(k => vs.flash(k, m('eq') + 3.6));
vs.flash('v0', m('ex1')); vs.flash('v1', m('ex1'));
- vs.to({ w0: 2, w1: 1 }, m('ex2') + .4, 1.6); vs.flash('w0', m('ex2') + .4); vs.flash('w1', m('ex2') + .4);
+ stepTo(vs, 'w', [-3, 2], [2, 1], m('ex2') + .4, .3); vs.flash('w0', m('ex2') + .4); vs.flash('w1', m('ex2') + .4);
say(p, ['w = v'], 330, 430, m('one'), { size: 40, fill: COL.good });
- vs.to({ u0: 1, u1: 2 }, m('ex3') + .3, 1.6); vs.flash('u0', m('ex3') + .3); vs.flash('u1', m('ex3') + .3);
- say(p, ['u ≠ v'], 330, 610, m('mirror'), { size: 40, fill: COL.bad });
- text(p, 'swapped: 1 right, 2 up', 330, 660, m('mirror') + .5, { size: 26, fill: COL.dim });
+ stepTo(vs, 'u', [1, -3], [1, 2], m('ex3') + .3, .3); vs.flash('u0', m('ex3') + .3); vs.flash('u1', m('ex3') + .3);
+ const ne = say(p, ['u ≠ v'], 330, 610, m('mirror'), { size: 40, fill: COL.bad });
+ const sw = text(p, 'swapped: 1 right, 2 up', 330, 660, m('mirror') + .5, { size: 26, fill: COL.dim });
+ hide(sw, m('half'), .3);
+ stepTo(vs, 'u', [1, 2], [2, -1], m('half') + .2, .3); vs.flash('u0', m('half') + 1.6); vs.flash('v0', m('half') + 1.6);
+ vs.flash('u1', m('half') + 3.6); vs.flash('v1', m('half') + 3.6);
+ text(p, 'top 2 = 2, but bottom −1 ≠ 1', 330, 660, m('half') + 1.4, { size: 26, fill: COL.dim });
+ pulse(ne, m('half2'), 1.3);
}],
['q3', 'Quick check', () => {
@@ -446,7 +488,7 @@ const BEATS = [
['wrap', 'Summary', (m) => {
const p = panel(0);
[['A vector is two numbers in a column, named by one letter.', 'w1'], ['Its arrow starts at the origin: top number right, bottom number up.', 'w2'],
- ['Negative numbers point left or down; [0, 0] is the zero vector, a dot.', 'w3'], ['Change the numbers, the arrow moves; move the arrow, the numbers change.', 'w4']].forEach(([str, mark], i) => {
+ ['Negative numbers point left or down; zero on top and below is the zero vector, a dot.', 'w3'], ['Change the numbers, the arrow moves; move the arrow, the numbers change.', 'w4']].forEach(([str, mark], i) => {
const g = G(p, { x: -16, y: 230 + i * 130, o: 0 });
const dg = G(g, { x: 150, y: -12 });
mk('circle', { r: 26, fill: COL.task }, dg);
@@ -488,6 +530,16 @@ const BEATS = [
id: `p-make${i + 1}`, prompt: q.prompt,
build: (body, api) => { S.vs.set({ v0: 1, v1: 1 }); return vsTask(S.vs, v => v.v0 === q.goal[0] && v.v1 === q.goal[1], `${across(...q.goal)}.`, makeHint(...q.goal), () => S.vs.set({ v0: q.goal[0], v1: q.goal[1] }))(body, api); },
})), done, 'Chapter practice · set 4 of 4') }],
+ ['play', 'Playground', (m) => {
+ const p = panel(0);
+ text(p, 'Playground', 60, 110, .2, { size: 40, weight: 600 });
+ S.vs = vecs(p, { vecs: { v: [3, 2], w: [-2, 1] } });
+ S.vs.row([{ t: 'v', fill: GREEN }, '=', { col: 'v' }], { x: 90, y: 230 });
+ S.vs.row([{ t: 'w', fill: VIOLET }, '=', { col: 'w' }], { x: 330, y: 230 });
+ const hint = G(p, { o: 0 });
+ ['try: make v point down and to the left', 'try: make w equal to v', 'try: make v the zero vector'].forEach((str, i) => T(hint, str, { x: 90, y: 336 + i * 36, size: 26, fill: COL.dim }));
+ show(hint, m('go'), .6);
+ }, { ask: playAsk(() => S.vs, { tip: 'Your two vectors. Change any number, drag either tip, or draw on the board. Nothing is marked.' }) }],
['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],
].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
diff --git a/site/linear-algebra/ch05/audio/en/minus2.mp3 b/site/linear-algebra/ch05/audio/en/minus2.mp3
new file mode 100644
index 0000000..58ebf63
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/minus2.mp3 differ
diff --git a/site/linear-algebra/ch05/audio/en/play.mp3 b/site/linear-algebra/ch05/audio/en/play.mp3
new file mode 100644
index 0000000..13e2491
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/play.mp3 differ
diff --git a/site/linear-algebra/ch05/audio/en/timings.js b/site/linear-algebra/ch05/audio/en/timings.js
index 003ffc8..7d14c0a 100644
--- a/site/linear-algebra/ch05/audio/en/timings.js
+++ b/site/linear-algebra/ch05/audio/en/timings.js
@@ -559,6 +559,70 @@ window.TIMINGS = {
]
]
},
+ "minus2": {
+ "dur": 40.896,
+ "marks": {
+ "ex": 1.562,
+ "tops": 5.586,
+ "bots": 9.089,
+ "res": 12.617,
+ "pic": 15.938,
+ "steps": 20.521,
+ "slide": 25.091,
+ "same": 30.26,
+ "check": 32.747
+ },
+ "cues": [
+ [
+ 0.104,
+ "One more subtraction."
+ ],
+ [
+ 1.562,
+ "v is two, three, and w is four, one."
+ ],
+ [
+ 5.586,
+ "Top minus top: two minus four is minus two."
+ ],
+ [
+ 9.089,
+ "Bottom minus bottom: three minus one is two."
+ ],
+ [
+ 12.617,
+ "So v minus w is minus two, two."
+ ],
+ [
+ 15.938,
+ "Now the picture."
+ ],
+ [
+ 17.057,
+ "Draw the arrow from the tip of w to the tip of v."
+ ],
+ [
+ 20.521,
+ "It goes two steps left, then two steps up: minus two, two."
+ ],
+ [
+ 25.091,
+ "Slide that arrow, without turning it, until its tail sits on the origin."
+ ],
+ [
+ 30.26,
+ "It is exactly v minus w."
+ ],
+ [
+ 32.747,
+ "And w, plus that arrow, gets you to v."
+ ],
+ [
+ 36.51,
+ "Four plus minus two is two, and one plus two is three."
+ ]
+ ]
+ },
"q4": {
"dur": 2.16,
"marks": {},
@@ -665,6 +729,30 @@ window.TIMINGS = {
]
]
},
+ "play": {
+ "dur": 12.024,
+ "marks": {
+ "go": 4.076
+ },
+ "cues": [
+ [
+ 0.117,
+ "Playground."
+ ],
+ [
+ 1.094,
+ "Nothing here is marked right or wrong."
+ ],
+ [
+ 4.076,
+ "Change the numbers, drag the arrow tips, or draw on the board, and watch the sum follow."
+ ],
+ [
+ 10.378,
+ "Press continue when you're done."
+ ]
+ ]
+ },
"finish": {
"dur": 11.712,
"marks": {},
diff --git a/site/linear-algebra/ch05/index.html b/site/linear-algebra/ch05/index.html
index 8f5e4ea..7ba9ae7 100644
--- a/site/linear-algebra/ch05/index.html
+++ b/site/linear-algebra/ch05/index.html
@@ -12,6 +12,7 @@
<script src="../lib/math.js"></script>
<script src="../lib/linsys.js"></script>
<script src="../lib/vecs.js"></script>
+<script src="../lib/play.js"></script>
<script src="audio/en/timings.js"></script>
<script>
'use strict';
@@ -46,14 +47,22 @@ const travel = (p, P, pts, t0, leg = 1.4, color = COL.task) => {
// v + w written out: v + w = [v] + [w] = [v0 + w0, v1 + w1] = [sum]; sign − for a difference.
const sumRow = (vs, x, y, { sign = '+', size = 46, fixed = false, o = 0 } = {}) => vs.row(
[{ t: 'v', fill: GREEN }, sign, { t: 'w', fill: VIOLET }, '=', { col: 'v', fixed }, sign, { col: 'w', fixed }, '=',
- { fn: v => sign === '+' ? [`${vs.fmt(v.v0)} + ${vs.paren(v.w0)}`, `${vs.fmt(v.v1)} + ${vs.paren(v.w1)}`] : [`${vs.fmt(v.v0)} − ${vs.paren(v.w0)}`, `${vs.fmt(v.v1)} − ${vs.paren(v.w1)}`], w: size * 4.2 },
+ { fn: v => sign === '+' ? [`${vs.fmt(v.v0)} + ${vs.paren(v.w0)}`, `${vs.fmt(v.v1)} + ${vs.paren(v.w1)}`] : [`${vs.fmt(v.v0)} − ${vs.paren(v.w0)}`, `${vs.fmt(v.v1)} − ${vs.paren(v.w1)}`], w: size * 4.9 },
'=', { col: 'sum', fixed: true }], { x, y, size, o });
+// Closer planes for beats whose arrows stay small (the plane is the default −6…6 elsewhere and in every question).
+const ZOOM = {
+ tiptail: { cx: 1060, cy: 570, u: 72, x0: -5, x1: 5, y0: -2, y1: 5 },
+ order: { cx: 900, cy: 650, u: 96, x0: -1, x1: 5, y0: -1, y1: 4 },
+ live: { cx: 880, cy: 580, u: 88, x0: -1, x1: 6, y0: -2, y1: 4 },
+ minus: { cx: 1000, cy: 520, u: 90, x0: -2, x1: 4, y0: -3, y1: 3 },
+ minus2: { cx: 1060, cy: 600, u: 84, x0: -3, x1: 5, y0: -1, y1: 4 },
+};
const vRow = (vs, n, fill, y, o = 0) => vs.row([{ t: n, fill }, '=', { col: n }], { x: 90, y, o });
const ringAt = (P, x, y, t0, into) => { // the amber target of a task
const g = G(into, { x: P.PX(x), y: P.PY(y), o: 0 });
mk('circle', { r: 16, fill: 'none', stroke: COL.task, 'stroke-width': 4 }, g);
mk('circle', { r: 4, fill: COL.task }, g);
- M(g, [`(${num(x)}, ${num(y)})`], { x: 22, y: -16, size: 26, fill: COL.task, anchor: 'start' });
+ M(g, [`(${num(x)}, ${num(y)})`], { x: 26, y: -20, size: 26, fill: COL.task, anchor: 'start' });
show(g, t0, .4);
return g;
};
@@ -155,7 +164,7 @@ const BEATS = [
['tiptail', 'Adding with arrows', (m) => {
const p = panel(0);
text(p, 'Adding with arrows: tip to tail', 60, 110, .2, { size: 40, weight: 600 });
- const vs = S.vs = vecs(p, { vecs: { v: [3, 1], w: [1, 2] }, show: [] });
+ const vs = S.vs = vecs(p, { vecs: { v: [3, 1], w: [1, 2] }, show: [], plane: ZOOM.tiptail });
vs.label('sum', ['v + w']); vs.label('v', ['v'], 'tip', [-24, 34]);
S.r1 = vs.row([{ t: 'v', fill: GREEN }, '+', { t: 'w', fill: VIOLET }, '=', { fn: v => [`${vs.fmt(v.v0)} + ${vs.paren(v.w0)}`, `${vs.fmt(v.v1)} + ${vs.paren(v.w1)}`], w: 46 * 4.2 }, '=', { col: 'sum' }], { x: 90, y: 610, o: 0 });
vs.row([{ t: 'v', fill: GREEN }, '=', { col: 'v' }], { x: 90, y: 250 }); vs.row([{ t: 'w', fill: VIOLET }, '=', { col: 'w' }], { x: 90, y: 430 });
@@ -172,7 +181,7 @@ const BEATS = [
showRow(S.r1, m('sum') + .4);
vs.legs('v', m('count') + .3); vs.legs('dw', m('count') + 2); vs.flash('sum0', m('count') + 1.5); vs.flash('sum1', m('count') + 4);
vs.legs(['v', 'dw'], m('match') - .2, false); vs.legs('sum', m('match'));
- vs.legs('sum', m('ex2') - .3, false); hide(end, m('ex2') - .3, .3);
+ vs.legs('sum', m('ex2') - .3, false); hide(end, m('ex2') - .3, .3); hide(vs.A.w.g, m('ex2') - .3, .3); // the faded first w would ride along as a stray arrow
vs.flash('sum0', m('match')); vs.flash('sum1', m('match'));
vs.to({ v0: 2, v1: -1, w0: -4, w1: 3 }, m('ex2') + .9, 2.4);
thick(vs, 'dw', m('follow') + .3); thick(vs, 'sum', m('follow') + 1.3, 6);
@@ -182,7 +191,7 @@ const BEATS = [
['order', 'The order does not matter', (m) => {
const p = panel(0);
text(p, 'v + w = w + v', 60, 110, .2, { size: 40, weight: 600 });
- const vs = vecs(p, { vecs: { v: [3, 1], w: [1, 2] }, show: ['v', 'dw', 'sum'] });
+ const vs = vecs(p, { vecs: { v: [3, 1], w: [1, 2] }, show: ['v', 'dw', 'sum'], plane: ZOOM.order });
vs.label('sum', ['v + w']);
const { PX, PY } = vs.P;
const par = path(p, `M${PX(0)} ${PY(0)}L${PX(3)} ${PY(1)}L${PX(4)} ${PY(3)}L${PX(1)} ${PY(2)}Z`, { fill: COL.task, stroke: 'none' }, { o: 0 });
@@ -218,7 +227,7 @@ const BEATS = [
['live', 'Still linked', (m) => {
const p = panel(0);
text(p, 'The sum follows', 60, 110, .2, { size: 40, weight: 600 });
- const vs = vecs(p, { vecs: { v: [3, 1], w: [1, 2] }, show: ['v', 'dw', 'sum'] });
+ const vs = vecs(p, { vecs: { v: [3, 1], w: [1, 2] }, show: ['v', 'dw', 'sum'], plane: ZOOM.live });
vs.label('sum', ['v + w']);
vRow(vs, 'v', GREEN, 250, 1); vRow(vs, 'w', VIOLET, 430, 1);
vs.row([{ t: 'v', fill: GREEN }, '+', { t: 'w', fill: VIOLET }, '=', { fn: v => [`${vs.fmt(v.v0)} + ${vs.paren(v.w0)}`, `${vs.fmt(v.v1)} + ${vs.paren(v.w1)}`], w: 46 * 4.2 }, '=', { col: 'sum' }], { x: 90, y: 610 });
@@ -267,17 +276,17 @@ const BEATS = [
showRow(vv, m('vv'), 0, 2); showRow(vv, m('tt'), 2, 5);
const copy = G(p, {});
vs.P.arrow(2, 1, 4, 2, GREEN, m('pic') + .8, { into: copy });
- travel(p, vs.P, [[0, 0], [2, 1], [4, 2]], m('pic') + .4, 1.2, GREEN);
+ hide(travel(p, vs.P, [[0, 0], [2, 1], [4, 2]], m('pic') + .4, 1.2, GREEN), m('long') + .6, .3);
hide(copy, m('two') + .4, .4);
vs.show('cv', m('two'), .6); thick(vs, 'cv', m('two') + .6);
const cr = vs.row([{ key: 'c' }, { t: 'v', fill: GREEN }, '=', { key: 'c' }, { col: 'v', fixed: true }, '=', { fn: v => [`${vs.fmt(v.c)}·${vs.paren(v.v0)}`, `${vs.fmt(v.c)}·${vs.paren(v.v1)}`], w: 150 }, '=', { col: 'cv' }], { x: 90, y: 430, o: 0 });
hide(vv.g, m('rule') - .4, .4);
showRow(cr, m('rule'));
vs.flash('c', m('name') + .2); vs.flash('c', m('name') + 3.5);
- const cin = G(p, {}), cInk = vs.num('c')[1];
- curve(cin, cInk, vs.num('v0')[1], m('rule') + 2, { color: COL.task }); curve(cin, cInk, vs.num('v1')[1], m('rule') + 3.8, { color: COL.task, up: false });
+ vs.flash('v0', m('rule') + 2); vs.flash('cv0', m('rule') + 2.6); vs.flash('v1', m('rule') + 3.8); vs.flash('cv1', m('rule') + 4.4); // "two times two is four, two times one is two"
vs.legs('cv', m('t3') + .4); vs.legs('cv', m('long3') + 2, false);
- text(p, 'c: a scalar (it scales v)', 90, 570, m('name') + .4, { size: 30, fill: COL.task, weight: 600 });
+ const cr2 = vs.row([{ t: 'c' }, '=', { key: 'c' }], { x: 90, y: 600, size: 40, o: 0 }); showRow(cr2, m('name') + .4); // the number's name, live
+ text(p, 'the number in front: a scalar (it scales v)', 290, 590, m('name') + .4, { size: 30, fill: COL.task, weight: 600 });
vs.to({ c: 3 }, m('three') + .2, 1.4); vs.flash('c', m('three') + .2);
vs.flash('cv0', m('t3') + .2); vs.flash('cv1', m('t3') + 1.8);
thick(vs, 'cv', m('long3'));
@@ -321,7 +330,10 @@ const BEATS = [
showRow(r, m('a'), 0, 5); vs.show('v', m('a') + .3, .5); vs.dim('v', m('at'), .4);
showRow(r, m('at'), 5, 9); vs.flash('cv0', m('at') + .4); vs.flash('cv1', m('at') + 2.6);
vs.show('cv', m('ar') - .4, .6); thick(vs, 'cv', m('ar') + 1.2);
- vs.to({ v0: 3, v1: -1, c: -2 }, m('b') + .2, 1.6); vs.flash('c', m('b') + .2); vs.flash('v0', m('b') + 1); vs.flash('v1', m('b') + 1);
+ // the second example: 3v goes, the new v comes in bright, then −2 times it is drawn (no collapse through zero on screen)
+ vs.hide(['cv', 'v'], m('b') - .1, .3); vs.to({ v0: 3, v1: -1, c: -2 }, m('b') + .25, .05);
+ tw(vs.A.v.g, { o: 1 }, m('b') + .4, .4); show(vs.A.v.lab, m('b') + .4, .4); vs.flash('c', m('b') + .3); vs.flash('v0', m('b') + 1); vs.flash('v1', m('b') + 1);
+ vs.dim('v', m('bt'), .4); vs.show('cv', m('bt') + .1, .6);
vs.flash('cv0', m('bt') + .6); vs.flash('cv1', m('bt') + 2.8);
vs.legs('cv', m('bt') + .4); vs.legs('cv', m('br') + 3, false);
text(p, '(−) × (−) = (+)', 90, 520, m('sign'), { size: 34, fill: COL.task, weight: 600 });
@@ -345,20 +357,21 @@ const BEATS = [
['minus', 'Subtracting', (m) => {
const p = panel(0);
text(p, 'Subtracting: v − w = v + (−w)', 60, 110, .2, { size: 40, weight: 600 });
- const vs = vecs(p, { vecs: { v: [3, 1], w: [1, 2] }, d: 1, show: [] });
- vs.label('sum', ['v − w']); vs.label('dw', v => [v.d === 1 ? 'w' : '−w'], 'mid', [-60, -36]);
+ const vs = vecs(p, { vecs: { v: [3, 1], w: [1, 2] }, d: 1, show: [], plane: ZOOM.minus });
+ vs.label('sum', ['v − w']); vs.label('dw', v => [v.d === 1 ? 'w' : '−w'], 'mid', [22, 26]);
+ vs.label('dw0', v => v.d === 1 ? ['w'] : v.d === -1 ? ['−w'] : []); // no "−1w" while d passes −0.97
const r = vs.row([{ t: 'v', fill: GREEN }, '−', { t: 'w', fill: VIOLET }, '=', { col: 'v', fixed: true }, '−', { col: 'w', fixed: true }, '=', { fn: () => ['3 − 1', '1 − 2'], w: 150 }, '=', { fn: () => ['2', '−1'], w: 40 * 1.9, fill: COL.task }], { x: 90, y: 250, size: 40, o: 0 });
showRow(r, m('ex'), 0, 7);
const [ft, fb] = r.parts[8].querySelectorAll('g[color]'), [rt, rb] = r.parts[10].querySelectorAll('g[color]');
put(fb, { o: 0 }); put(rb, { o: 0 });
showRow(r, m('tops'), 7, 11); show(fb, m('bots')); show(rb, m('bots') + 2.2);
- lightUp(rt, m('res') + .3); lightUp(rb, m('res') + .3);
+ lightUp(rt, m('res') + .3, COL.task); lightUp(rb, m('res') + .3, COL.task);
const lk = G(p, {});
curve(lk, vs.num('v0')[0], ft, m('tops') + .3, { color: GREEN }); curve(lk, vs.num('w0')[0], ft, m('tops') + 1.2, { color: VIOLET });
curve(lk, vs.num('v1')[0], fb, m('bots') + .3, { color: GREEN, up: false }); curve(lk, vs.num('w1')[0], fb, m('bots') + 1.2, { color: VIOLET, up: false });
boxAround(lk, [rt, rb], m('res') + .2);
hide(lk, m('how') + .5, .4);
- vs.show(['v', 'w'], m('how'), .6);
+ vs.show(['v', 'w'], m('ex') + .6, .6); thick(vs, 'v', m('how') + .2); thick(vs, 'w', m('how') + .8);
say(p, ['v − w = v + (−w)'], 90, 440, m('same'), { size: 44 });
vs.show('dw0', m('flip') - .2, .3);
vs.to({ d: -1 }, m('flip') + .2, 1.6);
@@ -373,6 +386,42 @@ const BEATS = [
say(p, ['w + (v − w) = v'], 90, 680, m('why') + 1, { size: 40 });
}],
+ ['minus2', 'One more subtraction', (m) => {
+ const p = panel(0);
+ text(p, 'One more: v − w', 60, 110, .2, { size: 40, weight: 600 });
+ const vs = vecs(p, { vecs: { v: [2, 3], w: [4, 1] }, d: -1, show: [], plane: ZOOM.minus2 });
+ vs.label('sum', ['v − w']);
+ const r = vs.row([{ t: 'v', fill: GREEN }, '−', { t: 'w', fill: VIOLET }, '=', { col: 'v', fixed: true }, '−', { col: 'w', fixed: true }, '=', { fn: () => ['2 − 4', '3 − 1'], w: 150 }, '=', { fn: () => ['−2', '2'], w: 40 * 1.9, fill: COL.task }], { x: 90, y: 250, size: 40, o: 0 });
+ showRow(r, m('ex'), 0, 7); vs.show(['v', 'w'], m('ex') + .6, .6);
+ const [ft, fb] = r.parts[8].querySelectorAll('g[color]'), [rt, rb] = r.parts[10].querySelectorAll('g[color]');
+ put(fb, { o: 0 }); put(rb, { o: 0 });
+ showRow(r, m('tops'), 7, 11); show(fb, m('bots')); show(rb, m('bots') + 2.2);
+ lightUp(rt, m('res') + .3, COL.task); lightUp(rb, m('res') + .3, COL.task);
+ const lk = G(p, {});
+ curve(lk, vs.num('v0')[0], ft, m('tops') + .3, { color: GREEN }); curve(lk, vs.num('w0')[0], ft, m('tops') + 1.2, { color: VIOLET });
+ curve(lk, vs.num('v1')[0], fb, m('bots') + .3, { color: GREEN, up: false }); curve(lk, vs.num('w1')[0], fb, m('bots') + 1.2, { color: VIOLET, up: false });
+ boxAround(lk, [rt, rb], m('res') + .2);
+ hide(lk, m('pic') - .2, .4);
+ // the arrow from the tip of w to the tip of v, its steps, then slid to the origin
+ const { PX, PY, u } = vs.P, gap = G(p, {});
+ vs.P.arrow(4, 1, 2, 3, COL.task, m('pic') + 1.4, { into: gap });
+ const legs = G(p, { o: 0 });
+ path(legs, `M${PX(4)} ${PY(1)}H${PX(2)}V${PY(3)}`, { stroke: COL.task, 'stroke-width': 3, 'stroke-dasharray': '7 7', fill: 'none' });
+ M(legs, ['−2'], { x: (PX(4) + PX(2)) / 2, y: PY(1) - 14, size: 28, fill: COL.task, anchor: 'middle' });
+ M(legs, ['2'], { x: PX(2) - 14, y: PY(2) + 10, size: 28, fill: COL.task, anchor: 'end' });
+ show(legs, m('steps') + .2, .5); hide(legs, m('slide') - .2, .3);
+ tw(gap, { x: -4 * u, y: 1 * u }, m('slide') + .4, 2);
+ vs.show('sum', m('same'), .4); hide(gap, m('same') + .4, .3); thick(vs, 'sum', m('same') + .5, 6);
+ text(p, 'moved without turning: still the same vector', 90, 440, m('same') + .3, { size: 28, fill: COL.task, weight: 600 });
+ // check: w, then v − w placed at its tip, ends on v
+ const back = G(p, { o: 0 });
+ vs.P.arrow(4, 1, 2, 3, COL.task, 0, { into: back });
+ show(back, m('check'), .4);
+ travel(p, vs.P, [[0, 0], [4, 1], [2, 3]], m('check') + .6, 1.4);
+ say(p, ['w + (v − w) = v'], 90, 540, m('check') + .4, { size: 40 });
+ say(p, ['4 + (−2) = 2, 1 + 2 = 3'], 90, 610, m('check') + 3, { size: 34, fill: COL.dim });
+ }],
+
['q4', 'Quick check', () => {
const p = panel(0);
text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
@@ -403,7 +452,7 @@ const BEATS = [
id: 'p-add', prompt: ['Add. Top plus top, bottom plus bottom.'], build: vcolBlanks(ADDQ),
}], done, 'Chapter practice · set 1 of 4') }],
['final2', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
- id: 'p-mul', prompt: ['Multiply each number by c.'], build: vcolBlanks(MULQ),
+ id: 'p-mul', prompt: ['Multiply both numbers by the number in front.'], build: vcolBlanks(MULQ),
}, {
id: 'p-sub', prompt: ['Subtract. Top minus top, bottom minus bottom.'], build: vcolBlanks(SUBQ),
}], done, 'Chapter practice · set 2 of 4') }],
@@ -418,6 +467,18 @@ const BEATS = [
S.vs.label('sum', ['v + w']);
S.row = S.vs.row([{ t: 'v', fill: GREEN }, '+', { t: 'w', fill: VIOLET }, '=', { col: 'v', fixed: true }, '+', { col: 'w' }, '=', { col: 'sum', fixed: true }], { x: 90, y: 230 });
}, { ask: done => quiz(CARD, MAKE5.map(q => ({ id: q.id, prompt: q.prompt, build: (body, api) => { q.setup(); return vsTask(S.vs, q.test, q.why, q.hint, q.show, q.opts)(body, api); } })), done, 'Chapter practice · set 4 of 4') }],
+ ['play', 'Playground', (m) => {
+ const p = panel(0);
+ text(p, 'Playground', 60, 110, .2, { size: 40, weight: 600 });
+ const vs = S.vs = vecs(p, { vecs: { v: [3, 1], w: [1, 2] }, show: ['cv', 'dw', 'sum'] });
+ vs.label('sum', v => v.c === 1 ? ['v + w'] : v.c === -1 ? ['−v + w'] : vs.nice(v.c) ? [vs.fmt(v.c) + 'v + w'] : []);
+ vs.row([{ key: 'c' }, { t: 'v', fill: GREEN }, '+', { t: 'w', fill: VIOLET }, '=', { key: 'c' }, { col: 'v' }, '+', { col: 'w' }, '=', { col: 'sum', fixed: true }], { x: 90, y: 230 });
+ const hint = G(p, { o: 0 });
+ ['try: make the sum land on the origin', 'make c = −1, then c = 0', 'drag the tip of w around the tip of v'].forEach((str, i) =>
+ T(hint, str, { x: i ? 156 : 90, y: 336 + i * 34, size: 26, fill: COL.dim }));
+ show(hint, m('go'), .5); hide(hint, m('go') + 7, .6);
+ }, { ask: playAsk(() => ({ v: S.vs.v, set: S.vs.set, live: on => S.vs.live(on, { move: true }) }), // tips carry v and w (not c)
+ { tip: 'c v + w, yours. Change any number, drag either arrow tip, or draw on the board. Nothing is marked.' }) }],
['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],
].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
diff --git a/site/linear-algebra/ch06/audio/en/parallel.mp3 b/site/linear-algebra/ch06/audio/en/parallel.mp3
index 099bd32..5a6b7da 100644
Binary files a/site/linear-algebra/ch06/audio/en/parallel.mp3 and b/site/linear-algebra/ch06/audio/en/parallel.mp3 differ
diff --git a/site/linear-algebra/ch06/audio/en/play.mp3 b/site/linear-algebra/ch06/audio/en/play.mp3
new file mode 100644
index 0000000..1c086f8
Binary files /dev/null and b/site/linear-algebra/ch06/audio/en/play.mp3 differ
diff --git a/site/linear-algebra/ch06/audio/en/scrub.mp3 b/site/linear-algebra/ch06/audio/en/scrub.mp3
index 0760c5d..6724d6d 100644
Binary files a/site/linear-algebra/ch06/audio/en/scrub.mp3 and b/site/linear-algebra/ch06/audio/en/scrub.mp3 differ
diff --git a/site/linear-algebra/ch06/audio/en/timings.js b/site/linear-algebra/ch06/audio/en/timings.js
index ee8b996..60e4208 100644
--- a/site/linear-algebra/ch06/audio/en/timings.js
+++ b/site/linear-algebra/ch06/audio/en/timings.js
@@ -220,13 +220,15 @@ window.TIMINGS = {
]
},
"scrub": {
- "dur": 19.176,
+ "dur": 28.608,
"marks": {
- "c": 2.409,
- "cpath": 6.458,
- "d": 9.922,
- "dpath": 12.93,
- "both": 15.651
+ "c": 2.448,
+ "cpath": 6.419,
+ "d": 9.818,
+ "dpath": 12.786,
+ "both": 15.482,
+ "s1": 19.128,
+ "s2": 23.099
},
"cues": [
[
@@ -234,24 +236,32 @@ window.TIMINGS = {
"Now let's move c and d, and watch."
],
[
- 2.409,
+ 2.448,
"Change c, and only the first arrow stretches."
],
[
- 6.458,
+ 6.419,
"The tip slides along the direction of v."
],
[
- 9.922,
+ 9.818,
"Change d, and the second arrow stretches."
],
[
- 12.93,
+ 12.786,
"The tip slides along the direction of w."
],
[
- 15.651,
+ 15.482,
"Change both, and you can steer the tip wherever you like."
+ ],
+ [
+ 19.128,
+ "c two and d three: the tip lands on one, four."
+ ],
+ [
+ 23.099,
+ "c minus one and d minus two: it lands on zero, minus three."
]
]
},
@@ -447,14 +457,20 @@ window.TIMINGS = {
]
},
"parallel": {
- "dur": 29.736,
+ "dur": 51.24,
"marks": {
- "turn": 1.458,
- "squash": 6.719,
- "par": 10.43,
- "line": 12.773,
- "miss": 15.521,
- "rule": 22.109
+ "turn": 1.419,
+ "squash": 6.732,
+ "par": 10.456,
+ "line": 13.047,
+ "try": 15.755,
+ "miss": 21.133,
+ "ex2": 26.263,
+ "x2": 33.216,
+ "line2": 38.581,
+ "rule": 41.042,
+ "rule2": 44.701,
+ "rule3": 47.708
},
"cues": [
[
@@ -462,27 +478,39 @@ window.TIMINGS = {
"But not always."
],
[
- 1.458,
+ 1.419,
"Let w turn, slowly, until it points along v."
],
[
- 6.719,
+ 6.732,
"Watch the grid: it squashes flatter and flatter."
],
[
- 10.43,
+ 10.456,
"Now w is two times v, and all the combinations lie on one line."
],
[
- 15.521,
- "A target off that line, like zero, three, can never be reached, whatever c and d you choose."
+ 15.755,
+ "Steer c and d however you like: the tip only slides along that line."
+ ],
+ [
+ 21.133,
+ "So a target off the line, like zero, three, can never be reached."
],
[
- 22.109,
- "Two vectors that point along different lines fill the plane."
+ 26.263,
+ "Another pair: v is one, one, and w is minus two, minus two."
],
[
- 26.107,
+ 33.216,
+ "w is minus two times v, so again they point along one line, and every combination lands on that line."
+ ],
+ [
+ 41.042,
+ "Two vectors that point along different lines fill the plane, like one, zero and one, one."
+ ],
+ [
+ 47.708,
"Two that point along the same line only fill a line."
]
]
@@ -589,6 +617,30 @@ window.TIMINGS = {
]
]
},
+ "play": {
+ "dur": 13.944,
+ "marks": {
+ "go": 4.154
+ },
+ "cues": [
+ [
+ 0.104,
+ "Playground."
+ ],
+ [
+ 1.094,
+ "Nothing here is marked right or wrong."
+ ],
+ [
+ 4.154,
+ "Change c and d, drag the tips, or move v and w themselves, and watch the grid of combinations follow."
+ ],
+ [
+ 12.279,
+ "Press continue when you're done."
+ ]
+ ]
+ },
"finish": {
"dur": 10.872,
"marks": {},
diff --git a/site/linear-algebra/ch06/index.html b/site/linear-algebra/ch06/index.html
index 3701f69..90dd48e 100644
--- a/site/linear-algebra/ch06/index.html
+++ b/site/linear-algebra/ch06/index.html
@@ -12,6 +12,7 @@
<script src="../lib/math.js"></script>
<script src="../lib/linsys.js"></script>
<script src="../lib/vecs.js"></script>
+<script src="../lib/play.js"></script>
<script src="audio/en/timings.js"></script>
<script>
'use strict';
@@ -52,7 +53,7 @@ const sumLinks = (p, vs, tTop, tBot, tBox) => {
};
// "2v − w", "v + w", "0": the combination's name from c and d.
const comboLabel = vs => v => {
- const term = (k, n) => k === 1 ? n : k === -1 ? '−' + n : vs.fmt(k) + n;
+ const term = (k, n) => Math.abs(k - 1) < 1e-9 ? n : Math.abs(k + 1) < 1e-9 ? '−' + n : vs.fmt(k) + n; // a tween ends a hair off 1
if (!vs.nice(v.c) || !vs.nice(v.d)) return [];
if (!v.c && !v.d) return ['0'];
if (!v.d) return [term(v.c, 'v')];
@@ -70,11 +71,11 @@ const slideIn = (vs, id, tail, t0, dur = 1.6) => {
tw(a.g, { o: 1 }, t0, .3); tw(a.g, { x: 0, y: 0 }, t0 + .4, dur);
show(a.lab, t0 + .4 + dur, .4);
};
-const ringAt = (P, x, y, t0, into, color = COL.task) => {
+const ringAt = (P, x, y, t0, into, color = COL.task, left = false) => { // left: the label on the ring's left; 'none': no label
const g = G(into, { x: P.PX(x), y: P.PY(y), o: 0 });
mk('circle', { r: 16, fill: 'none', stroke: color, 'stroke-width': 4 }, g);
mk('circle', { r: 4, fill: color }, g);
- M(g, [pairStr(x, y)], { x: 22, y: -16, size: 26, fill: color, anchor: 'start' });
+ if (left !== 'none') M(g, [pairStr(x, y)], { x: left ? -24 : 22, y: -16, size: 26, fill: color, anchor: left ? 'end' : 'start' });
show(g, t0, .4);
return g;
};
@@ -114,7 +115,9 @@ const FINDQ = [[3, 0, 2, 1], [-3, 3, -1, 1], [0, 3, 1, 2], [4, 1, 3, 2], [1, -2,
console.assert(Math.abs(2 * cv - dv - x) < 1e-9 && Math.abs(-cv + 2 * dv - y) < 1e-9, 'FINDQ', x, y);
const s = n => typeof n === 'number' ? String(n) : n.f.join('/');
return { parts: [`target ${pairStr(x, y)}: c = `, { box: s(c) }, ' d = ', { box: s(d) }],
- why: `${s(c)}·[2, −1] + ${s(d)}·[−1, 2] = [${num(x)}, ${num(y)}].`, hint: 'Top: 2c − d must be the first number. Bottom: −c + 2d must be the second. Try small whole numbers first.' };
+ why: `${s(c)}·[2, −1] + ${s(d)}·[−1, 2] = [${num(x)}, ${num(y)}].`,
+ hint: typeof c === 'number' ? 'Top: 2c − d must be the first number. Bottom: −c + 2d must be the second. Try small whole numbers first.'
+ : 'Not whole numbers this time. The bottom says −c + 2d = 0, so c = 2d. Put that into the top: 2·2d − d = 3d = 1, so d = 1/3.' };
});
const SPANQ = [[[1, 2], [2, 4], 'n', 'The second is 2 times the first: both lie on one line.'], [[1, 0], [1, 1], 'y', 'They point different ways: they fill the plane.'],
[[3, -1], [-6, 2], 'n', 'The second is −2 times the first: one line.'], [[1, 1], [1, -1], 'y', 'Different directions: the whole plane.'],
@@ -140,9 +143,16 @@ const BEATS = [
const p = panel(0);
text(p, 'Stretch each vector, then add', 60, 110, .2, { size: 40, weight: 600 });
const vs = lecture(p, { c: 1, d: 2, show: [] });
+ vs.label('sum', comboLabel(vs), 'tip', [40, 4]); // (0, 3) is on the y-axis: the name sits clear of it
vs.show(['v', 'w'], m('vw'), .6);
+ // the two vectors written out while they are named; then the recipe in letters; then the numbers
+ const named = vs.row([{ t: 'v', fill: GREEN }, '=', { col: 'v', fixed: true }, ' ', { t: 'w', fill: VIOLET }, '=', { col: 'w', fixed: true }], { x: 70, y: 240, size: 42, o: 0 });
+ showRow(named, m('vw') + .3); hide(named.g, m('cd') - .3, .3);
+ const letters = vs.row([{ t: 'c' }, { t: 'v', fill: GREEN }, '+', { t: 'd' }, { t: 'w', fill: VIOLET }], { x: 70, y: 240, size: 42, o: 0 });
+ showRow(letters, m('cd')); hide(letters.g, m('ex') - .3, .3);
+ [[[0, 1], 2.6], [[3, 4], 4], [[2], 5.6]].forEach(([ks, dt]) => ks.forEach(k => { const e = letters.parts[k], t = m('cd') + dt; tw(e, { o: .3 }, t, .2); tw(e, { o: 1 }, t + .3, .3); tw(e, { o: .3 }, t + .7, .2); tw(e, { o: 1 }, t + 1, .3); })); // stretch v by c, w by d, then add
const r1 = line1(vs, 240), r2 = line2(vs, 420);
- showRow(r1, m('cd'), 0, 4); showRow(r1, m('ex') - .2, 4, 9);
+ showRow(r1, m('ex'), 0, 4); showRow(r1, m('ex') + 1, 4, 9);
vs.flash('c', m('ex') + .6); vs.flash('d', m('ex') + 1.6);
showRow(r2, m('cv'), 0, 2); vs.flash('cv0', m('cv') + .4); vs.flash('cv1', m('cv') + .4);
showRow(r2, m('dw'), 2, 4); vs.flash('dw0', m('dw') + .4); vs.flash('dw1', m('dw') + .4);
@@ -153,11 +163,22 @@ const BEATS = [
vs.flash('cv1', m('addb') + .4); vs.flash('dw1', m('addb') + 1); vs.flash('sum1', m('addb') + 1.8);
vs.flash('sum0', m('res') + .4); vs.flash('sum1', m('res') + .4);
const lk = sumLinks(p, vs, m('add') + .5, m('addb') + .3, m('res') + .2); hide(lk, m('name') - .3, .4);
+ // the picture follows the sums: 1v (on top of v), then 2w (w stretched), then 2w moved onto the tip of 1v
+ vs.show('cv', m('cv') + .3, .6); thick(vs, 'cv', m('cv') + .6);
+ vs.dim('w', m('dw') + .3, .3); vs.show('dw0', m('dw') + .3, .6); thick(vs, 'dw0', m('dw') + 1);
vs.dim(['v', 'w'], m('pic'), .25); hide(vs.A.v.lab, m('pic'), .3); hide(vs.A.w.lab, m('pic'), .3);
- vs.show('cv', m('pic') + .2, .6);
+ thick(vs, 'cv', m('pic') + .3);
+ // a traveller makes the trip: along 1v, then along 2w, and stops at (0, 3)
+ const trip = G(vs.P.g, { o: 0 }); mk('circle', { r: 10, fill: COL.task, stroke: COL.board, 'stroke-width': 2 }, trip);
+ put(trip, { x: vs.P.PX(0), y: vs.P.PY(0) }); show(trip, m('pic') + .3, .3);
+ prog(q => put(trip, { x: vs.P.PX(2 * q), y: vs.P.PY(-q) }), m('pic') + .6, 1.4);
+ prog(q => put(trip, { x: vs.P.PX(2 - 2 * q), y: vs.P.PY(-1 + 4 * q) }), m('end') - .5, 1.2);
+ hide(trip, m('end') + 1.4, .3);
+ [['v0', 'v1', 1.6], ['w0', 'w1', 2.6], ['sum0', 'sum1', 3.6]].forEach(([a, b, dt]) => { vs.flash(a, m('keep') + dt); vs.flash(b, m('keep') + dt); });
+ vs.hide('dw0', m('pic2'), .3);
slideIn(vs, 'dw', LV, m('pic2') + .1, 1.6);
- vs.show('sum', m('end'), .6);
- vs.P.dot(0, 3, COL.task, m('end') + .3, { r: 9, label: '(0, 3)', dx: -80, dy: 8 });
+ vs.show('sum', m('end') + .7, .6);
+ vs.P.dot(0, 3, COL.task, m('end') + .7, { r: 9, label: '(0, 3)', dx: -80, dy: 8 });
const nm = G(p, { o: 0 });
T(nm, 'c v + d w: a linear combination of v and w', { x: 70, y: 600, size: 32, weight: 600, fill: COL.task });
show(nm, m('name'));
@@ -165,7 +186,7 @@ const BEATS = [
void s0;
}],
- ['ex2', 'More choices', (m) => {
+ ['ex2', 'More choices', (m, D) => {
const p = panel(0);
text(p, 'Each choice of c and d: one point', 60, 110, .2, { size: 40, weight: 600 });
const vs = lecture(p, { c: 1, d: 2, show: ['cv', 'dw', 'sum'] });
@@ -184,7 +205,14 @@ const BEATS = [
lightUp(f0, m('t3')); vs.flash('sum0', m('t3') + 1.6);
lightUp(f1, m('b3')); vs.flash('sum1', m('b3') + 1.4);
vs.P.dot(-3, 3, COL.task, m('r3'), { r: 8, into: dots });
- [...dots.children].forEach((d, i) => { if (d.tagName === 'g' && d.querySelector('circle')) pulse(d, m('same') + .3 + i * .2); });
+ // every step of the sums written out under the row, as the voice says it
+ const steps = [['top: 4 − 1 = 3', m('t') + 3.8, m('c3') - .3], ['bottom: −2 + 2 = 0', m('b') + 4, m('c3') - .3],
+ ['top: −2 − 1 = −3', m('t3') + 1.4, D - .4], ['bottom: 1 + 2 = 3', m('b3') + 1.2, D - .4]];
+ steps.forEach(([str, t0, t1], i) => hide(say(p, [str], 90, 580 + (i % 2) * 64, t0, { size: 36 }), t1, .3));
+ // "each choice lands on one point": the arrows step back and the three points carry their c and d
+ vs.dim(['cv', 'dw', 'sum'], m('same'), .15);
+ [[0, 3, 'v + 2w', -14, -18, 'end'], [3, 0, '2v + w', 14, -18, 'start'], [-3, 3, '−v + w', -14, -18, 'end']].forEach(([x, y, lab, dx, dy, anchor], i) =>
+ vs.P.dot(x, y, COL.task, m('same') + .3 + i * .4, { r: 9, label: lab, dx, dy, anchor, into: dots }));
}],
['special', 'Combinations you know', (m) => {
@@ -217,6 +245,7 @@ const BEATS = [
const p = panel(0);
text(p, 'c moves the tip along v, d along w', 60, 110, .2, { size: 40, weight: 600 });
const vs = lecture(p, { c: 1, d: 1, show: ['v', 'w', 'cv', 'dw', 'sum'] });
+ vs.label('sum', comboLabel(vs), 'tip', [40, 4]); // clear of the y-axis at (1, 4) and (0, −3)
vs.dim(['v', 'w'], .3, .25);
line1(vs, 240, 1);
const tr = G(p, {});
@@ -229,8 +258,16 @@ const BEATS = [
vs.P.line(2, -1, 1, 1, VIOLET, m('dpath') - .2, { dash: '8 9', w: 3, into: tr });
text(p, 'd changes: the tip slides along w', 70, 475, m('dpath'), { size: 30, fill: VIOLET, weight: 600 });
hide(tr, m('both') + .2, .4);
- vs.to({ c: 2, d: 3 }, m('both') + .4, 1.4); vs.to({ c: -1, d: -2 }, m('both') + 2, 1.6); vs.to({ c: 0, d: 2 }, m('both') + 3.8, 1.2);
+ vs.to({ c: 2, d: -1 }, m('both') + .4, 1.4); vs.to({ c: 0, d: 1 }, m('both') + 1.9, 1.4); // a wander first
text(p, 'both: anywhere you steer', 70, 530, m('both') + .3, { size: 30, fill: COL.task, weight: 600 });
+ // two worked steers, each written out and its landing point marked
+ const sumRow = vs.row([{ key: 'c' }, { t: 'v', fill: GREEN }, { key: 'd', signed: true }, { t: 'w', fill: VIOLET }, '=', { col: 'sum', fixed: true }], { x: 70, y: 680, size: 42, o: 0 });
+ [['s1', 2, 3, 1, 4], ['s2', -1, -2, 0, -3]].forEach(([k, c, d, x, y]) => {
+ vs.to({ c, d }, m(k) + .2, 1.6); vs.flash('c', m(k) + .2); vs.flash('d', m(k) + 1);
+ const r = ringAt(vs.P, x, y, m(k) + 1.6, p, COL.task, 'none'); hide(r, (k === 's1' ? m('s2') : m(k) + 4.4), .3);
+ vs.flash('sum0', m(k) + 2); vs.flash('sum1', m(k) + 2);
+ });
+ showRow(sumRow, m('s1') + 1.8);
}],
['reach', 'Reaching a target', (m) => {
@@ -239,9 +276,9 @@ const BEATS = [
const vs = lecture(p, { c: 0, d: 0, show: ['cv', 'dw', 'sum'] });
const whole = v => Number.isInteger(v.c) && Number.isInteger(v.d), lab = comboLabel(vs);
vs.label('cv', v => whole(v) ? (v.c === 1 ? ['v'] : [vs.fmt(v.c) + 'v']) : []); vs.label('dw', v => whole(v) ? (v.d === 1 ? ['w'] : [vs.fmt(v.d) + 'w']) : []);
- vs.label('sum', v => whole(v) ? lab(v) : []);
+ vs.label('sum', v => whole(v) ? lab(v) : [], 'tip', [40, 4]);
line1(vs, 240, 1); line2(vs, 420, 1);
- const ring = ringAt(vs.P, 0, 3, m('target'), p);
+ const ring = ringAt(vs.P, 0, 3, m('target'), p, COL.task, true);
pulse(ring, m('ask') + .3, 1.6); pulse(ring, m('ask') + 1.4, 1.6);
['c', 'd'].forEach(k => vs.flash(k, m('ask') + .8));
const o = vs.P.dot(0, 0, COL.task, m('start'), { r: 8 }); pulse(o, m('start') + .6, 1.8);
@@ -283,7 +320,14 @@ const BEATS = [
text(p, 'All the combinations', 60, 110, .2, { size: 40, weight: 600 });
const vs = lecture(p, { c: 1, d: 1, show: ['v', 'w'] });
line1(vs, 240, 1);
- vs.lattice(m('dots'), true, 1.2);
+ vs.lattice(m('dots'), true, .4);
+ // the lattice group is the first child of the arrows' layer: [lines along v, lines along w, dots, span]
+ const [latV, latW] = vs.latticeG.children;
+ put(latV, { o: 0 }); put(latW, { o: 0 }); show(latV, m('grid') + .3, .8); show(latW, m('grid') + 1.3, .8);
+ // values in passing are thirds here: only whole c and d get names on the arrows
+ const whole = v => Number.isInteger(v.c) && Number.isInteger(v.d), lab = comboLabel(vs);
+ vs.label('cv', v => whole(v) ? (v.c === 1 ? ['v'] : [vs.fmt(v.c) + 'v']) : []); vs.label('dw', v => whole(v) ? (v.d === 1 ? ['w'] : [vs.fmt(v.d) + 'w']) : []);
+ vs.label('sum', v => whole(v) ? lab(v) : []);
const ax = G(p, {});
vs.P.line(0, 0, 2, -1, GREEN, m('grid') + .3, { w: 4, into: ax });
vs.P.line(0, 0, -1, 2, VIOLET, m('grid') + 1.3, { w: 4, into: ax });
@@ -300,7 +344,7 @@ const BEATS = [
vs.show(['cv', 'dw', 'sum'], m('roam') - .3, .4);
vs.solve(true);
vs.to({ c: 1, d: 1 }, .1, .01);
- handPath(p, vs, [[1, 1], [3, 3], [-4, 1], [2, -5], [5, 2], [-2, 5], [-5, -4], [0, 0]], m('roam') + .2, 1.7);
+ handPath(p, vs, [[1, 1], [3, 3], [-4, 1], [2, -5], [4, 1], [-2, 5], [-3, -3], [0, 0]], m('roam') + .2, 1.7); // |2x + y| ≤ 9 keeps c·v inside the grid
const all = path(p, `M${vs.P.PX(-6)} ${vs.P.PY(6)}H${vs.P.PX(6)}V${vs.P.PY(-6)}H${vs.P.PX(-6)}Z`, { fill: COL.task, stroke: 'none' }, { o: 0 });
vs.P.g.insertBefore(all, vs.P.g.lastChild);
tw(all, { o: .12 }, m('plane'), 1);
@@ -315,7 +359,7 @@ const BEATS = [
vs.label('sum', []); // the ring names the target
line1(vs, 240, 1); line2(vs, 420, 1);
const go = (x, y, c, d, t0, tc, td, marks) => {
- const ring = ringAt(vs.P, x, y, t0, marks);
+ const ring = ringAt(vs.P, x, y, t0, marks, COL.task, x < 0);
for (let k = 1; k <= c; k++) { vs.to({ c: k }, tc + (k - 1) * .75, .5); vs.P.dot(2 * k, -k, GREEN, tc + (k - 1) * .75 + .4, { r: 6, label: String(k), dx: 4, dy: 30, into: marks }); }
for (let k = 1; k <= d; k++) { vs.to({ d: k }, td + (k - 1) * .75, .5); vs.P.dot(2 * c - k, -c + 2 * k, VIOLET, td + (k - 1) * .75 + .4, { r: 6, label: String(k), dx: 10, dy: -8, into: marks }); }
return ring;
@@ -331,7 +375,7 @@ const BEATS = [
vs.to({ c: 0, d: 0 }, m('t2') - .2, .6);
const m2 = G(p, {});
go(-1, 5, 1, 3, m('t2'), m('s2') + .2, m('s3') + .4, m2);
- vs.flash('c', m('r2') + .2); vs.flash('d', m('r2') + 1.4);
+ vs.flash('c', m('r2') + .2); vs.flash('d', m('r2') + .8);
}],
['parallel', 'Unless they line up', (m) => {
@@ -341,22 +385,45 @@ const BEATS = [
vs.row([{ t: 'v', fill: GREEN }, '=', { col: 'v', fixed: true }, ' ', { t: 'w', fill: VIOLET }, '=', { col: 'w', fixed: true }], { x: 70, y: 240, size: 42 });
vs.lattice(.3, true, .6);
vs.to({ w0: 4, w1: -2 }, m('turn') + .3, m('par') - m('turn') - .3, lin);
- const w2 = say(p, ['w = 2v'], 70, 420, m('par'), { size: 44, fill: VIOLET }); hide(w2, m('rule'), .3);
- vs.to({ w0: -1, w1: 2 }, m('rule') + .3, 1.6); vs.to({ w0: 4, w1: -2 }, m('rule') + 4, 1.8);
- text(p, 'the grid squashes flat', 70, 480, m('squash'), { size: 28, fill: COL.dim });
- text(p, 'every combination: on one line', 70, 530, m('line'), { size: 30, fill: COL.task, weight: 600 });
- const miss = ringAt(vs.P, 0, 3, m('miss'), p, COL.bad);
+ const w2 = say(p, ['w = 2v'], 70, 420, m('par'), { size: 44, fill: VIOLET }); hide(w2, m('ex2'), .3);
+ const n1 = text(p, 'the grid squashes flat', 70, 480, m('squash'), { size: 28, fill: COL.dim });
+ const n2 = text(p, 'every combination: on one line', 70, 530, m('line'), { size: 30, fill: COL.task, weight: 600 });
+ // steering on the line: whatever c and d are, the tip stays on it
+ vs.show('sum', m('try'), .4); // only the combination: its two parts lie on the same line and would hide each other
+ vs.to({ c: 2, d: -1 }, m('try') + .5, 1.2); vs.to({ c: -1, d: -1 }, m('try') + 1.9, 1.4); vs.to({ c: 1, d: -1 }, m('try') + 3.5, 1.4);
+ vs.flash('c', m('try') + .5); vs.flash('d', m('try') + .5);
+ const miss = ringAt(vs.P, 0, 3, m('miss'), p, COL.bad, true);
say(miss, ['✗'], -9, 10, m('miss') + .5, { size: 26, fill: COL.bad });
- text(p, '(0, 3) is off the line: no c and d reach it', 70, 590, m('miss') + .8, { size: 28, fill: COL.bad, weight: 600 });
+ const n3 = text(p, '(0, 3) is off the line: no c and d reach it', 70, 590, m('miss') + .8, { size: 28, fill: COL.bad, weight: 600 });
+ vs.to({ c: -1, d: 1 }, m('miss') + .4, 1.4); // −v + 2v = v: still on the line, nowhere near (0, 3)
+ // a second pair on one line
+ vs.hide('sum', m('ex2') - .2, .3);
+ [n1, n2].forEach(e => hide(e, m('ex2'), .3));
+ vs.to({ v0: 1, v1: 1, w0: -2, w1: -2, c: 1, d: 1 }, m('ex2') + .2, 1.6);
+ vs.flash('v0', m('ex2') + 1.6); vs.flash('v1', m('ex2') + 1.6); vs.flash('w0', m('ex2') + 3.6); vs.flash('w1', m('ex2') + 3.6);
+ hide(say(p, ['w = −2v'], 70, 420, m('x2'), { size: 44, fill: VIOLET }), m('rule'), .3);
+ thick(vs, 'v', m('x2') + .4); thick(vs, 'w', m('x2') + 1.4); thick(vs, 'v', m('x2') + 2.8); thick(vs, 'w', m('x2') + 3.8);
+ hide(text(p, 'every combination: on the line through (1, 1)', 70, 530, m('line2'), { size: 30, fill: COL.task, weight: 600 }), m('rule'), .3);
+ vs.show('sum', m('line2') + .2, .4);
+ vs.to({ c: 3, d: 2 }, m('line2') + .4, 1); vs.to({ c: -2, d: -2 }, m('line2') + 1.5, 1); // the tip runs along the line y = x
+ vs.hide('sum', m('rule') - .2, .3);
+ // the rule, with a third pair: different directions fill, the same line does not
+ hide(miss, m('rule'), .3); hide(n3, m('rule'), .3);
const r = G(p, { o: 0 });
T(r, 'different directions → the whole plane', { x: 70, y: 680, size: 30, weight: 600 });
- T(r, 'the same line → only that line', { x: 70, y: 730, size: 30, weight: 600 });
show(r, m('rule'));
+ vs.to({ v0: 1, v1: 0, w0: 1, w1: 1, c: 1, d: 1 }, m('rule') + .3, 1.6); // the grid opens out as the voice says 'fill the plane'
+ ['v0', 'v1'].forEach(k => vs.flash(k, m('rule2') + .3)); ['w0', 'w1'].forEach(k => vs.flash(k, m('rule2') + 1.3));
+ const r2 = G(p, { o: 0 });
+ T(r2, 'the same line → only that line', { x: 70, y: 730, size: 30, weight: 600 });
+ show(r2, m('rule3'));
+ vs.to({ v0: -1, v1: -1 }, m('rule3') + .2, 1.8, lin); // v turns onto w's line (y = x): the grid squashes to it
}],
['q3', 'Quick check', () => { panel(0); }, { ask: done => quiz({ x: 300, y: 200, w: 1000, cls: 'side' }, [{
id: 'c-span', prompt: ['Do the combinations ', $m('c v + d w'), ' reach every point of the plane?'],
- build: grid([SPANQ[0], SPANQ[1]], [['y', 'Every point', null, 'Y'], ['n', 'Only a line', null, 'N']], { multi: false, text: true }),
+ build: grid([[[2, 1], [-4, -2], 'n', 'The second is −2 times the first: one line.'], [[0, 1], [3, 0], 'y', 'One points up, one points right: the whole plane.']].map(([a, b, ans, why]) => ({ parts: [hcol(...a, GREEN), ' and ', hcol(...b, VIOLET)], ans: [ans], why })),
+ [['y', 'Every point', null, 'Y'], ['n', 'Only a line', null, 'N']], { multi: false, text: true }),
}], done) }],
['wrap', 'Summary', (m) => {
@@ -407,6 +474,16 @@ const BEATS = [
(v, k) => `The tip is at ${pairStr(k.sum[0], k.sum[1])}. Drag the amber tip onto the ring.`, () => S.vs.set(S.vs.solveFor(x, y)), { drag: ['sum'] })(body, api);
},
}))), done, 'Chapter practice · set 4 of 4') }],
+ ['play', 'Playground', (m) => {
+ const p = panel(0);
+ text(p, 'Playground', 60, 110, .2, { size: 40, weight: 600 });
+ S.vs = lecture(p, { c: 2, d: 1, show: ['v', 'w', 'cv', 'dw', 'sum'] });
+ S.vs.row([{ key: 'c' }, { t: 'v', fill: GREEN }, { key: 'd', signed: true }, { t: 'w', fill: VIOLET }, '=', { key: 'c' }, { col: 'v' }, { key: 'd', signed: true }, { col: 'w' }, '=', { col: 'sum' }], { x: 70, y: 240, size: 42 });
+ S.vs.lattice(.3, true, .6);
+ S.vs.solve(true);
+ const hint = text(p, 'try: make w point along v · land on (5, 5) · make c and d both 0', 70, 360, m('go'), { size: 28, fill: COL.dim });
+ hide(hint, m('go') + 8, .6);
+ }, { ask: playAsk(() => S.vs, { tip: 'Change c, d or the numbers of v and w; drag any tip; or draw on the board. Nothing is marked.' }) }],
['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],
].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
diff --git a/site/linear-algebra/ch07/audio/en/play.mp3 b/site/linear-algebra/ch07/audio/en/play.mp3
new file mode 100644
index 0000000..dbfec86
Binary files /dev/null and b/site/linear-algebra/ch07/audio/en/play.mp3 differ
diff --git a/site/linear-algebra/ch07/audio/en/timings.js b/site/linear-algebra/ch07/audio/en/timings.js
index 9542bd6..6a6ed99 100644
--- a/site/linear-algebra/ch07/audio/en/timings.js
+++ b/site/linear-algebra/ch07/audio/en/timings.js
@@ -430,46 +430,46 @@ window.TIMINGS = {
]
},
"which": {
- "dur": 27.072,
+ "dur": 26.568,
"marks": {
- "e": 2.721,
- "cols": 8.073,
- "colp": 13.672,
- "miss": 15.677,
- "rowp": 19.74,
- "both": 24.648
+ "e": 2.63,
+ "cols": 7.917,
+ "colp": 13.633,
+ "miss": 15.521,
+ "rowp": 19.128,
+ "both": 24.115
},
"cues": [
[
- 0.104,
+ 0.091,
"What if the two columns point the same way?"
],
[
- 2.721,
- "Take x plus two y equals three, and two x plus four y equals five."
+ 2.63,
+ "Take x plus two y equals three, and two x plus four y equals one."
],
[
- 8.073,
+ 7.917,
"The columns are one, two, and two, four."
],
[
- 11.237,
+ 11.302,
"The second is twice the first."
],
[
- 13.672,
- "All their mixes lie on one line, and b, three, five, is off that line."
+ 13.633,
+ "All their mixes lie on one line, and b, three, one, is off that line."
],
[
- 18.372,
+ 17.773,
"No mix reaches it."
],
[
- 19.74,
+ 19.128,
"The row picture says the same: the two lines are parallel, and never meet."
],
[
- 24.648,
+ 24.115,
"No solution, seen two ways."
]
]
@@ -572,6 +572,30 @@ window.TIMINGS = {
]
]
},
+ "play": {
+ "dur": 12.48,
+ "marks": {
+ "go": 3.906
+ },
+ "cues": [
+ [
+ 0.104,
+ "Playground."
+ ],
+ [
+ 1.068,
+ "Nothing here is marked right or wrong."
+ ],
+ [
+ 3.906,
+ "Change any number on the left, or drag the columns and b on the right, and watch both pictures move together."
+ ],
+ [
+ 10.872,
+ "Press continue when you're done."
+ ]
+ ]
+ },
"finish": {
"dur": 8.328,
"marks": {},
diff --git a/site/linear-algebra/ch07/audio/en/which.mp3 b/site/linear-algebra/ch07/audio/en/which.mp3
index f3cab51..24e553f 100644
Binary files a/site/linear-algebra/ch07/audio/en/which.mp3 and b/site/linear-algebra/ch07/audio/en/which.mp3 differ
diff --git a/site/linear-algebra/ch07/index.html b/site/linear-algebra/ch07/index.html
index 9385af5..a92b475 100644
--- a/site/linear-algebra/ch07/index.html
+++ b/site/linear-algebra/ch07/index.html
@@ -12,6 +12,7 @@
<script src="../lib/math.js"></script>
<script src="../lib/linsys.js"></script>
<script src="../lib/vecs.js"></script>
+<script src="../lib/play.js"></script>
<script src="audio/en/timings.js"></script>
<script>
'use strict';
@@ -23,6 +24,9 @@ const [BLUE, CORAL] = LS_ROW; // row 1 blue, ro
const LA = [[2, -1], [-1, 2]], LB = [0, 3]; // the lecture's system
const CARD = { x: 40, y: 320, w: 720, cls: 'side' };
const TOPCARD = { x: 840, y: 120, w: 720, cls: 'side' }; // over the column equation in the side-by-side layout
+// The side-by-side planes: u 40, x −6…6, y −4…6 (every b and column the chapter uses fits), labels 30 px.
+const TW = { u: 40, y0: -4, step: 2 }, TWL = { cx: 420, cy: 625, ...TW }, TWR = { cx: 1180, cy: 625, ...TW }, TWEQ = [110, 182];
+const twinHeads = (p, t0) => { const g = G(p, { o: 0 }); [['row picture', 420], ['column picture', 1180]].forEach(([s, x]) => T(g, s, { x, y: 886, size: 26, fill: COL.dim, anchor: 'middle', weight: 600 })); show(g, t0); return g; };
const say = (p, parts, x, y, t0, { size = 40, fill = COL.chalk, anchor = 'start' } = {}) => { const e = M(p, [].concat(parts), { x, y, size, fill, anchor, o: 0 }); show(e, t0); return e; };
const text = (p, str, x, y, t0, { size = 30, fill = COL.chalk, anchor = 'start', weight = 500 } = {}) => { const e = T(p, str, { x, y, size, fill, anchor, weight, o: 0 }); show(e, t0); return e; };
const showRow = (r, t0, from = 0, to = r.parts.length, dur = .5) => r.parts.slice(from, to).forEach(e => show(e, t0, dur));
@@ -34,7 +38,7 @@ const rbox = (p, x, y, w, h, color, t0) => { const r = path(p, `M${x + 12} ${y}H
// The column picture of a system: its columns as v (column 1) and w (column 2), x and y as c and d, the mix 'sum' = b.
const colPic = (p, A, opts = {}) => {
const vs = vecs(p, { vecs: { v: [A[0][0], A[1][0]], w: [A[0][1], A[1][1]] }, show: ['v', 'w', 'cv', 'dw', 'sum'], ...opts });
- vs.label('v', ['col 1']); vs.label('w', ['col 2']); vs.label('sum', ['b']); vs.label('cv', []); vs.label('dw', []);
+ vs.label('v', ['col 1'], 'tip', [-36, 40]); vs.label('w', ['col 2'], 'tip', [-14, 0]); vs.label('sum', ['b']); vs.label('cv', []); vs.label('dw', []); // col 1 under its tip (x·col 1 runs on past it)
return vs;
};
// x [col 1] + y [col 2] = [b], and below it the amounts: 1 [col 1] + 2 [col 2] = [b]
@@ -42,20 +46,52 @@ const colEq = (vs, x, y, size = 40, o = 1) => vs.row([{ t: 'x' }, { col: 'v', fi
const colAmt = (vs, x, y, size = 40, o = 1) => vs.row([{ key: 'c' }, { col: 'v', fixed: true }, { key: 'd', signed: true }, { col: 'w', fixed: true }, '=', { col: 'sum', fixed: true }], { x, y, size, o });
// Row picture (linsys, left) and column picture (vecs, right) of one system, linked both ways:
// change the system or b on the left and the mix follows on the right; drag b on the right and the lines follow.
-const twin = (p, A, b, { t0 = .1, rows = true } = {}) => {
- const sys = linsys(p, { A, b, mat: null, eq: [110, 190], size: 46, plane: { cx: 420, cy: 625, u: 28, step: 2 }, t0 });
+let twinN = 0;
+const twin = (p, A, b, { t0 = .1, rows = true, eqAt = t0 + .2, amtAt = t0 + .2 } = {}) => {
+ const sys = linsys(p, { A, b, mat: null, eq: TWEQ, size: 46, plane: TWL, t0 });
+ put(sys.readout, { y: -28 }); // the readout sits closer under the equations, clear of the plane's top
const s0 = sys.solve();
- const vs = colPic(p, A, { c: s0.x ?? 0, d: s0.y ?? 0, plane: { cx: 1180, cy: 625, u: 28, step: 2 }, labelSize: 24, t0 });
+ const vs = colPic(p, A, { c: s0.x ?? 0, d: s0.y ?? 0, plane: TWR, labelSize: 30, t0 });
vs.solve(true);
const r6 = n => Math.round(n * 1e6) / 1e6;
let busy = false;
- sys.onChange((v, s) => { if (busy) return; busy = true; vs.set({ v0: v.a00, v1: v.a10, w0: v.a01, w1: v.a11, ...(s.x !== undefined ? { c: r6(s.x), d: r6(s.y) } : {}) }); busy = false; });
- vs.onChange((v, k) => { if (busy) return; busy = true; sys.set({ a00: v.v0, a10: v.v1, a01: v.w0, a11: v.w1, b0: r6(k.sum[0]), b1: r6(k.sum[1]) }); busy = false; });
- const heads = G(p, { o: 0 });
- T(heads, 'row picture', { x: 420, y: 855, size: 26, fill: COL.dim, anchor: 'middle', weight: 600 });
- T(heads, 'column picture', { x: 1180, y: 855, size: 26, fill: COL.dim, anchor: 'middle', weight: 600 });
- show(heads, t0 + .3);
- const r = rows ? [colEq(vs, 860, 230), colAmt(vs, 860, 370)] : [];
+ // Arrows of a big mix (columns nearly in line) are clipped to the column picture's grid.
+ const clip = mk('clipPath', { id: `twclip${++twinN}` }, vs.P.g), { PX, PY } = vs.P;
+ mk('rect', { x: PX(vs.P.x0 - .7), y: PY(vs.P.y1 + .7), width: PX(vs.P.x1 + .7) - PX(vs.P.x0 - .7), height: PY(vs.P.y0 - .7) - PY(vs.P.y1 + .7) }, clip);
+ vs.A.sum.g.parentNode.parentNode.setAttribute('clip-path', `url(#twclip${twinN})`);
+ // Columns in one line (only the playground lets the reader make them): no mix, or no single mix, so the mix
+ // arrows and amounts go and b is drawn alone (vecs' sum would be a stale mix, not b).
+ const alt = G(vs.P.g, {}), altP = path(alt, '', { stroke: COL.task, fill: COL.task, 'stroke-width': 6, 'stroke-linejoin': 'round' });
+ const altL = T(alt, 'b', { x: 0, y: 0, size: 30, fill: COL.task, weight: 600, font: MATH });
+ const sync = () => {
+ const s = sys.solve(), one = s.x !== undefined, [bx, by] = [sys.v.b0, sys.v.b1];
+ ['cv', 'dw', 'sum'].forEach(id => { vs.A[id].g.style.visibility = vs.A[id].lab.style.visibility = vs.A[id].h.style.visibility = one ? '' : 'hidden'; });
+ if (r[1]) r[1].g.style.visibility = one ? '' : 'hidden';
+ alt.style.display = one ? 'none' : '';
+ if (one) return;
+ const L = Math.hypot(bx, by), ux = L ? bx / L : 0, uy = L ? by / L : 0, X = PX(bx), Y = PY(by);
+ altP.setAttribute('d', L < .1 ? '' : `M${PX(0)} ${PY(0)}L${X - ux * 12} ${Y + uy * 12}M${X - ux * 20 + uy * 10} ${Y + uy * 20 + ux * 10}L${X} ${Y}L${X - ux * 20 - uy * 10} ${Y + uy * 20 - ux * 10}Z`);
+ put(altL, { x: X + ux * 26 + 6, y: Y - uy * 26 + 10 });
+ };
+ sys.onChange((v, s) => { if (!busy) { busy = true; vs.set({ v0: v.a00, v1: v.a10, w0: v.a01, w1: v.a11, ...(s.x !== undefined ? { c: r6(s.x), d: r6(s.y) } : {}) }); busy = false; } sync(); });
+ // On the right, a column moved keeps b where it is (the mix changes, as when a number changes on the left);
+ // b moved, or an amount scrubbed, moves b on the left.
+ vs.onChange((v, k) => {
+ if (!busy) {
+ busy = true;
+ if (v.v0 !== sys.v.a00 || v.v1 !== sys.v.a10 || v.w0 !== sys.v.a01 || v.w1 !== sys.v.a11) {
+ sys.set({ a00: v.v0, a10: v.v1, a01: v.w0, a11: v.w1 });
+ const s = sys.solve();
+ if (s.x !== undefined) vs.set({ c: r6(s.x), d: r6(s.y) });
+ } else sys.set({ b0: r6(k.sum[0]), b1: r6(k.sum[1]) });
+ busy = false;
+ }
+ sync();
+ });
+ const heads = twinHeads(p, t0 + .3);
+ const r = rows ? [colEq(vs, 860, 204, 38, 0), colAmt(vs, 860, 318, 38, 0)] : [];
+ if (rows) { if (eqAt !== null) showRow(r[0], eqAt); showRow(r[1], amtAt); } // eqAt null: the beat reveals it
+ sync();
return { sys, vs, rows: r, heads };
};
// A task on the twin pictures: the reader moves b (right sides on the left, or b's tip on the right).
@@ -69,6 +105,8 @@ const twinTask = (T2, test, why, hint, reveal) => (body, api) => {
hint: [kbd('Tab'), ' pick a number ', kbd('↑'), kbd('↓'), ' change it, or drag b or a line'],
};
};
+// The twin handed over whole, for the playground: every number on the left, the column tips and b on the right.
+const twinPlay = T2 => ({ v: T2.sys.v, set: x => T2.sys.set(x), live(on) { T2.sys.live(on); T2.vs.live(on, { drag: ['v', 'w', 'sum'] }); } });
const solIs = (x, y) => (v, s) => s.x !== undefined && Math.abs(s.x - x) < 1e-9 && Math.abs(s.y - y) < 1e-9;
const bFor = (A, x, y) => [A[0][0] * x + A[0][1] * y, A[1][0] * x + A[1][1] * y];
// A system written out, each term placed so the x terms, the y terms and the right sides stand in columns.
@@ -78,19 +116,19 @@ const sysText = (p, rowsTxt, x, y, { size = 50, gap = 84, o = 1 } = {}) => {
const yy = y + i * gap, cs = [BLUE, CORAL][i];
mk('rect', { x: x - 30, y: yy - size * .7, width: 8, height: size * .8, rx: 4, fill: cs }, g);
const k = size / 50;
- parts.push([M(g, [a], { x: x + 90 * k, y: yy, size, anchor: 'end' }), M(g, [sg], { x: x + 125 * k, y: yy, size, anchor: 'middle' }), M(g, [bt], { x: x + 225 * k, y: yy, size, anchor: 'end' }),
- M(g, [rr], { x: x + 300 * k, y: yy, size, anchor: 'start' }), M(g, ['='], { x: x + 265 * k, y: yy, size, anchor: 'middle' })]);
+ parts.push([M(g, [a], { x: x + 100 * k, y: yy, size, anchor: 'end' }), M(g, [sg], { x: x + 162 * k, y: yy, size, anchor: 'middle' }), M(g, [bt], { x: x + 262 * k, y: yy, size, anchor: 'end' }),
+ M(g, [rr], { x: x + 352 * k, y: yy, size, anchor: 'start' }), M(g, ['='], { x: x + 312 * k, y: yy, size, anchor: 'middle' })]);
});
g.parts = parts;
// boxes around the x terms, the y terms and the right sides (for drawing round a column)
const k = size / 50, top = y - size * .95, h = gap * (rowsTxt.length - 1) + size * 1.3;
- g.boxes = [[x + 14 * k, 92 * k], [x + 150 * k, 92 * k], [x + 288 * k, 70 * k]].map(([bx, w]) => [bx, top, w, h]);
+ g.boxes = [[x + 16 * k, 98 * k], [x + 136 * k, 140 * k], [x + 338 * k, 64 * k]].map(([bx, w]) => [bx, top, w, h]); // the y box takes the sign: −y is −1
return g;
};
// Boxes round the x terms, the y terms and the right sides of a linsys system's equations, drawn on cue.
const sysCols = (p, sys, times, colors = [GREEN, VIOLET, COL.task]) => {
const g = G(p, {}), R = sys.eqRows;
- const groups = [R.flatMap(r => [r.a.t, r.a.l]), R.flatMap(r => [r.bb.t, r.bb.l]), R.map(r => r.c.t)];
+ const groups = [R.flatMap(r => [r.a.t, r.a.l]), R.flatMap(r => [r.sign, r.bb.t, r.bb.l]), R.map(r => r.c.t)]; // the sign belongs to the y number
groups.forEach((els, j) => {
const bs = els.filter(e => e && e.textContent).map(e => { const b = e.getBBox(), q = st(e); return { x: b.x + q.x, y: b.y + q.y, width: b.width, height: b.height }; }); // T() places text by its state
const x = Math.min(...bs.map(b => b.x)) - 12, y = Math.min(...bs.map(b => b.y)) - 6, w = Math.max(...bs.map(b => b.x + b.width)) + 12 - x, h = Math.max(...bs.map(b => b.y + b.height)) + 6 - y;
@@ -119,7 +157,7 @@ const RIGHTQ = [[[1, 2], [3, 1], [5, 5], 2, 1], [[2, 1], [1, 3], [4, 7], 1, 2],
return { parts: [$m('x'), hcol(...a, GREEN), ' + ', $m('y'), hcol(...b, VIOLET), ' = ', hcol(...B, COL.task), ` x = ${num(x)}, y = ${num(y)}`], ans: [ok ? 'y' : 'n'],
why: `${num(x)}·[${num(a[0])}, ${num(a[1])}] + ${num(y)}·[${num(b[0])}, ${num(b[1])}] = [${num(got[0])}, ${num(got[1])}]${ok ? ': that is b.' : `, not [${num(B[0])}, ${num(B[1])}].`}` };
});
-const MOVEQ = [[-1, 2], [2, 0], [0, -1], [1, 1]];
+const MOVEQ = [[-1, 1], [2, 0], [0, -1], [1, 1]]; // every b low enough to stay clear of the question card
/* ---------- beats: [id, title, run(m, D), { ask }?] ---------- */
const BEATS = [
@@ -130,7 +168,7 @@ const BEATS = [
tw(g, { o: 1, y: 0 }, .2, 1.1, out);
const r = text(scene, 'the same system, read down its columns', 800, 510, m('sub'), { size: 36, fill: COL.dim, anchor: 'middle' });
const pic = G(scene, { o: 0 });
- const st = sysText(pic, [['2x', '−', 'y', '0'], ['−x', '+', '2y', '3']], 640, 640, { size: 40, gap: 64 });
+ const st = sysText(pic, [['2x', '−', 'y', '0'], ['−x', '+', '2y', '3']], 650, 640, { size: 40, gap: 64 });
show(pic, m('sub') + .8, .5);
boxCol(pic, st, 0, GREEN, m('down')); boxCol(pic, st, 1, VIOLET, m('down') + .5); boxCol(pic, st, 2, COL.task, m('down') + 1);
tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(pic, D - .9, .8);
@@ -142,8 +180,8 @@ const BEATS = [
const sys = linsys(p, { A: LA, b: LB, mat: null, eq: [90, 220], t0: .1 });
put(sys.meetBox, { o: 0 }); put(sys.readout, { o: 0 });
sys.lines.forEach(l => put(l.g, { o: 0 }));
- sys.focus(0, m('e1')); show(sys.lines[0].g, m('e1') + .4, .8);
- sys.focus(1, m('e2')); show(sys.lines[1].g, m('e2') + .4, .8);
+ sys.focus(0, m('e1'), .5, { lines: false }); show(sys.lines[0].g, m('e1') + .4, .8);
+ sys.focus(1, m('e2'), .5, { lines: false }); show(sys.lines[1].g, m('e2') + .4, .8);
sys.focus(null, m('row'));
show(sys.meetBox, m('meet'), .5); pulse(sys.meet, m('meet') + .5, 1.6);
show(sys.readout, m('ans'), .5);
@@ -160,22 +198,36 @@ const BEATS = [
const xs = st.parts.map(r => r[0]), ys = st.parts.map(r => r[2]), bs = st.parts.map(r => r[3]);
boxCol(p, st, 0, GREEN, m('xcol')); xs.forEach((e, i) => tw(e, { s: 1.15 }, m('xcol') + .3 + i * .8, .3));
xs.forEach((e, i) => tw(e, { s: 1 }, m('xcol') + .7 + i * .8, .3));
- boxCol(p, st, 1, VIOLET, m('ycol'));
+ boxCol(p, st, 1, VIOLET, m('ycol')); ys.forEach((e, i) => { tw(e, { s: 1.15 }, m('ycol') + .4 + i * 1.2, .3); tw(e, { s: 1 }, m('ycol') + .8 + i * 1.2, .3); });
boxCol(p, st, 2, COL.task, m('bcol'));
+ // a letter alone carries a hidden 1: said once, beside the system
+ text(p, '−x means −1·x', 120, 410, m('xcol') + 3.6, { size: 28, fill: COL.dim });
+ text(p, '−y means −1·y', 420, 410, m('ycol') + 1.2, { size: 28, fill: COL.dim });
// the three columns, stood up on the right
const vs = colPic(p, LA, { c: 1, d: 2, hidePlane: true, show: [] });
const cx = [900, 1100, 1300];
const cA = vs.row([{ col: 'v', fixed: true }], { x: cx[0], y: 270, size: 50, o: 0 }), cB = vs.row([{ col: 'w', fixed: true }], { x: cx[1], y: 270, size: 50, o: 0 }), cC = vs.row([{ col: 'sum', fixed: true }], { x: cx[2], y: 270, size: 50, o: 0 });
- showRow(cA, m('xvec')); showRow(cB, m('yvec')); showRow(cC, m('bcol') + .4);
- text(p, 'column 1', cx[0] + 47, 370, m('xvec') + .3, { size: 26, fill: GREEN, anchor: 'middle', weight: 600 });
- text(p, 'column 2', cx[1] + 47, 370, m('yvec') + .3, { size: 26, fill: VIOLET, anchor: 'middle', weight: 600 });
- text(p, 'b', cx[2] + 47, 370, m('bcol') + .7, { size: 30, fill: COL.task, anchor: 'middle', weight: 600 });
+ // the numbers leave the equations and stand up in their column: [from x, top/bottom] → the column's slot
+ const fly = (str, fx, i, col, fill, t0) => {
+ const g = G(p, { o: 0 }); M(g, [str], { x: 0, y: 0, size: 50, fill, anchor: 'middle' });
+ put(g, { x: fx, y: 230 + i * 84 }); show(g, t0, .2); tw(g, { x: cx[col] + 47.5 }, t0 + .15, 1.1); // over the columns already standing, not through them
+ tw(g, { y: 168 + i * 26 }, t0 + .15, .5, out); tw(g, { y: 238.5 + i * 65 }, t0 + .7, .55); hide(g, t0 + 1.35, .15);
+ };
+ fly('2', 183, 0, 0, GREEN, m('xvec')); fly('−1', 186, 1, 0, GREEN, m('xvec') + .25);
+ fly('−1', 282, 0, 1, VIOLET, m('yvec')); fly('2', 345, 1, 1, VIOLET, m('yvec') + .25);
+ fly('0', 484, 0, 2, COL.task, m('bcol') + .3); fly('3', 484, 1, 2, COL.task, m('bcol') + .55);
+ showRow(cA, m('xvec') + 1.3, 0, 1, .3); showRow(cB, m('yvec') + 1.3, 0, 1, .3); showRow(cC, m('bcol') + 1.6, 0, 1, .3);
+ text(p, 'column 1', cx[0] + 47, 370, m('xvec') + 1.4, { size: 26, fill: GREEN, anchor: 'middle', weight: 600 });
+ text(p, 'column 2', cx[1] + 47, 370, m('yvec') + 1.4, { size: 26, fill: VIOLET, anchor: 'middle', weight: 600 });
+ text(p, 'b', cx[2] + 47, 370, m('bcol') + 1.7, { size: 30, fill: COL.task, anchor: 'middle', weight: 600 });
// the whole system as one vector equation
const eq = vs.row([{ t: 'x' }, { col: 'v', fixed: true }, '+', { t: 'y' }, { col: 'w', fixed: true }, '=', { col: 'sum', fixed: true }], { x: 120, y: 540, size: 54, o: 0 });
showRow(eq, m('eq'), 0, 2); showRow(eq, m('eq') + 2.4, 2, 5); showRow(eq, m('eq') + 4.6, 5, 7);
const top = [vs.num('v0').pop(), vs.num('w0').pop(), vs.num('sum0').pop()], bot = [vs.num('v1').pop(), vs.num('w1').pop(), vs.num('sum1').pop()];
const hl = (els, t0, dur) => els.forEach(e => { tw(e, { c_color: COL.task }, t0, .3); tw(e, { c_color: e.getAttribute('color') }, t0 + dur, .5); });
hl(top, m('top') + .4, m('bot') - m('top') - .8);
+ hide(rbox(p, 150, 460, 510, 60, COL.task, m('top') + .3), m('bot') - .2, .4); // read across the top
+ hide(rbox(p, 150, 530, 510, 60, COL.task, m('bot') + .3), m('same'), .4); // then across the bottom
say(p, ['x·2 + y·(−1) = 0'], 120, 720, m('top') + .6, { size: 40 });
say(p, ['→ 2x − y = 0'], 520, 720, m('top') + 4.2, { size: 40, fill: BLUE });
hl(bot, m('bot') + .4, m('same') - m('bot') - .6);
@@ -188,33 +240,40 @@ const BEATS = [
const p = panel(0);
text(p, 'The solution is a mix of the columns', 60, 110, .2, { size: 40, weight: 600 });
const vs = colPic(p, LA, { c: 1, d: 2, show: [] });
- colEq(vs, 70, 240, 42);
- const amt = colAmt(vs, 70, 420, 42, 0);
- const c6 = G(p, { o: 0 });
- T(c6, 'chapter 6: c v + d w = [0, 3] with c = 1, d = 2', { x: 70, y: 600, size: 28, fill: COL.dim, weight: 600 });
- show(c6, m('ch6'));
- tw(c6.firstChild, { c_fill: COL.task }, m('found'), .3);
- const here = G(p, { o: 0 });
- T(here, 'columns = v and w, x and y = c and d, b = the target', { x: 70, y: 650, size: 28, fill: COL.chalk, weight: 600 });
- show(here, m('here'));
+ vs.label('v', ['v']); vs.label('w', ['w']); // chapter 6's names first; they become col 1 and col 2 on 'here'
+ let named = false;
+ prog(() => { if (!named) { named = true; vs.label('v', ['col 1']); vs.label('w', ['col 2']); } }, m('here') + .3, .01);
+ const ra = colEq(vs, 70, 240, 42);
+ // chapter 6's equation, each part under its partner in the column equation
+ const ctr = i => { const b = ra.parts[i].getBBox(); return b.x + b.width / 2; };
+ // chapter 6's equation under it: the same columns, with c and d where x and y stand
+ const rb = vs.row([{ t: 'c' }, { col: 'v', fixed: true }, '+', { t: 'd' }, { col: 'w', fixed: true }, '=', { col: 'sum', fixed: true }], { x: 70, y: 420, size: 42, o: 0 });
+ text(p, '← chapter 6', ra.parts[6].getBBox().x + 100, 410, m('ch6'), { size: 26, fill: COL.dim, weight: 600 });
+ show(rb.parts[1], m('ch6') + 1.4); text(p, 'v', ctr(1), 500, m('ch6') + 1.6, { size: 30, fill: GREEN, anchor: 'middle', weight: 600 });
+ show(rb.parts[4], m('ch6') + 3.2); text(p, 'w', ctr(4), 500, m('ch6') + 3.4, { size: 30, fill: VIOLET, anchor: 'middle', weight: 600 });
+ [0, 2, 3, 5].forEach(i => show(rb.parts[i], m('ch6') + 5)); show(rb.parts[6], m('ch6') + 6.2);
+ say(p, ['c = 1, d = 2'], 70, 570, m('found'), { size: 40, fill: COL.task });
+ // the same equation: dashed links, partner to partner, as the narration pairs them
+ [[1, .3], [4, 1.1], [0, 2.8], [3, 3.5], [6, 5.6]].forEach(([i, dt]) => draw(path(p, `M${ctr(i)} 296V350`, { stroke: COL.task, 'stroke-width': 3, 'stroke-dasharray': '5 6', fill: 'none' }, { d: 0 }), m('here') + dt, .4));
+ const amt = colAmt(vs, 70, 680, 42, 0);
vs.show(['v', 'w'], m('seen'), .6);
thick(vs, 'v', m('ch6') + 1.6); thick(vs, 'w', m('ch6') + 3.4);
const tgt = G(vs.P.g, { x: vs.P.PX(0), y: vs.P.PY(3), o: 0 });
mk('circle', { r: 15, fill: 'none', stroke: COL.task, 'stroke-width': 4 }, tgt);
show(tgt, m('ch6') + 6.4, .3); pulse(tgt, m('ch6') + 7, 1.5); pulse(tgt, m('found') + .4, 1.5);
- ['v0', 'v1'].forEach(k => vs.flash(k, m('here') + .6)); thick(vs, 'v', m('here') + .6);
- ['w0', 'w1'].forEach(k => vs.flash(k, m('here') + 1.6)); thick(vs, 'w', m('here') + 1.6);
+ ['v0', 'v1'].forEach(k => vs.flash(k, m('here') + .3)); thick(vs, 'v', m('here') + .3);
+ ['w0', 'w1'].forEach(k => vs.flash(k, m('here') + 1.1)); thick(vs, 'w', m('here') + 1.1);
pulse(tgt, m('here') + 5.6, 1.5); ['sum0', 'sum1'].forEach(k => vs.flash(k, m('here') + 5.6));
hide(tgt, m('lands'), .3);
showRow(amt, m('mixit'));
vs.flash('c', m('mixit') + .4); vs.flash('d', m('mixit') + .9);
- vs.show('cv', m('mixit') + .4, .6); tw(vs.A.v.g, { o: .45 }, m('mixit') + .4, .4);
+ vs.show('cv', m('mixit') + .4, .6); tw(vs.A.v.g, { o: .45 }, m('mixit') + .4, .4); thick(vs, 'cv', m('mixit') + 1);
const u = vs.P.u;
put(vs.A.dw.g, { x: -LA[0][0] * u, y: LA[1][0] * u, o: 0 });
tw(vs.A.dw.g, { o: 1 }, m('plus'), .3); tw(vs.A.dw.g, { x: 0, y: 0 }, m('plus') + .4, 1.4);
vs.show('sum', m('lands'), .6); thick(vs, 'sum', m('lands') + .6, 6);
const nm = G(p, { o: 0 });
- T(nm, 'column picture: the solution is the mix that makes b', { x: 70, y: 720, size: 30, weight: 600, fill: COL.task });
+ T(nm, 'column picture: the solution is the mix that makes b', { x: 70, y: 780, size: 28, weight: 600, fill: COL.task });
show(nm, m('name'));
}],
@@ -241,18 +300,21 @@ const BEATS = [
show(sa, m('a'));
boxCol(p, sa, 0, GREEN, m('ax')); boxCol(p, sa, 1, VIOLET, m('ay')); boxCol(p, sa, 2, COL.task, m('ab'));
const va = colPic(p, [[1, 4], [3, -1]], { c: 1, d: 2, hidePlane: true, show: [] });
- const ea = va.row([{ t: 'x' }, { col: 'v', fixed: true }, '+', { t: 'y' }, { col: 'w', fixed: true }, '=', { col: 'sum', fixed: true }], { x: 640, y: 250, size: 42, o: 0 });
+ const ea = va.row([{ t: 'x' }, { col: 'v', fixed: true }, '+', { t: 'y' }, { col: 'w', fixed: true }, '=', { col: 'sum', fixed: true }], { x: 560, y: 250, size: 42, o: 0 });
showRow(ea, m('ax') + 1, 0, 2); showRow(ea, m('ay') + 1, 2, 5); showRow(ea, m('ab') + .8, 5, 7);
- const ca = va.row([{ key: 'c' }, { col: 'v', fixed: true }, { key: 'd', signed: true }, { col: 'w', fixed: true }, '=', { fn: () => ['1 + 8', '3 − 2'], w: 150 }, '=', { col: 'sum', fixed: true }], { x: 640, y: 400, size: 42, o: 0 });
- showRow(ca, m('acheck'), 0, 4); showRow(ca, m('acheck') + 3, 4, 6);
- const [ft, fb] = va.num('fn'); put(fb, { o: 0 }); show(fb, m('acheck2'));
- showRow(ca, m('acheck2') + 1.6, 6, 8); [ft, fb].forEach(e => lightUp(e, m('acheck2') + 1.8));
+ // 1·[1, 3] + 2·[4, −1] = [1, 3] + [8, −2] = [1 + 8, 3 − 2] = [9, 1]: every step on the board
+ const ca = va.row([{ key: 'c' }, { col: 'v', fixed: true }, { key: 'd', signed: true }, { col: 'w', fixed: true }, '=', { fn: () => ['1', '3'], w: 56, fill: GREEN }, '+', { fn: () => ['8', '−2'], w: 66, fill: VIOLET },
+ '=', { fn: () => ['1 + 8', '3 − 2'], w: 130 }, '=', { col: 'sum', fixed: true }], { x: 560, y: 400, size: 38, o: 0 });
+ showRow(ca, m('acheck'), 0, 4); showRow(ca, m('acheck') + 3.4, 4, 6); showRow(ca, m('acheck') + 4.8, 6, 8);
+ const fns = va.num('fn'), [ft, fb] = fns.slice(4); put(fb, { o: 0 }); showRow(ca, m('acheck') + 6.4, 8, 10); show(fb, m('acheck2'));
+ showRow(ca, m('acheck2') + 1.6, 10, 12); [ft, fb].forEach(e => lightUp(e, m('acheck2') + 1.8));
const sb = sysText(p, [['', '', 'y', '2'], ['x', '−', '3y', '0']], 120, 600, { size: 46, gap: 70, o: 0 });
show(sb, m('b'));
- say(p, ['0x'], 120 + 90 * .92, 600, m('bx') + .6, { size: 46, fill: COL.task, anchor: 'end' });
+ say(p, ['0x'], 120 + 100 * .92, 600, m('bx') + .6, { size: 46, fill: COL.task, anchor: 'end' });
+ say(p, ['+'], 120 + 162 * .92, 600, m('bx') + .6, { size: 46, fill: COL.task, anchor: 'middle' });
boxCol(p, sb, 0, GREEN, m('bx') + 1.2); boxCol(p, sb, 1, VIOLET, m('by')); boxCol(p, sb, 2, COL.task, m('bb'));
const vb = colPic(p, [[0, 1], [1, -3]], { c: 6, d: 2, hidePlane: true, show: [] });
- const eb = vb.row([{ t: 'x' }, { col: 'v', fixed: true }, '+', { t: 'y' }, { col: 'w', fixed: true }, '=', { col: 'sum', fixed: true }], { x: 640, y: 640, size: 42, o: 0 });
+ const eb = vb.row([{ t: 'x' }, { col: 'v', fixed: true }, '+', { t: 'y' }, { col: 'w', fixed: true }, '=', { col: 'sum', fixed: true }], { x: 560, y: 640, size: 42, o: 0 });
showRow(eb, m('bx') + 3, 0, 2); showRow(eb, m('by') + .6, 2, 5); showRow(eb, m('bb') + .6, 5, 7);
vb.flash('v0', m('bx') + 3.4);
}],
@@ -316,9 +378,11 @@ const BEATS = [
const p = panel(0);
text(p, 'Another system, both pictures', 60, 110, .2, { size: 40, weight: 600 });
const A2 = [[1, 1], [1, -1]];
- const { sys, vs, rows } = twin(p, A2, [5, 1]);
- put(sys.readout, { o: 0 }); rows[1].parts.forEach(e => put(e, { o: 0 })); // no answer before it is found
- show(sys.readout, m('rowp') + 1.4, .5); showRow(rows[1], m('colp'));
+ const { sys, vs, rows } = twin(p, A2, [5, 1], { eqAt: null, amtAt: m('colp') }); // no column or answer before the narration reads it
+ showRow(rows[0], m('cols') + .3, 0, 2); showRow(rows[0], m('cols') + 1.9, 2, 5); showRow(rows[0], m('cols') + 3.9, 5, 7);
+ vs.label('v', ['col 1'], 'tip', [-66, -4]); vs.label('w', ['col 2'], 'tip'); // short columns: labels at the tips, col 1's clear of 3·col 1
+ ['v', 'w'].forEach((id, i) => { put(vs.A[id].g, { o: 0 }); put(vs.A[id].lab, { o: 0 }); vs.show(id, m('cols') + .3 + i * 1.6, .5); });
+ put(sys.readout, { o: 0 }); show(sys.readout, m('rowp') + 1.4, .5);
sys.lines.forEach(l => put(l.g, { o: 0 })); put(sys.meetBox, { o: 0 });
['cv', 'dw', 'sum'].forEach(id => { put(vs.A[id].g, { o: 0 }); put(vs.A[id].lab, { o: 0 }); });
focusEq(sys, 0, m('e') + .2); focusEq(sys, 1, m('e') + 2.2); focusEq(sys, null, m('cols') - .2);
@@ -339,32 +403,37 @@ const BEATS = [
const p = panel(0);
text(p, 'Columns on one line: no mix reaches b', 60, 110, .2, { size: 40, weight: 600 });
const A3 = [[1, 2], [2, 4]];
- const sys = linsys(p, { A: A3, b: [3, 5], mat: null, eq: [110, 190], size: 46, plane: { cx: 420, cy: 625, u: 28, step: 2 } });
+ const sys = linsys(p, { A: A3, b: [3, 1], mat: null, eq: TWEQ, size: 46, plane: TWL });
+ put(sys.readout, { y: -28 });
put(sys.stage, { o: 0 }); show(sys.stage, m('rowp') - .2, .5);
put(sys.readout, { o: 0 }); show(sys.readout, m('rowp') + 2, .5);
- const vs = colPic(p, A3, { c: 1, d: 0, plane: { cx: 1180, cy: 625, u: 28, step: 2 }, labelSize: 24, show: ['v', 'w'] });
- vs.label('w', ['col 2'], 'tip', [30, 16]);
- vs.row([{ t: 'x' }, { col: 'v', fixed: true }, '+', { t: 'y' }, { col: 'w', fixed: true }, '=', { fn: () => ['3', '5'], w: 76, fill: COL.task }], { x: 860, y: 230, size: 40 });
- const heads = G(p, {});
- T(heads, 'row picture', { x: 420, y: 855, size: 26, fill: COL.dim, anchor: 'middle', weight: 600 });
- T(heads, 'column picture', { x: 1180, y: 855, size: 26, fill: COL.dim, anchor: 'middle', weight: 600 });
+ const vs = colPic(p, A3, { c: 1, d: 0, plane: TWR, labelSize: 30, show: [] });
+ vs.show('v', m('cols') + .3); vs.show('w', m('cols') + 1.3);
+ vs.label('w', ['col 2'], 'tip', [30, 16]); vs.label('v', ['col 1'], 'tip', [30, 40]);
+ const cq = vs.row([{ t: 'x' }, { col: 'v', fixed: true }, '+', { t: 'y' }, { col: 'w', fixed: true }, '=', { fn: () => ['3', '1'], w: 72, fill: COL.task }], { x: 860, y: 204, size: 38, o: 0 });
+ showRow(cq, m('cols') - .2);
+ twinHeads(p, 0);
thick(vs, 'v', m('cols') + .3); thick(vs, 'w', m('cols') + 1.3);
focusEq(sys, 0, m('e') + .2); focusEq(sys, 1, m('e') + 2.6); focusEq(sys, null, m('cols') - .2);
- vs.lattice(m('colp'), true, .8); // parallel columns: the lattice is one amber line
+ vs.lattice(m('colp'), true, .8); // parallel columns: the lattice is one line
+ vs.latticeG.lastChild.setAttribute('stroke', COL.chalk); // the lattice's one line: chalk, not amber (amber is b here)
+ text(p, 'every mix', vs.P.PX(-2.1), vs.P.PY(-3.4), m('colp') + .6, { size: 26, fill: COL.dim, anchor: 'end', weight: 600 });
const bArr = G(vs.P.g, {});
- vs.P.arrow(0, 0, 3, 5, COL.task, m('miss'), { label: 'b', into: bArr });
- const ring = G(vs.P.g, { x: vs.P.PX(3), y: vs.P.PY(5), o: 0 });
+ vs.P.arrow(0, 0, 3, 1, COL.task, m('miss'), { into: bArr });
+ text(bArr, 'b', vs.P.PX(3) + 22, vs.P.PY(1) + 12, m('miss') + .4, { size: 30, fill: COL.task, weight: 600 });
+ const ring = G(vs.P.g, { x: vs.P.PX(3), y: vs.P.PY(1), o: 0 });
mk('circle', { r: 14, fill: 'none', stroke: COL.bad, 'stroke-width': 3 }, ring);
show(ring, m('miss') + 1, .3); pulse(ring, m('miss') + 1.4, 1.6);
- text(p, 'no mix of the columns reaches b', 860, 400, m('miss') + 1.6, { size: 26, fill: COL.bad, weight: 600 });
+ text(p, 'no mix of the columns reaches b', 860, 318, m('miss') + 1.6, { size: 26, fill: COL.bad, weight: 600 });
sys.lines.forEach((l, i) => { tw(l.l, { 'a_stroke-width': 9 }, m('rowp') + .8 + i * .5, .3); tw(l.l, { 'a_stroke-width': 5 }, m('rowp') + 1.5 + i * .5, .4); });
- text(p, 'no solution, seen two ways', 800, 820, m('both'), { size: 30, fill: COL.task, weight: 600, anchor: 'middle' });
+ text(p, 'no solution, seen two ways', 800, 886, m('both'), { size: 30, fill: COL.task, weight: 600, anchor: 'middle' });
}],
['q3', 'Quick check', () => {
const p = panel(0);
text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
S.vs = colPic(p, [[2, 1], [1, 3]], { c: 2, d: 1, show: ['v', 'w'] });
+ S.vs.label('v', ['col 1'], 'tip'); S.vs.label('w', ['col 2'], 'tip');
S.vs.P.arrow(0, 0, 5, 5, COL.task, .4, { label: 'b' });
S.vs.row([{ t: 'x' }, { col: 'v', fixed: true }, '+', { t: 'y' }, { col: 'w', fixed: true }, '=', { col: 'sum', fixed: true }], { x: 90, y: 230, size: 42 });
}, { ask: done => quiz(CARD, [{
@@ -416,6 +485,13 @@ const BEATS = [
() => S.T2.sys.set({ b0: B[0], b1: B[1] }))(body, api);
},
})), done, 'Chapter practice · set 4 of 4') }],
+ ['play', 'Playground', (m) => {
+ const p = panel(0);
+ text(p, 'Playground', 60, 110, .2, { size: 40, weight: 600 });
+ S.T2 = twin(p, LA, LB, { rows: false });
+ text(p, 'try: make the two lines parallel', 420, 846, m('go'), { size: 24, fill: COL.dim, anchor: 'middle' });
+ text(p, 'try: line the columns up, or put b on col 1', 1180, 846, m('go') + .6, { size: 24, fill: COL.dim, anchor: 'middle' });
+ }, { ask: playAsk(() => twinPlay(S.T2), { pos: { x: 640, y: 24, w: 930, cls: 'side' }, tip: 'Change any number on the left; drag col 1, col 2 or b on the right. Nothing is marked.' }) }],
['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],
].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
diff --git a/site/linear-algebra/lib/vecs.js b/site/linear-algebra/lib/vecs.js
index 9d5b0e6..c5b147a 100644
--- a/site/linear-algebra/lib/vecs.js
+++ b/site/linear-algebra/lib/vecs.js
@@ -29,11 +29,13 @@ function vecs(p, { vecs: list = { v: [3, 2] }, c = 1, d = 1, plane: po = {}, sna
/* ---------- numbers ---------- */
const isInt = n => Math.abs(n - Math.round(n)) < 1e-9;
- // A value as math parts: whole numbers, fractions in lowest terms (denominators up to 12), else one decimal.
+ // A value as math parts: whole numbers, fractions in lowest terms (denominators up to 12; a value rounded to 6 places,
+ // like 0.666667, still reads 2/3), else one decimal.
const parts = n => {
if (isInt(n)) return [num(Math.round(n) || 0)];
- for (let q = 2; q <= 12; q++) { const k = Math.round(n * q); if (Math.abs(n * q - k) < 1e-6) return [k < 0 ? '−' : '', F(Math.abs(k), q)]; }
- return [num(Math.round(n * 10) / 10)];
+ for (let q = 2; q <= 12; q++) { const k = Math.round(n * q); if (Math.abs(n * q - k) < 5e-6) return [k < 0 ? '−' : '', F(Math.abs(k), q)]; }
+ const r = Math.round(n * 10) / 10; // a value in passing: always with its decimal sign (−0.97 is "−1.0", not a whole −1)
+ return [num(r) + (Number.isInteger(r) ? DECIMAL_SIGN + '0' : '')];
};
const fmt = n => parts(n).map(x => typeof x === 'string' ? x : x.f.join('/')).join('');
const vec = n => [v[n + '0'], v[n + '1']];
@@ -152,11 +154,11 @@ function vecs(p, { vecs: list = { v: [3, 2] }, c = 1, d = 1, plane: po = {}, sna
} else if (it.key) {
if (it.signed) {
slot(part, 'sign', cx + sz * .3, y, { sz, scrub: false, pf: vv => [vv[it.key] < -1e-9 ? '−' : '+'] });
- cx += sz * .6 + gap;
+ cx += sz * .45 + gap * .5;
}
const w = sz * 1.15, k = it.key;
slot(part, k, cx + w, y, { sz, fill: it.fill ?? COL.chalk, w, anchor: 'end', pf: it.signed ? vv => parts(Math.abs(vv[k])) : undefined });
- cx += w + gap * .25;
+ cx += w + gap * .5; // clear of a bracket after it
}
out.push(part);
}
@@ -280,10 +282,10 @@ function vecs(p, { vecs: list = { v: [3, 2] }, c = 1, d = 1, plane: po = {}, sna
const lk = fmt(xb - xa) + '|' + fmt(yb - ya) + '|' + [xa, ya, xb, yb].join();
if (lk !== a.legKey) {
a.legKey = lk; a.legX.replaceChildren(); a.legY.replaceChildren();
- // The across number sits inside the corner (between the leg and the arrow) when the rise leaves room,
- // else on the far side, clear of the axis numbers; the up number sits beside its leg, away from the tail.
+ // Going up, the across number sits inside the corner (between the leg and the arrow) when the rise leaves room,
+ // else under the leg; going down, always above it (clear of the x-axis numbers). The up number sits beside its leg, away from the tail.
const rise = yb - ya, inside = Math.abs(rise) >= 1.5;
- const hy = rise >= 0 ? (inside ? -12 : 50) : (inside ? 34 : -14);
+ const hy = rise >= 0 ? (inside ? -12 : 50) : -14; // pointing down: above the leg, clear of the x-axis numbers
if (Math.abs(xb - xa) > 1e-9) M(a.legX, parts(xb - xa), { x: (PX(xa) + PX(xb)) / 2, y: PY(ya) + hy, size: 28, fill: colorOf[id], anchor: 'middle' });
const run = xb - xa, toTail = Math.abs(run) >= 1.5, right = (run >= 0) !== toTail;
if (Math.abs(rise) > 1e-9) M(a.legY, parts(rise), { x: PX(xb) + (right ? 14 : -14), y: (PY(ya) + PY(yb)) / 2 + 10, size: 28, fill: colorOf[id], anchor: right ? 'start' : 'end' });
@@ -328,7 +330,7 @@ function vecs(p, { vecs: list = { v: [3, 2] }, c = 1, d = 1, plane: po = {}, sna
draw();
const vs = {
- v, P: P2, stage: holder, A, names, calc, solveFor, parts, fmt, row, lattice: latG,
+ v, P: P2, stage: holder, A, names, calc, solveFor, parts, fmt, row, latticeG: latG, // vs.lattice() shows it; vs.latticeG is the group
paren: n => n < 0 ? `(${fmt(n)})` : fmt(n), // a number inside a sum: 1 + (−4)
nice: n => !fmt(n).includes(DECIMAL_SIGN), // whole, or a simple fraction (not a value in passing)
// Move the numbers to new values over dur seconds, on the beat clock (deterministic, so seeking replays it).
@@ -357,6 +359,7 @@ function vecs(p, { vecs: list = { v: [3, 2] }, c = 1, d = 1, plane: po = {}, sna
const ok = on && s.box && canScrub(s.key) && st(s.box.parentNode).o > .3;
if (!s.box) continue;
s.box.style.cursor = ok ? 'ew-resize' : '';
+ s.box.style.touchAction = ok ? 'none' : ''; // a finger scrubs the number instead of scrolling the page
s.box.setAttribute('stroke', ok ? COL.faint : 'none');
s.box.setAttribute('stroke-dasharray', '4 6');
if (ok) s.box.setAttribute('tabindex', 0); else s.box.removeAttribute('tabindex');
@@ -365,6 +368,7 @@ function vecs(p, { vecs: list = { v: [3, 2] }, c = 1, d = 1, plane: po = {}, sna
const a = A[id], can = on && (id === 'sum' ? solving : id in onDrag) && (dragSet ? dragSet.includes(id) : st(a.g).o > .3);
a.h.style.pointerEvents = can ? '' : 'none';
a.h.style.cursor = can ? 'grab' : '';
+ a.h.style.touchAction = can ? 'none' : '';
a.ring.style.opacity = can ? 1 : 0;
}
},
@@ -385,7 +389,7 @@ const vsTask = (vs, test, why, hint, reveal, opts) => (body, api) => {
check: () => { const ok = !!test(vs.v, vs.calc()); api.grade(ok, typeof (ok ? why : hint) === 'function' ? (ok ? why : hint)(vs.v, vs.calc()) : ok ? why : hint); },
reveal: () => { reveal?.(); return typeof why === 'function' ? why(vs.v, vs.calc()) : why; },
lock: () => vs.live(false),
- hint: [kbd('Tab'), 'pick a number', kbd('↑'), kbd('↓'), 'change it, or drag a tip'],
+ hint: [kbd('Tab'), ' pick a number ', kbd('↑'), kbd('↓'), ' change it, or drag a tip'],
};
};