Skip to content

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

feat(linear-algebra): chapters 20-22 reviewed; Unit 2 complete on the contents

yzr51b78fcc8938
diff --git a/site/linear-algebra/ch20/index.html b/site/linear-algebra/ch20/index.html
index 4ef1241..45acb07 100644
--- a/site/linear-algebra/ch20/index.html
+++ b/site/linear-algebra/ch20/index.html
@@ -47,11 +47,11 @@ const dashSame = sys => sys.onChange((v, s) => {
if ((sys.lines[1].l.getAttribute('stroke-dasharray') || '') !== d) sys.lines[1].l.setAttribute('stroke-dasharray', d);
});
// Two equations top left, the plane on the right, [A | b] under the equations; no readout (elimination finds it).
-const two = (p, A, b, { t0 = .1, meet = true, table = true } = {}) => {
+const two = (p, A, b, { t0 = .1, meet = true, table = true, at = MAT } = {}) => {
const sys = linsys(p, { A, b, eq: [90, 200], mat: null, sol: false, t0 });
if (!meet) put(sys.meetBox, { o: 0 });
dashSame(sys);
- const el = table ? elim(p, sys, { at: MAT, t0 }) : null;
+ const el = table ? elim(p, sys, { at, t0 }) : null;
return { sys, el };
};
// The old line of row 2, dashed, through (sx, sy): a·x + b·y = c runs along (b, −a).
@@ -75,11 +75,7 @@ const three = (p, { A, b }, caption, { t0 = .1, view = VIEW } = {}) => {
const el = elim(p, sys, { at: TBL, size: 44, cw: 84, rh: 66, t0, labelX: 530 });
return { sys, el, V: sys.space };
};
-const triangle = (p, el, t0) => {
- const e = path(p, `M${el.cx(0) - 40} ${el.ry(0) - 48}L${el.cx(2) + 42} ${el.ry(0) - 48}L${el.cx(2) + 42} ${el.ry(2) + 20}Z`, { fill: COL.chalk, stroke: COL.chalk, 'stroke-width': 2, 'fill-opacity': .1 }, { o: 0 });
- show(e, t0, .6);
- return e;
-};
+const triangle = (p, el, t0) => el.upper(t0, { color: COL.chalk }); // the staircase behind the numbers: nothing struck through
// A small system with no picture (title card, the flow in "decide"): the .v, .to, .set, .onChange elim uses.
const bare = (A, b) => {
const v = {}, fs = [];
@@ -94,7 +90,7 @@ const keys2 = (A, b) => ({ a00: A[0][0], a01: A[0][1], a10: A[1][0], a11: A[1][1
const fr = v => { const r = Math.round(v * 10) / 10; return Math.abs(v - Math.round(v)) < 1e-9 ? num(Math.round(v)) : Math.abs(v * 2 - Math.round(v * 2)) < 1e-9 ? num(Math.round(v * 2)) + '/2' : num(r); };
// Under the table, live: what row 2 − ℓ × row 1 (ℓ = number to remove ÷ pivot) leaves, and what that row says.
const verdict = (p, sys, el, t0) => {
- const g = G(p, { o: 0 }), y = el.ry(2) + 50, out = G(g, {});
+ const g = G(p, { o: 0 }), y = el.ry(2) - 6, out = G(g, {}); // a third row under the table; the words beside it
show(g, t0);
let key = '';
const drawV = v => {
@@ -103,12 +99,12 @@ const verdict = (p, sys, el, t0) => {
if (k === key) return;
key = k;
out.replaceChildren();
- if (!v.a00) { T(out, 'pivot spot 0: swap first', { x: 90, y: y - 50, size: 28, fill: COL.bad, weight: 600 }); return; }
- T(out, `row 2 − ${fr(l).replace('-', '−')} × row 1 gives:`, { x: 90, y: y - 50, size: 28, fill: COL.dim, weight: 600 });
- r.forEach((x, j) => M(out, [fr(x).replace('-', '−')], { x: el.cx(j), y: y + 10, size: 40, fill: j === 2 ? COL.task : COL.chalk, anchor: 'middle' }));
+ if (!v.a00) { T(out, 'pivot spot 0: swap first', { x: 470, y, size: 28, fill: COL.bad, weight: 600 }); return; }
+ T(out, `row 2 − ${fr(l).replace('-', '−')} × row 1 leaves:`, { x: 470, y: y - 34, size: 24, fill: COL.dim, weight: 600 });
+ r.forEach((x, j) => M(out, [fr(x).replace('-', '−')], { x: el.cx(j), y: y + 4, size: 40, fill: j === 2 ? COL.task : COL.chalk, anchor: 'middle' }));
const z = Math.abs(r[1]) < 1e-9;
const say_ = z ? (Math.abs(r[2]) < 1e-9 ? '0 = 0: endlessly many' : `0 = ${fr(r[2]).replace('-', '−')}: no solution`) : 'a pivot: one solution';
- T(out, say_, { x: 470, y: y + 6, size: 30, fill: z ? (Math.abs(r[2]) < 1e-9 ? COL.good : COL.bad) : COL.chalk, weight: 600 });
+ T(out, say_, { x: 470, y: y + 6, size: 28, fill: z ? (Math.abs(r[2]) < 1e-9 ? COL.good : COL.bad) : COL.chalk, weight: 600 });
};
sys.onChange(drawV); drawV(sys.v);
return g;
@@ -166,7 +162,8 @@ const BEATS = [
const p = panel(0);
text(p, 'A zero in the pivot spot', 60, 110, .2, { size: 40, weight: 600 });
const A = [[0, 2], [3, 1]], b = [4, 5];
- const { sys, el } = two(p, A, b, { t0: m('eq') - .3, meet: false });
+ const { sys, el } = two(p, A, b, { t0: .4, meet: false });
+ thick(sys, 0, m('eq') + .6); el.flash(0, m('eq') + .6); thick(sys, 1, m('eq') + 3.4); el.flash(1, m('eq') + 3.4); // each line as its equation is read
show(sys.meetBox, m('meet'), .5); pulse(sys.meet, m('meet') + .3);
el.ring(0, 0, m('piv'), { color: COL.bad, label: 'pivot spot', below: false });
el.ring(1, 0, m('div'), { dash: true });
@@ -178,7 +175,9 @@ const BEATS = [
el.mult(1, m('l1'), 1.4);
el.mult(2, m('l2'), 1.4);
el.mult(-1, m('l3'), 1.8);
- [m('l1') + 1.4, m('l2') + 1.4, m('l3') + 1.8, m('stays') + .3].forEach(t => el.flash(1, t, 0));
+ // while the voice says the 3x never changes, the multiplier keeps sweeping: the line turns, the 3 stays lit
+ el.mult(3, m('stays') + .5, 2.6); el.mult(-2, m('stays') + 3.6, 3); el.mult(-1, m('stays') + 7.1, 1.6);
+ [m('l1') + 1.4, m('l2') + 1.4, m('l3') + 1.8, m('stays') + .3, m('stays') + 3.1, m('stays') + 6.6, m('stays') + 8.7].forEach(t => el.flash(1, t, 0));
pin(sys, 1, 2, m('stays'));
say(p, ['0 · ℓ = 0, so 3 − 0 = 3'], 90, 680, m('stays') + 3, { size: 36, fill: COL.chalk });
text(p, 'no multiplier removes the 3x', 90, 750, m('none'), { size: 32, fill: COL.bad, weight: 600 });
@@ -200,11 +199,11 @@ const BEATS = [
text(p, 'already 0: a triangle', 90, 640, m('zero') + .6, { size: 28, fill: COL.good, weight: 600 });
wl(p, '2y', '4', 710, m('y'), { xEq: 200, size: 38 });
say(p, ['→'], 320, 710, m('y') + 2, { size: 38, fill: COL.dim });
- wl(p, 'y', '2', 710, m('y') + 2, { xEq: 420, size: 38, fill: COL.task });
+ wl(p, 'y', '2', 710, m('y') + 2, { xEq: 450, size: 38, fill: COL.task });
wl(p, '3x + 2', '5', 780, m('x'), { xEq: 200, size: 38 });
say(p, ['→'], 320, 780, m('x') + 2.4, { size: 38, fill: COL.dim });
- wl(p, '3x', '3', 780, m('x') + 2.4, { xEq: 420, size: 38 });
- say(p, ['→ x = 1'], 520, 780, m('x') + 4, { size: 38, fill: COL.task });
+ wl(p, '3x', '3', 780, m('x') + 2.4, { xEq: 450, size: 38 });
+ say(p, ['→ x = 1'], 560, 780, m('x') + 4, { size: 38, fill: COL.task });
text(p, 'a row exchange: temporary trouble', 90, 850, m('temp'), { size: 30, fill: COL.good, weight: 600 });
el.flash(0, m('temp') + 3); el.flash(1, m('temp') + 5); pulse(sys.meet, m('temp') + 6.5);
}],
@@ -212,7 +211,7 @@ const BEATS = [
['zero3', 'A zero in the middle', (m) => {
const p = panel(0);
text(p, 'A zero in the middle', 60, 110, .2, { size: 40, weight: 600 });
- const { sys, el, V } = three(p, { A: [[1, 2, 1], [2, 4, 3], [3, 7, 5]], b: [1, 3, 4] }, 'x + 2y + z = 1, 2x + 4y + 3z = 3, 3x + 7y + 5z = 4', { t0: m('eq') - .3, view: { yaw: -30, pitch: 22 } });
+ const { sys, el, V } = three(p, { A: [[1, 2, 1], [2, 4, 3], [3, 7, 5]], b: [1, 3, 4] }, 'x + 2y + z = 1, 2x + 4y + 3z = 3, 3x + 7y + 5z = 4', { t0: .4, view: { yaw: -30, pitch: 22 } });
V.sway(5, 13);
tw(sys.meet.e, { o: 0 }, 0, 0);
el.ring(0, 0, m('c1'));
@@ -284,11 +283,11 @@ const BEATS = [
say(p, ['0 = 0'], 90, 730, m('zero'), { size: 44, fill: COL.good });
text(p, 'always true: it rules nothing out', 260, 726, m('zero') + 1.5, { size: 30, fill: COL.good, weight: 600 });
thick(sys, 0, m('say') + 1.5);
- const pts = [[1, 0, 'p1', '1 + 0 = 1'], [3, -1, 'p2', '3 − 2 = 1'], [-1, 1, 'p3', '−1 + 2 = 1']];
+ const pts = [[1, 0, 'p1', '1 + 2·0 = 1'], [3, -1, 'p2', '3 + 2·(−1) = 1'], [-1, 1, 'p3', '−1 + 2·1 = 1']];
pts.forEach(([x, y, k, chk], i) => {
- sys.P.dot(x, y, COL.chalk, m(k), { label: `(${num(x)}, ${num(y)})`, dx: 14, dy: 30, into: sys.stage });
- say(p, [chk], 90 + 225 * i, 800, m(k) + .2, { size: 32, fill: COL.chalk });
- okMark(p, 90 + 225 * i + 170, 800, m(k) + .8, 30);
+ sys.P.dot(x, y, COL.chalk, m(k), { label: `(${num(x)}, ${num(y)})`, dx: 12, dy: -14, into: sys.stage });
+ say(p, [chk], 90 + 238 * i, 800, m(k) + .2, { size: 28, fill: COL.chalk });
+ okMark(p, 90 + 238 * i + 200, 800, m(k) + .8, 28);
});
text(p, 'endlessly many solutions', 90, 860, m('many'), { size: 32, fill: COL.good, weight: 600 });
}],
@@ -307,7 +306,7 @@ const BEATS = [
['planes', 'Parallel planes', (m) => {
const p = panel(0);
text(p, 'Three planes, no point', 60, 110, .2, { size: 40, weight: 600 });
- const { sys, el, V } = three(p, { A: [[1, 1, 1], [1, 2, 3], [2, 3, 4]], b: [2, 5, 9] }, 'x + y + z = 2, x + 2y + 3z = 5, 2x + 3y + 4z = 9', { t0: m('eq') - .3 });
+ const { sys, el, V } = three(p, { A: [[1, 1, 1], [1, 2, 3], [2, 3, 4]], b: [2, 5, 9] }, 'x + y + z = 2, x + 2y + 3z = 5, 2x + 3y + 4z = 9', { t0: .4 });
V.sway(5, 13);
el.step(1, 0, 1, m('c1') + 1, 2, { lead: .5 });
el.step(2, 0, 2, m('c1b'), 2.2, { lead: .5 });
@@ -344,10 +343,11 @@ const BEATS = [
el.flash(2, m('row'));
say(p, ['0 = 0'], 90, 560, m('zero'), { size: 44, fill: COL.good });
text(p, 'row 3 says nothing', 230, 556, m('zero') + .5, { size: 30, fill: COL.good, weight: 600 });
+ V.turn({ yaw: 35, pitch: 30 }, m('line') - 1.2, 3); // turn until the shared line lies across the view
prog(q => sys.lines[0].e.setAttribute('stroke-width', 2.5 + 6 * Math.sin(Math.PI * q)), m('line'), 2, lin);
prog(q => sys.lines[0].e.setAttribute('stroke-width', 2.5 + 6 * Math.sin(Math.PI * q)), m('line') + 2.4, 2, lin);
const pts = [[-1, 3, 0], [0, 1, 1], [1, -1, 2]].map((q, i) => {
- const pt = V.point(q, { label: `(${q.map(num).join(', ')})`, size: 24 });
+ const pt = V.point(q, { label: `(${q.map(num).join(', ')})`, size: 24, halo: true });
put(pt.e, { o: 0 }); show(pt.e, m('pts') + 1.4 * i, .4);
return pt;
});
@@ -357,11 +357,11 @@ const BEATS = [
['why', 'The pictures said so', (m) => {
const p = panel(0);
text(p, 'The pictures said so too', 60, 110, .2, { size: 40, weight: 600 });
- const { sys } = two(p, [[1, 2], [2, 4]], [1, 6], { t0: m('rows') - .3, table: false });
+ const { sys } = two(p, [[1, 2], [2, 4]], [1, 6], { t0: .4, table: false });
sys.labels(['col 1', 'col 2', 'b']);
text(p, 'chapter 3: same tilt, different right sides', 90, 420, m('par'), { size: 28, fill: COL.dim, weight: 600 });
thick(sys, 0, m('rows') + 1.5); thick(sys, 1, m('rows') + 3); thick(sys, 0, m('par') + 2); thick(sys, 1, m('par') + 2);
- say(p, ['parallel: no solution'], 90, 475, m('par') + 3, { size: 34, fill: COL.bad });
+ const v1 = say(p, ['parallel: no solution'], 90, 475, m('par') + 3, { size: 34, fill: COL.bad });
sys.view('col', m('cols'));
text(p, 'chapter 14: the columns', 90, 560, m('cols'), { size: 28, fill: COL.dim, weight: 600 });
const ln = sys.P.line(-3, -6, 3, 6, COL.dim, m('line') + 1, { dash: '8 10', w: 3, into: sys.stage });
@@ -376,11 +376,14 @@ const BEATS = [
const ring = G(sys.stage, { x: sys.P.PX(1), y: sys.P.PY(6), o: 0 });
mk('circle', { r: 22, fill: 'none', stroke: COL.bad, 'stroke-width': 3.5 }, ring);
show(ring, m('off'), .3); hide(ring, m('move'), .3); pulse(ring, m('off') + 2.5, 1.3);
- say(p, ['b off the line: no mix reaches it'], 90, 670, m('off') + .6, { size: 30, fill: COL.bad });
+ const v2 = say(p, ['b off the line: no mix reaches it'], 90, 670, m('off') + .6, { size: 30, fill: COL.bad });
+ [v1, v2].forEach(e => tw(e, { o: .28 }, m('move'), .5)); // they were true of b = (1, 6), not of (1, 2)
sys.to({ b1: 2 }, m('move') + .3, 1.6);
say(p, ['b = 1 · col 1 = ½ · col 2 = …'], 90, 725, m('on'), { size: 32, fill: COL.good });
+ [0, 1].forEach(j => { tw(sys.cols[j], { 'a_stroke-width': 9 }, m('on') + 1 + 2.6 * j, .35); tw(sys.cols[j], { 'a_stroke-width': 5 }, m('on') + 1.9 + 2.6 * j, .5); }); // one of col 1, half of col 2
sys.view('row', m('rows2'));
thick(sys, 1, m('one') + .2);
+ say(p, ['one line: endlessly many'], 460, 475, m('one') + .3, { size: 30, fill: COL.good });
text(p, 'elimination: a row of zeros, then 0 = 4 or 0 = 0', 90, 800, m('sum'), { size: 28, fill: COL.chalk, weight: 600 });
thick(sys, 0, m('sum') + 3); thick(sys, 1, m('sum') + 5);
}],
@@ -404,9 +407,9 @@ const BEATS = [
step('a 0 in the pivot spot', 90, 210, m('q') - .4);
step('look below it, in the same column:', 90, 270, m('q') + .4, COL.dim);
step('a number that is not 0?', 130, 350, m('below'));
- step('→ swap that row up: temporary', 520, 350, m('swap'), COL.good);
+ step('→ swap that row up: temporary', 560, 350, m('swap'), COL.good);
step('every number below is 0?', 130, 450, m('none'));
- step('→ no pivot in this column', 520, 450, m('none') + 1.5, COL.bad);
+ step('→ no pivot in this column', 560, 450, m('none') + 1.5, COL.bad);
step('elimination ends with a row of zeros on the left:', 130, 540, m('row'));
step('0 = 0', 170, 620, m('zero0'), COL.good); step('endlessly many solutions', 330, 620, m('zero0') + .5, COL.good);
step('0 = 4', 170, 690, m('zeroc'), COL.bad); step('no solution', 330, 690, m('zeroc') + .5, COL.bad);
@@ -444,10 +447,10 @@ const BEATS = [
['final4', 'Chapter practice', () => {
const p = panel(0);
text(p, 'Break it on purpose', 60, 110, .2, { size: 40, weight: 600 });
- const t = two(p, HANDS[0].A, HANDS[0].b);
+ const t = two(p, HANDS[0].A, HANDS[0].b, { at: [108, 390] }); // higher than elsewhere: the card and its hints need the room
S.sys = t.sys; S.el = t.el;
S.ver = verdict(p, t.sys, t.el, .3);
- }, { ask: done => quiz({ x: 40, y: 672, w: 720, cls: 'side' }, [...HANDS.map((h, k) => ({
+ }, { ask: done => quiz({ x: 40, y: 572, w: 720, cls: 'side' }, [...HANDS.map((h, k) => ({
id: `p-break${k + 1}`, prompt: [h.prompt],
build: (body, api) => { put(S.ver, { o: 1 }); S.el.load(keys2(h.A, h.b)); return lsTask(S.sys, h.test, h.why, h.hint, () => S.sys.set(h.answer), { only: h.only })(body, api); },
})), {
diff --git a/site/linear-algebra/ch21/audio/en/both.mp3 b/site/linear-algebra/ch21/audio/en/both.mp3
index ef6d18e..6102376 100644
Binary files a/site/linear-algebra/ch21/audio/en/both.mp3 and b/site/linear-algebra/ch21/audio/en/both.mp3 differ
diff --git a/site/linear-algebra/ch21/audio/en/timings.js b/site/linear-algebra/ch21/audio/en/timings.js
index 5887478..bbc7255 100644
--- a/site/linear-algebra/ch21/audio/en/timings.js
+++ b/site/linear-algebra/ch21/audio/en/timings.js
@@ -359,17 +359,18 @@ window.TIMINGS = {
]
},
"both": {
- "dur": 57.24,
+ "dur": 69.192,
"marks": {
- "write": 2.461,
- "read": 8.854,
- "one": 13.294,
- "r": 19.544,
- "r12": 26.458,
- "r3": 33.568,
- "res": 47.331,
- "ea": 49.792,
- "go": 54.062
+ "write": 2.513,
+ "read": 8.568,
+ "one": 13.542,
+ "r": 19.779,
+ "r12": 26.576,
+ "r3": 33.164,
+ "res": 47.07,
+ "ea": 49.609,
+ "go": 53.919,
+ "check": 57.266
},
"cues": [
[
@@ -377,48 +378,56 @@ window.TIMINGS = {
"Two steps, two matrices."
],
[
- 2.461,
+ 2.513,
"In symbols: E three two, times E two one times A, equals U."
],
[
- 8.854,
+ 8.568,
"Read it from the right."
],
[
- 10.104,
+ 9.792,
"E two one acts first, so it stands next to A."
],
[
- 13.294,
+ 13.542,
"We can also multiply the two matrices first, and get one matrix that does both steps."
],
[
- 19.544,
+ 19.779,
"Each row of E three two mixes the rows of E two one, the same way as before."
],
[
- 26.458,
+ 26.576,
"Rows one and two of E three two are rows of the identity, so they copy rows one and two of E two one."
],
[
- 33.568,
+ 33.164,
"Row three is minus two times row two, plus row three."
],
[
- 38.294,
+ 38.138,
"Minus two times minus three, one, zero is six, minus two, zero."
],
[
- 44.375,
+ 44.062,
"Add zero, zero, one, and you get six, minus two, one."
],
[
- 49.792,
+ 49.609,
"This one matrix E, times A, gives U at once."
],
[
- 54.062,
+ 53.919,
"Both planes turn together, each on its hinge."
+ ],
+ [
+ 57.266,
+ "Row three of the answer is six times row one, minus two times row two, plus row three: zero, zero, five, minus ten."
+ ],
+ [
+ 66.419,
+ "The same U as before, in one step."
]
]
},
diff --git a/site/linear-algebra/ch21/index.html b/site/linear-algebra/ch21/index.html
index 2ebbcf3..3caef96 100644
--- a/site/linear-algebra/ch21/index.html
+++ b/site/linear-algebra/ch21/index.html
@@ -67,11 +67,7 @@ const matDraw = (p, rows, x, y, t0, { size = 34, cw = 50, rh = 46, name = '', ri
show(g, t0, .5);
return g;
};
-const triangle = (p, el, t0) => {
- const e = path(p, `M${el.cx(0) - 28} ${el.ry(0) - 40}L${el.cx(2) + 30} ${el.ry(0) - 40}L${el.cx(2) + 30} ${el.ry(2) + 16}Z`, { fill: COL.chalk, stroke: COL.chalk, 'stroke-width': 2, 'fill-opacity': .1 }, { o: 0 });
- show(e, t0, .6);
- return e;
-};
+const triangle = (p, el, t0) => el.upper(t0, { color: COL.chalk }); // the staircase behind the numbers: nothing struck through
const keysOf = ({ A, b }, E = null) => {
const o = {}, n = A.length;
A.forEach((r, i) => { r.forEach((x, j) => { o[`a${i}${j}`] = x; o[`e${i}${j}`] = E ? E[i][j] : +(i === j); }); o[`b${i}`] = b[i]; });
@@ -102,11 +98,12 @@ const PRODQ = [
];
// Hands-on in 3D: lecture A, then a system of our own through column 1 (two numbers at once) and column 2.
const OWN = { A: [[1, 1, 1], [2, 3, 1], [-1, 1, 2]], b: [3, 6, 2] }, OWN1 = { A: [[1, 1, 1], [0, 1, -1], [0, 2, 3]], b: [3, 0, 5] };
+const xs = c => { const r = Math.round(c * 10) / 10; return r === 1 ? 'x' : r === -1 ? '−x' : `${num(r)}x`; }; // 1x and −1x written x and −x
const HANDS = [
{ sys: LEC, only: ['e10'], test: (v, pr) => Math.abs(pr.a10) < 1e-9, ans: { e10: -3 }, prompt: 'Make row 2 of the answer lose its x (the lecture’s first step).',
why: '−3 in row 2, column 1: row 2 − 3 × row 1 = (0, 2, −2 | 6).', hint: (v, pr) => `Row 2 still has ${num(Math.round(pr.a10 * 10) / 10)}x. ℓ = 3 ÷ 1; the entry is −ℓ.` },
{ sys: OWN, only: ['e10', 'e20'], test: (v, pr) => Math.abs(pr.a10) < 1e-9 && Math.abs(pr.a20) < 1e-9, ans: { e10: -2, e20: 1 }, prompt: 'One E for both steps of column 1: clear the x from rows 2 and 3.',
- why: '−2 and 1: row 2 − 2 × row 1 and row 3 + row 1. Rows 2 and 3 become (0, 1, −1 | 0) and (0, 2, 3 | 5).', hint: (v, pr) => `Rows 2 and 3 still have ${num(Math.round(pr.a10 * 10) / 10)}x and ${num(Math.round(pr.a20 * 10) / 10)}x. The pivot is 1.` },
+ why: '−2 and 1: row 2 − 2 × row 1 and row 3 + row 1. Rows 2 and 3 become (0, 1, −1 | 0) and (0, 2, 3 | 5).', hint: (v, pr) => `Rows 2 and 3 still have ${xs(pr.a10)} and ${xs(pr.a20)}. The pivot is 1.` },
{ sys: OWN1, only: ['e21'], test: (v, pr) => Math.abs(pr.a21) < 1e-9, ans: { e21: -2 }, prompt: 'Column 2: make the yellow plane flat.',
why: '−2 in row 3, column 2: row 3 − 2 × row 2 = (0, 0, 5 | 5), so z = 1.', hint: (v, pr) => `Row 3 still has ${num(Math.round(pr.a21 * 10) / 10)}y. The pivot of row 2 is 1, the number to remove 2.` },
];
@@ -123,8 +120,8 @@ const BEATS = [
const s = bare([[1, 2], [3, 4]]); s.v.b0 = 5; s.v.b1 = 11;
const em = emat(lg, s, { A: [[1, 2], [3, 4]], b: [5, 11], at: [380, 640], size: 36, cw: 62, ecw: 54, rh: 56, t0: 0 });
show(lg, m('sub') + 1.5, .5);
- em.ringE(1, 0, m('move') + .2);
- em.to({ e10: -3 }, m('move') + .8, 2.2);
+ em.ringE(1, 0, m('move'));
+ em.to({ e10: -3 }, m('move') + .3, 1.6); // done before the card fades
tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(lg, D - .9, .8);
}],
@@ -132,18 +129,19 @@ const BEATS = [
const p = panel(0);
text(p, 'Numbers on the left mix the rows', 60, 110, .2, { size: 40, weight: 600 });
const L = { A: [[1, 2], [3, 4]], b: [5, 11] };
- const { sys, em } = two(p, L, 'x + 2y = 5, 3x + 4y = 11', { t0: m('sys') - .3 });
+ const { sys, em } = two(p, L, 'x + 2y = 5, 3x + 4y = 11', { t0: .4 });
put(em.Eg, { o: 0 }); show(em.Eg, m('E'), .5);
put(em.eqSign, { o: 0 }); show(em.eqSign, m('row2'), .4);
- put(em.Pt.g, { o: 0 }); show(em.Pt.g, m('row2'), .5);
+ tw(em.Pt.g, { o: 0 }, 0, 0); show(em.Pt.g, m('row2'), .5); // elim's own fade-in would show it at once
em.focusE(1, m('row2')); em.Pt.focus(1, m('row2'));
em.flashE(1, m('row2') + .4);
em.work(1, 0, { times: [m('w'), m('w') + 1.8, m('sum')] });
em.Pt.flash(1, m('sum'));
// chapter 9 in one line, then the new idea, while the voice recalls them
- const c9 = text(p, 'chapter 9: A times a column of numbers = a mix of the columns of A', 70, 480, .6, { size: 26, fill: COL.dim, weight: 600 });
- const nw = text(p, 'now: numbers on the left of A = a mix of the rows of A', 70, 530, 4.6, { size: 28, fill: COL.chalk, weight: 600 });
+ const c9 = text(p, 'chapter 9: A times a column = a mix of the columns of A', 70, 480, .6, { size: 26, fill: COL.dim, weight: 600 });
+ const nw = text(p, 'now: numbers on the left of A mix its rows', 70, 530, 4.6, { size: 28, fill: COL.chalk, weight: 600 });
[c9, nw].forEach(e => hide(e, m('sys') + 1, .4));
+ em.B.flash(0, 6.6); em.B.flash(1, 7.6); // "they mix its rows"
[0, 1].forEach(i => em.B.flash(i, m('sys') + 2 + 2.5 * i));
ghost(sys, 3, 4, 1, 2, m('one'));
em.ringE(1, 0, m('one'));
@@ -290,11 +288,13 @@ const BEATS = [
e1.Pt.flash(0, m('r12') + .6); e1.Pt.flash(1, m('r12') + 2.8); e1.Pt.flash(2, m('res'));
const part2 = G(p, { o: 0 }); show(part2, m('ea'), .5);
const e2 = emat(part2, sys, { A: LEC.A, b: LEC.b, at: AT3, size: 32, cw: 52, ecw: 44, rh: 54, gap: 64, t0: 0 });
- e2.to({ e10: -3, e20: 6, e21: -2 }, m('ea') + 1, Math.max(2, D - m('ea') - .8));
+ e2.to({ e10: -3, e20: 6, e21: -2 }, m('go') - .4, 3); // the three numbers of the one matrix slide in while both planes turn
e2.setName('E₃₂E₂₁');
e2.work(2, m('ea') + .5);
V.turn({ yaw: 10, pitch: 28 }, m('ea'), Math.max(2, D - m('ea')));
- hinge(sys, 0, m('go') - .5, 1.6); hinge(sys, 2, m('go') - .5, 1.6);
+ hinge(sys, 0, m('go') + .4, 1.6); hinge(sys, 2, m('go') + .4, 1.6);
+ e2.Pt.flash(2, m('check') + 1); e2.Pt.flash(2, m('check') + 6);
+ triangle(p, e2.Pt, m('check') + 7);
}],
['order', 'Order matters', (m) => {
diff --git a/site/linear-algebra/ch22/audio/en/cycle.mp3 b/site/linear-algebra/ch22/audio/en/cycle.mp3
new file mode 100644
index 0000000..23aafae
Binary files /dev/null and b/site/linear-algebra/ch22/audio/en/cycle.mp3 differ
diff --git a/site/linear-algebra/ch22/audio/en/right2.mp3 b/site/linear-algebra/ch22/audio/en/right2.mp3
new file mode 100644
index 0000000..88a106d
Binary files /dev/null and b/site/linear-algebra/ch22/audio/en/right2.mp3 differ
diff --git a/site/linear-algebra/ch22/audio/en/timings.js b/site/linear-algebra/ch22/audio/en/timings.js
index 67eea08..8cc7726 100644
--- a/site/linear-algebra/ch22/audio/en/timings.js
+++ b/site/linear-algebra/ch22/audio/en/timings.js
@@ -210,16 +210,16 @@ window.TIMINGS = {
]
},
"twice": {
- "dur": 29.616,
+ "dur": 32.136,
"marks": {
- "again": 2.135,
- "r1": 4.701,
- "back": 8.607,
- "pp": 10.599,
- "undo": 13.529,
- "calc": 15.716,
- "calc2": 22.695,
- "eye": 27.669
+ "again": 2.279,
+ "r1": 6.979,
+ "back": 10.951,
+ "pp": 12.969,
+ "undo": 15.755,
+ "calc": 18.086,
+ "calc2": 25.0,
+ "eye": 30.117
},
"cues": [
[
@@ -227,35 +227,35 @@ window.TIMINGS = {
"What happens if we swap twice?"
],
[
- 2.135,
- "Multiply by P one two once more."
+ 2.279,
+ "Put the answer back in, and multiply by P one two once more."
],
[
- 4.701,
+ 6.979,
"Row one of P takes row two, which is now the old row one."
],
[
- 8.607,
+ 10.951,
"Everything is back where it started."
],
[
- 10.599,
+ 12.969,
"So P times P is the identity: a swap undoes itself."
],
[
- 15.716,
+ 18.086,
"We can check it on P itself."
],
[
- 17.513,
+ 19.896,
"Row one of P, zero, one, takes row two of P, which is one, zero."
],
[
- 22.695,
+ 25.0,
"Row two of P, one, zero, takes row one of P, which is zero, one."
],
[
- 27.669,
+ 30.117,
"The answer is the identity."
]
]
@@ -307,6 +307,83 @@ window.TIMINGS = {
]
]
},
+ "cycle": {
+ "dur": 53.088,
+ "marks": {
+ "want": 3.32,
+ "s1": 7.201,
+ "s2": 11.107,
+ "read": 15.677,
+ "r2": 21.849,
+ "r3": 25.872,
+ "same": 30.404,
+ "again": 35.82,
+ "twice": 40.234,
+ "third": 47.578
+ },
+ "cues": [
+ [
+ 0.104,
+ "Let's build one of the two that move every row."
+ ],
+ [
+ 3.32,
+ "We want row three on top, then row one, then row two."
+ ],
+ [
+ 7.201,
+ "Start from the identity, and swap its rows one and three."
+ ],
+ [
+ 11.107,
+ "Then swap its rows two and three."
+ ],
+ [
+ 13.685,
+ "That's one swap after another."
+ ],
+ [
+ 15.677,
+ "Now read the rows of P."
+ ],
+ [
+ 17.578,
+ "Row one is zero, zero, one: it takes row three."
+ ],
+ [
+ 21.849,
+ "Row two is one, zero, zero: it takes row one."
+ ],
+ [
+ 25.872,
+ "Row three is zero, one, zero: it takes row two."
+ ],
+ [
+ 30.404,
+ "The answer starts with four y plus z equals two, and the planes have not moved."
+ ],
+ [
+ 35.82,
+ "Now put the answer back in, and multiply by this P once more."
+ ],
+ [
+ 40.234,
+ "Every row moves down one more place."
+ ],
+ [
+ 43.125,
+ "That's not where we started: this P does not undo itself."
+ ],
+ [
+ 47.578,
+ "A third time brings every row home."
+ ],
+ [
+ 49.987,
+ "So P times P times P is the identity."
+ ]
+ ]
+ },
"q2": {
"dur": 5.016,
"marks": {},
@@ -390,6 +467,64 @@ window.TIMINGS = {
]
]
},
+ "right2": {
+ "dur": 42.24,
+ "marks": {
+ "sys": 1.302,
+ "swap": 7.513,
+ "eq": 11.602,
+ "blue": 18.464,
+ "coral": 29.466,
+ "pt": 32.487,
+ "check": 36.328
+ },
+ "cues": [
+ [
+ 0.104,
+ "One more on the right."
+ ],
+ [
+ 1.302,
+ "x plus y equals four, and x minus two y equals one."
+ ],
+ [
+ 5.82,
+ "They meet at three, one."
+ ],
+ [
+ 7.513,
+ "Put P one two on the right of A: the columns of A trade places."
+ ],
+ [
+ 11.602,
+ "The equations become x plus y equals four, and minus two x plus y equals one."
+ ],
+ [
+ 18.464,
+ "Look at the blue line."
+ ],
+ [
+ 19.727,
+ "Its two numbers were one and one, so trading them changes nothing, and it stays where it was."
+ ],
+ [
+ 26.445,
+ "It is its own mirror image in the diagonal."
+ ],
+ [
+ 29.466,
+ "The coral line flips over the diagonal."
+ ],
+ [
+ 32.487,
+ "So the meeting point moves from three, one to one, three."
+ ],
+ [
+ 36.328,
+ "Check it: one plus three is four, and minus two plus three is one."
+ ]
+ ]
+ },
"q3": {
"dur": 6.432,
"marks": {},
diff --git a/site/linear-algebra/ch22/audio/en/twice.mp3 b/site/linear-algebra/ch22/audio/en/twice.mp3
index c1618af..3fc7d0d 100644
Binary files a/site/linear-algebra/ch22/audio/en/twice.mp3 and b/site/linear-algebra/ch22/audio/en/twice.mp3 differ
diff --git a/site/linear-algebra/ch22/index.html b/site/linear-algebra/ch22/index.html
index d82d91c..df9fb53 100644
--- a/site/linear-algebra/ch22/index.html
+++ b/site/linear-algebra/ch22/index.html
@@ -50,11 +50,7 @@ const bare = A => {
return { v, set(to) { Object.assign(v, to); fs.forEach(f => f(v)); }, onChange: f => fs.push(f), solve: () => ({}), live() {}, to() {} };
};
const pin = (sys, x, y, t0, color = COL.chalk) => { const g = G(sys.stage, { x: sys.P.PX(x), y: sys.P.PY(y), o: 0 }); mk('circle', { r: 20, fill: 'none', stroke: color, 'stroke-width': 3.5, 'stroke-dasharray': '6 5' }, g); show(g, t0, .4); return g; };
-const triangle = (p, el, t0) => {
- const e = path(p, `M${el.cx(0) - 28} ${el.ry(0) - 40}L${el.cx(2) + 30} ${el.ry(0) - 40}L${el.cx(2) + 30} ${el.ry(2) + 16}Z`, { fill: COL.chalk, stroke: COL.chalk, 'stroke-width': 2, 'fill-opacity': .1 }, { o: 0 });
- show(e, t0, .6);
- return e;
-};
+const triangle = (p, el, t0) => el.upper(t0, { color: COL.chalk }); // the staircase behind the numbers: nothing struck through
const colFlash = (el, j, at) => [...Array(el.n).keys()].forEach(i => el.flash(i, at, j));
// E's numbers as keys, from a matrix
const eKeys = P => Object.fromEntries(P.flatMap((r, i) => r.map((x, j) => [`e${i}${j}`, x])));
@@ -137,7 +133,7 @@ const BEATS = [
put(em.Eg, { o: 0 }); show(em.Eg, m('eye'), .5);
em.setName('I');
hide(em.B.ring(0, 0, m('zero'), { color: COL.bad }), m('swap'), .3);
- text(p, 'a 0 in the pivot spot (chapter 20)', 70, 640, m('zero') + .5, { size: 26, fill: COL.bad, weight: 600 });
+ hide(text(p, 'a 0 in the pivot spot (chapter 20)', 70, 640, m('zero') + .5, { size: 26, fill: COL.bad, weight: 600 }), m('piv') - .4, .4);
em.flashE(0, m('eye') + .8, 0); em.flashE(1, m('eye') + 1.2, 1);
emSwap(em, 0, 1, m('swap') + .3, 1.8, { sys });
prog(q => { if (q > 0) em.setName('P'); else em.setName('I'); }, m('p'), 0, lin);
@@ -207,9 +203,11 @@ const BEATS = [
em.setName('P₁₂');
const part1 = G(p, {});
part1.appendChild(em.g);
- emSwap(em, 0, 1, m('again') + .4, 1.8, { sys });
- prog(q => em.setName(q > 0 ? 'I' : 'P₁₂'), m('again') + 2.2, 0, lin);
- em.work(0, m('r1'));
+ // the answer P A goes back in as the table on the right of P; P's rows take it apart again
+ em.Pt.flash(0, m('again') - 1.4); em.Pt.flash(1, m('again') - 1.2);
+ emSwap(em, 0, 1, m('again') + .6, 1.8, { sys, base: true });
+ prog(q => em.names(q > 0 ? ['PA', 'Pb', 'P(PA)', 'P(Pb)'] : ['A', 'b', 'PA', 'Pb']), m('again') + .6, 0, lin);
+ em.flashE(0, m('r1') + .2); em.work(0, m('r1') + .4);
text(p, 'back where it started', 70, 620, m('back'), { size: 30, fill: COL.good, weight: 600 });
say(p, ['P P = I'], 70, 700, m('pp'), { size: 44, fill: COL.chalk });
text(p, 'a swap undoes itself', 300, 694, m('undo'), { size: 30, fill: COL.chalk, weight: 600 });
@@ -243,6 +241,47 @@ const BEATS = [
text(p, 'each = one swap after another', 620, 860, m('two'), { size: 26, fill: COL.chalk, weight: 600 });
}],
+ ['cycle', 'Move every row', (m) => {
+ const p = panel(0);
+ text(p, 'A P that moves every row', 60, 110, .2, { size: 40, weight: 600 });
+ const { sys, em, V } = three(p, LEC, 'x + 2y + z = 2, 3x + 8y + z = 12, 4y + z = 2', { t0: .4 });
+ V.sway(5, 13);
+ em.setName('I');
+ // the order of the rows in the answer, as chips in their own colours (top = left)
+ const ch = G(p, { o: 0 }), cy = 800, slot = k => 340 + k * 130;
+ T(ch, 'answer, top to bottom:', { x: 64, y: cy + 8, size: 24, fill: COL.dim, weight: 600 });
+ const chips = [0, 1, 2].map(k => { const c = G(ch, { x: slot(k), y: cy }); mk('rect', { x: 0, y: -18, width: 110, height: 34, rx: 8, fill: EM_ROW[k], 'fill-opacity': .25, stroke: EM_ROW[k], 'stroke-width': 2.5 }, c); T(c, `row ${k + 1}`, { x: 55, y: 7, size: 22, fill: EM_ROW[k], weight: 700, anchor: 'middle' }); return c; });
+ let last = null;
+ const count = (str, t) => { if (last) hide(last, t, .3); last = text(p, str, 760, cy + 8, t, { size: 24, fill: COL.chalk, weight: 600 }); };
+ show(ch, m('want'), .4);
+ const order = (ord, t) => ord.forEach((k, pos) => tw(chips[k], { x: slot(pos) }, t, 1.2)); // ord: which row of A sits at each place
+ const goal = say(p, ['want: row 3, row 1, row 2'], 64, 670, m('want') + .3, { size: 30, fill: COL.chalk });
+ const fade = (t, d = 2.2) => { [0, 1, 2].forEach(i => { sys.planes[i].fade(.3, t, .3); sys.planes[i].fade(1, t + d, .4); }); };
+ fade(m('s1'), 2.4); emSwap(em, 0, 2, m('s1') + .4, 1.6); order([2, 1, 0], m('s1') + .4);
+ const n1 = text(p, 'swap rows 1, 3 of I', 540, 655, m('s1') + .3, { size: 24, fill: COL.dim, weight: 600 });
+ fade(m('s2'), 2.4); emSwap(em, 1, 2, m('s2') + .4, 1.6); order([2, 0, 1], m('s2') + .4);
+ const n2 = text(p, 'then rows 2, 3', 540, 690, m('s2') + .3, { size: 24, fill: COL.dim, weight: 600 });
+ prog(q => em.setName(q > 0 ? 'P' : 'I'), m('s2') + 2, 0, lin);
+ count('P once', m('s2') + 1.6);
+ [goal, n1, n2].forEach(e => hide(e, m('read') - .3, .3));
+ em.focusE(0, m('read') + 1.5); em.work(0, m('read') + 1.5);
+ em.focusE(1, m('r2')); em.work(1, m('r2'));
+ em.focusE(2, m('r3')); em.work(2, m('r3'));
+ em.focusE(null, m('same')); em.work(null, m('same'));
+ em.Pt.flash(0, m('same') + .5); pulse(sys.meet.e, m('same') + 3);
+ // again: the answer goes back in, P acts on it once more (the planes stay; only their order and colours change)
+ const PA = { a00: 0, a01: 4, a02: 1, b0: 2, a10: 1, a11: 2, a12: 1, b1: 2, a20: 3, a21: 8, a22: 1, b2: 12 };
+ const P2A = { a00: 3, a01: 8, a02: 1, b0: 12, a10: 0, a11: 4, a12: 1, b1: 2, a20: 1, a21: 2, a22: 1, b2: 2 };
+ fade(m('again') + .3, 1.6); em.to(PA, m('again') + .8, 0); em.B.flash(0, m('again') + .8); em.B.flash(1, m('again') + 1); em.B.flash(2, m('again') + 1.2);
+ prog(q => em.names(q > 0 ? ['PA', 'Pb', 'P(PA)', 'P(Pb)'] : ['A', 'b', 'PA', 'Pb']), m('again') + .8, 0, lin);
+ order([1, 2, 0], m('twice')); count('P twice', m('twice'));
+ text(p, 'not back: this P does not undo itself', 64, 860, m('twice') + 1.5, { size: 26, fill: COL.bad, weight: 600 });
+ fade(m('third') - .2, 1.6); em.to(P2A, m('third') + .3, 0);
+ prog(q => em.names(q > 0 ? ['P²A', 'P²b', 'P³A', 'P³b'] : ['PA', 'Pb', 'P(PA)', 'P(Pb)']), m('third') + .3, 0, lin);
+ order([0, 1, 2], m('third') + .3); count('three times: home', m('third') + .3);
+ say(p, ['P P P = I'], 620, 860, m('third') + 3, { size: 34, fill: COL.good });
+ }],
+
['q2', 'Your turn', () => {
const p = panel(0);
text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
@@ -286,6 +325,32 @@ const BEATS = [
text(p, 'P A: rows trade, nothing moves. A P: columns trade, x and y trade.', 70, 730, m('rows'), { size: 26, fill: COL.chalk, weight: 600 });
}],
+ ['right2', 'One more on the right', (m) => {
+ const p = panel(0);
+ text(p, 'One more: a line that stays', 60, 110, .2, { size: 40, weight: 600 });
+ const { sys, em } = two(p, { A: [[1, 1], [1, -2]], b: [4, 1] }, 'x + y = 4, x − 2y = 1', { t0: .4, side: 'right' });
+ const old = G(sys.stage, { o: 0 });
+ sys.P.line(3, 1, 1, 3, BLUE, 0, { dash: '8 9', w: 3, into: old }); sys.P.line(3, 1, 1, 0, CORAL, 0, { dash: '8 9', w: 3, into: old });
+ show(old, m('swap'), .3); tw(old, { o: .5 }, m('swap') + .4, .4);
+ [0, 1].forEach(i => em.B.flash(i, m('sys') + 1 + 2.5 * i));
+ pin(sys, 3, 1, m('sys') + 5, COL.dim);
+ emSwap(em, 0, 1, m('swap') + .6, 1.8, { cols: true });
+ prog(q => em.setName(q > 0 ? 'P₁₂' : 'I'), m('swap') + 2.4, 0, lin);
+ em.setName('I');
+ say(p, ['x + y = 4, −2x + y = 1'], 70, 470, m('eq'), { size: 34, fill: COL.chalk });
+ em.Pt.flash(0, m('eq') + .4); em.Pt.flash(1, m('eq') + 2.5);
+ const diag = sys.P.line(-6, -6, 6, 6, COL.dim, m('blue') + 2, { dash: '10 10', w: 3, into: sys.stage });
+ thick(sys, 0, m('blue') + .5); thick(sys, 0, m('blue') + 4); thick(sys, 0, m('blue') + 8.5); em.Pt.flash(0, m('blue') + 8.5); em.Pt.flash(0, m('blue') + 1.5);
+ text(p, 'x + y = 4: its numbers 1 and 1 trade, nothing changes', 70, 530, m('blue') + .5, { size: 26, fill: BLUE, weight: 600 });
+ thick(sys, 1, m('coral') + .3); tw(diag, { 'a_stroke-width': 7 }, m('coral') + 1, .4); tw(diag, { 'a_stroke-width': 3 }, m('coral') + 1.6, .5);
+ text(p, 'the coral line flips over y = x', 70, 580, m('coral') + .3, { size: 26, fill: CORAL, weight: 600 });
+ pin(sys, 1, 3, m('pt') + 1);
+ draw(path(sys.stage, `M${sys.P.PX(3) + 8} ${sys.P.PY(1) - 18}Q${sys.P.PX(3) + 14} ${sys.P.PY(3) - 14} ${sys.P.PX(1) + 22} ${sys.P.PY(3) - 6}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' }, { d: 0 }), m('pt') + .3, .8);
+ say(p, ['(3, 1) → (1, 3)'], 70, 640, m('pt') + .3, { size: 32, fill: COL.chalk });
+ say(p, ['1 + 3 = 4, −2 + 3 = 1'], 70, 710, m('check') + .3, { size: 32, fill: COL.task });
+ text(p, '✓', 470, 710, m('check') + 4, { size: 34, fill: COL.good, weight: 700 });
+ }],
+
['q3', 'Your turn', () => {
const p = panel(0);
text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
diff --git a/site/linear-algebra/index.html b/site/linear-algebra/index.html
index 3ae8feb..ace6d87 100644
--- a/site/linear-algebra/index.html
+++ b/site/linear-algebra/index.html
@@ -73,7 +73,7 @@ Contents.book({
start: { unit: 1, chapter: 1 },
units: [ // [unit title, [[chapter title, minutes], ...]]
['The Geometry of Linear Equations', [['One Equation, One Line', 10], ['Two Equations, One Point', 11], ['Crossing, Parallel or the Same Line', 10], ['Vectors: Arrows and Columns of Numbers', 9], ['Adding and Stretching Vectors', 10], ['Linear Combinations', 10], ['The Column Picture', 10], ['Matrices and Ax = b', 10], ['Matrix Times Vector, Two Ways', 10], ['A Matrix Moves the Whole Plane', 10], ['Three Unknowns: A Plane in Space', 12], ['Three Planes, One Point', 14], ['Three Columns in Space', 13], ['Can We Solve for Every b?', 10], ['More Numbers Than Axes', 9]]],
- ['Elimination with Matrices', [['Elimination: Two Equations', 12], ['Pivots and Multipliers', 10], ['Elimination: Three Equations', 11], ['Back Substitution', 11]]],
+ ['Elimination with Matrices', [['Elimination: Two Equations', 12], ['Pivots and Multipliers', 10], ['Elimination: Three Equations', 11], ['Back Substitution', 11], ['When Elimination Breaks Down', 11], ['Elimination Matrices', 11], ['Row Exchanges as Matrices', 10]]],
],
hues: ['#f4a48c', '#86c9e8', '#f3c95c', '#e8a0c8', '#8fd6b0', '#bba8ee', '#f0b45a'], // one colour per unit, cycling
});
diff --git a/site/linear-algebra/lib/elim.js b/site/linear-algebra/lib/elim.js
index 0c4dd23..0fb6b9d 100644
--- a/site/linear-algebra/lib/elim.js
+++ b/site/linear-algebra/lib/elim.js
@@ -11,6 +11,8 @@
// el.ring(0, 0, at) // a circle round an entry: the pivot
// el.diag(at); el.upper(at) // behind the numbers: the diagonal band, the upper triangle (U)
// el.opNow(2, 1) // inside a question: open "row 3 − ℓ × row 2" at once
+// el.swap(1, 2, at, dur, { label: [x, y] }) // rows 2 and 3 slide past each other (elSwap, below)
+// elim(p, sys, { noB: true }) // A alone: no divider, no b column (a matrix times a matrix)
//
// While elim is attached, move the system through el.to(next, at, dur) (or el.step, el.mult): elim keeps the plan
// that the next step starts from. Hands on: el.scrub(true) makes the open operation's multiplier a number to drag
@@ -19,12 +21,12 @@
// Loads after engine.js (and linsys.js or space3.js).
const EL_ROW = [COL.whole, COL.nat, COL.int];
-function elim(p, sys, { at: [x0, y0] = [130, 450], size = 46, cw = 96, rh = 70, t0 = .1, dens = [1], step: lStep = 1, o = 0, labelX = null } = {}) {
+function elim(p, sys, { at: [x0, y0] = [130, 450], size = 46, cw = 96, rh = 70, t0 = .1, dens = [1], step: lStep = 1, o = 0, labelX = null, noB = false } = {}) {
const n = 'a22' in sys.v ? 3 : 2, I = [...Array(n).keys()], svg = $('stage');
const keysOf = i => [...I.map(j => `a${i}${j}`), `b${i}`];
const g = G(p, { o });
show(g, t0 + .2);
- const W = n * cw + 24 + cw; // A, the divider, b
+ const W = noB ? n * cw : n * cw + 24 + cw; // A, the divider, b (A alone with noB)
const cx = j => j < n ? x0 + cw * (j + .5) : x0 + n * cw + 24 + cw / 2;
const ry = i => y0 + i * rh;
let plan = { ...sys.v };
@@ -63,8 +65,9 @@ function elim(p, sys, { at: [x0, y0] = [130, 450], size = 46, cw = 96, rh = 70,
}));
const names = G(g, {}); // "A" over the numbers in front of the letters, "b" over the right sides
T(names, 'A', { x: x0 + n * cw / 2, y: top - 16, size: 28, fill: COL.dim, font: MATH, weight: 700, anchor: 'middle' });
- T(names, 'b', { x: cx(n), y: top - 16, size: 28, fill: COL.dim, font: MATH, weight: 700, anchor: 'middle' });
+ if (!noB) T(names, 'b', { x: cx(n), y: top - 16, size: 28, fill: COL.dim, font: MATH, weight: 700, anchor: 'middle' });
put(names, { o: 0 });
+ if (noB) { put(divider, { o: 0 }); I.forEach(i => put(cells[i][n].c, { o: 0 })); }
function draw() {
const v = sys.v;
@@ -313,7 +316,7 @@ function elim(p, sys, { at: [x0, y0] = [130, 450], size = 46, cw = 96, rh = 70,
draw();
sys.onChange(draw);
- return {
+ const api = {
g, n, cells, rowG, bars, names, divider, W, cx, ry, size, rh,
get plan() { return plan; },
get l() { return lNow; },
@@ -341,7 +344,49 @@ function elim(p, sys, { at: [x0, y0] = [130, 450], size = 46, cw = 96, rh = 70,
scrub(on);
},
solve: () => sys.solve(),
+ swap: (i, j, at, dur, opts) => elSwap(api, sys, i, j, at, dur, opts),
+ };
+ return api;
+}
+
+// Swap rows i and j of an elim table and of its system, on the beat clock (or on the answer clock with { now: true },
+// inside a question). The numbers slide past each other while the row colours trade (the table's bars, the equations'
+// bars and, in 2D, the lines), then the system takes the swapped numbers. Lines and planes stay where they are: the same
+// equations in a new order. label: [x, y] writes "row i ↔ row j" there (the open operation's label goes as it comes).
+function elSwap(el, sys, i, j, at, dur = 1.4, { label = null, now = false } = {}) {
+ const n = el.n, keys = r => [...[...Array(n).keys()].map(c => `a${r}${c}`), `b${r}`];
+ const from = now ? { ...sys.v } : { ...el.plan }, next = {};
+ keys(i).forEach((k, c) => { const k2 = keys(j)[c]; next[k] = from[k2]; next[k2] = from[k]; });
+ const dy = el.ry(j) - el.ry(i);
+ const eqs = sys.eqRows ? sys.eqRows.map(r => r.g) : sys.rows || [];
+ const eqBar = g => g?.querySelector('rect');
+ const eqDy = eqs[i] && eqs[j] ? +eqBar(eqs[j]).getAttribute('y') - +eqBar(eqs[i]).getAttribute('y') : 0;
+ const lines = sys.lines?.[0]?.l ? sys.lines.map(l => l.l) : []; // 2D lines (lin3's lines are its meeting lines)
+ let lab = null;
+ if (label && !now) {
+ if (el.op_?.lab?.g.parentNode) hide(el.op_.lab.g, at - .7, .3);
+ lab = G(el.g, { x: label[0], y: label[1], o: 0 });
+ M(lab, [`row ${i + 1}`], { size: 34, fill: EL_ROW[i], anchor: 'start' });
+ M(lab, ['↔'], { x: 112, size: 34, fill: COL.chalk, anchor: 'start' });
+ M(lab, [`row ${j + 1}`], { x: 166, size: 34, fill: EL_ROW[j], anchor: 'start' });
+ show(lab, at - .4, .4);
+ }
+ const frame = q => {
+ const s = q < 1 ? q : 0, c = (a, b) => q < 1 ? mix(a, b, q) : a;
+ el.cells[i].forEach(cl => put(cl.c, { y: el.ry(i) + dy * s }));
+ el.cells[j].forEach(cl => put(cl.c, { y: el.ry(j) - dy * s }));
+ el.bars[i].setAttribute('fill', c(EL_ROW[i], EL_ROW[j])); el.bars[j].setAttribute('fill', c(EL_ROW[j], EL_ROW[i]));
+ if (eqs[i] && eqs[j]) {
+ put(eqs[i], { y: eqDy * s }); put(eqs[j], { y: -eqDy * s });
+ eqBar(eqs[i]).setAttribute('fill', c(EL_ROW[i], EL_ROW[j])); eqBar(eqs[j]).setAttribute('fill', c(EL_ROW[j], EL_ROW[i]));
+ }
+ if (lines[i] && lines[j]) { lines[i].setAttribute('stroke', c(EL_ROW[i], EL_ROW[j])); lines[j].setAttribute('stroke', c(EL_ROW[j], EL_ROW[i])); }
+ if (q >= 1 && now) el.load(next);
};
+ if (now) { fxp(frame, 0, dur); return next; }
+ prog(frame, at, dur);
+ el.to(next, at + dur, 0);
+ return lab;
}
// A question on the multiplier: the reader scrubs it (and, with only, some of the system's numbers) until test holds.
diff --git a/site/linear-algebra/lib/emat.js b/site/linear-algebra/lib/emat.js
index 75021c7..8d2e5b9 100644
--- a/site/linear-algebra/lib/emat.js
+++ b/site/linear-algebra/lib/emat.js
@@ -1,52 +1,12 @@
// Row exchanges on an elim table, and a matrix on the left (or right) of a system, shown as a product computed row by row.
//
-// elSwap(el, sys, 1, 2, at) // rows 2 and 3 of [A | b] slide past each other; the system takes the new order
+// elSwap(el, sys, 1, 2, at) // (in elim.js since 10-28; el.swap does the same) rows of [A | b] slide past each other
//
// Loads after engine.js, elim.js (and linsys.js or space3.js).
const EM_ROW = [COL.whole, COL.nat, COL.int], EM_COL = [COL.irr, COL.real, COL.rat];
-// Swap rows i and j of an elim table and of its system, on the beat clock (or on the answer clock with { now: true },
-// inside a question). The numbers slide past each other while the row colours trade (the table's bars, the equations'
-// bars and, in 2D, the lines), then the system takes the swapped numbers. Lines and planes stay where they are: the same
-// equations in a new order. label: [x, y] writes "row i ↔ row j" there.
-function elSwap(el, sys, i, j, at, dur = 1.4, { label = null, now = false } = {}) {
- const n = el.n, keys = r => [...[...Array(n).keys()].map(c => `a${r}${c}`), `b${r}`];
- const from = now ? { ...sys.v } : { ...el.plan }, next = {};
- keys(i).forEach((k, c) => { const k2 = keys(j)[c]; next[k] = from[k2]; next[k2] = from[k]; });
- const dy = el.ry(j) - el.ry(i);
- const eqs = sys.eqRows ? sys.eqRows.map(r => r.g) : sys.rows || [];
- const eqBar = g => g?.querySelector('rect');
- const eqDy = eqs[i] && eqs[j] ? +eqBar(eqs[j]).getAttribute('y') - +eqBar(eqs[i]).getAttribute('y') : 0;
- const lines = sys.lines?.[0]?.l ? sys.lines.map(l => l.l) : []; // 2D lines (lin3's lines are its meeting lines)
- let lab = null;
- if (label && !now) {
- if (el.op_?.lab?.g.parentNode) hide(el.op_.lab.g, at, .3);
- lab = G(el.g, { x: label[0], y: label[1], o: 0 });
- M(lab, [`row ${i + 1}`], { size: 34, fill: EM_ROW[i], anchor: 'start' });
- M(lab, ['↔'], { x: 112, size: 34, fill: COL.chalk, anchor: 'start' });
- M(lab, [`row ${j + 1}`], { x: 166, size: 34, fill: EM_ROW[j], anchor: 'start' });
- show(lab, at - .6, .4);
- }
- const frame = q => {
- const s = q < 1 ? q : 0, c = (a, b) => q < 1 ? mix(a, b, q) : a;
- el.cells[i].forEach(cl => put(cl.c, { y: el.ry(i) + dy * s }));
- el.cells[j].forEach(cl => put(cl.c, { y: el.ry(j) - dy * s }));
- el.bars[i].setAttribute('fill', c(EM_ROW[i], EM_ROW[j])); el.bars[j].setAttribute('fill', c(EM_ROW[j], EM_ROW[i]));
- if (eqs[i] && eqs[j]) {
- put(eqs[i], { y: eqDy * s }); put(eqs[j], { y: -eqDy * s });
- eqBar(eqs[i]).setAttribute('fill', c(EM_ROW[i], EM_ROW[j])); eqBar(eqs[j]).setAttribute('fill', c(EM_ROW[j], EM_ROW[i]));
- }
- if (lines[i] && lines[j]) { lines[i].setAttribute('stroke', c(EM_ROW[i], EM_ROW[j])); lines[j].setAttribute('stroke', c(EM_ROW[j], EM_ROW[i])); }
- if (q >= 1 && now) el.load(next);
- };
- if (now) { fxp(frame, 0, dur); return next; }
- prog(frame, at, dur);
- el.to(next, at + dur, 0);
- return lab;
-}
-
/* ---------- a matrix times [A | b], computed row by row ---------- */
-// emat draws E · [A | b] = [EA | Eb] (side 'left') or A · P = AP with b kept (side 'right'), in one line from `at`.
+// emat draws E · [A | b] = [EA | Eb] (side 'left') or A · P = [AP | b] (side 'right': A first, then P), in one line from `at`.
// The product is the system sys (a linsys or lin3) shows: change a number of E, or of A and b, and the product, the
// lines or planes and the working all follow. E's numbers are drawn here; [A | b] and the product are elim tables
// (read-only uses of elim.js), so their rings, flashes and working rows are elim's.
@@ -77,11 +37,15 @@ function emat(p, sys, { A, b, E = null, at: [x0, y0] = [70, 270], size = 40, cw
const key = ps => ps.map(q => typeof q === 'string' ? q : q.f.join('/')).join('');
/* ---------- E ---------- */
- const ex = x0 + 30, ecx = j => ex + ecw * (j + .5), ry = i => y0 + i * rh;
+ // left: E, then [A | b]; right: A alone, then P (whose row bars are hidden: on the right P mixes columns)
+ const right = side === 'right', BW = right || noB ? n * cw : n * cw + 24 + cw, EW0 = n * ecw;
+ const bx = right ? x0 + 52 : x0 + 30 + EW0 + gap + 16;
+ const ex = right ? bx + BW + gap : x0 + 30, ecx = j => ex + ecw * (j + .5), ry = i => y0 + i * rh;
const top = y0 - size * .95, bot = y0 + (n - 1) * rh + size * .35, EW = n * ecw;
const Eg = G(g, {});
path(Eg, `M${ex - 2} ${top}H${ex - 14}V${bot}H${ex - 2}M${ex + EW + 2} ${top}H${ex + EW + 14}V${bot}H${ex + EW + 2}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' });
const Ebars = I.map(i => mk('rect', { x: ex - 34, y: ry(i) - size * .7, width: 7, height: size * .8, rx: 3.5, fill: EM_ROW[i] }, Eg));
+ if (right) Ebars.forEach(e => put(e, { o: 0 }));
const Ename = G(Eg, {});
const setName = nm => { Ename.replaceChildren(); M(Ename, [].concat(nm), { x: ex + EW / 2, y: top - 16, size: 28, fill: COL.dim, anchor: 'middle' }); };
setName(name);
@@ -97,19 +61,17 @@ function emat(p, sys, { A, b, E = null, at: [x0, y0] = [70, 270], size = 40, cw
}));
/* ---------- [A | b] (a bare system drawn by elim) and the product ---------- */
- const bx = ex + EW + gap + 16;
const base = { v: {}, fs: [], set(to) { Object.assign(this.v, to); this.fs.forEach(f => f(this.v)); }, onChange(f) { this.fs.push(f); }, to() {}, solve: () => ({}), live() {} };
I.forEach(i => { I.forEach(j => { base.v[`a${i}${j}`] = s[`a${i}${j}`]; }); base.v[`b${i}`] = s[`b${i}`]; });
- const B = elim(g, base, { at: [bx, y0], size, cw, rh, t0: -1, dens });
- const px = bx + B.W + 120;
- const eqSign = M(g, ['='], { x: bx + B.W + 42, y: y0 + (n - 1) * rh / 2 + 12, size: size * 1.1, fill: COL.chalk, anchor: 'middle' });
- const Pt = elim(g, sys, { at: [px, y0], size, cw, rh, t0: -1, dens });
+ const B = elim(g, base, { at: [bx, y0], size, cw, rh, t0: -1, dens, noB: right || noB });
+ const last = right ? ex + EW : bx + B.W, px = last + 120;
+ const eqSign = M(g, ['='], { x: last + 42, y: y0 + (n - 1) * rh / 2 + 12, size: size * 1.1, fill: COL.chalk, anchor: 'middle' });
+ const Pt = elim(g, sys, { at: [px, y0], size, cw, rh, t0: -1, dens, noB });
const label = (el, a, bb) => { el.names.replaceChildren(); [[a, el.cx(0) + (el.cx(n - 1) - el.cx(0)) / 2], [bb, el.cx(n)]].forEach(([t, x]) => { if (t) M(el.names, [t], { x, y: top - 16, size: 28, fill: COL.dim, anchor: 'middle' }); }); };
// names: [over A, over b, over the product's A part, over its b part]; noB hides the b columns (a matrix times a matrix)
- const nm = names || (side === 'right' ? ['A', '', 'AP', 'b'] : ['A', 'b', 'EA', 'Eb']);
+ let nm = names || (side === 'right' ? ['A', '', 'AP', 'b'] : ['A', 'b', 'EA', 'Eb']);
+ const relabel = to => { nm = to; label(B, nm[0], nm[1]); label(Pt, nm[2], nm[3]); workKey = ''; drawWork(); };
label(B, nm[0], nm[1]); label(Pt, nm[2], nm[3]);
- if (side === 'right' || noB) { I.forEach(i => put(B.cells[i][n].c, { o: 0 })); put(B.divider, { o: 0 }); }
- if (noB) { I.forEach(i => put(Pt.cells[i][n].c, { o: 0 })); put(Pt.divider, { o: 0 }); }
put(B.names, { o: 1 }); put(Pt.names, { o: 1 });
const prod = v => {
@@ -236,7 +198,7 @@ function emat(p, sys, { A, b, E = null, at: [x0, y0] = [70, 270], size = 40, cw
draw();
const api = {
- g, n, side, Eg, ecells, Ebars, B, Pt, eqSign, W, ecx, ry, bx, px, setName,
+ g, n, side, Eg, ecells, Ebars, B, Pt, eqSign, W, ecx, ry, bx, px, setName, names: relabel,
get plan() { return plan; },
// Move numbers of E (e..) and of [A | b] (a.., b..) over dur seconds on the beat clock; product and picture follow.
to(next, at, dur = 1.4, ease = io) {
@@ -286,9 +248,14 @@ const emTask = (em, test, why, hint, reveal, { only = null } = {}) => (body, api
// rows slide past each other while the product's row colours (and a linsys's lines) trade; then E takes the swapped
// rows. { cols: true } swaps E's columns instead; on the right (side 'right') the product's columns slide past each
// other, and the picture jumps to the swapped system at the end. sys: the linsys whose line colours should trade.
-function emSwap(em, i, j, at, dur = 1.4, { cols = false, sys = null } = {}) {
+// { base: true } swaps rows i and j of [A | b] instead (E stays): its rows and the product's slide, as when the answer
+// PA is put back in to be multiplied again.
+function emSwap(em, i, j, at, dur = 1.4, { cols = false, sys = null, base = false } = {}) {
const n = em.n, I = [...Array(n).keys()], E = em.plan, next = {};
- I.forEach(r => I.forEach(c => {
+ if (base) {
+ const ks = r => [...I.map(c => `a${r}${c}`), `b${r}`];
+ ks(i).forEach((k, c) => { next[k] = E[ks(j)[c]]; next[ks(j)[c]] = E[k]; });
+ } else I.forEach(r => I.forEach(c => {
const [r2, c2] = cols ? [r, c === i ? j : c === j ? i : c] : [r === i ? j : r === j ? i : r, c];
next[`e${r}${c}`] = E[`e${r2}${c2}`];
}));
@@ -297,8 +264,8 @@ function emSwap(em, i, j, at, dur = 1.4, { cols = false, sys = null } = {}) {
prog(q => {
const s = q < 1 ? q : 0, c = (a, b) => q < 1 ? mix(a, b, q) : a;
if (rowsMove) {
- const dy = em.ry(j) - em.ry(i);
- em.ecells[i].forEach(cl => put(cl.c, { y: em.ry(i) + dy * s })); em.ecells[j].forEach(cl => put(cl.c, { y: em.ry(j) - dy * s }));
+ const dy = em.ry(j) - em.ry(i), moving = base ? em.B.cells : em.ecells;
+ moving[i].forEach(cl => put(cl.c, { y: em.ry(i) + dy * s })); moving[j].forEach(cl => put(cl.c, { y: em.ry(j) - dy * s }));
if (!right) {
Pt.cells[i].forEach(cl => put(cl.c, { y: Pt.ry(i) + dy * s })); Pt.cells[j].forEach(cl => put(cl.c, { y: Pt.ry(j) - dy * s }));
Pt.bars[i].setAttribute('fill', c(EM_ROW[i], EM_ROW[j])); Pt.bars[j].setAttribute('fill', c(EM_ROW[j], EM_ROW[i]));