Skip to content

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

wip(linear-algebra): chapters 2-6, 8-9, 11-12 in progress; vecs.js, grid2.js

yzr7e54b09d79ce
diff --git a/site/linear-algebra/ch02/audio/en/between.mp3 b/site/linear-algebra/ch02/audio/en/between.mp3
new file mode 100644
index 0000000..84917ee
Binary files /dev/null and b/site/linear-algebra/ch02/audio/en/between.mp3 differ
diff --git a/site/linear-algebra/ch02/audio/en/between2.mp3 b/site/linear-algebra/ch02/audio/en/between2.mp3
new file mode 100644
index 0000000..2293268
Binary files /dev/null and b/site/linear-algebra/ch02/audio/en/between2.mp3 differ
diff --git a/site/linear-algebra/ch02/audio/en/check.mp3 b/site/linear-algebra/ch02/audio/en/check.mp3
new file mode 100644
index 0000000..cda021c
Binary files /dev/null and b/site/linear-algebra/ch02/audio/en/check.mp3 differ
diff --git a/site/linear-algebra/ch02/audio/en/final1.mp3 b/site/linear-algebra/ch02/audio/en/final1.mp3
new file mode 100644
index 0000000..8c6e5d1
Binary files /dev/null and b/site/linear-algebra/ch02/audio/en/final1.mp3 differ
diff --git a/site/linear-algebra/ch02/audio/en/final2.mp3 b/site/linear-algebra/ch02/audio/en/final2.mp3
new file mode 100644
index 0000000..5b20634
Binary files /dev/null and b/site/linear-algebra/ch02/audio/en/final2.mp3 differ
diff --git a/site/linear-algebra/ch02/audio/en/final3.mp3 b/site/linear-algebra/ch02/audio/en/final3.mp3
new file mode 100644
index 0000000..0dab168
Binary files /dev/null and b/site/linear-algebra/ch02/audio/en/final3.mp3 differ
diff --git a/site/linear-algebra/ch02/audio/en/final4.mp3 b/site/linear-algebra/ch02/audio/en/final4.mp3
new file mode 100644
index 0000000..8484c26
Binary files /dev/null and b/site/linear-algebra/ch02/audio/en/final4.mp3 differ
diff --git a/site/linear-algebra/ch02/audio/en/finish.mp3 b/site/linear-algebra/ch02/audio/en/finish.mp3
new file mode 100644
index 0000000..6f99fa8
Binary files /dev/null and b/site/linear-algebra/ch02/audio/en/finish.mp3 differ
diff --git a/site/linear-algebra/ch02/audio/en/intro.mp3 b/site/linear-algebra/ch02/audio/en/intro.mp3
new file mode 100644
index 0000000..ed07386
Binary files /dev/null and b/site/linear-algebra/ch02/audio/en/intro.mp3 differ
diff --git a/site/linear-algebra/ch02/audio/en/q1.mp3 b/site/linear-algebra/ch02/audio/en/q1.mp3
new file mode 100644
index 0000000..1f5edb5
Binary files /dev/null and b/site/linear-algebra/ch02/audio/en/q1.mp3 differ
diff --git a/site/linear-algebra/ch02/audio/en/q2.mp3 b/site/linear-algebra/ch02/audio/en/q2.mp3
new file mode 100644
index 0000000..a105a78
Binary files /dev/null and b/site/linear-algebra/ch02/audio/en/q2.mp3 differ
diff --git a/site/linear-algebra/ch02/audio/en/q3.mp3 b/site/linear-algebra/ch02/audio/en/q3.mp3
new file mode 100644
index 0000000..130daa8
Binary files /dev/null and b/site/linear-algebra/ch02/audio/en/q3.mp3 differ
diff --git a/site/linear-algebra/ch02/audio/en/riddle.mp3 b/site/linear-algebra/ch02/audio/en/riddle.mp3
new file mode 100644
index 0000000..19163f2
Binary files /dev/null and b/site/linear-algebra/ch02/audio/en/riddle.mp3 differ
diff --git a/site/linear-algebra/ch02/audio/en/riddle2.mp3 b/site/linear-algebra/ch02/audio/en/riddle2.mp3
new file mode 100644
index 0000000..5c01280
Binary files /dev/null and b/site/linear-algebra/ch02/audio/en/riddle2.mp3 differ
diff --git a/site/linear-algebra/ch02/audio/en/rowpic.mp3 b/site/linear-algebra/ch02/audio/en/rowpic.mp3
new file mode 100644
index 0000000..0af9198
Binary files /dev/null and b/site/linear-algebra/ch02/audio/en/rowpic.mp3 differ
diff --git a/site/linear-algebra/ch02/audio/en/slide.mp3 b/site/linear-algebra/ch02/audio/en/slide.mp3
new file mode 100644
index 0000000..7b40977
Binary files /dev/null and b/site/linear-algebra/ch02/audio/en/slide.mp3 differ
diff --git a/site/linear-algebra/ch02/audio/en/timings.js b/site/linear-algebra/ch02/audio/en/timings.js
new file mode 100644
index 0000000..0ca1934
--- /dev/null
+++ b/site/linear-algebra/ch02/audio/en/timings.js
@@ -0,0 +1,834 @@
+window.TIMINGS = {
+ "intro": {
+ "dur": 10.848,
+ "marks": {
+ "sub": 3.203,
+ "cross": 8.164
+ },
+ "cues": [
+ [
+ 0.104,
+ "Chapter two."
+ ],
+ [
+ 1.211,
+ "Two equations, one point."
+ ],
+ [
+ 3.203,
+ "Last time, one equation was one line."
+ ],
+ [
+ 5.964,
+ "Today we take two equations at once, and find the one point their lines share."
+ ]
+ ]
+ },
+ "riddle": {
+ "dur": 60.144,
+ "marks": {
+ "add": 2.917,
+ "sub": 5.221,
+ "name": 8.242,
+ "and": 13.984,
+ "both": 16.068,
+ "try": 22.995,
+ "p1": 26.003,
+ "p2": 27.07,
+ "p3": 28.424,
+ "p4": 29.857,
+ "test": 34.401,
+ "t1": 36.758,
+ "t2": 40.417,
+ "t3": 43.958,
+ "t4": 47.135,
+ "win": 50.0
+ },
+ "cues": [
+ [
+ 0.117,
+ "Here's a riddle."
+ ],
+ [
+ 1.081,
+ "I'm thinking of two numbers."
+ ],
+ [
+ 2.917,
+ "When I add them, I get five."
+ ],
+ [
+ 5.221,
+ "When I take the second away from the first, I get one."
+ ],
+ [
+ 8.242,
+ "Call the numbers x and y."
+ ],
+ [
+ 10.221,
+ "The riddle says two things: x plus y equals five, and x minus y equals one."
+ ],
+ [
+ 16.068,
+ "Both must be true at the same time."
+ ],
+ [
+ 18.268,
+ "Equations that must all hold together are called a system of equations."
+ ],
+ [
+ 22.995,
+ "Let's hunt."
+ ],
+ [
+ 23.906,
+ "Here are pairs that add up to five: one and four, two and three, three and two, four and one."
+ ],
+ [
+ 31.237,
+ "Every one of them passes the first equation."
+ ],
+ [
+ 34.401,
+ "Now test each one in the second."
+ ],
+ [
+ 36.758,
+ "One minus four is negative three."
+ ],
+ [
+ 39.479,
+ "Not one."
+ ],
+ [
+ 40.417,
+ "Two minus three is negative one."
+ ],
+ [
+ 42.956,
+ "Not one."
+ ],
+ [
+ 43.958,
+ "Three minus two is one."
+ ],
+ [
+ 46.172,
+ "Yes!"
+ ],
+ [
+ 47.135,
+ "Four minus one is three."
+ ],
+ [
+ 49.271,
+ "No."
+ ],
+ [
+ 50.0,
+ "Only three, two passes both."
+ ],
+ [
+ 52.435,
+ "So x equals three, y equals two is the solution of the system: the pair that makes both equations true."
+ ]
+ ]
+ },
+ "check": {
+ "dur": 55.152,
+ "marks": {
+ "eq": 1.484,
+ "into": 8.359,
+ "a": 10.56,
+ "a1": 11.992,
+ "a2": 17.904,
+ "ano": 23.451,
+ "b": 27.865,
+ "b1": 29.583,
+ "bno": 35.911,
+ "b2": 41.641,
+ "c": 44.31,
+ "c1": 45.56,
+ "c2": 47.812,
+ "cok": 50.768
+ },
+ "cues": [
+ [
+ 0.117,
+ "Here's another system."
+ ],
+ [
+ 1.484,
+ "Two x minus y equals zero, and negative x plus two y equals three."
+ ],
+ [
+ 7.292,
+ "To check a pair, put it into both equations."
+ ],
+ [
+ 10.56,
+ "Try two, four."
+ ],
+ [
+ 11.992,
+ "First equation: two times two, minus four, is zero."
+ ],
+ [
+ 16.875,
+ "It works."
+ ],
+ [
+ 17.904,
+ "Second: negative two, plus two times four, is six."
+ ],
+ [
+ 22.396,
+ "Not three."
+ ],
+ [
+ 23.451,
+ "So two, four solves the first equation, but not the system."
+ ],
+ [
+ 27.865,
+ "Try negative one, one."
+ ],
+ [
+ 29.583,
+ "First: two times negative one, minus one, is negative three."
+ ],
+ [
+ 34.675,
+ "Not zero."
+ ],
+ [
+ 35.911,
+ "One failed equation is enough: it's not a solution, even though the second equation does work, because one plus two is three."
+ ],
+ [
+ 44.31,
+ "Try one, two."
+ ],
+ [
+ 45.56,
+ "Two minus two is zero."
+ ],
+ [
+ 47.812,
+ "Negative one plus four is three."
+ ],
+ [
+ 50.768,
+ "Both work."
+ ],
+ [
+ 51.849,
+ "One, two is the solution of this system."
+ ]
+ ]
+ },
+ "q1": {
+ "dur": 3.936,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.107,
+ "Which equations does each pair pass?"
+ ]
+ ]
+ },
+ "rowpic": {
+ "dur": 75.408,
+ "marks": {
+ "blue": 1.315,
+ "o": 10.807,
+ "p": 15.26,
+ "l1": 21.966,
+ "coral": 26.901,
+ "q1": 31.172,
+ "frac": 37.565,
+ "q2": 41.953,
+ "l2": 49.245,
+ "meet": 57.253,
+ "on": 60.117,
+ "read": 64.01,
+ "same": 65.651,
+ "name": 67.552
+ },
+ "cues": [
+ [
+ 0.104,
+ "Now let's draw it."
+ ],
+ [
+ 1.315,
+ "Each equation is a line, just as in chapter one."
+ ],
+ [
+ 4.74,
+ "The first one, two x minus y equals zero, is the line from the end of chapter one."
+ ],
+ [
+ 10.807,
+ "Its right side is zero, so it passes through zero, zero."
+ ],
+ [
+ 15.26,
+ "And x equals one gives two minus y equals zero, so y is two: the point one, two."
+ ],
+ [
+ 21.966,
+ "Connect them: the blue line."
+ ],
+ [
+ 24.036,
+ "Every point on it solves the first equation."
+ ],
+ [
+ 26.901,
+ "Now the second: negative x plus two y equals three."
+ ],
+ [
+ 31.172,
+ "Set y to zero: negative x equals three, so x is negative three."
+ ],
+ [
+ 37.565,
+ "Setting x to zero would give a fraction, so let's pick an easier x: three."
+ ],
+ [
+ 42.917,
+ "Negative three plus two y equals three, so two y is six, and y is three."
+ ],
+ [
+ 49.245,
+ "Connect negative three, zero and three, three: the coral line."
+ ],
+ [
+ 54.401,
+ "Every point on it solves the second equation."
+ ],
+ [
+ 57.253,
+ "The two lines cross at exactly one point."
+ ],
+ [
+ 60.117,
+ "That point is on both lines, so it solves both equations."
+ ],
+ [
+ 64.01,
+ "Read it off: one, two."
+ ],
+ [
+ 65.651,
+ "The same pair we found by checking."
+ ],
+ [
+ 67.552,
+ "Drawing each equation as a line and looking for the crossing is called the row picture: one line for each row of the system."
+ ]
+ ]
+ },
+ "riddle2": {
+ "dur": 35.448,
+ "marks": {
+ "eq": 1.562,
+ "a": 4.336,
+ "l1": 7.487,
+ "eq2": 8.828,
+ "b": 11.107,
+ "b2": 13.867,
+ "l2": 19.128,
+ "meet": 20.521,
+ "miss": 24.531,
+ "blue": 29.531,
+ "off": 31.146,
+ "sum": 33.529
+ },
+ "cues": [
+ [
+ 0.104,
+ "Let's draw the riddle too."
+ ],
+ [
+ 1.562,
+ "x plus y equals five crosses the axes at five, zero and zero, five."
+ ],
+ [
+ 7.487,
+ "That's the blue line."
+ ],
+ [
+ 8.828,
+ "x minus y equals one: y zero gives x equals one."
+ ],
+ [
+ 13.867,
+ "x zero gives negative y equals one, so y is negative one."
+ ],
+ [
+ 19.128,
+ "That's the coral line."
+ ],
+ [
+ 20.521,
+ "They cross at three, two: the answer to the riddle."
+ ],
+ [
+ 24.531,
+ "And the pairs that failed?"
+ ],
+ [
+ 26.081,
+ "One, four; two, three; four, one."
+ ],
+ [
+ 29.531,
+ "They're all on the blue line, but not one of them is on the coral line."
+ ],
+ [
+ 33.529,
+ "Only the crossing is on both."
+ ]
+ ]
+ },
+ "q2": {
+ "dur": 4.008,
+ "marks": {},
+ "cues": [
+ [
+ 0.091,
+ "Quick check."
+ ],
+ [
+ 1.094,
+ "Click the point that solves both equations."
+ ]
+ ]
+ },
+ "between": {
+ "dur": 41.784,
+ "marks": {
+ "eq": 2.63,
+ "draw": 6.927,
+ "meet": 8.451,
+ "x": 10.872,
+ "y": 15.547,
+ "guess": 20.508,
+ "c1": 24.492,
+ "c2": 28.164,
+ "ok": 32.057,
+ "lesson": 36.458
+ },
+ "cues": [
+ [
+ 0.104,
+ "Not every crossing lands on the grid."
+ ],
+ [
+ 2.63,
+ "Take x plus y equals two, and x minus y equals one."
+ ],
+ [
+ 6.927,
+ "Draw both lines."
+ ],
+ [
+ 8.451,
+ "They cross here, between the grid lines."
+ ],
+ [
+ 10.872,
+ "x is between one and two, about halfway: maybe one and a half."
+ ],
+ [
+ 15.547,
+ "y is between zero and one, about halfway: maybe one half."
+ ],
+ [
+ 20.508,
+ "A picture can only say about."
+ ],
+ [
+ 22.487,
+ "So let's check the guess exactly."
+ ],
+ [
+ 24.492,
+ "Three halves plus one half is four halves, and that's two."
+ ],
+ [
+ 28.164,
+ "Three halves minus one half is two halves, and that's one."
+ ],
+ [
+ 32.057,
+ "Both exactly right."
+ ],
+ [
+ 33.555,
+ "The crossing is three halves, one half."
+ ],
+ [
+ 36.458,
+ "The picture tells us where to look."
+ ],
+ [
+ 38.398,
+ "Putting the numbers back into the equations proves it."
+ ]
+ ]
+ },
+ "between2": {
+ "dur": 46.488,
+ "marks": {
+ "eq": 3.203,
+ "meet": 7.865,
+ "guess": 11.25,
+ "c1": 14.362,
+ "no": 22.565,
+ "read": 26.966,
+ "c2": 34.557,
+ "c3": 41.081,
+ "ok": 45.469
+ },
+ "cues": [
+ [
+ 0.104,
+ "Sometimes the guess is close but not exact."
+ ],
+ [
+ 3.203,
+ "Two x plus y equals three, and x minus y equals one."
+ ],
+ [
+ 7.865,
+ "They cross a little past one, a little above zero."
+ ],
+ [
+ 11.25,
+ "Guess one point three, zero point three."
+ ],
+ [
+ 14.362,
+ "Check the first equation: two times one point three is two point six, plus zero point three is two point nine."
+ ],
+ [
+ 22.565,
+ "Close, but not three."
+ ],
+ [
+ 24.44,
+ "So the guess is near the point, not on it."
+ ],
+ [
+ 26.966,
+ "The exact crossing is four thirds, one third."
+ ],
+ [
+ 30.456,
+ "You'll learn how to find numbers like these later in the book."
+ ],
+ [
+ 33.242,
+ "For now, let's check it."
+ ],
+ [
+ 34.557,
+ "Two times four thirds is eight thirds, plus one third is nine thirds: three."
+ ],
+ [
+ 41.081,
+ "Four thirds minus one third is three thirds: one."
+ ],
+ [
+ 45.469,
+ "Exact."
+ ]
+ ]
+ },
+ "slide": {
+ "dur": 62.304,
+ "marks": {
+ "sys": 2.188,
+ "b1": 9.831,
+ "slides": 13.307,
+ "along": 19.57,
+ "new": 24.987,
+ "rem": 27.24,
+ "back": 38.229,
+ "b0": 39.609,
+ "slides2": 43.568,
+ "new2": 48.711,
+ "chk": 50.378,
+ "rule": 56.562
+ },
+ "cues": [
+ [
+ 0.104,
+ "Now let's make the picture move."
+ ],
+ [
+ 2.188,
+ "Back to two x minus y equals zero, and negative x plus two y equals three, meeting at one, two."
+ ],
+ [
+ 9.831,
+ "Change the second right side from three to six."
+ ],
+ [
+ 13.307,
+ "Only the coral line moves."
+ ],
+ [
+ 15.195,
+ "It slides, just as in chapter one, and the blue line stays put."
+ ],
+ [
+ 19.57,
+ "Watch the meeting point: it travels along the blue line, because it has to stay on the blue line."
+ ],
+ [
+ 24.987,
+ "Now they meet at two, four."
+ ],
+ [
+ 27.24,
+ "Remember two, four?"
+ ],
+ [
+ 29.102,
+ "It solved the first equation but not the second."
+ ],
+ [
+ 32.37,
+ "With the new right side, negative two plus eight is six: now it solves both."
+ ],
+ [
+ 38.229,
+ "Put the three back."
+ ],
+ [
+ 39.609,
+ "This time change the first right side, from zero to three."
+ ],
+ [
+ 43.568,
+ "Now the blue line slides, and the meeting point travels along the coral line, to three, three."
+ ],
+ [
+ 50.378,
+ "Check: six minus three is three, and negative three plus six is three."
+ ],
+ [
+ 56.562,
+ "Change one right side: that line slides, and the meeting point slides along the other line."
+ ]
+ ]
+ },
+ "turn": {
+ "dur": 58.824,
+ "marks": {
+ "a": 2.982,
+ "turns": 5.43,
+ "along": 15.026,
+ "new": 19.062,
+ "chk": 20.703,
+ "ex2": 27.148,
+ "c": 33.034,
+ "turns2": 36.289,
+ "along2": 44.505,
+ "new2": 47.057,
+ "chk2": 50.052,
+ "rule": 54.479
+ },
+ "cues": [
+ [
+ 0.104,
+ "What if we change a number in front of x or y?"
+ ],
+ [
+ 2.982,
+ "Change two x into one x."
+ ],
+ [
+ 5.43,
+ "The blue line turns."
+ ],
+ [
+ 7.24,
+ "It turns about zero, zero, because the right side is still zero, and zero, zero always gives zero."
+ ],
+ [
+ 15.026,
+ "The meeting point slides along the coral line, the one that didn't move, to three, three."
+ ],
+ [
+ 20.703,
+ "Check: three minus three is zero, and negative three plus six is three."
+ ],
+ [
+ 27.148,
+ "One more, on the riddle: x plus y equals five, and x minus y equals one."
+ ],
+ [
+ 33.034,
+ "Change x minus y into two x minus y."
+ ],
+ [
+ 36.289,
+ "The coral line turns about the point zero, negative one: there x is zero, so the number in front of x makes no difference."
+ ],
+ [
+ 44.505,
+ "The meeting point slides along the blue line, from three, two to two, three."
+ ],
+ [
+ 50.052,
+ "Two plus three is five."
+ ],
+ [
+ 52.266,
+ "Four minus three is one."
+ ],
+ [
+ 54.479,
+ "Whichever line moves, the meeting point stays on the line that doesn't."
+ ]
+ ]
+ },
+ "q3": {
+ "dur": 6.432,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn."
+ ],
+ [
+ 1.029,
+ "Change only the right sides, or drag the lines, until they meet at the ring."
+ ]
+ ]
+ },
+ "wrap": {
+ "dur": 23.928,
+ "marks": {
+ "w1": 0.977,
+ "w2": 5.286,
+ "w3": 12.083,
+ "w4": 18.073,
+ "end": 21.927
+ },
+ "cues": [
+ [
+ 0.104,
+ "To sum up."
+ ],
+ [
+ 0.977,
+ "A system is a set of equations that must all be true at once."
+ ],
+ [
+ 5.286,
+ "A pair solves the system only if it passes every equation."
+ ],
+ [
+ 9.57,
+ "One failure is enough to reject it."
+ ],
+ [
+ 12.083,
+ "In the row picture each equation is a line, and the solution is where the lines cross."
+ ],
+ [
+ 18.073,
+ "The picture shows where to look."
+ ],
+ [
+ 19.857,
+ "Putting the numbers back in proves it."
+ ],
+ [
+ 21.927,
+ "Now try the chapter practice."
+ ]
+ ]
+ },
+ "final1": {
+ "dur": 4.032,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Chapter practice."
+ ],
+ [
+ 1.536,
+ "Does the pair solve the whole system?"
+ ]
+ ]
+ },
+ "final2": {
+ "dur": 2.784,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Next, find where the lines cross."
+ ]
+ ]
+ },
+ "final3": {
+ "dur": 3.624,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Now choose the right sides that make a pair the solution."
+ ]
+ ]
+ },
+ "final4": {
+ "dur": 3.576,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Last set."
+ ],
+ [
+ 1.198,
+ "Make the lines meet with your hands."
+ ]
+ ]
+ },
+ "finish": {
+ "dur": 12.312,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Well done."
+ ],
+ [
+ 1.081,
+ "That's the end of chapter two, two equations, one point."
+ ],
+ [
+ 4.974,
+ "Next: two lines don't always cross at one point."
+ ],
+ [
+ 8.346,
+ "They can miss each other completely, or lie on top of each other."
+ ]
+ ]
+ }
+};
diff --git a/site/linear-algebra/ch02/audio/en/turn.mp3 b/site/linear-algebra/ch02/audio/en/turn.mp3
new file mode 100644
index 0000000..7ef94a4
Binary files /dev/null and b/site/linear-algebra/ch02/audio/en/turn.mp3 differ
diff --git a/site/linear-algebra/ch02/audio/en/wrap.mp3 b/site/linear-algebra/ch02/audio/en/wrap.mp3
new file mode 100644
index 0000000..c5fbee9
Binary files /dev/null and b/site/linear-algebra/ch02/audio/en/wrap.mp3 differ
diff --git a/site/linear-algebra/ch02/index.html b/site/linear-algebra/ch02/index.html
new file mode 100644
index 0000000..5aaab7c
--- /dev/null
+++ b/site/linear-algebra/ch02/index.html
@@ -0,0 +1,496 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>Two Equations, One Point</title>
+<link rel="stylesheet" href="../lib/engine.css">
+<link rel="expect" href="#bar" blocking="render"><!-- hold the first frame until the player exists, so the page transition can run -->
+</head>
+<body>
+<script src="../lib/engine.js"></script>
+<script src="../lib/math.js"></script>
+<script src="../lib/linsys.js"></script>
+<script src="audio/en/timings.js"></script>
+<script>
+'use strict';
+const CHAPTER = { number: 2, title: 'Two Equations, One Point', minutes: 11, language: 'en' };
+
+/* ---------- chapter drawing helpers (the same as chapter 1's) ---------- */
+const BLUE = LS_ROW[0], CORAL = LS_ROW[1]; // first equation and its line, second equation and its line
+const CARD = { x: 40, y: 345, w: 720, cls: 'side' }; // question card under the two equations, beside the plane
+const RCARD = { x: 790, y: 150, w: 770, cls: 'side' }; // question card on the right when the plane is not needed
+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 flash = (sys, key, t0) => sys.num(key).forEach(e => { tw(e, { c_fill: COL.task }, t0, .25); tw(e, { c_fill: COL.chalk }, t0 + 1.2, .6); });
+const pairStr = (x, y) => `(${num(x)}, ${num(y)})`;
+const drop = (sys, x, y, t0, color = COL.chalk, label = pairStr(x, y), dx = 16, dy = -16, into) => sys.P.dot(x, y, color, t0, { label, dx, dy, into });
+const okMark = (p, ok, x, y, t0, size = 34) => text(p, ok ? '✓' : '✗', x, y, t0, { size, fill: ok ? COL.good : COL.bad, weight: 700, anchor: 'middle' });
+// Two equations a·x + b·y = c in the top left, the plane on the right. Options hide the lines, the meeting point
+// and the x = …, y = … readout until a beat shows them.
+const twoLines = (p, A, b, { t0 = .1, lines = true, meet = true, readout = true, hidePlane = false } = {}) => {
+ const sys = linsys(p, { A, b, eq: [90, 200], mat: null, t0, hidePlane });
+ if (!lines) sys.lines.forEach(({ l }) => put(l, { o: 0 }));
+ if (!meet) put(sys.meetBox, { o: 0 });
+ if (!readout) put(sys.readout, { o: 0 });
+ return sys;
+};
+// A dashed guide from a point straight down (or across) to an axis.
+const guide = (sys, x, y, toAxis, t0, into) => {
+ const { PX, PY } = sys.P, d = toAxis === 'x' ? `M${PX(x)} ${PY(y)}V${PY(0)}` : `M${PX(x)} ${PY(y)}H${PX(0)}`;
+ const g = path(into, d, { stroke: COL.task, 'stroke-width': 2.5, 'stroke-dasharray': '6 7', fill: 'none' }, { o: 0 });
+ show(g, t0, .4);
+ return g;
+};
+// A dashed amber ring: the target a hands-on question asks for.
+const ring = (sys, x, y, into, label = pairStr(x, y)) => {
+ const g = G(into, { x: sys.P.PX(x), y: sys.P.PY(y) });
+ mk('circle', { r: 17, fill: 'none', stroke: COL.task, 'stroke-width': 3.5, 'stroke-dasharray': '5 5' }, g);
+ M(g, [label], { x: 22, y: 30, size: 26, fill: COL.task });
+ return g;
+};
+// Which equations of a 2 × 2 system does (x, y) pass? [first, second]
+const near = (s, x, y) => s.x !== undefined && Math.abs(s.x - x) < 1e-9 && Math.abs(s.y - y) < 1e-9;
+const passes = (A, b, x, y) => [0, 1].map(i => A[i][0] * x + A[i][1] * y === b[i]);
+const eqStr = (a, bb, c) => {
+ const t = (k, s) => (k === 1 ? '' : k === -1 ? '−' : num(k)) + s;
+ const L = a === 0 ? t(bb, 'y') : bb === 0 ? t(a, 'x') : `${t(a, 'x')} ${bb < 0 ? '−' : '+'} ${t(Math.abs(bb), 'y')}`;
+ return `${L} = ${num(c)}`;
+};
+
+/* ---------- practice data ---------- */
+const BOTHQ = [
+ { pair: [4, 2], ans: ['b'], why: '4 + 2 = 6 ✓ and 4 − 2 = 2 ✓: it passes both, so it is the solution.' },
+ { pair: [1, 5], ans: ['o'], why: '1 + 5 = 6 ✓, but 1 − 5 = −4, not 2 ✗. Only the first.' },
+ { pair: [3, 1], ans: ['o'], why: '3 + 1 = 4, not 6 ✗; 3 − 1 = 2 ✓. Only the second.' },
+ { pair: [0, 0], ans: ['n'], why: '0 + 0 = 0, not 6, and 0 − 0 = 0, not 2: neither.' },
+];
+const SOLQ = [
+ { pair: [2, 1], sys: [[1, 1, 3], [1, -1, 1]], ans: ['y'], why: '2 + 1 = 3 ✓ and 2 − 1 = 1 ✓. Yes.' },
+ { pair: [1, 2], sys: [[1, 1, 3], [1, -1, 1]], ans: ['n'], why: '1 + 2 = 3 ✓, but 1 − 2 = −1, not 1 ✗. One failure is enough: no.' },
+ { pair: [3, -1], sys: [[2, 1, 5], [1, 3, 0]], ans: ['y'], why: '6 − 1 = 5 ✓ and 3 − 3 = 0 ✓. Yes.' },
+ { pair: [0, 4], sys: [[1, 1, 4], [3, -1, 4]], ans: ['n'], why: '0 + 4 = 4 ✓, but 0 − 4 = −4, not 4 ✗. No.' },
+ { pair: [-2, 3], sys: [[1, 1, 1], [2, 1, -1]], ans: ['y'], why: '−2 + 3 = 1 ✓ and −4 + 3 = −1 ✓. Yes.' },
+ { pair: [4, 4], sys: [[1, -1, 0], [1, 1, 6]], ans: ['n'], why: '4 − 4 = 0 ✓, but 4 + 4 = 8, not 6 ✗. No.' },
+].map(q => ({ ...q, parts: ['Is ', $m(pairStr(...q.pair)), ' a solution of ', $m(eqStr(...q.sys[0])), ' and ', $m(eqStr(...q.sys[1])), '?'] }));
+const CROSSQ = [
+ { A: [[1, 1], [1, -1]], b: [4, 2], at: [3, 1] },
+ { A: [[2, 1], [1, -1]], b: [1, 5], at: [2, -3] },
+ { A: [[1, 2], [-1, 1]], b: [2, 4], at: [-2, 2] },
+ { A: [[0, 1], [1, 1]], b: [3, -1], at: [-4, 3] },
+];
+const RIGHTQ = [
+ { parts: [pairStr(3, -2), ': 2x + y = ', { box: '4' }, ', x − 3y = ', { box: '9' }], why: '2·3 + (−2) = 4 and 3 − 3·(−2) = 3 + 6 = 9.', hint: 'Put x = 3 and y = −2 into each left side. The number you get is the right side.' },
+ { parts: [pairStr(-1, 4), ': x + y = ', { box: '3' }, ', 3x + y = ', { box: '1' }], why: '−1 + 4 = 3 and −3 + 4 = 1.', hint: 'Put x = −1 and y = 4 into each left side. 3 times −1 is −3.' },
+ { parts: [pairStr(0, 5), ': 4x − y = ', { box: '-5' }, ', x + 2y = ', { box: '10' }], why: '0 − 5 = −5 and 0 + 10 = 10.', hint: 'With x = 0 the x parts are 0. Then −y is −5, and 2y is 10.' },
+];
+const MISSQ = [
+ { parts: ['x + y = 7, x − y = 1: (4, ', { box: '3' }, ')'], why: '4 + 3 = 7 and 4 − 3 = 1: y = 3 passes both.', hint: 'The first equation says 4 + y = 7. Then check your y in the second.' },
+ { parts: ['x + y = 3, 2x + y = 8: (', { box: '5' }, ', −2)'], why: '5 − 2 = 3 and 10 − 2 = 8: x = 5 passes both.', hint: 'The first equation says x − 2 = 3. Then check your x in the second.' },
+];
+const MAKEQ = [
+ { start: { a00: 1, a01: 1, b0: 1, a10: 2, a11: -1, b1: 2 }, at: [-1, 3], only: ['b0', 'b1'],
+ prompt: ['Change only the right sides so the lines meet at ', $m('(−1, 3)'), '.'],
+ why: 'x + y = 2 and 2x − y = −5: −1 + 3 = 2, and −2 − 3 = −5.', hint: 'Put x = −1, y = 3 into each left side: that number must be the right side. Or drag each line through the ring.',
+ answer: { b0: 2, b1: -5 } },
+ { start: { a00: 1, a01: 1, b0: 6, a10: 1, a11: -1, b1: 1 }, at: [3, 2], only: ['a00', 'a01'],
+ prompt: ['Change only the numbers in front of ', $m('x'), ' and ', $m('y'), ' in the first equation, so the lines meet at ', $m('(3, 2)'), '.'],
+ why: 'Any first equation with 3·(x number) + 2·(y number) = 6 works: 2x = 6, or 3y = 6, or 4x − 3y = 6. The blue line turns until it passes through (3, 2).',
+ hint: '(3, 2) is already on the coral line. Turn the blue line so it passes through (3, 2) too: 3 times the x number plus 2 times the y number must make 6.',
+ answer: { a00: 2, a01: 0 } },
+ { start: { a00: 1, a01: 1, b0: 0, a10: 1, a11: -1, b1: 4 }, at: [1, 1], only: null,
+ prompt: ['Make any system whose lines cross at ', $m('(1, 1)'), '. Change whatever you like.'],
+ why: 'For example x + y = 2 and x − y = 0. Any two different lines through (1, 1) will do.',
+ hint: 'Put x = 1, y = 1 into each left side and use that as the right side. The two lines must not be the same line.',
+ answer: { b0: 2, b1: 0 } },
+];
+
+/* ---------- beats: [id, title, run(m, D), { ask }?] ---------- */
+const BEATS = [
+ ['intro', 'Two equations, one point', (m, D) => {
+ const g = G(scene, { o: 0, y: 24 });
+ T(g, 'Unit 1, Chapter 2', { x: 800, y: 320, size: 28, fill: COL.dim, anchor: 'middle' });
+ T(g, 'Two Equations, One Point', { x: 800, y: 430, size: 88, weight: 600, anchor: 'middle' });
+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);
+ const r = text(scene, 'two lines, and the one point they share', 800, 560, m('sub'), { size: 36, fill: COL.dim, anchor: 'middle' });
+ const lg = G(scene, { x: 800, y: 700 });
+ const l1 = path(lg, 'M-170 50L170 -50', { stroke: BLUE, 'stroke-width': 6, 'stroke-linecap': 'round' }, { d: 0 });
+ const l2 = path(lg, 'M-170 -50L170 50', { stroke: CORAL, 'stroke-width': 6, 'stroke-linecap': 'round' }, { d: 0 });
+ draw(l1, m('sub') + 1.5, .8); draw(l2, m('sub') + 2.4, .8);
+ const d = G(lg, { s: 0, o: 0 }); mk('circle', { r: 12, fill: COL.chalk, stroke: COL.board, 'stroke-width': 3 }, d);
+ tw(d, { s: 1, o: 1 }, m('cross') + .8, .5, back); pulse(d, m('cross') + 1.6);
+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(lg, D - .9, .8);
+ }],
+
+ ['riddle', 'Both at once', (m) => {
+ const p = panel(0);
+ text(p, 'Two conditions at the same time', 60, 110, .2, { size: 40, weight: 600 });
+ const r1 = text(p, 'two numbers that add up to 5', 90, 470, m('add'), { size: 32, fill: BLUE, weight: 600 });
+ const r2 = text(p, 'the first minus the second is 1', 90, 530, m('sub'), { size: 32, fill: CORAL, weight: 600 });
+ const sys = twoLines(p, [[1, 1], [1, -1]], [5, 1], { t0: m('name') - .3, readout: false, hidePlane: true });
+ put(sys.eqRows[1].g, { o: 0 }); show(sys.eqRows[1].g, m('and'));
+ // the brace: one system, both rows
+ const br = path(p, 'M48 140Q30 140 30 160V205Q30 222 16 222Q30 222 30 239V284Q30 304 48 304', { stroke: COL.task, 'stroke-width': 3.5, fill: 'none' }, { d: 0 });
+ draw(br, m('both'), .6);
+ hide(r1, m('both'), .4); hide(r2, m('both'), .4);
+ text(p, 'a system of equations:', 90, 470, m('both') + .5, { size: 32, fill: COL.task, weight: 600 });
+ text(p, 'both must be true at once', 90, 520, m('both') + .9, { size: 32, fill: COL.task, weight: 600 });
+ // the hunt: pairs that add to 5, each tested in the second equation
+ const cx = [890, 1110, 1390], hy = 220, rh = 82;
+ const head = G(p, { o: 0 });
+ T(head, 'pair', { x: cx[0], y: hy, size: 28, fill: COL.dim, anchor: 'middle' });
+ M(head, ['x + y = 5'], { x: cx[1], y: hy, size: 32, fill: BLUE, anchor: 'middle' });
+ M(head, ['x − y = 1'], { x: cx[2], y: hy, size: 32, fill: CORAL, anchor: 'middle' });
+ path(head, `M800 ${hy + 22}H1540`, { stroke: COL.faint, 'stroke-width': 2 });
+ show(head, m('try'));
+ const pairs = [[1, 4], [2, 3], [3, 2], [4, 1]], rowsG = [];
+ pairs.forEach(([x, y], i) => {
+ const yy = hy + 80 + i * rh, g = G(p, {});
+ rowsG.push(g);
+ say(g, [pairStr(x, y)], cx[0], yy, m('p' + (i + 1)), { size: 36, anchor: 'middle' });
+ say(g, [`${x} + ${y} = 5`], cx[1] - 20, yy, m('p' + (i + 1)) + .4, { size: 32, anchor: 'middle' });
+ okMark(g, true, cx[1] + 95, yy, m('p' + (i + 1)) + .7);
+ const ok = x - y === 1;
+ say(g, [`${x} − ${y} = ${num(x - y)}`], cx[2] - 20, yy, m('t' + (i + 1)), { size: 32, anchor: 'middle', fill: ok ? COL.chalk : COL.dim });
+ okMark(g, ok, cx[2] + 110, yy, m('t' + (i + 1)) + .5);
+ });
+ // "every one of them passes the first equation": the blue column lights up, then the coral one is tested
+ const colHi = mk('rect', { x: cx[1] - 120, y: hy - 34, width: 240, height: 4 * rh + 60, rx: 14, fill: BLUE }, p);
+ p.insertBefore(colHi, p.firstChild);
+ put(colHi, { x: 0, o: 0 });
+ tw(colHi, { o: .1 }, m('p4') + 1.6, .5); tw(colHi, { x: cx[2] - cx[1], c_fill: CORAL }, m('test'), .7); tw(colHi, { o: 0 }, m('win'), .5);
+ [0, 1, 3].forEach(i => tw(rowsG[i], { o: .3 }, m('win'), .5));
+ const box = mk('rect', { x: 805, y: hy + 80 + 2 * rh - 46, width: 740, height: 66, rx: 14, fill: 'none', stroke: COL.task, 'stroke-width': 3 }, p);
+ put(box, { o: 0 }); show(box, m('win'), .4);
+ const sol = G(p, { o: 0 });
+ T(sol, 'the solution of the system:', { x: 90, y: 620, size: 32, fill: COL.dim });
+ M(sol, ['x = 3, y = 2'], { x: 90, y: 690, size: 48, fill: COL.task, anchor: 'start' });
+ show(sol, m('win') + 1.5);
+ say(p, ['3 + 2 = 5'], 90, 760, m('win') + 4.5, { size: 34, fill: BLUE }); okMark(p, true, 270, 760, m('win') + 5.3);
+ say(p, ['3 − 2 = 1'], 330, 760, m('win') + 6.5, { size: 34, fill: CORAL }); okMark(p, true, 510, 760, m('win') + 7.3);
+ }],
+
+ ['check', 'Check a pair in both', (m) => {
+ const p = panel(0);
+ text(p, 'Checking a pair: put it into both equations', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = twoLines(p, [[2, -1], [-1, 2]], [0, 3], { t0: m('eq') - .3, readout: false, hidePlane: true });
+ put(sys.eqRows[1].g, { o: 0 }); show(sys.eqRows[1].g, m('eq') + 2.4);
+ const cx = [170, 520, 960, 1360], hy = 395, rh = 96;
+ const head = G(p, { o: 0 });
+ T(head, 'pair', { x: cx[0], y: hy, size: 28, fill: COL.dim, anchor: 'middle' });
+ M(head, ['2x − y = 0'], { x: cx[1], y: hy, size: 32, fill: BLUE, anchor: 'middle' });
+ M(head, ['−x + 2y = 3'], { x: cx[2], y: hy, size: 32, fill: CORAL, anchor: 'middle' });
+ T(head, 'the system?', { x: cx[3], y: hy, size: 28, fill: COL.dim, anchor: 'middle' });
+ path(head, `M70 ${hy + 22}H1540`, { stroke: COL.faint, 'stroke-width': 2 });
+ [...head.children].forEach((e, i) => { put(e, { o: 0 }); show(e, m('into') + [0, .7, 1.3, 2, 0][i], .4); });
+ put(head, { o: 1 });
+ hide(say(p, ['(x, y)'], cx[0], hy + 80, m('into') + .3, { size: 34, anchor: 'middle', fill: COL.dim }), m('a') - .3, .3);
+ const row = (i, pair, c1, c2, ok1, ok2, t, verdict) => {
+ const yy = hy + 80 + i * rh;
+ say(p, [pair], cx[0], yy, t[0], { size: 38, anchor: 'middle' });
+ say(p, [c1], cx[1] - 20, yy, t[1], { size: 32, anchor: 'middle', fill: ok1 ? COL.chalk : COL.bad });
+ okMark(p, ok1, cx[1] + 165, yy, t[1] + .8);
+ if (c2) { say(p, [c2], cx[2] - 20, yy, t[2], { size: 32, anchor: 'middle', fill: ok2 ? COL.chalk : COL.bad }); okMark(p, ok2, cx[2] + 175, yy, t[2] + .8); }
+ text(p, verdict[0], cx[3], yy, t[3], { size: 32, fill: verdict[1], weight: 700, anchor: 'middle' });
+ };
+ row(0, '(2, 4)', '2·2 − 4 = 0', '−2 + 2·4 = 6', true, false, [m('a'), m('a1'), m('a2'), m('ano')], ['no', COL.bad]);
+ row(1, '(−1, 1)', '2·(−1) − 1 = −3', '1 + 2·1 = 3', false, true, [m('b'), m('b1'), m('b2'), m('bno')], ['no', COL.bad]);
+ row(2, '(1, 2)', '2·1 − 2 = 0', '−1 + 2·2 = 3', true, true, [m('c'), m('c1'), m('c2'), m('cok')], ['yes: the solution', COL.good]);
+ const n1 = text(p, 'not 3', cx[2] + 175, hy + 80 + 40, m('a2') + 1.2, { size: 22, fill: COL.bad, anchor: 'middle' });
+ const n2 = text(p, 'not 0', cx[1] + 165, hy + 80 + rh + 40, m('b1') + 1.6, { size: 22, fill: COL.bad, anchor: 'middle' });
+ S.chk = [n1, n2];
+ const rule = G(p, { o: 0 });
+ T(rule, 'a solution of the system passes every equation', { x: 90, y: 790, size: 32, weight: 600, fill: COL.task });
+ show(rule, m('cok') + 1.4);
+ }],
+
+ ['q1', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ twoLines(p, [[1, 1], [1, -1]], [6, 2], { readout: false, hidePlane: true });
+ }, { ask: done => quiz(RCARD, [{
+ id: 'c-both', prompt: ['Which equations does each pair pass: ', $m('x + y = 6'), ' and ', $m('x − y = 2'), '?'],
+ build: grid(BOTHQ.map(q => ({ parts: [$m(pairStr(...q.pair))], ans: q.ans, why: q.why })),
+ [['b', 'Both', COL.good, 'B'], ['o', 'Only one', COL.task, 'O'], ['n', 'Neither', COL.bad, 'N']], { multi: false, text: true }),
+ }], done) }],
+
+ ['rowpic', 'The row picture', (m) => {
+ const p = panel(0);
+ text(p, 'The row picture: one line for each equation', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = twoLines(p, [[2, -1], [-1, 2]], [0, 3], { lines: false, meet: false, readout: false });
+ const [l1, l2] = sys.lines.map(L => L.l);
+ sys.focus(0, m('blue'));
+ const recall = text(p, 'chapter 1: an equation in x and y is a line', 90, 470, m('blue') + .6, { size: 30, fill: COL.dim });
+ ['a00', 'a01', 'b0'].forEach((k, i) => flash(sys, k, m('blue') + 5 + i * .3));
+ hide(recall, m('o') - .3, .3);
+ const pre = sys.P.line(-3, -6, 3, 6, BLUE, m('blue') + 5.5, { dash: '10 10', w: 3 }); hide(pre, m('o') - .3, .4);
+ say(p, ['right side 0: through (0, 0)'], 90, 470, m('o'), { size: 32, fill: BLUE });
+ drop(sys, 0, 0, m('o') + .6, BLUE, '');
+ say(p, ['(0, 0)'], sys.P.PX(0) - 16, sys.P.PY(0) - 14, m('o') + .8, { size: 26, fill: BLUE, anchor: 'end' });
+ say(p, ['x = 1: 2 − y = 0, y = 2'], 90, 525, m('p'), { size: 32, fill: BLUE });
+ drop(sys, 1, 2, m('p') + 2.5, BLUE, '');
+ const l12 = say(p, ['(1, 2)'], sys.P.PX(1) - 18, sys.P.PY(2) - 8, m('p') + 2.7, { size: 26, fill: BLUE, anchor: 'end' });
+ hide(l12, m('meet'), .3);
+ show(l1, m('l1'), .9);
+ sys.focus(1, m('coral'));
+ say(p, ['y = 0: −x = 3, x = −3'], 90, 605, m('q1'), { size: 32, fill: CORAL });
+ drop(sys, -3, 0, m('q1') + 2.5, CORAL, '(−3, 0)', -50, -18);
+ const fr = say(p, ['x = 0 would give 2y = 3: a fraction'], 90, 660, m('frac'), { size: 28, fill: COL.dim });
+ hide(fr, m('q2') - .2, .3);
+ say(p, ['x = 3: −3 + 2y = 3, y = 3'], 90, 660, m('q2'), { size: 32, fill: CORAL });
+ drop(sys, 3, 3, m('q2') + 3.5, CORAL, '(3, 3)', 16, -14);
+ show(l2, m('l2'), .9);
+ // a probe walks the coral line: −x + 2y stays 3 all the way
+ const { PX, PY } = sys.P, pr = G(p, { o: 0 });
+ mk('circle', { r: 11, fill: CORAL, stroke: COL.board, 'stroke-width': 3 }, pr);
+ const prT = T(pr, '', { x: -18, y: -16, size: 24, fill: CORAL, font: MATH, weight: 600, anchor: 'end' });
+ show(pr, m('l2') + 2, .3);
+ prog(q => {
+ const x = -5 + q * 9, y = (3 + x) / 2, f = n => { const r = Math.round(n * 10) / 10; return r < 0 ? `(${num(r)})` : num(r); };
+ put(pr, { x: PX(x), y: PY(y) });
+ const str = `−${f(x)} + 2·${f(y)} = 3`;
+ if (prT.textContent !== str) prT.textContent = str;
+ }, m('l2') + 2, m('meet') - m('l2') - 2.4, io);
+ hide(pr, m('meet') - .3, .3);
+ sys.focus(null, m('meet'));
+ show(sys.meetBox, m('meet') + .4, .4); pulse(sys.meet, m('on')); pulse(sys.meet, m('on') + 1);
+ show(sys.readout, m('read'));
+ text(p, 'the same pair as in the table', 330, 396, m('same') + .2, { size: 26, fill: COL.dim });
+ sys.focus(0, m('name') + 2.5); sys.focus(1, m('name') + 4.5); sys.focus(null, m('name') + 6.5);
+ const n = G(p, { o: 0 });
+ T(n, 'the crossing is on both lines: it solves both equations', { x: 90, y: 760, size: 30, weight: 600, fill: COL.task });
+ show(n, m('on') + .3);
+ }],
+
+ ['riddle2', 'The riddle, drawn', (m) => {
+ const p = panel(0);
+ text(p, 'The riddle as a picture', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = twoLines(p, [[1, 1], [1, -1]], [5, 1], { lines: false, meet: false, readout: false });
+ sys.focus(0, m('eq'));
+ say(p, ['y = 0: x = 5; x = 0: y = 5'], 90, 470, m('a'), { size: 32, fill: BLUE });
+ drop(sys, 5, 0, m('a') + .3, BLUE, '', 0, 0); drop(sys, 0, 5, m('a') + 1.2, BLUE, '', 0, 0);
+ show(sys.lines[0].l, m('l1'), .9);
+ sys.focus(1, m('eq2'));
+ say(p, ['y = 0: x = 1'], 90, 545, m('b'), { size: 32, fill: CORAL });
+ say(p, ['x = 0: −y = 1, y = −1'], 90, 600, m('b2'), { size: 32, fill: CORAL });
+ drop(sys, 1, 0, m('b') + .8, CORAL, '', 0, 0); drop(sys, 0, -1, m('b2') + 2, CORAL, '', 0, 0);
+ show(sys.lines[1].l, m('l2'), .9);
+ sys.focus(null, m('meet'));
+ show(sys.meetBox, m('meet'), .4); pulse(sys.meet, m('meet') + .5);
+ show(sys.readout, m('meet') + 1);
+ const fails = G(p, {});
+ [[1, 4], [2, 3], [4, 1]].forEach(([x, y], i) => drop(sys, x, y, m('miss') + .6 + i * 1.1, COL.dim, pairStr(x, y), 16, -12, fails));
+ tw(sys.lines[0].l, { 'a_stroke-width': 9 }, m('blue'), .3); tw(sys.lines[0].l, { 'a_stroke-width': 5 }, m('blue') + 1, .5);
+ tw(sys.lines[1].l, { 'a_stroke-width': 9 }, m('off'), .3); tw(sys.lines[1].l, { 'a_stroke-width': 5 }, m('off') + 1, .5);
+ say(p, ['(1, 4): 1 − 4 = −3, (2, 3): −1, (4, 1): 3'], 90, 680, m('off') + .3, { size: 28, fill: COL.dim });
+ text(p, 'none of them is 1: off the coral line', 90, 725, m('off') + 1.4, { size: 28, fill: CORAL, weight: 600 });
+ text(p, 'only the crossing (3, 2) is on both', 90, 790, m('sum'), { size: 32, fill: COL.task, weight: 600 });
+ }],
+
+ ['q2', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ S.sys = twoLines(p, [[1, 2], [1, -1]], [4, 1], { meet: false, readout: false });
+ }, { ask: done => quiz(CARD, [{
+ id: 'c-cross', prompt: ['Click the point that solves both ', $m('x + 2y = 4'), ' and ', $m('x − y = 1'), '.'],
+ build: pickPoint(S.sys.P, [2, 1], '(2, 1): 2 + 2·1 = 4 and 2 − 1 = 1. It is where the lines cross.', (x, y) => {
+ const [a, b] = passes([[1, 2], [1, -1]], [4, 1], x, y);
+ return a ? `${pairStr(x, y)} is on the blue line only: it passes x + 2y = 4, but x − y = ${num(x - y)}, not 1. Look for where the lines cross.`
+ : b ? `${pairStr(x, y)} is on the coral line only: x − y = 1 works, but x + 2y = ${num(x + 2 * y)}, not 4. Look for where the lines cross.`
+ : `${pairStr(x, y)} is on neither line. The solution is on both: where the blue and the coral line cross.`;
+ }, () => fx(S.sys.meetBox, { o: 1 }, 0, .4)),
+ }], done) }],
+
+ ['between', 'Between the grid lines', (m) => {
+ const p = panel(0);
+ text(p, 'A crossing between the grid lines', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = twoLines(p, [[1, 1], [1, -1]], [2, 1], { t0: m('eq') - .3, lines: false, meet: false, readout: false });
+ sys.lines.forEach(({ l }, i) => show(l, m('draw') + i * .6, .8));
+ const { PX, PY } = sys.P;
+ const pt = drop(sys, 1.5, .5, m('meet'), COL.chalk, '');
+ pulse(pt, m('meet') + .6);
+ guide(sys, 1.5, .5, 'x', m('x'), p);
+ say(p, ['x ≈ 1.5'], PX(1.5), PY(-1.7), m('x') + .5, { size: 30, fill: COL.task, anchor: 'middle' });
+ guide(sys, 1.5, .5, 'y', m('y'), p);
+ say(p, ['y ≈ 0.5'], PX(0) - 70, PY(.5) - 18, m('y') + .5, { size: 30, fill: COL.task, anchor: 'end' });
+ text(p, 'guess:', 90, 470, m('guess'), { size: 30, fill: COL.dim });
+ say(p, ['x = ', F(3, 2), ', y = ', F(1, 2)], 200, 470, m('guess') + .3, { size: 38 });
+ say(p, [F(3, 2), ' + ', F(1, 2), ' = ', F(4, 2), ' = 2'], 90, 570, m('c1'), { size: 38, fill: BLUE });
+ okMark(p, true, 470, 570, m('c1') + 3);
+ say(p, [F(3, 2), ' − ', F(1, 2), ' = ', F(2, 2), ' = 1'], 90, 670, m('c2'), { size: 38, fill: CORAL });
+ okMark(p, true, 470, 670, m('c2') + 3);
+ show(sys.readout, m('ok'));
+ const n = G(p, { o: 0 });
+ T(n, 'the picture says where to look;', { x: 90, y: 760, size: 30, weight: 600, fill: COL.task });
+ T(n, 'putting the numbers back in proves it', { x: 90, y: 802, size: 30, weight: 600, fill: COL.task });
+ show(n, m('lesson'));
+ }],
+
+ ['between2', 'Close is not exact', (m) => {
+ const p = panel(0);
+ text(p, 'Close is not the same as exact', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = twoLines(p, [[2, 1], [1, -1]], [3, 1], { t0: m('eq') - .3, lines: false, meet: false, readout: false });
+ sys.lines.forEach(({ l }, i) => show(l, m('eq') + .8 + i * .6, .8));
+ const g = drop(sys, 1.3, .3, m('guess'), COL.task, '');
+ const gx = guide(sys, 1.3, .3, 'x', m('c1') + 1, p), gy = guide(sys, 1.3, .3, 'y', m('c1') + 2.5, p);
+ hide(gx, m('read'), .4); hide(gy, m('read'), .4);
+ hide(say(p, ['guess: x = 1.3, y = 0.3'], 90, 396, m('guess') + .3, { size: 36, fill: COL.task }), m('read') - .3, .3);
+ tw(sys.lines[0].l, { 'a_stroke-width': 9 }, m('meet'), .3); tw(sys.lines[0].l, { 'a_stroke-width': 5 }, m('meet') + 1, .5);
+ say(p, ['2·1.3'], 90, 470, m('c1') + 1.5, { size: 36, fill: BLUE });
+ say(p, ['= 2.6'], 185, 470, m('c1') + 3.4, { size: 36, fill: BLUE });
+ say(p, ['+ 0.3'], 290, 470, m('c1') + 5, { size: 36, fill: BLUE });
+ say(p, ['= 2.9'], 395, 470, m('c1') + 6.8, { size: 36, fill: BLUE });
+ text(p, 'not 3: close, but not on the line', 90, 520, m('no'), { size: 30, fill: COL.bad, weight: 600 });
+ tw(g, { o: .45 }, m('read'), .4);
+ show(sys.readout, m('read'));
+ show(sys.meetBox, m('read') + .3);
+ say(p, ['2·', F(4, 3), ' + ', F(1, 3), ' = ', F(8, 3), ' + ', F(1, 3), ' = ', F(9, 3), ' = 3'], 90, 620, m('c2'), { size: 36, fill: BLUE });
+ okMark(p, true, 640, 620, m('c2') + 5);
+ say(p, [F(4, 3), ' − ', F(1, 3), ' = ', F(3, 3), ' = 1'], 90, 720, m('c3'), { size: 36, fill: CORAL });
+ okMark(p, true, 640, 720, m('c3') + 3);
+ text(p, 'exact', 90, 800, m('ok'), { size: 34, fill: COL.good, weight: 700 });
+ }, { lead: false }],
+
+ ['slide', 'Move a right side', (m) => {
+ const p = panel(0);
+ text(p, 'Change a right side', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = twoLines(p, [[2, -1], [-1, 2]], [0, 3], { t0: m('sys') - .3 });
+ const ghost = (a, b, c, color, t) => { // the old place of a line, dashed
+ const ps = [-6, 6].map(x => b ? [x, (c - a * x) / b] : [c / a, x]);
+ const l = sys.P.line(...ps[0], ...ps[1], color, t, { dash: '10 10', w: 3 }); tw(l, { o: .35 }, t + .6, .4);
+ return l;
+ };
+ pulse(sys.meet, m('sys') + 4); pulse(sys.meet, m('sys') + 5.2);
+ const g1 = ghost(-1, 2, 3, CORAL, m('b1'));
+ tw(sys.lines[1].l, { 'a_stroke-width': 9 }, m('slides') + .8, .3); tw(sys.lines[1].l, { 'a_stroke-width': 8 }, m('slides') + 2.5, .5);
+ sys.focus(1, m('b1'));
+ const t1 = sys.to({ b1: 6 }, m('b1') + .3, 2.2, io, { trail: true }); flash(sys, 'b1', m('b1') + .3);
+ tw(sys.lines[0].l, { 'a_stroke-width': 9 }, m('along'), .3); tw(sys.lines[0].l, { 'a_stroke-width': 5 }, m('along') + 1.2, .5);
+ pulse(sys.meet, m('new'));
+ const w0 = say(p, ['before: −2 + 2·4 = 6, not 3'], 90, 470, m('rem') + 1.5, { size: 32, fill: COL.bad });
+ const w = say(p, ['now: −2 + 2·4 = 6 ✓'], 90, 525, m('rem') + 5.5, { size: 32, fill: COL.good });
+ flash(sys, 'b1', m('rem') + 7);
+ [g1, t1, w, w0].forEach(e => hide(e, m('back'), .4));
+ sys.to({ b1: 3 }, m('back'), 1.2); flash(sys, 'b1', m('back'));
+ sys.focus(null, m('back'));
+ const g2 = ghost(2, -1, 0, BLUE, m('b0'));
+ sys.focus(0, m('b0'));
+ sys.to({ b0: 3 }, m('b0') + .5, 2.2, io, { trail: true }); flash(sys, 'b0', m('b0') + .5);
+ tw(sys.lines[1].l, { 'a_stroke-width': 9 }, m('slides2') + 1.5, .3); tw(sys.lines[1].l, { 'a_stroke-width': 5 }, m('slides2') + 2.7, .5);
+ pulse(sys.meet, m('new2'));
+ say(p, ['2·3 − 3 = 3 ✓'], 90, 470, m('chk'), { size: 34, fill: BLUE });
+ say(p, ['−3 + 2·3 = 3 ✓'], 90, 525, m('chk') + 2, { size: 34, fill: CORAL });
+ sys.focus(null, m('rule'));
+ const n = G(p, { o: 0 });
+ T(n, 'one right side changes: that line slides,', { x: 90, y: 720, size: 30, weight: 600, fill: COL.task });
+ T(n, 'and the meeting point slides along the other line', { x: 90, y: 762, size: 30, weight: 600, fill: COL.task });
+ show(n, m('rule'));
+ S.g2 = g2;
+ }],
+
+ ['turn', 'Turn a line', (m) => {
+ const p = panel(0);
+ text(p, 'Change a number in front of x or y', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = twoLines(p, [[2, -1], [-1, 2]], [0, 3]);
+ const { PX, PY } = sys.P;
+ const pivot = (x, y, t, color) => { const d = G(p, { x: PX(x), y: PY(y), o: 0 }); mk('circle', { r: 16, fill: 'none', stroke: color, 'stroke-width': 3.5 }, d); show(d, t, .3); pulse(d, t + .4); return d; };
+ sys.focus(0, m('a'));
+ const t1 = sys.to({ a00: 1 }, m('a') + .3, 2.4, io, { trail: true }); flash(sys, 'a00', m('a') + .3);
+ const pv = pivot(0, 0, m('turns') + 1.5, BLUE);
+ tw(sys.lines[1].l, { 'a_stroke-width': 9 }, m('along'), .3); tw(sys.lines[1].l, { 'a_stroke-width': 5 }, m('along') + 1.2, .5);
+ pulse(sys.meet, m('new'));
+ const c0 = say(p, ['(0, 0): 2·0 − 0 = 0, 1·0 − 0 = 0'], 90, 470, m('turns') + 3.5, { size: 30, fill: BLUE });
+ flash(sys, 'b0', m('turns') + 5);
+ const c1 = say(p, ['3 − 3 = 0 ✓, −3 + 2·3 = 3 ✓'], 90, 535, m('chk'), { size: 32 });
+ [t1, pv, c1, c0].forEach(e => hide(e, m('ex2') - .2, .4));
+ sys.focus(null, m('ex2'));
+ sys.to({ a00: 1, a01: 1, b0: 5, a10: 1, a11: -1, b1: 1 }, m('ex2') + .3, 1.6);
+ sys.focus(1, m('c'));
+ const t2 = sys.to({ a10: 2 }, m('c') + .4, 2.4, io, { trail: true }); flash(sys, 'a10', m('c') + .4);
+ pivot(0, -1, m('turns2') + 1.2, CORAL);
+ tw(sys.lines[0].l, { 'a_stroke-width': 9 }, m('along2'), .3); tw(sys.lines[0].l, { 'a_stroke-width': 5 }, m('along2') + 1.2, .5);
+ pulse(sys.meet, m('new2') + 1);
+ say(p, ['2 + 3 = 5 ✓, 2·2 − 3 = 1 ✓'], 90, 470, m('chk2'), { size: 32 });
+ sys.focus(null, m('rule'));
+ const n = G(p, { o: 0 });
+ T(n, 'a line moves: the meeting point', { x: 90, y: 720, size: 30, weight: 600, fill: COL.task });
+ T(n, 'stays on the line that does not', { x: 90, y: 762, size: 30, weight: 600, fill: COL.task });
+ show(n, m('rule'));
+ S.t2 = t2;
+ }],
+
+ ['q3', 'Your turn', () => {
+ const p = panel(0);
+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = twoLines(p, [[2, -1], [-1, 2]], [0, 3], { readout: false });
+ const r = ring(sys, 2, -1, p); put(r, { o: 0 }); show(r, .5);
+ }, { ask: done => quiz(CARD, [{
+ id: 'c-meet', prompt: ['Make the lines meet at ', $m('(2, −1)'), '. Change only the right sides: drag them sideways, or drag a line.'],
+ build: lsTask(S.sys, (v, s) => near(s, 2, -1),
+ 'Right: 2x − y = 5 and −x + 2y = −4. Each right side is what its left side gives at (2, −1): 4 + 1 = 5 and −2 − 2 = −4.',
+ 'Put x = 2 and y = −1 into each left side: that number must be the right side. Or slide each line until it passes through the ring.',
+ () => S.sys.set({ b0: 5, b1: -4 }), { only: ['b0', 'b1'], trail: true }),
+ }], done) }],
+
+ ['wrap', 'Summary', (m) => {
+ const p = panel(0);
+ [['A system: equations that must all be true at once.', 'w1'], ['A pair solves the system only if it passes every equation.', 'w2'],
+ ['Row picture: each equation is a line; the solution is where they cross.', 'w3'], ['The picture shows where to look; putting the numbers back in proves it.', 'w4']].forEach(([str, mark], i) => {
+ const g = G(p, { x: -16, y: 230 + i * 130, o: 0 });
+ mk('circle', { cx: 150, cy: -12, r: 26, fill: COL.task }, g);
+ T(g, String(i + 1), { x: 150, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });
+ T(g, str, { x: 210, size: 36, weight: 600 });
+ tw(g, { o: 1, x: 0 }, m(mark), .6);
+ });
+ }],
+ ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
+ id: 'p-sol', prompt: ['Does the pair solve the whole system? Check it in both equations.'],
+ build: grid(SOLQ, [['y', 'Yes', null, 'Y'], ['n', 'No', null, 'N']], { multi: false, text: true }),
+ }], done, 'Chapter practice · set 1 of 4') }],
+ ['final2', 'Chapter practice', () => {
+ const p = panel(0);
+ text(p, 'Find the crossing', 60, 110, .2, { size: 40, weight: 600 });
+ const q = CROSSQ[0];
+ S.sys = twoLines(p, q.A, q.b, { meet: false, readout: false });
+ }, { ask: done => quiz(CARD, CROSSQ.map((q, k) => ({
+ id: 'p-cross' + (k + 1), prompt: ['Click the point that solves both ', $m(eqStr(...q.A[0], q.b[0])), ' and ', $m(eqStr(...q.A[1], q.b[1])), '.'],
+ build: (body, api) => {
+ const sys = S.sys;
+ sys.set({ a00: q.A[0][0], a01: q.A[0][1], a10: q.A[1][0], a11: q.A[1][1], b0: q.b[0], b1: q.b[1] });
+ put(sys.meetBox, { o: 0 });
+ const [x0, y0] = q.at;
+ return pickPoint(sys.P, q.at, `${pairStr(x0, y0)} is on both lines: check it in both equations.`, (x, y) => {
+ const [a, b] = passes(q.A, q.b, x, y);
+ return a ? `${pairStr(x, y)} is on the blue line only. The solution must be on the coral line too.`
+ : b ? `${pairStr(x, y)} is on the coral line only. The solution must be on the blue line too.`
+ : `${pairStr(x, y)} is on neither line. Find where the two lines cross.`;
+ }, () => fx(sys.meetBox, { o: 1 }, 0, .4))(body, api);
+ },
+ })), done, 'Chapter practice · set 2 of 4') }],
+ ['final3', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
+ id: 'p-right', prompt: ['Fill in the right sides so that the pair solves both equations.'],
+ build: blanks(RIGHTQ),
+ }, {
+ id: 'p-miss', prompt: ['Find the missing number so that the pair solves both equations.'],
+ build: blanks(MISSQ),
+ }], done, 'Chapter practice · set 3 of 4') }],
+ ['final4', 'Chapter practice', () => {
+ const p = panel(0);
+ text(p, 'Make the lines meet', 60, 110, .2, { size: 40, weight: 600 });
+ S.sys = twoLines(p, [[1, 1], [2, -1]], [1, 2], { readout: false });
+ }, { ask: done => quiz(CARD, MAKEQ.map((q, k) => ({
+ id: 'p-make' + (k + 1), prompt: q.prompt,
+ build: (body, api) => {
+ const sys = S.sys;
+ sys.set(q.start);
+ ring(sys, ...q.at, qlayer());
+ return lsTask(sys, (v, s) => near(s, ...q.at), q.why, q.hint, () => sys.set(q.answer), { only: q.only, trail: true })(body, api);
+ },
+ })), done, 'Chapter practice · set 4 of 4') }],
+ ['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],
+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
+
+boot();
+</script>
+</body>
+</html>
diff --git a/site/linear-algebra/ch03/audio/en/final1.mp3 b/site/linear-algebra/ch03/audio/en/final1.mp3
new file mode 100644
index 0000000..1454f4b
Binary files /dev/null and b/site/linear-algebra/ch03/audio/en/final1.mp3 differ
diff --git a/site/linear-algebra/ch03/audio/en/final2.mp3 b/site/linear-algebra/ch03/audio/en/final2.mp3
new file mode 100644
index 0000000..6cc6737
Binary files /dev/null and b/site/linear-algebra/ch03/audio/en/final2.mp3 differ
diff --git a/site/linear-algebra/ch03/audio/en/final3.mp3 b/site/linear-algebra/ch03/audio/en/final3.mp3
new file mode 100644
index 0000000..5f4838a
Binary files /dev/null and b/site/linear-algebra/ch03/audio/en/final3.mp3 differ
diff --git a/site/linear-algebra/ch03/audio/en/final4.mp3 b/site/linear-algebra/ch03/audio/en/final4.mp3
new file mode 100644
index 0000000..dd338c7
Binary files /dev/null and b/site/linear-algebra/ch03/audio/en/final4.mp3 differ
diff --git a/site/linear-algebra/ch03/audio/en/finish.mp3 b/site/linear-algebra/ch03/audio/en/finish.mp3
new file mode 100644
index 0000000..74e856c
Binary files /dev/null and b/site/linear-algebra/ch03/audio/en/finish.mp3 differ
diff --git a/site/linear-algebra/ch03/audio/en/intro.mp3 b/site/linear-algebra/ch03/audio/en/intro.mp3
new file mode 100644
index 0000000..a2c3a35
Binary files /dev/null and b/site/linear-algebra/ch03/audio/en/intro.mp3 differ
diff --git a/site/linear-algebra/ch03/audio/en/parallel.mp3 b/site/linear-algebra/ch03/audio/en/parallel.mp3
new file mode 100644
index 0000000..c273cb6
Binary files /dev/null and b/site/linear-algebra/ch03/audio/en/parallel.mp3 differ
diff --git a/site/linear-algebra/ch03/audio/en/parallel2.mp3 b/site/linear-algebra/ch03/audio/en/parallel2.mp3
new file mode 100644
index 0000000..d3bf9e2
Binary files /dev/null and b/site/linear-algebra/ch03/audio/en/parallel2.mp3 differ
diff --git a/site/linear-algebra/ch03/audio/en/q1.mp3 b/site/linear-algebra/ch03/audio/en/q1.mp3
new file mode 100644
index 0000000..14e8aa8
Binary files /dev/null and b/site/linear-algebra/ch03/audio/en/q1.mp3 differ
diff --git a/site/linear-algebra/ch03/audio/en/q2.mp3 b/site/linear-algebra/ch03/audio/en/q2.mp3
new file mode 100644
index 0000000..9bc4cf5
Binary files /dev/null and b/site/linear-algebra/ch03/audio/en/q2.mp3 differ
diff --git a/site/linear-algebra/ch03/audio/en/q3.mp3 b/site/linear-algebra/ch03/audio/en/q3.mp3
new file mode 100644
index 0000000..8a8226a
Binary files /dev/null and b/site/linear-algebra/ch03/audio/en/q3.mp3 differ
diff --git a/site/linear-algebra/ch03/audio/en/rule.mp3 b/site/linear-algebra/ch03/audio/en/rule.mp3
new file mode 100644
index 0000000..faf6250
Binary files /dev/null and b/site/linear-algebra/ch03/audio/en/rule.mp3 differ
diff --git a/site/linear-algebra/ch03/audio/en/runaway.mp3 b/site/linear-algebra/ch03/audio/en/runaway.mp3
new file mode 100644
index 0000000..58f2de3
Binary files /dev/null and b/site/linear-algebra/ch03/audio/en/runaway.mp3 differ
diff --git a/site/linear-algebra/ch03/audio/en/same.mp3 b/site/linear-algebra/ch03/audio/en/same.mp3
new file mode 100644
index 0000000..b6d9262
Binary files /dev/null and b/site/linear-algebra/ch03/audio/en/same.mp3 differ
diff --git a/site/linear-algebra/ch03/audio/en/same2.mp3 b/site/linear-algebra/ch03/audio/en/same2.mp3
new file mode 100644
index 0000000..b36e8fa
Binary files /dev/null and b/site/linear-algebra/ch03/audio/en/same2.mp3 differ
diff --git a/site/linear-algebra/ch03/audio/en/three.mp3 b/site/linear-algebra/ch03/audio/en/three.mp3
new file mode 100644
index 0000000..8c8fc69
Binary files /dev/null and b/site/linear-algebra/ch03/audio/en/three.mp3 differ
diff --git a/site/linear-algebra/ch03/audio/en/timings.js b/site/linear-algebra/ch03/audio/en/timings.js
new file mode 100644
index 0000000..43b2327
--- /dev/null
+++ b/site/linear-algebra/ch03/audio/en/timings.js
@@ -0,0 +1,662 @@
+window.TIMINGS = {
+ "intro": {
+ "dur": 10.296,
+ "marks": {
+ "sub": 4.31,
+ "three": 6.888
+ },
+ "cues": [
+ [
+ 0.104,
+ "Chapter three."
+ ],
+ [
+ 1.354,
+ "Crossing, parallel or the same line."
+ ],
+ [
+ 4.31,
+ "Two lines don't always meet at one point."
+ ],
+ [
+ 6.888,
+ "They can meet once, never, or everywhere."
+ ]
+ ]
+ },
+ "three": {
+ "dur": 32.496,
+ "marks": {
+ "one": 5.013,
+ "but": 7.031,
+ "cross": 11.042,
+ "par": 13.49,
+ "same": 18.451,
+ "sizes": 22.526,
+ "none": 25.482,
+ "inf": 26.745
+ },
+ "cues": [
+ [
+ 0.104,
+ "In chapter two, every system we drew had two lines crossing at one point."
+ ],
+ [
+ 5.013,
+ "One crossing, one solution."
+ ],
+ [
+ 7.031,
+ "But two straight lines can sit together in only three ways."
+ ],
+ [
+ 11.042,
+ "They can cross, at exactly one point."
+ ],
+ [
+ 13.49,
+ "They can run side by side and never meet."
+ ],
+ [
+ 16.263,
+ "Lines like that are called parallel."
+ ],
+ [
+ 18.451,
+ "Or they can be the very same line, lying on top of each other."
+ ],
+ [
+ 22.526,
+ "So a system of two equations has one solution, no solution, or endlessly many."
+ ],
+ [
+ 28.268,
+ "Let's see each one, and learn to tell them apart from the numbers alone."
+ ]
+ ]
+ },
+ "parallel": {
+ "dur": 45.384,
+ "marks": {
+ "eq": 1.289,
+ "ask": 5.182,
+ "try": 9.596,
+ "sum": 13.125,
+ "never": 18.776,
+ "l1": 23.112,
+ "l2": 27.201,
+ "slid": 30.456,
+ "tilt": 37.695,
+ "gap": 39.805,
+ "none": 42.63
+ },
+ "cues": [
+ [
+ 0.117,
+ "Here's a system."
+ ],
+ [
+ 1.289,
+ "x plus y equals two, and x plus y equals five."
+ ],
+ [
+ 5.182,
+ "Can two numbers add up to two, and also add up to five?"
+ ],
+ [
+ 9.596,
+ "Try any pair."
+ ],
+ [
+ 10.768,
+ "One and one: the sum is two."
+ ],
+ [
+ 13.125,
+ "It can't also be five."
+ ],
+ [
+ 14.701,
+ "Whatever x and y are, x plus y is one number."
+ ],
+ [
+ 18.776,
+ "It can't be two and five at the same time."
+ ],
+ [
+ 21.393,
+ "So no pair solves both."
+ ],
+ [
+ 23.112,
+ "Look at the picture."
+ ],
+ [
+ 24.31,
+ "x plus y equals two is the blue line."
+ ],
+ [
+ 27.201,
+ "x plus y equals five is the coral line."
+ ],
+ [
+ 30.456,
+ "The left sides are the same, only the right side changed, and in chapter one you saw what that does: it slides the line."
+ ],
+ [
+ 37.695,
+ "Same tilt, slid over."
+ ],
+ [
+ 39.805,
+ "The lines are parallel."
+ ],
+ [
+ 41.432,
+ "They never meet, so the system has no solution."
+ ]
+ ]
+ },
+ "parallel2": {
+ "dur": 40.392,
+ "marks": {
+ "eq": 1.901,
+ "look": 7.044,
+ "twice": 8.763,
+ "half": 16.016,
+ "after": 18.034,
+ "still": 23.177,
+ "now": 31.315,
+ "and": 34.479,
+ "no": 36.12,
+ "none": 38.854
+ },
+ "cues": [
+ [
+ 0.104,
+ "Parallel lines can hide."
+ ],
+ [
+ 1.901,
+ "Two x plus y equals one, and four x plus two y equals six."
+ ],
+ [
+ 7.044,
+ "The left sides look different."
+ ],
+ [
+ 8.763,
+ "But four x is twice two x, and two y is twice y: the second left side is twice the first."
+ ],
+ [
+ 16.016,
+ "Halve the whole second equation."
+ ],
+ [
+ 18.034,
+ "Four x plus two y equals six becomes two x plus y equals three."
+ ],
+ [
+ 23.177,
+ "Look: the coral line didn't move."
+ ],
+ [
+ 25.469,
+ "Halving both sides keeps every solution, so it's the same line, just written smaller."
+ ],
+ [
+ 31.315,
+ "Now the system says two x plus y is one, and also three."
+ ],
+ [
+ 36.12,
+ "Impossible."
+ ],
+ [
+ 37.279,
+ "The lines are parallel, and there's no solution."
+ ]
+ ]
+ },
+ "q1": {
+ "dur": 3.816,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.133,
+ "Do the lines cross, or are they parallel?"
+ ]
+ ]
+ },
+ "same": {
+ "dur": 51.264,
+ "marks": {
+ "eq": 1.55,
+ "twice": 6.536,
+ "six": 14.531,
+ "half": 16.888,
+ "after": 17.747,
+ "draw": 22.852,
+ "p1": 27.24,
+ "p1b": 32.5,
+ "p2": 35.99,
+ "p2b": 39.74,
+ "all": 42.943,
+ "inf": 46.667
+ },
+ "cues": [
+ [
+ 0.091,
+ "Now a different case."
+ ],
+ [
+ 1.55,
+ "x plus two y equals three, and two x plus four y equals six."
+ ],
+ [
+ 6.536,
+ "This time the whole second equation, both sides, is twice the first: two times x plus two y is two x plus four y, and two times three is six."
+ ],
+ [
+ 16.888,
+ "Halve it, and it's x plus two y equals three again: the very same equation."
+ ],
+ [
+ 22.852,
+ "In the picture, the coral line lies exactly on top of the blue line."
+ ],
+ [
+ 27.24,
+ "Take any point on it."
+ ],
+ [
+ 28.568,
+ "Three, zero: three plus zero is three, and six plus zero is six."
+ ],
+ [
+ 34.922,
+ "Both work."
+ ],
+ [
+ 35.99,
+ "One, one: one plus two is three, and two plus four is six."
+ ],
+ [
+ 41.862,
+ "Both work."
+ ],
+ [
+ 42.943,
+ "Every point on this line solves both equations."
+ ],
+ [
+ 46.667,
+ "So this system has endlessly many solutions: the whole line."
+ ]
+ ]
+ },
+ "same2": {
+ "dur": 31.464,
+ "marks": {
+ "eq": 3.581,
+ "times": 10.052,
+ "a": 13.06,
+ "b": 14.427,
+ "c": 16.042,
+ "match": 17.734,
+ "draw": 20.117,
+ "inf": 22.122,
+ "say": 24.57
+ },
+ "cues": [
+ [
+ 0.104,
+ "The multiple can be any number, even a negative one."
+ ],
+ [
+ 3.581,
+ "x minus y equals one, and negative two x plus two y equals negative two."
+ ],
+ [
+ 10.052,
+ "Multiply the first equation by negative two: negative two x, plus two y, equals negative two."
+ ],
+ [
+ 17.734,
+ "That's exactly the second equation."
+ ],
+ [
+ 20.117,
+ "So the two lines are one line, and every point on it is a solution."
+ ],
+ [
+ 24.57,
+ "Multiplying both sides of an equation by the same number, as long as it isn't zero, never moves its line."
+ ]
+ ]
+ },
+ "q2": {
+ "dur": 3.696,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.185,
+ "How many solutions does this system have?"
+ ]
+ ]
+ },
+ "rule": {
+ "dur": 71.856,
+ "marks": {
+ "s1": 2.878,
+ "s2": 12.773,
+ "s3": 17.227,
+ "s4": 20.495,
+ "s5": 25.312,
+ "ex": 28.763,
+ "e1": 29.766,
+ "e1a": 35.729,
+ "e1b": 43.346,
+ "e1c": 47.721,
+ "e2": 48.867,
+ "e2a": 50.69,
+ "e2b": 53.568,
+ "e2c": 56.732,
+ "e3": 58.919,
+ "e3a": 61.107,
+ "e3b": 66.51,
+ "e3c": 68.034
+ },
+ "cues": [
+ [
+ 0.117,
+ "So here's how to tell, from the numbers alone."
+ ],
+ [
+ 2.878,
+ "First, compare the left sides."
+ ],
+ [
+ 5.078,
+ "Is the second one a multiple of the first?"
+ ],
+ [
+ 7.982,
+ "Both the x number and the y number must be multiplied by the same thing."
+ ],
+ [
+ 12.773,
+ "If not, the lines have different tilts, so they cross at one point."
+ ],
+ [
+ 17.227,
+ "If yes, compare the right sides with the same multiple."
+ ],
+ [
+ 20.495,
+ "Same multiple: the same line, endlessly many solutions."
+ ],
+ [
+ 25.312,
+ "Different: parallel lines, no solution."
+ ],
+ [
+ 28.763,
+ "Let's try it."
+ ],
+ [
+ 29.766,
+ "x plus two y equals four, and three x plus six y equals twelve."
+ ],
+ [
+ 35.729,
+ "Left side: one times three is three, two times three is six."
+ ],
+ [
+ 41.341,
+ "A multiple, times three."
+ ],
+ [
+ 43.346,
+ "Right side: four times three is twelve."
+ ],
+ [
+ 46.38,
+ "The same multiple."
+ ],
+ [
+ 47.721,
+ "The same line."
+ ],
+ [
+ 48.867,
+ "Change the twelve to ten."
+ ],
+ [
+ 50.69,
+ "The left side is still three times."
+ ],
+ [
+ 53.568,
+ "But four times three is twelve, not ten."
+ ],
+ [
+ 56.732,
+ "Parallel: no solution."
+ ],
+ [
+ 58.919,
+ "Now change the six to a five."
+ ],
+ [
+ 61.107,
+ "One times three is three, but two times three is six, not five."
+ ],
+ [
+ 66.51,
+ "Not a multiple at all."
+ ],
+ [
+ 68.034,
+ "So the lines cross at one point: four, zero."
+ ]
+ ]
+ },
+ "runaway": {
+ "dur": 44.52,
+ "marks": {
+ "eq": 2.096,
+ "meet": 6.732,
+ "turn": 9.232,
+ "run": 15.612,
+ "six": 19.206,
+ "off": 22.643,
+ "far": 27.24,
+ "gone": 34.44,
+ "back": 41.406,
+ "home": 42.63
+ },
+ "cues": [
+ [
+ 0.104,
+ "What happens on the way to parallel?"
+ ],
+ [
+ 2.096,
+ "Take x plus y equals two, and two x plus y equals five."
+ ],
+ [
+ 6.732,
+ "They cross at three, negative one."
+ ],
+ [
+ 9.232,
+ "Now turn the coral line, slowly, toward the blue line's tilt, by making the two smaller."
+ ],
+ [
+ 15.612,
+ "Watch the meeting point: it runs away along the blue line."
+ ],
+ [
+ 19.206,
+ "At one and a half, it's at six, negative four."
+ ],
+ [
+ 22.643,
+ "At one point two, it's off the picture: fifteen, negative thirteen."
+ ],
+ [
+ 27.24,
+ "At one point one, thirty, negative twenty eight."
+ ],
+ [
+ 30.69,
+ "The closer the tilts, the farther away the lines meet."
+ ],
+ [
+ 34.44,
+ "And at exactly one, the lines are parallel, and the meeting point is gone."
+ ],
+ [
+ 39.974,
+ "No solution at all."
+ ],
+ [
+ 41.406,
+ "Turn it back, and the meeting point comes home."
+ ]
+ ]
+ },
+ "q3": {
+ "dur": 2.856,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn."
+ ],
+ [
+ 1.068,
+ "Make the system you're asked for."
+ ]
+ ]
+ },
+ "wrap": {
+ "dur": 32.232,
+ "marks": {
+ "w1": 1.003,
+ "w2": 9.792,
+ "w3": 16.029,
+ "w4": 24.193,
+ "end": 30.052
+ },
+ "cues": [
+ [
+ 0.104,
+ "To sum up."
+ ],
+ [
+ 1.003,
+ "Two lines can cross once, never meet, or be the same line: one solution, none, or endlessly many."
+ ],
+ [
+ 9.792,
+ "First compare the left sides: if one isn't a multiple of the other, the lines cross at one point."
+ ],
+ [
+ 16.029,
+ "If it is, compare the right sides with the same multiple."
+ ],
+ [
+ 19.245,
+ "The same: the same line."
+ ],
+ [
+ 21.341,
+ "Different: parallel, no solution."
+ ],
+ [
+ 24.193,
+ "Multiplying both sides of an equation by a number other than zero doesn't move its line."
+ ],
+ [
+ 30.052,
+ "Now try the chapter practice."
+ ]
+ ]
+ },
+ "final1": {
+ "dur": 4.968,
+ "marks": {},
+ "cues": [
+ [
+ 0.117,
+ "Chapter practice."
+ ],
+ [
+ 1.51,
+ "One solution, none, or endlessly many?"
+ ]
+ ]
+ },
+ "final2": {
+ "dur": 2.472,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Next, find the missing numbers."
+ ]
+ ]
+ },
+ "final3": {
+ "dur": 1.872,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Now think it through."
+ ]
+ ]
+ },
+ "final4": {
+ "dur": 3.648,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Last set."
+ ],
+ [
+ 1.237,
+ "Build each system with your hands."
+ ]
+ ]
+ },
+ "finish": {
+ "dur": 11.544,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Well done."
+ ],
+ [
+ 1.094,
+ "That's the end of chapter three, crossing, parallel or the same line."
+ ],
+ [
+ 6.12,
+ "Next: a new idea, vectors, arrows made from columns of numbers."
+ ]
+ ]
+ }
+};
diff --git a/site/linear-algebra/ch03/audio/en/wrap.mp3 b/site/linear-algebra/ch03/audio/en/wrap.mp3
new file mode 100644
index 0000000..95ffe86
Binary files /dev/null and b/site/linear-algebra/ch03/audio/en/wrap.mp3 differ
diff --git a/site/linear-algebra/ch03/index.html b/site/linear-algebra/ch03/index.html
new file mode 100644
index 0000000..3601ada
--- /dev/null
+++ b/site/linear-algebra/ch03/index.html
@@ -0,0 +1,400 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>Crossing, Parallel or the Same Line</title>
+<link rel="stylesheet" href="../lib/engine.css">
+<link rel="expect" href="#bar" blocking="render"><!-- hold the first frame until the player exists, so the page transition can run -->
+</head>
+<body>
+<script src="../lib/engine.js"></script>
+<script src="../lib/math.js"></script>
+<script src="../lib/linsys.js"></script>
+<script src="audio/en/timings.js"></script>
+<script>
+'use strict';
+const CHAPTER = { number: 3, title: 'Crossing, Parallel or the Same Line', minutes: 10, language: 'en' };
+
+/* ---------- chapter drawing helpers (chapter 2's, plus the same-line dash and the off-grid marker) ---------- */
+const BLUE = LS_ROW[0], CORAL = LS_ROW[1];
+const CARD = { x: 40, y: 345, w: 720, cls: 'side' };
+const RCARD = { x: 790, y: 150, w: 770, cls: 'side' };
+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 flash = (sys, key, t0) => sys.num(key).forEach(e => { tw(e, { c_fill: COL.task }, t0, .25); tw(e, { c_fill: COL.chalk }, t0 + 1.2, .6); });
+const pairStr = (x, y) => `(${num(x)}, ${num(y)})`;
+const drop = (sys, x, y, t0, color = COL.chalk, label = pairStr(x, y), dx = 16, dy = -16, into) => sys.P.dot(x, y, color, t0, { label, dx, dy, into });
+const okMark = (p, ok, x, y, t0, size = 34) => text(p, ok ? '✓' : '✗', x, y, t0, { size, fill: ok ? COL.good : COL.bad, weight: 700, anchor: 'middle' });
+const near = (s, x, y) => s.x !== undefined && Math.abs(s.x - x) < 1e-9 && Math.abs(s.y - y) < 1e-9;
+const eqStr = (a, bb, c) => {
+ const t = (k, s) => (k === 1 ? '' : k === -1 ? '−' : num(k)) + s;
+ const L = a === 0 ? t(bb, 'y') : bb === 0 ? t(a, 'x') : `${t(a, 'x')} ${bb < 0 ? '−' : '+'} ${t(Math.abs(bb), 'y')}`;
+ return `${L} = ${num(c)}`;
+};
+// Two equations in the top left, the plane on the right. When the two lines are one line, the coral one is drawn
+// dashed so the blue one shows through it. When the lines meet off the picture, an arrow at the edge points there.
+const twoLines = (p, A, b, { t0 = .1, lines = true, meet = true, readout = true, hidePlane = false, offMark = false } = {}) => {
+ const sys = linsys(p, { A, b, eq: [90, 200], mat: null, t0, hidePlane });
+ if (!lines) sys.lines.forEach(({ l }) => put(l, { o: 0 }));
+ if (!meet) put(sys.meetBox, { o: 0 });
+ if (!readout) put(sys.readout, { o: 0 });
+ const l2 = sys.lines[1].l;
+ const { PX, PY, x1 } = sys.P, mark = G(sys.P.g, { o: 0 });
+ const arr = path(mark, '', { stroke: COL.chalk, fill: COL.chalk, 'stroke-width': 4, 'stroke-linejoin': 'round' });
+ const lab = T(mark, '', { size: 26, fill: COL.chalk, font: MATH, weight: 600 });
+ const fmt1 = n => num(Math.round(n * 10) / 10);
+ const onChange = (v, s) => {
+ const dash = s.many ? '22 16' : '';
+ if ((l2.getAttribute('stroke-dasharray') || '') !== dash) dash ? l2.setAttribute('stroke-dasharray', dash) : l2.removeAttribute('stroke-dasharray');
+ const out = offMark && s.x !== undefined && Math.max(Math.abs(s.x), Math.abs(s.y)) > x1;
+ put(mark, { o: out ? 1 : 0 });
+ if (!out) { arr.setAttribute('d', ''); lab.textContent = ''; put(lab, { x: 0, y: 0 }); return; } // nothing left over, so a seek shows the same page
+ const k = x1 / Math.max(Math.abs(s.x), Math.abs(s.y)), ex = s.x * k, ey = s.y * k, n = Math.hypot(s.x, s.y), ux = s.x / n, uy = s.y / n;
+ const a = [PX(ex - ux * 1.1), PY(ey - uy * 1.1)], c = [PX(ex), PY(ey)];
+ arr.setAttribute('d', `M${a[0]} ${a[1]}L${c[0]} ${c[1]}M${c[0] - 16 * ux - 9 * uy} ${c[1] + 16 * uy - 9 * ux}L${c[0]} ${c[1]}L${c[0] - 16 * ux + 9 * uy} ${c[1] + 16 * uy + 9 * ux}Z`);
+ lab.textContent = `meets at (${fmt1(s.x)}, ${fmt1(s.y)})`;
+ put(lab, { x: c[0] + (ux > 0 ? -30 : 30), y: c[1] + (uy < 0 ? 44 : -26) }); // beside the arrow's tip, outside the grid's numbers
+ lab.setAttribute('text-anchor', ux > 0 ? 'end' : 'start');
+ };
+ sys.onChange(onChange);
+ onChange(sys.v, sys.solve());
+ return sys;
+};
+// A small framed picture of two lines, for comparing the three cases side by side.
+const mini = (p, cx, cy, l1, l2, t0, caption, sub, tPlane = t0) => {
+ const P = plane(p, { cx, cy, u: 30, x0: -5, x1: 5, y0: -5, y1: 5, labels: false, t0: tPlane });
+ P.line(...l1, BLUE, t0 + .4, { w: 5 });
+ P.line(...l2, CORAL, t0 + .8, { w: 5, dash: l2.dash });
+ text(p, caption, cx, cy + 225, t0 + .6, { size: 32, weight: 600, anchor: 'middle' });
+ return { P, sub: sub ? T(p, sub, { x: cx, y: cy + 270, size: 28, fill: COL.task, weight: 600, anchor: 'middle', o: 0 }) : null };
+};
+
+/* ---------- practice data ---------- */
+const KINDS = [['one', 'One', null, 'O'], ['none', 'None', null, 'N'], ['many', 'Endlessly many', null, 'E']];
+const CLASSQ = [
+ { sys: [[1, 1, 4], [1, 1, 1]], ans: ['none'], why: 'Same left side, different right sides: parallel. No pair adds up to 4 and to 1.' },
+ { sys: [[1, -1, 2], [3, -3, 6]], ans: ['many'], why: 'The second is the first times 3, both sides: the same line.' },
+ { sys: [[1, 1, 4], [1, -1, 2]], ans: ['one'], why: 'x − y is not a multiple of x + y (1·1 = 1, but 1·1 ≠ −1): they cross, at (3, 1).' },
+ { sys: [[2, 1, 3], [6, 3, 3]], ans: ['none'], why: 'Left side times 3, but 3·3 = 9, not 3: parallel.' },
+ { sys: [[1, 3, 2], [2, 5, 4]], ans: ['one'], why: '1·2 = 2, but 3·2 = 6, not 5: not a multiple, so they cross.' },
+ { sys: [[-1, 2, 5], [2, -4, -10]], ans: ['many'], why: 'Times −2: −1 → 2, 2 → −4, 5 → −10. The same line.' },
+ { sys: [[0, 1, 2], [0, 1, 5]], ans: ['none'], why: 'y = 2 and y = 5: two flat lines, one above the other. Parallel.' },
+ { sys: [[1, 0, 1], [0, 1, 3]], ans: ['one'], why: 'x = 1 stands up, y = 3 lies flat: they cross at (1, 3).' },
+].map(q => ({ ...q, parts: [$m(eqStr(...q.sys[0])), ' and ', $m(eqStr(...q.sys[1]))] }));
+const PARQ = [
+ { parts: ['x + 2y = 3, 2x + ', { box: '4' }, 'y = 1'], why: '2x is twice x, so the y number must be twice 2: 4. Then 2·3 = 6 ≠ 1, so they are parallel.', hint: 'The second x number is twice the first. Make the y number twice as well.' },
+ { parts: ['3x − y = 2, ', { box: '6' }, 'x − 2y = 5'], why: '−2y is twice −y, so the x number must be twice 3: 6. And 2·2 = 4 ≠ 5: parallel.', hint: 'Compare the y numbers: −2 is twice −1. So the x number is twice 3.' },
+];
+const SAMEQ = [
+ { parts: ['x + y = 4, 5x + 5y = ', { box: '20' }], why: 'Both sides times 5: 4·5 = 20.', hint: 'The left side is 5 times. Multiply the right side by 5 too.' },
+ { parts: ['2x − y = 1, −4x + ', { box: '2' }, 'y = −2'], why: 'Times −2: 2 → −4, −1 → 2, 1 → −2.', hint: '−4 is 2 times −2. What is −1 times −2?' },
+ { parts: ['4x + 2y = 6, 2x + y = ', { box: '3' }], why: 'The second is the first halved: 6 halved is 3.', hint: 'The second left side is half of the first. Halve the right side too.' },
+];
+const NONEQ = [
+ { parts: ['x + 3y = 2, 2x + 6y = ', { box: '5' }], test: ([v]) => v !== 4, why: 'Any number except 4. With 4 it would be the same line (2·2 = 4); anything else makes the lines parallel.', hint: 'Left side times 2. The same multiple of the right side, 4, would give the same line, so pick anything else.' },
+];
+const THINKQ = [
+ { prompt: ['Can one pair ', $m('(x, y)'), ' make both ', $m('x + y = 3'), ' and ', $m('x + y = 8'), ' true?'],
+ opts: ['Yes, exactly one pair', 'No, never', 'Yes, endlessly many'], right: 1,
+ why: 'x + y is one number. It cannot be 3 and 8 at the same time: parallel lines, no solution.',
+ no: ['There is no crossing: the lines have the same tilt. Try a pair: if x + y = 3, it is not 8.', '', 'Only if 3 and 8 were the same number.'] },
+ { prompt: ['Two different points both solve a system of two equations. How many solutions does it have?'],
+ opts: ['Exactly two', 'Endlessly many', 'None'], right: 1,
+ why: 'Two different lines share at most one point. Sharing two means they are the same line, and every point on it is a solution.',
+ no: ['Two straight lines cannot meet at exactly two points. If they share two, they are the same line.', '', 'The two points do solve it, so there are solutions.'] },
+ { prompt: ['The lines of a system cross at ', $m('(2, 1)'), '. Can ', $m('(5, 0)'), ' also solve both equations?'],
+ opts: ['Yes', 'No', 'Only if the right sides are 0'], right: 1,
+ why: 'Crossing lines meet at exactly one point. (2, 1) is that point, so no other pair solves both.',
+ no: ['Lines that cross share one point only.', '', 'The right sides do not matter: crossing lines share one point only.'] },
+ { prompt: ['Multiply both sides of ', $m('x − 2y = 4'), ' by 3. What happens to its line?'],
+ opts: ['It slides', 'It turns', 'It stays where it is'], right: 2,
+ why: '3x − 6y = 12 has exactly the same solutions, for example (4, 0) and (0, −2): the same line.',
+ no: ['Only changing the right side alone slides it. Here every number is multiplied, so every solution still works.', 'Every point that solved x − 2y = 4 still solves 3x − 6y = 12. Check (4, 0).', ''] },
+];
+const BUILDQ = [
+ { start: { a00: 1, a01: -2, b0: 2, a10: 1, a11: 1, b1: 1 }, only: ['a10', 'a11'], test: s => !!s.none,
+ prompt: ['Change only the ', $m('x'), ' and ', $m('y'), ' numbers of the second equation so the lines never meet.'],
+ why: 'For example x − 2y = 1: the same tilt as x − 2y = 2, with a different right side. Parallel, no solution.',
+ hint: 'Copy the tilt: make the second left side a multiple of x − 2y, such as x − 2y or 2x − 4y.', answer: { a10: 1, a11: -2 } },
+ { start: { a00: 1, a01: 2, b0: 3, a10: 2, a11: 4, b1: 1 }, only: ['b1'], test: s => !!s.many,
+ prompt: ['Change only the second right side so the two lines become one line.'],
+ why: '2x + 4y = 6: the whole second equation is now twice x + 2y = 3.',
+ hint: 'The left side is twice x + 2y. Make the right side twice 3.', answer: { b1: 6 } },
+ { start: { a00: 1, a01: 1, b0: 1, a10: 1, a11: 1, b1: 4 }, only: ['a10', 'a11'], test: s => near(s, -1, 2),
+ prompt: ['These lines are parallel. Change only the ', $m('x'), ' and ', $m('y'), ' numbers of the second equation so they cross at ', $m('(−1, 2)'), '.'],
+ why: 'For example 2y = 4 (0x + 2y), or 2x + 3y = 4: −1 times the x number plus 2 times the y number must make 4.',
+ hint: '(−1, 2) is already on the blue line. The coral line turns about (0, 4) here; make −1·(x number) + 2·(y number) = 4.', answer: { a10: 0, a11: 2 } },
+];
+
+/* ---------- beats ---------- */
+const BEATS = [
+ ['intro', 'Crossing, parallel or the same line', (m, D) => {
+ const g = G(scene, { o: 0, y: 24 });
+ T(g, 'Unit 1, Chapter 3', { x: 800, y: 300, size: 28, fill: COL.dim, anchor: 'middle' });
+ T(g, 'Crossing, Parallel or the Same Line', { x: 800, y: 410, size: 80, weight: 600, anchor: 'middle' });
+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);
+ const r = text(scene, 'two lines meet once, never, or everywhere', 800, 540, m('sub'), { size: 36, fill: COL.dim, anchor: 'middle' });
+ const pics = G(scene, { y: 690 });
+ [[-1, 1, 1, -1, 1, 1, -1, -1], [-1, .4, 1, .4, -1, -.4, 1, -.4], [-1, 0, 1, 0, -1, 0, 1, 0]].forEach((s, i) => {
+ const g2 = G(pics, { x: 470 + i * 330 }), k = 110;
+ const a = path(g2, `M${s[0] * k} ${-s[1] * 60}L${s[2] * k} ${-s[3] * 60}`, { stroke: BLUE, 'stroke-width': 6, 'stroke-linecap': 'round' }, { d: 0 });
+ const b = path(g2, `M${s[4] * k} ${-s[5] * 60}L${s[6] * k} ${-s[7] * 60}`, { stroke: CORAL, 'stroke-width': 6, 'stroke-linecap': 'round', ...(i === 2 ? { 'stroke-dasharray': '18 14' } : {}) }, { d: 0 });
+ draw(a, m('three') + i * .9, .6); draw(b, m('three') + i * .9 + .3, .6);
+ hide(g2, D - .9, .8);
+ });
+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8);
+ }],
+
+ ['three', 'Three ways', (m) => {
+ const p = panel(0);
+ text(p, 'Two lines can sit together in three ways', 60, 110, .2, { size: 40, weight: 600 });
+ const a = mini(p, 300, 420, [-4, -2, 4, 2], [-4, 3, 4, -1], .4, 'they cross', 'one solution');
+ const b = mini(p, 800, 420, [-4, -3, 4, 1], [-4, 0, 4, 4], m('par'), 'parallel', 'no solution', m('but') + .3);
+ const l2 = [-4, 4, 4, -4]; l2.dash = '18 14';
+ const c = mini(p, 1300, 420, [-4, 4, 4, -4], l2, m('same'), 'the same line', 'endlessly many', m('but') + .7);
+ const d1 = a.P.dot(2, 1, COL.chalk, 2);
+ pulse(d1, m('one')); pulse(d1, m('cross') + .3); show(a.sub, m('one') + .4);
+ pulse(d1, m('sizes')); show(b.sub, m('none')); show(c.sub, m('inf'));
+ const gap = G(p, {}), { PX, PY } = b.P;
+ path(gap, `M${PX(0)} ${PY(-1)}V${PY(2)}`, { stroke: COL.dim, 'stroke-width': 2.5, 'stroke-dasharray': '5 6' }, { o: 0 });
+ show(gap.firstChild, m('par') + 1.6, .4);
+ [-3, 0, 3].forEach((x, i) => c.P.dot(x, -x, COL.task, m('same') + 1.5 + i * .3, { r: 8 }));
+ }],
+
+ ['parallel', 'Lines that never meet', (m) => {
+ const p = panel(0);
+ text(p, 'Parallel lines: no solution', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = twoLines(p, [[1, 1], [1, 1]], [2, 5], { t0: m('eq') - .3, lines: false, readout: false });
+ say(p, ['x + y = 2 and x + y = 5 ?'], 90, 470, m('ask'), { size: 38 });
+ say(p, ['1 + 1 = 2'], 90, 545, m('try'), { size: 36, fill: BLUE });
+ say(p, ['1 + 1 ≠ 5'], 90, 600, m('sum'), { size: 36, fill: CORAL });
+ text(p, 'x + y is one number: it cannot be 2 and 5 at once', 90, 670, m('never'), { size: 28, fill: COL.task, weight: 600 });
+ const { PX, PY } = sys.P;
+ show(sys.lines[0].l, m('l1'), .9); show(sys.lines[1].l, m('l2'), .9);
+ // a probe walks along each line: its sum never changes
+ const probe = (row, c, t, dur) => {
+ const g = G(p, { o: 0 }); mk('circle', { r: 11, fill: LS_ROW[row], stroke: COL.board, 'stroke-width': 3 }, g);
+ const lb = T(g, '', { x: 18, y: -16, size: 24, fill: LS_ROW[row], font: MATH, weight: 600 });
+ show(g, t, .3);
+ prog(q => { const x = -1 + q * 5, y = c - x; put(g, { x: PX(x), y: PY(y) }); const s = `${num(Math.round(x * 10) / 10)} + ${num(Math.round(y * 10) / 10)} = ${c}`; if (lb.textContent !== s) lb.textContent = s; }, t, dur, io);
+ hide(g, t + dur + .3, .4);
+ };
+ probe(0, 2, m('l1') + .9, 3); probe(1, 5, m('l2') + .9, 3);
+ const ghost = sys.P.line(0, 2, 2, 0, BLUE, m('slid'), { dash: '10 10', w: 3 }); tw(ghost, { o: .45 }, m('slid') + .6, .3);
+ prog(q => { const s = q * 1.5; put(ghost, { x: s * sys.P.u, y: -s * sys.P.u }); }, m('slid') + .8, 2.2, io);
+ hide(ghost, m('tilt') + 1.6, .4);
+ // the gap stays the same: two equal gaps marked
+ const gaps = G(p, { o: 0 });
+ put(gaps, { o: 1 });
+ [[-2.5, 4.5, -1, 6], [-1, 3, .5, 4.5], [.5, 1.5, 2, 3], [2, 0, 3.5, 1.5], [3.5, -1.5, 5, 0]].forEach(([x1, y1, x2, y2], i) =>
+ draw(path(gaps, `M${PX(x1)} ${PY(y1)}L${PX(x2)} ${PY(y2)}`, { stroke: COL.dim, 'stroke-width': 3 }, { d: 0 }), m('tilt') + .5 + i * .5, .4));
+ text(p, 'always the same gap', PX(-5.6), PY(-3), m('gap'), { size: 26, fill: COL.dim });
+ show(sys.readout, m('none'));
+ }],
+
+ ['parallel2', 'Twice the left side', (m) => {
+ const p = panel(0);
+ text(p, 'A hidden pair of parallel lines', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = twoLines(p, [[2, 1], [4, 2]], [1, 6], { t0: m('eq') - .3, readout: false });
+ sys.lines.forEach(({ l }, i) => { put(l, { o: 0 }); show(l, m('eq') + 1 + i * .5, .8); });
+ const w = G(p, {});
+ say(w, ['4x = 2 · 2x'], 90, 470, m('twice'), { size: 36, fill: CORAL });
+ say(w, ['2y = 2 · y'], 90, 525, m('twice') + 1.6, { size: 36, fill: CORAL });
+ say(w, ['halve both sides: ÷ 2'], 90, 600, m('half'), { size: 32, fill: COL.dim });
+ flash(sys, 'a10', m('after')); flash(sys, 'a11', m('after')); flash(sys, 'b1', m('after'));
+ sys.to({ a10: 2, a11: 1, b1: 3 }, m('after'), 1.6);
+ tw(sys.lines[1].l, { 'a_stroke-width': 9 }, m('still'), .3); tw(sys.lines[1].l, { 'a_stroke-width': 5 }, m('still') + 1.2, .5);
+ text(p, 'the coral line did not move', 90, 660, m('still') + .5, { size: 28, fill: CORAL, weight: 600 });
+ hide(w, m('now') - .3, .4);
+ say(p, ['2x + y = 1'], 470, 470, m('now'), { size: 38, fill: BLUE });
+ say(p, ['2x + y = 3'], 470, 535, m('and'), { size: 38, fill: CORAL });
+ text(p, '1 or 3? impossible', 470, 600, m('no'), { size: 30, fill: COL.bad, weight: 600 });
+ show(sys.readout, m('none'));
+ }],
+
+ ['q1', 'Quick check', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
+ id: 'c-par', prompt: ['Do the two lines cross, or are they parallel? Compare the left sides first.'],
+ build: grid([
+ { parts: [$m('x + y = 3'), ' and ', $m('x + y = 7')], ans: ['p'], why: 'The same left side, different right sides: parallel.' },
+ { parts: [$m('x + 2y = 1'), ' and ', $m('2x + 4y = 5')], ans: ['p'], why: 'Left side times 2, but 1·2 = 2, not 5: parallel.' },
+ { parts: [$m('x + y = 3'), ' and ', $m('x − y = 3')], ans: ['c'], why: 'x − y is not a multiple of x + y: they cross (at (3, 0)).' },
+ { parts: [$m('3x − y = 2'), ' and ', $m('6x − 2y = 1')], ans: ['p'], why: 'Left side times 2, but 2·2 = 4, not 1: parallel.' },
+ { parts: [$m('2x + y = 4'), ' and ', $m('x + 2y = 4')], ans: ['c'], why: '2 → 1 is halving, but 1 → 2 is doubling: not one multiple. They cross.' },
+ ], [['c', 'Cross', null, 'C'], ['p', 'Parallel', null, 'P']], { multi: false, text: true }),
+ }], done) }],
+
+ ['same', 'The same line twice', (m) => {
+ const p = panel(0);
+ text(p, 'The same line: endlessly many solutions', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = twoLines(p, [[1, 2], [2, 4]], [3, 6], { t0: m('eq') - .3, lines: false, readout: false });
+ const w = G(p, {});
+ say(w, ['2 · (x + 2y) = 2x + 4y'], 90, 470, m('twice'), { size: 36, fill: CORAL });
+ say(w, ['2 · 3 = 6'], 90, 525, m('six'), { size: 36, fill: CORAL });
+ [['a00', 'a10', 2.5], ['a01', 'a11', 4.5], ['b0', 'b1', 8]].forEach(([k1, k2, d]) => { flash(sys, k1, m('twice') + d); flash(sys, k2, m('twice') + d + .6); });
+ sys.to({ a10: 1, a11: 2, b1: 3 }, m('after'), 1.4);
+ ['a10', 'a11', 'b1'].forEach(k => flash(sys, k, m('after')));
+ show(sys.lines[0].l, m('draw') - .6, .6); show(sys.lines[1].l, m('draw') + .4, .9);
+ hide(w, m('p1') - .3, .3);
+ drop(sys, 3, 0, m('p1'), COL.task, '(3, 0)', 12, -18);
+ say(p, ['3 + 0 = 3'], 90, 470, m('p1') + .6, { size: 34, fill: BLUE }); okMark(p, true, 290, 470, m('p1') + 2);
+ say(p, ['6 + 0 = 6'], 360, 470, m('p1b'), { size: 34, fill: CORAL }); okMark(p, true, 560, 470, m('p1b') + 1);
+ drop(sys, 1, 1, m('p2'), COL.task, '(1, 1)');
+ say(p, ['1 + 2 = 3'], 90, 535, m('p2') + .6, { size: 34, fill: BLUE }); okMark(p, true, 290, 535, m('p2') + 2);
+ say(p, ['2 + 4 = 6'], 360, 535, m('p2b'), { size: 34, fill: CORAL }); okMark(p, true, 560, 535, m('p2b') + 1);
+ [-5, -3, 5].forEach((x, i) => drop(sys, x, (3 - x) / 2, m('all') + i * .4, COL.task, ''));
+ show(sys.readout, m('inf'));
+ }],
+
+ ['same2', 'Any multiple', (m) => {
+ const p = panel(0);
+ text(p, 'Times any number but zero', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = twoLines(p, [[1, -1], [-2, 2]], [1, -2], { t0: m('eq') - .3, readout: false });
+ put(sys.eqRows[1].g, { o: 0 }); show(sys.eqRows[1].g, m('eq') + 2.2);
+ ['a00', 'a01', 'b0'].forEach((k, i) => flash(sys, k, m('times') + .4 + i * .3));
+ sys.lines.forEach(({ l }, i) => { put(l, { o: 0 }); show(l, m('draw') + i * .7, .9); });
+ say(p, ['−2 · (x − y = 1)'], 90, 470, m('times'), { size: 36, fill: BLUE });
+ say(p, ['−2x'], 90, 540, m('a'), { size: 38, fill: CORAL });
+ say(p, ['+ 2y'], 190, 540, m('b'), { size: 38, fill: CORAL });
+ say(p, ['= −2'], 310, 540, m('c'), { size: 38, fill: CORAL });
+ ['a10', 'a11', 'b1'].forEach((k, i) => flash(sys, k, m('match') + i * .25));
+ okMark(p, true, 450, 540, m('match') + .5);
+ show(sys.readout, m('inf'));
+ const n = G(p, { o: 0 });
+ T(n, 'both sides times the same number (not 0):', { x: 90, y: 720, size: 30, weight: 600, fill: COL.task });
+ T(n, 'the line does not move', { x: 90, y: 762, size: 30, weight: 600, fill: COL.task });
+ show(n, m('say'));
+ sys.focus(0, m('say') + 2);
+ sys.to({ a00: 3, a01: -3, b0: 3 }, m('say') + 2.5, 2.5); ['a00', 'a01', 'b0'].forEach(k => flash(sys, k, m('say') + 2.5));
+ text(p, '×3: still the same line', 90, 640, m('say') + 3, { size: 28, fill: BLUE, weight: 600 });
+ sys.focus(null, m('say') + 5.5);
+ }],
+
+ ['q2', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ S.sys = twoLines(p, [[1, -3], [2, -6]], [2, 4], { lines: false, meet: false, readout: false });
+ }, { ask: done => quiz(CARD, [{
+ id: 'c-many', prompt: ['How many solutions does ', $m('x − 3y = 2'), ', ', $m('2x − 6y = 4'), ' have?'],
+ build: choice(['One', 'None', 'Endlessly many'], 2, 'Both sides of the second are twice the first: the same line, so every point on it is a solution.',
+ ['The lines do not cross at one point: 2x − 6y is exactly twice x − 3y, so they have the same tilt.',
+ 'Compare the right sides with the same multiple: 2 · 2 = 4. They match, so it is the same line, not parallel.'],
+ () => S.sys.lines.forEach(({ l }) => fx(l, { o: 1 }, 0, .6))),
+ }], done) }],
+
+ ['rule', 'Read it from the numbers', (m) => {
+ const p = panel(0);
+ text(p, 'How to tell from the numbers', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = twoLines(p, [[1, 2], [3, 6]], [4, 12], { t0: m('ex') - .3, readout: false });
+ put(sys.E, { o: 0 }); put(sys.stage, { o: 0 }); show(sys.stage, m('ex'), .6);
+ // the two questions, as a little flow, under where the equations will be
+ const F0 = G(p, {}), steps = [];
+ const st_ = (str, x, y, mk_, fill = COL.chalk, size = 30) => { const e = text(F0, str, x, y, m(mk_), { size, fill, weight: 600 }); steps.push(e); return e; };
+ const q1 = st_('1 Is the second left side a multiple of the first?', 90, 250, 's1');
+ const no1 = st_('no → they cross: one solution', 150, 305, 's2', COL.dim);
+ const q2 = st_('2 yes → compare the right sides (same multiple)', 90, 375, 's3');
+ const y2 = st_('the same → the same line: endlessly many', 150, 430, 's4', COL.dim);
+ const n2 = st_('different → parallel: no solution', 150, 485, 's5', COL.dim);
+ const ex1 = say(p, ['2x + 3y → ×2 → 4x + 6y'], 150, 620, m('s1') + 5, { size: 34, fill: COL.dim });
+ hide(ex1, m('s2') - .3, .3);
+ tw(F0, { y: 250 }, m('ex') - .2, .8); // the steps move down under the equations
+ const hl = (e, t, t2) => { tw(e, { c_fill: COL.task }, t, .3); tw(e, { c_fill: COL.dim }, t2, .3); };
+ // example 1: times 3 on both sides
+ const l1 = say(p, ['left: 1·3 = 3, 2·3 = 6: times 3'], 90, 395, m('e1a'), { size: 30, fill: CORAL });
+ [['a00', 'a10', 1.2], ['a01', 'a11', 3.4]].forEach(([k1, k2, d]) => { flash(sys, k1, m('e1a') + d); flash(sys, k2, m('e1a') + d + .6); });
+ tw(sys.lines[1].l, { 'a_stroke-width': 9 }, m('e1a') + 5, .3); tw(sys.lines[1].l, { 'a_stroke-width': 5 }, m('e1a') + 6.2, .5);
+ const r1 = say(p, ['right: 4·3 = 12: the same multiple'], 90, 445, m('e1b'), { size: 30, fill: COL.good });
+ hl(y2, m('e1c'), m('e2') + .2);
+ // example 2: the twelve becomes ten
+ sys.to({ b1: 10 }, m('e2'), 1.2); flash(sys, 'b1', m('e2'));
+ hide(r1, m('e2'), .3);
+ const r2 = say(p, ['right: 4·3 = 12, not 10'], 90, 445, m('e2b'), { size: 30, fill: COL.bad });
+ hl(n2, m('e2c'), m('e3') + .2);
+ // example 3: the six becomes five
+ sys.to({ b1: 12, a11: 5 }, m('e3'), 1.4); flash(sys, 'a11', m('e3'));
+ hide(r2, m('e3'), .3); hide(l1, m('e3'), .3);
+ say(p, ['left: 1·3 = 3, but 2·3 = 6, not 5'], 90, 395, m('e3a'), { size: 30, fill: COL.bad });
+ flash(sys, 'a01', m('e3a') + 2); flash(sys, 'a11', m('e3a') + 3.6);
+ tw(sys.lines[1].l, { 'a_stroke-width': 9 }, m('e3a') + 4, .3); tw(sys.lines[1].l, { 'a_stroke-width': 5 }, m('e3b'), .5);
+ tw(no1, { c_fill: COL.task }, m('e3c'), .3);
+ pulse(sys.meet, m('e3c') + .6); pulse(sys.meet, m('e3c') + 1.8);
+ void q1; void q2;
+ }],
+
+ ['runaway', 'On the way to parallel', (m) => {
+ const p = panel(0);
+ text(p, 'Turning toward parallel', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = twoLines(p, [[1, 1], [2, 1]], [2, 5], { t0: m('eq') - .3, offMark: true });
+ put(sys.meet.lastChild, { x: -18, y: 42 }); sys.meet.lastChild.setAttribute('text-anchor', 'end'); // below left of the point, clear of the axis numbers and the lines
+ pulse(sys.meet, m('meet'));
+ sys.focus(1, m('turn'));
+ const steps = [['six', 1.5], ['off', 1.2], ['far', 1.1], ['gone', 1]];
+ const trails = [sys.to({ a10: 1.5 }, m('six') - 1.2, 1.4, io, { trail: true })];
+ steps.slice(1).forEach(([mk_, a]) => sys.to({ a10: a }, m(mk_) - .6, 1.2));
+ steps.forEach(([mk_]) => flash(sys, 'a10', m(mk_) - .6));
+ tw(sys.lines[0].l, { 'a_stroke-width': 9 }, m('run'), .3); tw(sys.lines[0].l, { 'a_stroke-width': 5 }, m('run') + 1.2, .5);
+ trails.forEach(t => hide(t, m('back') - .2, .3));
+ sys.focus(null, m('back'));
+ sys.to({ a10: 2 }, m('back'), 2.4, io);
+ flash(sys, 'a10', m('back'));
+ pulse(sys.meet, m('home'));
+ }],
+
+ ['q3', 'Your turn', () => {
+ const p = panel(0);
+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
+ S.sys = twoLines(p, [[1, 1], [1, -1]], [2, 0], { readout: false, offMark: true });
+ }, { ask: done => quiz(CARD, [{
+ id: 'c-none', prompt: ['Make a system with no solution. Change any numbers.'],
+ build: (body, api) => { S.sys.set({ a00: 1, a01: 1, b0: 2, a10: 1, a11: -1, b1: 0 }); return lsTask(S.sys, (v, s) => !!s.none,
+ 'No solution: your second left side is a multiple of the first, and the right side is not the same multiple. Parallel lines.',
+ 'Make the second left side a copy (or a multiple) of the first, for example x + y. Then give it a different right side.',
+ () => S.sys.set({ a10: 1, a11: 1, b1: 5 }))(body, api); },
+ }, {
+ id: 'c-many', prompt: ['Now make a system with endlessly many solutions.'],
+ build: (body, api) => { S.sys.set({ a00: 1, a01: 1, b0: 2, a10: 1, a11: -1, b1: 0 }); return lsTask(S.sys, (v, s) => !!s.many,
+ 'The same line: the whole second equation is a multiple of the first, both sides.',
+ 'Make the second equation a multiple of the first on both sides, for example 2x + 2y = 4. The coral line will lie on the blue one.',
+ () => S.sys.set({ a10: 2, a11: 2, b1: 4 }))(body, api); },
+ }], done) }],
+
+ ['wrap', 'Summary', (m) => {
+ const p = panel(0);
+ [['Two lines cross once, never meet, or are one line: one solution, none, or endlessly many.', 'w1'],
+ ['Left sides not multiples of each other: the lines cross at one point.', 'w2'],
+ ['Multiples: compare the right sides. Same multiple: one line. Not: parallel.', 'w3'],
+ ['Both sides times the same number (not 0): the line stays put.', 'w4']].forEach(([str, mark], i) => {
+ const g = G(p, { x: -16, y: 230 + i * 130, o: 0 });
+ mk('circle', { cx: 150, cy: -12, r: 26, fill: COL.task }, g);
+ T(g, String(i + 1), { x: 150, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });
+ T(g, str, { x: 210, size: 32, weight: 600 });
+ tw(g, { o: 1, x: 0 }, m(mark), .6);
+ });
+ }],
+ ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
+ id: 'p-kind', prompt: ['How many solutions? Compare the left sides, then the right sides.'],
+ build: grid(CLASSQ, KINDS, { multi: false, text: true }),
+ }], done, 'Chapter practice · set 1 of 4') }],
+ ['final2', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [
+ { id: 'p-par', prompt: ['Find the missing number that makes the two lines parallel.'], build: blanks(PARQ) },
+ { id: 'p-same', prompt: ['Find the missing number that makes the two equations the same line.'], build: blanks(SAMEQ) },
+ { id: 'p-none', prompt: ['Find a number that makes the system have no solution.'], build: blanks(NONEQ) },
+ ], done, 'Chapter practice · set 2 of 4') }],
+ ['final3', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, THINKQ.map((q, k) => ({
+ id: 'p-think' + (k + 1), prompt: q.prompt, build: choice(q.opts, q.right, q.why, q.no),
+ })), done, 'Chapter practice · set 3 of 4') }],
+ ['final4', 'Chapter practice', () => {
+ const p = panel(0);
+ text(p, 'Build the system', 60, 110, .2, { size: 40, weight: 600 });
+ S.sys = twoLines(p, [[1, -2], [1, 1]], [2, 1], { readout: false, offMark: true });
+ }, { ask: done => quiz(CARD, BUILDQ.map((q, k) => ({
+ id: 'p-build' + (k + 1), prompt: q.prompt,
+ build: (body, api) => { S.sys.set(q.start); return lsTask(S.sys, (v, s) => q.test(s), q.why, q.hint, () => S.sys.set(q.answer), { only: q.only })(body, api); },
+ })), done, 'Chapter practice · set 4 of 4') }],
+ ['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],
+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
+
+boot();
+</script>
+</body>
+</html>
diff --git a/site/linear-algebra/ch04/audio/en/.intro-3s6cozug.mp3 b/site/linear-algebra/ch04/audio/en/.intro-3s6cozug.mp3
new file mode 100644
index 0000000..ed7c7b9
Binary files /dev/null and b/site/linear-algebra/ch04/audio/en/.intro-3s6cozug.mp3 differ
diff --git a/site/linear-algebra/ch04/audio/en/arrow.mp3 b/site/linear-algebra/ch04/audio/en/arrow.mp3
new file mode 100644
index 0000000..85993aa
Binary files /dev/null and b/site/linear-algebra/ch04/audio/en/arrow.mp3 differ
diff --git a/site/linear-algebra/ch04/audio/en/column.mp3 b/site/linear-algebra/ch04/audio/en/column.mp3
new file mode 100644
index 0000000..9a65ff0
Binary files /dev/null and b/site/linear-algebra/ch04/audio/en/column.mp3 differ
diff --git a/site/linear-algebra/ch04/audio/en/every.mp3 b/site/linear-algebra/ch04/audio/en/every.mp3
new file mode 100644
index 0000000..e16327b
Binary files /dev/null and b/site/linear-algebra/ch04/audio/en/every.mp3 differ
diff --git a/site/linear-algebra/ch04/audio/en/final1.mp3 b/site/linear-algebra/ch04/audio/en/final1.mp3
new file mode 100644
index 0000000..004a2e9
Binary files /dev/null and b/site/linear-algebra/ch04/audio/en/final1.mp3 differ
diff --git a/site/linear-algebra/ch04/audio/en/final2.mp3 b/site/linear-algebra/ch04/audio/en/final2.mp3
new file mode 100644
index 0000000..44fc547
Binary files /dev/null and b/site/linear-algebra/ch04/audio/en/final2.mp3 differ
diff --git a/site/linear-algebra/ch04/audio/en/final3.mp3 b/site/linear-algebra/ch04/audio/en/final3.mp3
new file mode 100644
index 0000000..aa88961
Binary files /dev/null and b/site/linear-algebra/ch04/audio/en/final3.mp3 differ
diff --git a/site/linear-algebra/ch04/audio/en/final4.mp3 b/site/linear-algebra/ch04/audio/en/final4.mp3
new file mode 100644
index 0000000..9088c64
Binary files /dev/null and b/site/linear-algebra/ch04/audio/en/final4.mp3 differ
diff --git a/site/linear-algebra/ch04/audio/en/finish.mp3 b/site/linear-algebra/ch04/audio/en/finish.mp3
new file mode 100644
index 0000000..0074ffa
Binary files /dev/null and b/site/linear-algebra/ch04/audio/en/finish.mp3 differ
diff --git a/site/linear-algebra/ch04/audio/en/intro.mp3 b/site/linear-algebra/ch04/audio/en/intro.mp3
new file mode 100644
index 0000000..1b6daba
Binary files /dev/null and b/site/linear-algebra/ch04/audio/en/intro.mp3 differ
diff --git a/site/linear-algebra/ch04/audio/en/link.mp3 b/site/linear-algebra/ch04/audio/en/link.mp3
new file mode 100644
index 0000000..4611940
Binary files /dev/null and b/site/linear-algebra/ch04/audio/en/link.mp3 differ
diff --git a/site/linear-algebra/ch04/audio/en/neg.mp3 b/site/linear-algebra/ch04/audio/en/neg.mp3
new file mode 100644
index 0000000..13a6401
Binary files /dev/null and b/site/linear-algebra/ch04/audio/en/neg.mp3 differ
diff --git a/site/linear-algebra/ch04/audio/en/q1.mp3 b/site/linear-algebra/ch04/audio/en/q1.mp3
new file mode 100644
index 0000000..a99f51d
Binary files /dev/null and b/site/linear-algebra/ch04/audio/en/q1.mp3 differ
diff --git a/site/linear-algebra/ch04/audio/en/q2.mp3 b/site/linear-algebra/ch04/audio/en/q2.mp3
new file mode 100644
index 0000000..9efa129
Binary files /dev/null and b/site/linear-algebra/ch04/audio/en/q2.mp3 differ
diff --git a/site/linear-algebra/ch04/audio/en/q3.mp3 b/site/linear-algebra/ch04/audio/en/q3.mp3
new file mode 100644
index 0000000..ac185fd
Binary files /dev/null and b/site/linear-algebra/ch04/audio/en/q3.mp3 differ
diff --git a/site/linear-algebra/ch04/audio/en/read.mp3 b/site/linear-algebra/ch04/audio/en/read.mp3
new file mode 100644
index 0000000..7ec2f30
Binary files /dev/null and b/site/linear-algebra/ch04/audio/en/read.mp3 differ
diff --git a/site/linear-algebra/ch04/audio/en/same.mp3 b/site/linear-algebra/ch04/audio/en/same.mp3
new file mode 100644
index 0000000..eea5389
Binary files /dev/null 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
new file mode 100644
index 0000000..e4082da
--- /dev/null
+++ b/site/linear-algebra/ch04/audio/en/timings.js
@@ -0,0 +1,640 @@
+window.TIMINGS = {
+ "intro": {
+ "dur": 12.024,
+ "marks": {
+ "sub": 4.948,
+ "arrow": 9.583
+ },
+ "cues": [
+ [
+ 0.091,
+ "Chapter four."
+ ],
+ [
+ 1.315,
+ "Vectors: arrows and columns of numbers."
+ ],
+ [
+ 4.948,
+ "Two numbers, written one above the other, make a new kind of object."
+ ],
+ [
+ 9.583,
+ "And every one of them is also an arrow."
+ ]
+ ]
+ },
+ "column": {
+ "dur": 50.904,
+ "marks": {
+ "stand": 4.284,
+ "br": 8.815,
+ "name": 11.029,
+ "v": 12.5,
+ "top": 16.224,
+ "bot": 18.984,
+ "apples": 21.172,
+ "more": 28.737,
+ "more2": 33.125,
+ "order": 35.69,
+ "why": 42.786
+ },
+ "cues": [
+ [
+ 0.091,
+ "Up to now, two numbers together meant a point, like three, two."
+ ],
+ [
+ 4.284,
+ "Now we stand the same two numbers up: three on top, two underneath, inside square brackets."
+ ],
+ [
+ 11.029,
+ "This is called a vector."
+ ],
+ [
+ 12.5,
+ "We give it a single letter, v."
+ ],
+ [
+ 14.349,
+ "One letter for the whole column."
+ ],
+ [
+ 16.224,
+ "The top number is the first number of the vector."
+ ],
+ [
+ 18.984,
+ "The bottom number is the second."
+ ],
+ [
+ 21.172,
+ "A vector keeps its two numbers together without mixing them, like three steps east and two steps north on a map."
+ ],
+ [
+ 28.737,
+ "Here are two more vectors: minus one on top and five below, and zero on top and four below."
+ ],
+ [
+ 35.69,
+ "Order matters."
+ ],
+ [
+ 36.953,
+ "Three on top and two below is not the same vector as two on top and three below."
+ ],
+ [
+ 42.786,
+ "Why stand the numbers up?"
+ ],
+ [
+ 44.219,
+ "Because in chapter seven, the numbers of a system of equations will stand in exactly these columns."
+ ]
+ ]
+ },
+ "arrow": {
+ "dur": 45.216,
+ "marks": {
+ "axes": 2.578,
+ "right": 4.44,
+ "up": 8.581,
+ "tip": 12.24,
+ "same": 20.482,
+ "w": 28.164,
+ "w1": 32.018,
+ "w4": 32.721,
+ "wtip": 33.906,
+ "swap": 36.458,
+ "diff": 40.599
+ },
+ "cues": [
+ [
+ 0.091,
+ "Every vector is also an arrow."
+ ],
+ [
+ 2.578,
+ "Here's the plane from chapter one."
+ ],
+ [
+ 4.44,
+ "The top number, three, says: go three steps right."
+ ],
+ [
+ 8.581,
+ "The bottom number, two, says: then go two steps up."
+ ],
+ [
+ 12.24,
+ "The arrow starts at the origin, zero, zero, and ends where those steps end: at the point three, two."
+ ],
+ [
+ 20.482,
+ "So the point and the vector carry the same two numbers."
+ ],
+ [
+ 24.648,
+ "The vector is the arrow from the origin to the point."
+ ],
+ [
+ 28.164,
+ "Another one."
+ ],
+ [
+ 29.193,
+ "Call it w: one on top, four below."
+ ],
+ [
+ 32.018,
+ "One step right, four steps up."
+ ],
+ [
+ 33.906,
+ "Its arrow ends at the point one, four."
+ ],
+ [
+ 36.458,
+ "And here is two on top, three below: the swap of v."
+ ],
+ [
+ 40.599,
+ "Two right, three up: a different arrow."
+ ],
+ [
+ 43.659,
+ "That's why order matters."
+ ]
+ ]
+ },
+ "neg": {
+ "dur": 32.472,
+ "marks": {
+ "n1": 1.667,
+ "left": 4.349,
+ "up": 8.216,
+ "n2": 9.948,
+ "four": 12.565,
+ "down": 13.568,
+ "n3": 17.63,
+ "ld": 20.573,
+ "sum": 25.234
+ },
+ "cues": [
+ [
+ 0.104,
+ "Numbers can be negative."
+ ],
+ [
+ 1.667,
+ "Take minus two on top, three below."
+ ],
+ [
+ 4.349,
+ "A negative top number means go left: two steps left."
+ ],
+ [
+ 8.216,
+ "Then three steps up."
+ ],
+ [
+ 9.948,
+ "Now four on top, minus one below."
+ ],
+ [
+ 12.565,
+ "Four steps right, and one step down."
+ ],
+ [
+ 15.039,
+ "A negative bottom number means go down."
+ ],
+ [
+ 17.63,
+ "Minus three on top, minus two below: three left, two down."
+ ],
+ [
+ 22.526,
+ "This arrow points down and to the left."
+ ],
+ [
+ 25.234,
+ "So the signs give the direction."
+ ],
+ [
+ 27.526,
+ "The top sign says left or right, the bottom sign says down or up."
+ ]
+ ]
+ },
+ "zero": {
+ "dur": 30.0,
+ "marks": {
+ "z": 2.214,
+ "stay": 4.818,
+ "name": 9.779,
+ "one": 16.979,
+ "yaxis": 23.568,
+ "flat": 25.273
+ },
+ "cues": [
+ [
+ 0.104,
+ "One vector is special."
+ ],
+ [
+ 2.214,
+ "Zero on top, zero below."
+ ],
+ [
+ 4.818,
+ "No steps right, no steps up: the arrow never leaves the origin."
+ ],
+ [
+ 9.779,
+ "This is the zero vector."
+ ],
+ [
+ 11.745,
+ "It's too short to draw as an arrow, so we draw it as a dot at the origin."
+ ],
+ [
+ 16.979,
+ "A single zero is different."
+ ],
+ [
+ 19.297,
+ "Zero on top and three below is three steps straight up, along the y axis."
+ ],
+ [
+ 25.273,
+ "And four on top, zero below lies flat, along the x axis."
+ ]
+ ]
+ },
+ "every": {
+ "dur": 22.896,
+ "marks": {
+ "pts": 1.51,
+ "fan": 3.086,
+ "back": 8.685,
+ "so": 12.018,
+ "diff": 14.883
+ },
+ "cues": [
+ [
+ 0.104,
+ "Here's a neat fact."
+ ],
+ [
+ 1.51,
+ "Pick any point of the plane."
+ ],
+ [
+ 3.086,
+ "There's exactly one arrow from the origin to it, so exactly one vector."
+ ],
+ [
+ 8.685,
+ "And every vector ends at exactly one point."
+ ],
+ [
+ 12.018,
+ "Points and vectors match up, one to one."
+ ],
+ [
+ 14.883,
+ "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."
+ ]
+ ]
+ },
+ "read": {
+ "dur": 31.968,
+ "marks": {
+ "a1": 3.737,
+ "count1": 6.107,
+ "top1": 10.859,
+ "count2": 14.57,
+ "bot1": 16.641,
+ "col1": 18.464,
+ "a2": 21.432,
+ "count3": 22.331,
+ "count4": 25.26,
+ "bot2": 26.966,
+ "col2": 29.479
+ },
+ "cues": [
+ [
+ 0.065,
+ "Now the other way: from an arrow to its numbers."
+ ],
+ [
+ 3.737,
+ "Here's an arrow."
+ ],
+ [
+ 4.805,
+ "Where does its tip land?"
+ ],
+ [
+ 6.107,
+ "Count across first: one, two, three, four steps, to the left."
+ ],
+ [
+ 10.859,
+ "Left means negative, so the top number is minus four."
+ ],
+ [
+ 14.57,
+ "Now count up: one step."
+ ],
+ [
+ 16.641,
+ "The bottom number is one."
+ ],
+ [
+ 18.464,
+ "So this vector is minus four, one."
+ ],
+ [
+ 21.432,
+ "One more."
+ ],
+ [
+ 22.331,
+ "Two steps right: the top number is two."
+ ],
+ [
+ 25.26,
+ "Then five steps down, so the bottom number is minus five."
+ ],
+ [
+ 29.479,
+ "The vector is two, minus five."
+ ]
+ ]
+ },
+ "q1": {
+ "dur": 3.456,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.094,
+ "Read this arrow as a vector."
+ ]
+ ]
+ },
+ "link": {
+ "dur": 36.864,
+ "marks": {
+ "nums": 1.289,
+ "five": 4.349,
+ "moves": 7.044,
+ "minus": 9.427,
+ "down": 12.643,
+ "drag": 15.286,
+ "pull": 18.424,
+ "read": 21.185,
+ "again": 25.104,
+ "again2": 28.815,
+ "always": 31.862
+ },
+ "cues": [
+ [
+ 0.104,
+ "Now the best part."
+ ],
+ [
+ 1.289,
+ "The numbers and the arrow are one object."
+ ],
+ [
+ 4.349,
+ "Change the top number from three to five, and the tip moves two steps right."
+ ],
+ [
+ 9.427,
+ "Change the bottom number from two to minus one, and the tip drops below the x axis."
+ ],
+ [
+ 15.286,
+ "It works the other way too."
+ ],
+ [
+ 16.849,
+ "Grab the tip of the arrow, and pull it to the point minus two, four."
+ ],
+ [
+ 21.185,
+ "The numbers follow: minus two on top, four below."
+ ],
+ [
+ 25.104,
+ "Pull it once more, to three, minus three, and the column reads three, minus three."
+ ],
+ [
+ 31.862,
+ "Whatever you change, the numbers or the arrow, the other one changes with it."
+ ]
+ ]
+ },
+ "q2": {
+ "dur": 9.192,
+ "marks": {},
+ "cues": [
+ [
+ 0.091,
+ "Your turn."
+ ],
+ [
+ 0.977,
+ "Make v the vector minus four, three: minus four on top, three below."
+ ],
+ [
+ 6.38,
+ "Change the numbers, or drag the tip."
+ ]
+ ]
+ },
+ "same": {
+ "dur": 33.24,
+ "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
+ },
+ "cues": [
+ [
+ 0.104,
+ "We can have several vectors at once."
+ ],
+ [
+ 2.383,
+ "Each one gets its own letter and its own colour: v in green, w in violet, u in pink."
+ ],
+ [
+ 9.362,
+ "When are two vectors equal?"
+ ],
+ [
+ 11.12,
+ "When the top numbers match, and the bottom numbers match."
+ ],
+ [
+ 14.44,
+ "Both."
+ ],
+ [
+ 15.312,
+ "Say v is two, one."
+ ],
+ [
+ 17.161,
+ "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,
+ "But one, two is not equal to v."
+ ],
+ [
+ 29.609,
+ "The numbers are swapped, and the arrow is a different arrow."
+ ]
+ ]
+ },
+ "q3": {
+ "dur": 4.728,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.133,
+ "Which arrow is the vector minus one, three?"
+ ]
+ ]
+ },
+ "wrap": {
+ "dur": 26.352,
+ "marks": {
+ "w1": 0.977,
+ "w2": 5.404,
+ "w3": 11.784,
+ "w4": 18.646,
+ "end": 24.141
+ },
+ "cues": [
+ [
+ 0.104,
+ "To sum up."
+ ],
+ [
+ 0.977,
+ "A vector is two numbers in a column, with one letter for its name."
+ ],
+ [
+ 5.404,
+ "Its arrow starts at the origin."
+ ],
+ [
+ 7.539,
+ "The top number says how far right, the bottom number how far up."
+ ],
+ [
+ 11.784,
+ "Negative numbers point left or down, and zero, zero is the zero vector, a dot."
+ ],
+ [
+ 18.646,
+ "Change the numbers and the arrow moves."
+ ],
+ [
+ 21.419,
+ "Move the arrow and the numbers change."
+ ],
+ [
+ 24.141,
+ "Now try the chapter practice."
+ ]
+ ]
+ },
+ "final1": {
+ "dur": 4.128,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Chapter practice."
+ ],
+ [
+ 1.536,
+ "Read each arrow as a vector."
+ ]
+ ]
+ },
+ "final2": {
+ "dur": 2.088,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Which way does each vector point?"
+ ]
+ ]
+ },
+ "final3": {
+ "dur": 3.0,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Now find the arrow that matches each vector."
+ ]
+ ]
+ },
+ "final4": {
+ "dur": 3.36,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Last set."
+ ],
+ [
+ 1.25,
+ "Make each vector with your hands."
+ ]
+ ]
+ },
+ "finish": {
+ "dur": 9.456,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Well done."
+ ],
+ [
+ 1.107,
+ "That's the end of chapter four, vectors: arrows and columns of numbers."
+ ],
+ [
+ 6.172,
+ "Next: adding vectors, and stretching them."
+ ]
+ ]
+ }
+};
diff --git a/site/linear-algebra/ch04/audio/en/wrap.mp3 b/site/linear-algebra/ch04/audio/en/wrap.mp3
new file mode 100644
index 0000000..6eb1263
Binary files /dev/null and b/site/linear-algebra/ch04/audio/en/wrap.mp3 differ
diff --git a/site/linear-algebra/ch04/audio/en/zero.mp3 b/site/linear-algebra/ch04/audio/en/zero.mp3
new file mode 100644
index 0000000..3aff34c
Binary files /dev/null and b/site/linear-algebra/ch04/audio/en/zero.mp3 differ
diff --git a/site/linear-algebra/ch04/index.html b/site/linear-algebra/ch04/index.html
new file mode 100644
index 0000000..407ba47
--- /dev/null
+++ b/site/linear-algebra/ch04/index.html
@@ -0,0 +1,512 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>Vectors: Arrows and Columns of Numbers</title>
+<link rel="stylesheet" href="../lib/engine.css">
+<link rel="expect" href="#bar" blocking="render"><!-- hold the first frame until the player exists, so the page transition can run -->
+</head>
+<body>
+<script src="../lib/engine.js"></script>
+<script src="../lib/math.js"></script>
+<script src="../lib/linsys.js"></script>
+<script src="../lib/vecs.js"></script>
+<script src="audio/en/timings.js"></script>
+<script>
+'use strict';
+const CHAPTER = { number: 4, title: 'Vectors: Arrows and Columns of Numbers', minutes: 9, language: 'en' };
+
+/* ---------- chapter drawing helpers ---------- */
+const [GREEN, VIOLET, PINK] = VS_COL; // v, w, u: their colours everywhere in the book
+const CARD = { x: 40, y: 320, w: 720, cls: 'side' }; // question card under the column, beside the plane
+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; };
+// Math whose colour can be tweened (c_color), for numbers that flash.
+const inkM = (p, parts, { x, y, size = 46, fill = COL.chalk, anchor = 'middle', o = 1 } = {}) => {
+ const g = G(p, { o }); g.setAttribute('color', fill);
+ M(g, [].concat(parts), { x, y, size, fill: 'currentColor', anchor });
+ return g;
+};
+const lightUp = (e, t0, base) => { tw(e, { c_color: COL.task }, t0, .25); tw(e, { c_color: base }, t0 + 1.2, .6); };
+// A fixed column in brackets centred on x, on the same grid as vecs rows (baseline y of the line it sits in).
+const colm = (p, top, bot, x, y, { size = 46, fill = COL.chalk, o = 1 } = {}) => {
+ const g = G(p, { o }), mid = y - size * .32, w = size * 1.9, x0 = x - w / 2, t = mid - size * 1.32, b = mid + size * 1.32;
+ path(g, `M${x0 + 14} ${t}H${x0}V${b}H${x0 + 14}M${x0 + w - 14} ${t}H${x0 + w}V${b}H${x0 + w - 14}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' });
+ const f = n => typeof n === 'string' ? n : num(n);
+ g.top = inkM(g, [f(top)], { x, y: mid - size * .31, size, fill });
+ g.bot = inkM(g, [f(bot)], { x, y: mid + size * .99, size, fill });
+ return g;
+};
+const showRow = (r, t0, dur = .5) => r.parts.forEach(e => show(e, t0, dur));
+// The walk to a vector's tip: across, then up (or down), each step labelled with its number.
+const walk = (vs, x, y, color, t0, into) => {
+ const g = G(into, {});
+ if (x) vs.P.arrow(0, 0, x, 0, color, t0, { label: num(x), into: g });
+ if (y) vs.P.arrow(x, 0, x, y, color, t0 + (x ? 1 : 0), { label: num(y), into: g });
+ 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) => {
+ 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 });
+ tw(t, { o: 1 }, t0 + dur * q - .1, .2);
+ return t;
+ });
+ prog(q => ln.setAttribute('d', `M${P.PX(xa)} ${P.PY(ya)}L${P.PX(xa + (xb - xa) * q)} ${P.PY(ya + (yb - ya) * q)}`), t0, dur, lin);
+ g.marks = marks;
+ return g;
+};
+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 ---------- */
+const READQ = [[2, 5], [-4, -1], [5, -3], [0, -4], [-6, 2]];
+const DIRS = [['ru', 'right, up', null, '1'], ['lu', 'left, up', null, '2'], ['ld', 'left, down', null, '3'], ['rd', 'right, down', null, '4']];
+const dirOf = (x, y) => (x > 0 ? 'r' : 'l') + (y > 0 ? 'u' : 'd');
+const DIRQ = [[-3, 2], [5, 1], [-1, -6], [2, -4], [-7, 3], [4, 4]].map(([x, y]) => ({
+ parts: [hcol(x, y)], ans: [dirOf(x, y)], why: `The top number ${num(x)} says ${x > 0 ? 'right' : 'left'}; the bottom number ${num(y)} says ${y > 0 ? 'up' : 'down'}.`,
+}));
+const EQQ = [[[2, 5], [5, 2]], [[-1, 3], [-1, 3]], [[0, 4], [4, 0]], [[3, -2], [3, -2]], [[6, 1], [6, -1]]].map(([a, b]) => {
+ const same = a[0] === b[0] && a[1] === b[1];
+ return { parts: [hcol(...a), ' and ', hcol(...b)], ans: [same ? 'y' : 'n'],
+ why: same ? 'Top matches top, bottom matches bottom: equal.' : a[0] !== b[0] && a[1] !== b[1] ? 'Neither number matches its partner.' : 'One number matches, the other does not: not equal.' };
+});
+const MATCHQ = [
+ { goal: [2, -3], arrows: [[2, -3], [-3, 2], [-2, 3]], right: 0 },
+ { goal: [-4, -1], arrows: [[4, 1], [-1, -4], [-4, -1]], right: 2 },
+ { goal: [0, 5], arrows: [[5, 0], [0, 5], [0, -5]], right: 1 },
+ { goal: [-5, 2], arrows: [[5, -2], [-5, 2], [2, 5]], right: 1 },
+];
+const MAKEQ = [
+ { prompt: ['Make ', $m('v'), ' = ', hcol(2, -3, GREEN), '.'], goal: [2, -3] },
+ { prompt: ['Make ', $m('v'), ' = ', hcol(-5, 0, GREEN), '.'], goal: [-5, 0] },
+ { prompt: ['Make ', $m('v'), ' the arrow from the origin to the point ', $m('(−1, −4)'), '.'], goal: [-1, -4] },
+ { prompt: ['Make ', $m('v'), ' point straight down, 3 steps long.'], goal: [0, -3] },
+ { prompt: ['Make ', $m('v'), ' the swap of ', hcol(4, 1), ': the same two numbers in the other order.'], goal: [1, 4] },
+];
+// The hint for a make-the-vector task, aimed at what the reader has now.
+const makeHint = (gx, gy) => v => {
+ const x = v.v0, y = v.v1;
+ if (x === gy && y === gx && gx !== gy) return 'Your numbers are swapped: the top number is how far right, the bottom number how far up.';
+ if (x === -gx && y === gy) return `The top number has the wrong sign: ${gx < 0 ? 'left is negative' : 'right is positive'}.`;
+ if (x === gx && y === -gy) return `The bottom number has the wrong sign: ${gy < 0 ? 'down is negative' : 'up is positive'}.`;
+ return `You have ${across(x, y)}. The goal is ${across(gx, gy)}.`;
+};
+
+/* ---------- beats: [id, title, run(m, D), { ask }?] ---------- */
+const BEATS = [
+ ['intro', 'Vectors: arrows and columns', (m, D) => {
+ const g = G(scene, { o: 0, y: 24 });
+ T(g, 'Unit 1, Chapter 4', { x: 800, y: 300, size: 28, fill: COL.dim, anchor: 'middle' });
+ T(g, 'Vectors: Arrows and Columns of Numbers', { x: 800, y: 410, size: 64, weight: 600, anchor: 'middle' });
+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);
+ const r = text(scene, 'two numbers in a column, and the arrow they make', 800, 510, m('sub'), { size: 36, fill: COL.dim, anchor: 'middle' });
+ const pic = G(scene, { o: 0 });
+ const c = colm(pic, 3, 2, 640, 720, { size: 44, fill: GREEN });
+ const a = path(pic, 'M820 760L955 670', { stroke: GREEN, 'stroke-width': 6, 'stroke-linecap': 'round' }, { d: 0 });
+ const head = path(pic, 'M934 668L962 665L951 692Z', { fill: GREEN, stroke: GREEN, 'stroke-width': 4, 'stroke-linejoin': 'round' }, { o: 0 });
+ mk('circle', { cx: 820, cy: 760, r: 7, fill: COL.chalk }, pic);
+ show(pic, m('sub') + .6, .5); draw(a, m('arrow'), .9); show(head, m('arrow') + .8, .2);
+ lightUp(c.top, m('arrow') + .2, GREEN); lightUp(c.bot, m('arrow') + .6, GREEN);
+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(pic, D - .9, .8);
+ }],
+
+ ['column', 'A column of numbers', (m) => {
+ const p = panel(0);
+ text(p, 'A vector: two numbers in a column', 60, 110, .2, { size: 40, weight: 600 });
+ // 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' });
+ 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 });
+ 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);
+ tw(three, { x: 300, y: mid - sz * .31 }, m('stand') + .2, 1);
+ tw(two, { x: 300, y: mid + sz * .99 }, m('stand') + .5, 1);
+ const w = sz * 1.9, x0 = 300 - w / 2, t = mid - sz * 1.32, b = mid + sz * 1.32;
+ const br = path(p, `M${x0 + 16} ${t}H${x0}V${b}H${x0 + 16}M${x0 + w - 16} ${t}H${x0 + w}V${b}H${x0 + w - 16}`, { stroke: COL.chalk, 'stroke-width': 3.5, fill: 'none' }, { d: 0 });
+ draw(br, m('br'), .8);
+ text(p, 'a vector', 300, b + 52, m('name'), { size: 32, fill: COL.task, anchor: 'middle', weight: 600 });
+ say(p, ['v'], 170, y, m('v'), { size: sz, fill: GREEN, anchor: 'end' });
+ say(p, ['='], 232, y, m('v') + .1, { size: sz, anchor: 'end' });
+ [three, two].forEach(e => tw(e, { c_color: GREEN }, m('v') + .3, .6));
+ text(p, '← top: the first number', 400, mid - sz * .31 - 8, m('top'), { size: 28, fill: COL.dim });
+ 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);
+ // more vectors, and the order
+ const r2 = 610;
+ show(colm(p, -1, 5, 150, r2, { o: 0 }), m('more'));
+ show(colm(p, 0, 4, 300, r2, { o: 0 }), m('more2'));
+ const ord = G(p, { o: 0 });
+ colm(ord, 3, 2, 500, r2);
+ M(ord, ['≠'], { x: 590, y: r2 - 4, size: 54, fill: COL.bad, anchor: 'middle' });
+ colm(ord, 2, 3, 680, r2);
+ show(ord, m('order'));
+ text(p, 'order matters', 590, r2 + 112, m('order') + .6, { size: 28, fill: COL.bad, anchor: 'middle', weight: 600 });
+ // preview: the numbers of chapter 2's system stand in columns
+ const pv = G(p, { o: 0 }), px = 1010;
+ T(pv, 'coming in chapter 7', { x: 1180, y: 250, size: 26, fill: COL.dim, anchor: 'middle' });
+ [['2x', '−', 'y', '= 0', 340], ['−x', '+', '2y', '= 3', 420]].forEach(([a, sg, b, r, yy]) => {
+ M(pv, [a], { x: px + 90, y: yy, size: 46, anchor: 'end' });
+ M(pv, [sg], { x: px + 130, y: yy, size: 46, anchor: 'middle' });
+ M(pv, [b], { x: px + 230, y: yy, size: 46, anchor: 'end' });
+ 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);
+ 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' });
+ show(pv, m('why'), .7);
+ pv.querySelectorAll('rect').forEach((r, i) => { put(r, { o: 0 }); show(r, m('why') + 2 + i * 2.6, .5); });
+ [...pv.children].slice(-3).forEach((e, i) => put(e, { o: 0 }));
+ const cols = [...pv.children].slice(-3);
+ show(cols[2], m('why') + 2.6, .6); // the arrows
+ show(cols[0], m('why') + 3.2, .6); show(cols[1], m('why') + 5.8, .6);
+ }],
+
+ ['arrow', 'Every vector is an arrow', (m) => {
+ const p = panel(0);
+ text(p, 'Every vector is an arrow', 60, 110, .2, { size: 40, weight: 600 });
+ const vs = vecs(p, { vecs: { v: [3, 2], w: [1, 4], u: [2, 3] }, show: [], hidePlane: true });
+ const r1 = vs.row([{ t: 'v', fill: GREEN }, '=', { col: 'v' }], { x: 90, y: 250, o: 0 });
+ 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);
+ const trav = G(p, { o: 0 });
+ mk('circle', { r: 9, fill: COL.task }, trav);
+ show(trav, m('tip') + 1.2, .3);
+ prog(q => put(trav, { x: vs.P.PX(3 * q), y: vs.P.PY(2 * q) }), m('tip') + 1.6, 3.2, io);
+ hide(trav, m('same') - .2, .3);
+ 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 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 });
+ 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 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);
+ say(p, ['u ≠ v'], 330, 610, m('diff'), { size: 40, fill: COL.bad });
+ text(p, '2 right, 3 up — not 3 right, 2 up', 330, 660, m('diff') + .6, { size: 26, fill: COL.dim });
+ [['u', 'diff'], ['v', 'diff']].forEach(([id], i) => { const t0 = m('diff') + i * .5; tw(vs.A[id].path, { 'a_stroke-width': 9 }, t0, .3); tw(vs.A[id].path, { 'a_stroke-width': 5 }, t0 + .8, .5); });
+ }],
+
+ ['neg', 'Negative numbers', (m) => {
+ const p = panel(0);
+ text(p, 'Negative numbers point left or down', 60, 110, .2, { size: 40, weight: 600 });
+ const vs = vecs(p, { vecs: { v: [-2, 3], w: [4, -1], u: [-3, -2] }, show: [] });
+ const rows = [['v', GREEN, 250, 'n1'], ['w', VIOLET, 430, 'n2'], ['u', PINK, 610, 'n3']].map(([n, fill, y, mk_]) => {
+ const r = vs.row([{ t: n, fill }, '=', { col: n }], { x: 90, y, o: 0 });
+ showRow(r, m(mk_));
+ return r;
+ });
+ // v: left, then up
+ const wv = G(p, {});
+ countWalk(vs.P, [0, 0], [-2, 0], GREEN, m('left') + .3, 1.2, wv);
+ 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 });
+ 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 });
+ 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 });
+ 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 });
+ T(s, 'bottom number: − down, + up', { x: 90, y: 790, size: 30, weight: 600, fill: COL.task });
+ show(s, m('sum'));
+ ['v0', 'w0', 'u0'].forEach((k, i) => vs.flash(k, m('sum') + 2.2 + i * .35));
+ ['v1', 'w1', 'u1'].forEach((k, i) => vs.flash(k, m('sum') + 4.8 + i * .35));
+ [['v', 2.2], ['u', 2.9], ['w', 4.8], ['u', 5.5]].forEach(([id, dt]) => { tw(vs.A[id].path, { 'a_stroke-width': 9 }, m('sum') + dt, .3); tw(vs.A[id].path, { 'a_stroke-width': 5 }, m('sum') + dt + .6, .4); });
+ }],
+
+ ['zero', 'The zero vector', (m) => {
+ const p = panel(0);
+ text(p, 'The zero vector', 60, 110, .2, { size: 40, weight: 600 });
+ const vs = vecs(p, { vecs: { v: [0, 0], w: [2, 1], u: [4, 0] }, show: [] });
+ const r1 = vs.row([{ col: 'v' }], { x: 90, y: 250, o: 0 });
+ showRow(r1, m('z'));
+ const o = vs.P.dot(0, 0, GREEN, m('stay'), { r: 11 });
+ pulse(o, m('stay') + .6); pulse(o, m('stay') + 1.6);
+ text(p, '0 right, 0 up: it stays at the origin', 240, 236, m('stay') + .3, { size: 28, fill: COL.dim });
+ text(p, 'the zero vector: a dot, not an arrow', 240, 280, m('name'), { size: 28, fill: GREEN, weight: 600 });
+ vs.P.dot(0, 0, GREEN, m('name') + .3, { r: 0, label: 'zero vector', dx: -186, dy: -18 });
+ // a short arrow, shrinking: at length zero only the dot is left
+ vs.label('w', []);
+ show(vs.A.w.g, m('name') + 2.2, .3);
+ vs.to({ w0: 0, w1: 0 }, m('name') + 2.6, 3, lin);
+ hide(vs.A.w.g, m('name') + 5.8, .3);
+ vs.to({ w0: 0, w1: 3 }, m('one') - .3, .1);
+ 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);
+ 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);
+ text(p, 'flat, on the x-axis', 330, 640, m('flat') + 1.2, { size: 28, fill: PINK, weight: 600 });
+ }],
+
+ ['every', 'Points and vectors', (m) => {
+ const p = panel(0);
+ text(p, 'Every point: one vector', 60, 110, .2, { size: 40, weight: 600 });
+ const vs = vecs(p, { vecs: { v: [-5, 2] }, show: [] });
+ 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);
+ 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) => {
+ const t = m('fan') + 1.6 + i * .28;
+ P2.dot(x, y, COL.chalk, t, { r: 6, into: fan });
+ P2.arrow(0, 0, x, y, COL.dim, t + .1, { into: fan });
+ });
+ const tips = G(p, { o: 0 });
+ fanPts.forEach(([x, y]) => mk('circle', { cx: P2.PX(x), cy: P2.PY(y), r: 9, fill: COL.task }, tips));
+ show(tips, m('back'), .4); hide(tips, m('so'), .6);
+ const eq = G(p, { o: 0 });
+ M(eq, ['point (x, y)'], { x: 90, y: 330, size: 44, anchor: 'start' });
+ M(eq, ['↔'], { x: 400, y: 330, size: 44, fill: COL.task, anchor: 'middle' });
+ M(eq, ['vector'], { x: 460, y: 330, size: 44, anchor: 'start' });
+ colm(eq, 'x', 'y', 660, 330, { fill: GREEN });
+ show(eq, m('so'), .6);
+ const d2 = G(p, { o: 0 });
+ T(d2, 'a point: a place', { x: 90, y: 520, size: 32, weight: 600 });
+ T(d2, 'a vector: the trip from the origin to that place', { x: 90, y: 575, size: 32, weight: 600, fill: GREEN });
+ show(d2, m('diff'), .6);
+ const trav = G(p, { o: 0 });
+ mk('circle', { r: 10, fill: COL.task }, trav);
+ show(trav, m('diff') + 2.4, .3);
+ prog(q => put(trav, { x: P2.PX(-5 * q), y: P2.PY(2 * q) }), m('diff') + 2.6, 3, io);
+ }],
+
+ ['read', 'From arrow to numbers', (m) => {
+ const p = panel(0);
+ text(p, 'Reading a vector off its arrow', 60, 110, .2, { size: 40, weight: 600 });
+ const vs = vecs(p, { vecs: { v: [-4, 1] }, show: [] });
+ vs.show('v', m('a1'), .6);
+ const w1 = G(p, {});
+ countWalk(vs.P, [0, 0], [-4, 0], GREEN, m('count1') + 1.3, 2.2, w1, true);
+ countWalk(vs.P, [-4, 0], [-4, 1], GREEN, m('count2') + .6, .6, w1);
+ const c1 = colm(p, -4, 1, 150, 330, { fill: GREEN, o: 0 });
+ put(c1.top, { o: 0 }); put(c1.bot, { o: 0 });
+ show(c1, m('top1')); show(c1.top, m('top1') + .8); lightUp(c1.top, m('top1') + 1.4, GREEN);
+ 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 });
+ 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);
+ 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 });
+ 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);
+ }],
+
+ ['q1', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ S.vs = vecs(p, { vecs: { v: [-3, 2] } });
+ }, { 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.',
+ 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.' },
+ ]),
+ }], done) }],
+
+ ['link', 'Numbers and arrow, linked', (m) => {
+ const p = panel(0);
+ text(p, 'Change one, the other follows', 60, 110, .2, { size: 40, weight: 600 });
+ const vs = vecs(p, { vecs: { v: [3, 2] } });
+ vs.row([{ t: 'v', fill: GREEN }, '=', { col: 'v' }], { x: 90, y: 250 });
+ 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);
+ // 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);
+ put(hand, { x: PX(5), y: PY(-1) });
+ show(hand, m('drag') + 1, .4);
+ const t0 = m('pull'), dur = 2.4;
+ prog(q => {
+ const x = 5 + (-2 - 5) * q, y = -1 + (4 + 1) * q;
+ put(hand, { x: PX(x), y: PY(y) });
+ vs.set({ v0: Math.round(x), v1: Math.round(y) });
+ }, t0, dur, io);
+ hide(hand, t0 + dur + .4, .4);
+ vs.flash('v0', m('read')); vs.flash('v1', m('read') + .6);
+ show(hand, m('again') - .2, .3);
+ prog(q => {
+ const x = -2 + (3 + 2) * q, y = 4 + (-3 - 4) * q;
+ put(hand, { x: PX(x), y: PY(y) });
+ vs.set({ v0: Math.round(x), v1: Math.round(y) });
+ }, m('again') + .4, 2, io);
+ hide(hand, m('again') + 2.8, .4);
+ vs.flash('v0', m('again2')); vs.flash('v1', m('again2'));
+ const n = G(p, { o: 0 });
+ T(n, 'change a number → the arrow moves', { x: 90, y: 450, size: 32, weight: 600, fill: COL.task });
+ T(n, 'move the arrow → the numbers change', { x: 90, y: 505, size: 32, weight: 600, fill: GREEN });
+ show(n, m('always'));
+ }],
+
+ ['q2', 'Your turn', () => {
+ const p = panel(0);
+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
+ S.vs = vecs(p, { vecs: { v: [1, 1] } });
+ S.vs.row([{ t: 'v', fill: GREEN }, '=', { col: 'v' }], { x: 90, y: 230 });
+ }, { ask: done => quiz(CARD, [{
+ id: 'c-make', prompt: ['Make ', $m('v'), ' = ', hcol(-4, 3, GREEN), '. Change the numbers, or drag the tip of the arrow.'],
+ build: vsTask(S.vs, v => v.v0 === -4 && v.v1 === 3, 'Four steps left, three steps up.', makeHint(-4, 3), () => S.vs.set({ v0: -4, v1: 3 })),
+ }], done) }],
+
+ ['same', 'Equal vectors', (m) => {
+ const p = panel(0);
+ text(p, 'Many vectors, and when two are equal', 60, 110, .2, { size: 40, weight: 600 });
+ const vs = vecs(p, { vecs: { v: [2, 1], w: [-3, 2], u: [1, -3] }, show: [] });
+ const eqv = () => vs.v.v0 === vs.v.w0 && vs.v.v1 === vs.v.w1;
+ vs.label('v', () => eqv() ? [] : ['v']);
+ vs.label('w', () => eqv() ? ['v = w'] : ['w']);
+ [['v', GREEN, 250], ['w', VIOLET, 430], ['u', PINK, 610]].forEach(([n, fill, y]) => {
+ const r = vs.row([{ t: n, fill }, '=', { col: n }], { x: 90, y, o: 0 });
+ showRow(r, m(n)); vs.show(n, m(n) + .3, .6);
+ });
+ const e = G(p, { o: 0 });
+ T(e, 'equal: top = top and bottom = bottom', { x: 90, y: 760, size: 30, weight: 600, fill: COL.task });
+ show(e, m('eq'));
+ ['v', 'w', 'u'].forEach((id, i) => [2, 3.6].forEach(dt => { tw(vs.A[id].path, { 'a_stroke-width': 9 }, m('eq') + dt + i * .15, .3); tw(vs.A[id].path, { 'a_stroke-width': 5 }, m('eq') + dt + i * .15 + .6, .4); }));
+ ['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);
+ 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 });
+ }],
+
+ ['q3', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ S.vs = vecs(p, { vecs: { v: [3, -1], w: [-1, 3], u: [1, 3] } });
+ S.vs.names.forEach(n => S.vs.label(n, []));
+ }, { ask: done => quiz(CARD, [matchQ('c-match', { goal: [-1, 3], arrows: [[3, -1], [-1, 3], [1, 3]], right: 1 })], done) }],
+
+ ['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) => {
+ 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);
+ T(dg, String(i + 1), { x: 0, y: 11, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });
+ T(g, str, { x: 210, size: 34, weight: 600 });
+ tw(g, { o: 1, x: 0 }, m(mark), .6);
+ pulse(dg, m('end') + i * .3, 1.25);
+ });
+ }],
+ ['final1', 'Chapter practice', () => {
+ const p = panel(0);
+ text(p, 'Read the arrow', 60, 110, .2, { size: 40, weight: 600 });
+ S.vs = vecs(p, { vecs: { v: READQ[0] } });
+ }, { ask: done => quiz(CARD, READQ.map(([x, y], i) => ({
+ id: `p-read${i + 1}`, prompt: ['Write ', $m('v'), ' as a column: its top number, then its bottom number.'],
+ build: (body, api) => { S.vs.set({ v0: x, v1: y }); fx(S.vs.A.v.leg, { o: 0 }, 0, .01); return blanks([{ parts: ['top ', { box: String(x) }, ' bottom ', { box: String(y) }],
+ why: `${across(x, y)}: top ${num(x)}, bottom ${num(y)}.`, hint: 'Top: steps across from the origin (left is negative). Bottom: steps up from the x-axis (down is negative).',
+ fx: () => fx(S.vs.A.v.leg, { o: 1 }, 0, .6) }])(body, api); },
+ })), done, 'Chapter practice · set 1 of 4') }],
+ ['final2', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
+ id: 'p-dir', prompt: ['Which way does each arrow go from the origin?'],
+ build: grid(DIRQ, DIRS, { multi: false, text: true }),
+ }, {
+ id: 'p-equal', prompt: ['Are the two vectors equal?'],
+ build: grid(EQQ, [['y', 'Equal', null, 'Y'], ['n', 'Not equal', null, 'N']], { multi: false, text: true }),
+ }], done, 'Chapter practice · set 2 of 4') }],
+ ['final3', 'Chapter practice', () => {
+ const p = panel(0);
+ text(p, 'Find the arrow', 60, 110, .2, { size: 40, weight: 600 });
+ S.vs = vecs(p, { vecs: { v: [1, 1], w: [2, 2], u: [3, 3] } });
+ S.vs.names.forEach(n => S.vs.label(n, []));
+ }, { ask: done => quiz(CARD, MATCHQ.map((q, i) => matchQ(`p-match${i + 1}`, q)), done, 'Chapter practice · set 3 of 4') }],
+ ['final4', 'Chapter practice', () => {
+ const p = panel(0);
+ text(p, 'Make the vector', 60, 110, .2, { size: 40, weight: 600 });
+ S.vs = vecs(p, { vecs: { v: [1, 1] } });
+ S.vs.row([{ t: 'v', fill: GREEN }, '=', { col: 'v' }], { x: 90, y: 230 });
+ }, { ask: done => quiz(CARD, MAKEQ.map((q, i) => ({
+ 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') }],
+ ['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],
+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
+
+// Which of three arrows is this column? The arrows are S.vs's v, w, u; the tips are the targets.
+function matchQ(id, { goal, arrows, right }) {
+ return {
+ id, prompt: ['Which arrow is ', hcol(...goal), '? Click its tip.'],
+ build: (body, api) => {
+ const vs = S.vs, ns = vs.names;
+ arrows.forEach(([x, y], i) => vs.set({ [ns[i] + '0']: x, [ns[i] + '1']: y }));
+ const { PX, PY } = vs.P;
+ return pickEls(arrows.map(([x, y], i) => ({ el: vs.A[ns[i]].g, box: [PX(x) - 36, PY(y) - 36, 72, 72], label: `(${num(x)}, ${num(y)})` })), right,
+ [hcol(...goal), ': ', across(...goal), '.'],
+ i => { const [x, y] = arrows[i]; return ['That arrow goes ', across(x, y), ': it is ', hcol(x, y), '. Read the top number as right or left, the bottom as up or down.']; })(body, api);
+ },
+ };
+}
+
+boot();
+</script>
+</body>
+</html>
diff --git a/site/linear-algebra/ch05/audio/en/add.mp3 b/site/linear-algebra/ch05/audio/en/add.mp3
new file mode 100644
index 0000000..be61456
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/add.mp3 differ
diff --git a/site/linear-algebra/ch05/audio/en/final1.mp3 b/site/linear-algebra/ch05/audio/en/final1.mp3
new file mode 100644
index 0000000..9c8c4b3
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/final1.mp3 differ
diff --git a/site/linear-algebra/ch05/audio/en/final2.mp3 b/site/linear-algebra/ch05/audio/en/final2.mp3
new file mode 100644
index 0000000..22a1fc4
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/final2.mp3 differ
diff --git a/site/linear-algebra/ch05/audio/en/final3.mp3 b/site/linear-algebra/ch05/audio/en/final3.mp3
new file mode 100644
index 0000000..2018a38
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/final3.mp3 differ
diff --git a/site/linear-algebra/ch05/audio/en/final4.mp3 b/site/linear-algebra/ch05/audio/en/final4.mp3
new file mode 100644
index 0000000..72fdfbb
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/final4.mp3 differ
diff --git a/site/linear-algebra/ch05/audio/en/finish.mp3 b/site/linear-algebra/ch05/audio/en/finish.mp3
new file mode 100644
index 0000000..3a5bc20
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/finish.mp3 differ
diff --git a/site/linear-algebra/ch05/audio/en/intro.mp3 b/site/linear-algebra/ch05/audio/en/intro.mp3
new file mode 100644
index 0000000..40c7f07
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/intro.mp3 differ
diff --git a/site/linear-algebra/ch05/audio/en/live.mp3 b/site/linear-algebra/ch05/audio/en/live.mp3
new file mode 100644
index 0000000..6f88663
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/live.mp3 differ
diff --git a/site/linear-algebra/ch05/audio/en/minus.mp3 b/site/linear-algebra/ch05/audio/en/minus.mp3
new file mode 100644
index 0000000..3c97260
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/minus.mp3 differ
diff --git a/site/linear-algebra/ch05/audio/en/more.mp3 b/site/linear-algebra/ch05/audio/en/more.mp3
new file mode 100644
index 0000000..ba77d4f
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/more.mp3 differ
diff --git a/site/linear-algebra/ch05/audio/en/order.mp3 b/site/linear-algebra/ch05/audio/en/order.mp3
new file mode 100644
index 0000000..ed0b93b
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/order.mp3 differ
diff --git a/site/linear-algebra/ch05/audio/en/q1.mp3 b/site/linear-algebra/ch05/audio/en/q1.mp3
new file mode 100644
index 0000000..e4fc8bd
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/q1.mp3 differ
diff --git a/site/linear-algebra/ch05/audio/en/q2.mp3 b/site/linear-algebra/ch05/audio/en/q2.mp3
new file mode 100644
index 0000000..3dae96f
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/q2.mp3 differ
diff --git a/site/linear-algebra/ch05/audio/en/q3.mp3 b/site/linear-algebra/ch05/audio/en/q3.mp3
new file mode 100644
index 0000000..aaa8b05
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/q3.mp3 differ
diff --git a/site/linear-algebra/ch05/audio/en/q4.mp3 b/site/linear-algebra/ch05/audio/en/q4.mp3
new file mode 100644
index 0000000..88c901d
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/q4.mp3 differ
diff --git a/site/linear-algebra/ch05/audio/en/scale.mp3 b/site/linear-algebra/ch05/audio/en/scale.mp3
new file mode 100644
index 0000000..8fe46a3
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/scale.mp3 differ
diff --git a/site/linear-algebra/ch05/audio/en/shrink.mp3 b/site/linear-algebra/ch05/audio/en/shrink.mp3
new file mode 100644
index 0000000..7683e73
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/shrink.mp3 differ
diff --git a/site/linear-algebra/ch05/audio/en/timings.js b/site/linear-algebra/ch05/audio/en/timings.js
new file mode 100644
index 0000000..003ffc8
--- /dev/null
+++ b/site/linear-algebra/ch05/audio/en/timings.js
@@ -0,0 +1,690 @@
+window.TIMINGS = {
+ "intro": {
+ "dur": 12.384,
+ "marks": {
+ "sub": 3.49,
+ "both": 7.643
+ },
+ "cues": [
+ [
+ 0.104,
+ "Chapter five."
+ ],
+ [
+ 1.237,
+ "Adding and stretching vectors."
+ ],
+ [
+ 3.49,
+ "Vectors can be added, and they can be multiplied by a number."
+ ],
+ [
+ 7.643,
+ "Each one is easy with the numbers, and each one has a picture."
+ ]
+ ]
+ },
+ "add": {
+ "dur": 40.248,
+ "marks": {
+ "v": 1.992,
+ "w": 3.568,
+ "q": 5.208,
+ "tops": 6.367,
+ "bots": 9.805,
+ "res": 13.529,
+ "never": 17.122,
+ "ex2": 26.497,
+ "t2": 31.172,
+ "b2": 34.401,
+ "r2": 37.878
+ },
+ "cues": [
+ [
+ 0.117,
+ "Here are two vectors."
+ ],
+ [
+ 1.992,
+ "v is three, one."
+ ],
+ [
+ 3.568,
+ "w is one, two."
+ ],
+ [
+ 5.208,
+ "How do we add them?"
+ ],
+ [
+ 6.367,
+ "Add the top numbers: three plus one is four."
+ ],
+ [
+ 9.805,
+ "Add the bottom numbers: one plus two is three."
+ ],
+ [
+ 13.529,
+ "So v plus w is the vector four, three."
+ ],
+ [
+ 17.122,
+ "Tops add to tops, and bottoms add to bottoms."
+ ],
+ [
+ 20.872,
+ "They never mix: steps to the right add up with steps to the right, and steps up with steps up."
+ ],
+ [
+ 26.497,
+ "Another one: two, minus one, plus minus four, three."
+ ],
+ [
+ 31.172,
+ "Top: two plus minus four is minus two."
+ ],
+ [
+ 34.401,
+ "Bottom: minus one plus three is two."
+ ],
+ [
+ 37.878,
+ "So the sum is minus two, two."
+ ]
+ ]
+ },
+ "tiptail": {
+ "dur": 49.848,
+ "marks": {
+ "arrows": 1.315,
+ "slide": 6.172,
+ "same": 12.018,
+ "trip": 17.266,
+ "then": 20.312,
+ "end": 21.693,
+ "sum": 24.01,
+ "count": 28.255,
+ "match": 35.56,
+ "ex2": 38.685,
+ "follow": 42.409,
+ "read": 46.224
+ },
+ "cues": [
+ [
+ 0.104,
+ "Now the picture."
+ ],
+ [
+ 1.315,
+ "Here are v and w as arrows, both starting at the origin."
+ ],
+ [
+ 6.172,
+ "To add them, slide w, without turning it, until its tail sits on the tip of v."
+ ],
+ [
+ 12.018,
+ "It's still w: one step right and two steps up."
+ ],
+ [
+ 15.781,
+ "It has only moved."
+ ],
+ [
+ 17.266,
+ "Now follow the trip: first along v, then along w."
+ ],
+ [
+ 21.693,
+ "You end up at the point four, three."
+ ],
+ [
+ 24.01,
+ "The arrow from the origin to that end is v plus w."
+ ],
+ [
+ 28.255,
+ "Count the steps."
+ ],
+ [
+ 29.714,
+ "Three right, then one more right: four right."
+ ],
+ [
+ 32.5,
+ "One up, then two more up: three up."
+ ],
+ [
+ 35.56,
+ "Four, three: the same answer the numbers gave."
+ ],
+ [
+ 38.685,
+ "Now change v and w into the second example."
+ ],
+ [
+ 42.409,
+ "w rides on the tip of v, and the sum follows them."
+ ],
+ [
+ 46.224,
+ "It ends at minus two, two, just as the numbers said."
+ ]
+ ]
+ },
+ "order": {
+ "dur": 29.664,
+ "marks": {
+ "wv": 1.341,
+ "route": 5.898,
+ "land": 8.425,
+ "para": 10.964,
+ "nums": 17.018,
+ "rule": 26.133
+ },
+ "cues": [
+ [
+ 0.104,
+ "Does the order matter?"
+ ],
+ [
+ 1.341,
+ "Let's add the other way round: w first, then v."
+ ],
+ [
+ 5.898,
+ "Walk along w, then along v."
+ ],
+ [
+ 8.425,
+ "We land on the same point, four, three."
+ ],
+ [
+ 10.964,
+ "The two trips are two sides of a parallelogram, and v plus w is its diagonal."
+ ],
+ [
+ 17.018,
+ "The numbers agree."
+ ],
+ [
+ 18.281,
+ "Three plus one and one plus three are both four."
+ ],
+ [
+ 22.188,
+ "One plus two and two plus one are both three."
+ ],
+ [
+ 26.133,
+ "So v plus w equals w plus v."
+ ]
+ ]
+ },
+ "q1": {
+ "dur": 3.048,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.12,
+ "Add these two vectors."
+ ]
+ ]
+ },
+ "live": {
+ "dur": 22.104,
+ "marks": {
+ "grab": 2.695,
+ "pull": 5.651,
+ "sum": 6.927,
+ "rule": 9.505,
+ "scrub": 13.359,
+ "move": 16.315,
+ "sum2": 19.388
+ },
+ "cues": [
+ [
+ 0.104,
+ "The numbers and the picture stay linked."
+ ],
+ [
+ 2.695,
+ "Grab the tip of the moved w and pull it."
+ ],
+ [
+ 5.651,
+ "w changes, and so does v plus w."
+ ],
+ [
+ 9.505,
+ "Whatever w is, the sum ends where w ends."
+ ],
+ [
+ 13.359,
+ "Or change a number."
+ ],
+ [
+ 14.596,
+ "Make v's top number one: v gets shorter, w rides along with it, and the sum's top number drops by two as well."
+ ]
+ ]
+ },
+ "q2": {
+ "dur": 7.128,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn."
+ ],
+ [
+ 1.029,
+ "v stays where it is."
+ ],
+ [
+ 2.656,
+ "Move w, so that v plus w lands on the amber target."
+ ]
+ ]
+ },
+ "scale": {
+ "dur": 40.32,
+ "marks": {
+ "v": 4.023,
+ "vv": 5.781,
+ "tt": 7.474,
+ "pic": 11.393,
+ "long": 15.716,
+ "two": 18.125,
+ "rule": 19.505,
+ "name": 26.354,
+ "three": 31.953,
+ "t3": 33.333,
+ "long3": 37.018
+ },
+ "cues": [
+ [
+ 0.104,
+ "The second operation: multiplying a vector by a number."
+ ],
+ [
+ 4.023,
+ "Take v equals two, one."
+ ],
+ [
+ 5.781,
+ "What is v plus v?"
+ ],
+ [
+ 7.474,
+ "Two plus two is four, and one plus one is two."
+ ],
+ [
+ 11.393,
+ "In the picture: v, and then v again, tip to tail."
+ ],
+ [
+ 15.716,
+ "The same direction, twice as long."
+ ],
+ [
+ 18.125,
+ "We call it two v."
+ ],
+ [
+ 19.505,
+ "The quick way: multiply both numbers by two."
+ ],
+ [
+ 22.917,
+ "Two times two is four, two times one is two."
+ ],
+ [
+ 26.354,
+ "The number in front is called a scalar, because it scales the vector."
+ ],
+ [
+ 30.664,
+ "We'll call it c."
+ ],
+ [
+ 31.953,
+ "Make c three."
+ ],
+ [
+ 33.333,
+ "Three times two is six, three times one is three."
+ ],
+ [
+ 37.018,
+ "Three times as long, still pointing the same way."
+ ]
+ ]
+ },
+ "shrink": {
+ "dur": 45.672,
+ "marks": {
+ "half": 2.07,
+ "th": 3.581,
+ "short": 7.773,
+ "neg": 10.365,
+ "tn": 12.461,
+ "flip": 18.854,
+ "neg2": 25.573,
+ "zero": 28.451,
+ "tz": 30.13,
+ "dot": 32.669,
+ "line": 37.096,
+ "all": 39.753
+ },
+ "cues": [
+ [
+ 0.104,
+ "c doesn't have to be a whole number."
+ ],
+ [
+ 2.07,
+ "Make c one half."
+ ],
+ [
+ 3.581,
+ "Half of two is one, and half of one is one half."
+ ],
+ [
+ 7.773,
+ "The arrow shrinks to half its length."
+ ],
+ [
+ 10.365,
+ "Now make c minus one."
+ ],
+ [
+ 12.461,
+ "Minus one times two is minus two, and minus one times one is minus one."
+ ],
+ [
+ 18.854,
+ "The arrow flips around: the same length, the opposite direction."
+ ],
+ [
+ 23.659,
+ "We write it minus v."
+ ],
+ [
+ 25.573,
+ "c equals minus two flips it and doubles it."
+ ],
+ [
+ 28.451,
+ "And c equals zero?"
+ ],
+ [
+ 30.13,
+ "Zero times anything is zero, so zero v is the zero vector, a dot at the origin."
+ ],
+ [
+ 37.096,
+ "Now watch c run through the numbers."
+ ],
+ [
+ 39.753,
+ "Every multiple of v lies on one line through the origin: the line through v."
+ ]
+ ]
+ },
+ "more": {
+ "dur": 33.792,
+ "marks": {
+ "a": 2.175,
+ "at": 4.284,
+ "ar": 9.193,
+ "b": 16.432,
+ "bt": 19.453,
+ "sign": 26.25,
+ "br": 29.076
+ },
+ "cues": [
+ [
+ 0.104,
+ "Two more, to practise."
+ ],
+ [
+ 2.175,
+ "Three times minus one, two."
+ ],
+ [
+ 4.284,
+ "Three times minus one is minus three."
+ ],
+ [
+ 7.188,
+ "Three times two is six."
+ ],
+ [
+ 9.193,
+ "Minus three, six: the same direction as minus one, two, and three times as far."
+ ],
+ [
+ 16.432,
+ "Now minus two times three, minus one."
+ ],
+ [
+ 19.453,
+ "Minus two times three is minus six."
+ ],
+ [
+ 22.812,
+ "Minus two times minus one is plus two: a minus times a minus gives a plus."
+ ],
+ [
+ 29.076,
+ "Minus six, two: twice as long, and pointing the opposite way."
+ ]
+ ]
+ },
+ "q3": {
+ "dur": 6.0,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn."
+ ],
+ [
+ 1.003,
+ "Change c until c times v is minus four, minus two."
+ ]
+ ]
+ },
+ "minus": {
+ "dur": 39.792,
+ "marks": {
+ "ex": 1.732,
+ "tops": 7.279,
+ "bots": 10.938,
+ "res": 15.339,
+ "how": 18.424,
+ "same": 19.583,
+ "flip": 23.867,
+ "ride": 25.234,
+ "end": 27.344,
+ "gap": 30.065,
+ "why": 35.885
+ },
+ "cues": [
+ [
+ 0.104,
+ "Last, subtraction."
+ ],
+ [
+ 1.732,
+ "v minus w, with v three, one, and w one, two."
+ ],
+ [
+ 7.279,
+ "Subtract the tops: three minus one is two."
+ ],
+ [
+ 10.938,
+ "Subtract the bottoms: one minus two is minus one."
+ ],
+ [
+ 15.339,
+ "v minus w is two, minus one."
+ ],
+ [
+ 18.424,
+ "Here's the picture."
+ ],
+ [
+ 19.583,
+ "Taking away w is the same as adding minus w."
+ ],
+ [
+ 23.867,
+ "So flip w around, put its tail on the tip of v, and the trip ends at two, minus one."
+ ],
+ [
+ 30.065,
+ "And look: v minus w is also the arrow from the tip of w to the tip of v."
+ ],
+ [
+ 35.885,
+ "Because w, plus that arrow, gets you to v."
+ ]
+ ]
+ },
+ "q4": {
+ "dur": 2.16,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.133,
+ "Subtract."
+ ]
+ ]
+ },
+ "wrap": {
+ "dur": 30.264,
+ "marks": {
+ "w1": 1.029,
+ "w2": 5.964,
+ "w3": 14.74,
+ "w4": 23.711,
+ "end": 28.073
+ },
+ "cues": [
+ [
+ 0.104,
+ "To sum up."
+ ],
+ [
+ 1.029,
+ "To add two vectors, add the top numbers and add the bottom numbers."
+ ],
+ [
+ 5.964,
+ "In the picture, put the second arrow's tail on the first arrow's tip."
+ ],
+ [
+ 10.443,
+ "The sum goes from the origin to the end, and the order doesn't matter."
+ ],
+ [
+ 14.74,
+ "To multiply by a number c, multiply both numbers by c."
+ ],
+ [
+ 19.336,
+ "The arrow stretches, shrinks, flips, or vanishes."
+ ],
+ [
+ 23.711,
+ "v minus w is v plus minus one times w."
+ ],
+ [
+ 28.073,
+ "Now try the chapter practice."
+ ]
+ ]
+ },
+ "final1": {
+ "dur": 2.832,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Chapter practice."
+ ],
+ [
+ 1.523,
+ "Add the vectors."
+ ]
+ ]
+ },
+ "final2": {
+ "dur": 2.592,
+ "marks": {},
+ "cues": [
+ [
+ 0.091,
+ "Now multiply, and subtract."
+ ]
+ ]
+ },
+ "final3": {
+ "dur": 3.072,
+ "marks": {},
+ "cues": [
+ [
+ 0.091,
+ "What does each number c do to the arrow?"
+ ]
+ ]
+ },
+ "final4": {
+ "dur": 3.168,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Last set."
+ ],
+ [
+ 1.185,
+ "Make it happen with your hands."
+ ]
+ ]
+ },
+ "finish": {
+ "dur": 11.712,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Well done."
+ ],
+ [
+ 1.133,
+ "That's the end of chapter five, adding and stretching vectors."
+ ],
+ [
+ 5.443,
+ "Next: we stretch two vectors and add them, both at once."
+ ],
+ [
+ 9.727,
+ "That's called a linear combination."
+ ]
+ ]
+ }
+};
diff --git a/site/linear-algebra/ch05/audio/en/tiptail.mp3 b/site/linear-algebra/ch05/audio/en/tiptail.mp3
new file mode 100644
index 0000000..211e049
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/tiptail.mp3 differ
diff --git a/site/linear-algebra/ch05/audio/en/wrap.mp3 b/site/linear-algebra/ch05/audio/en/wrap.mp3
new file mode 100644
index 0000000..a91f05b
Binary files /dev/null and b/site/linear-algebra/ch05/audio/en/wrap.mp3 differ
diff --git a/site/linear-algebra/ch05/index.html b/site/linear-algebra/ch05/index.html
new file mode 100644
index 0000000..8f5e4ea
--- /dev/null
+++ b/site/linear-algebra/ch05/index.html
@@ -0,0 +1,438 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>Adding and Stretching Vectors</title>
+<link rel="stylesheet" href="../lib/engine.css">
+<link rel="expect" href="#bar" blocking="render"><!-- hold the first frame until the player exists, so the page transition can run -->
+</head>
+<body>
+<script src="../lib/engine.js"></script>
+<script src="../lib/math.js"></script>
+<script src="../lib/linsys.js"></script>
+<script src="../lib/vecs.js"></script>
+<script src="audio/en/timings.js"></script>
+<script>
+'use strict';
+const CHAPTER = { number: 5, title: 'Adding and Stretching Vectors', minutes: 10, language: 'en' };
+
+/* ---------- chapter drawing helpers ---------- */
+const [GREEN, VIOLET] = VS_COL; // v green, w violet (chapter 4); sums amber
+const CARD = { x: 40, y: 320, w: 720, cls: 'side' }; // question card under one row of algebra, beside the plane
+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));
+const thick = (vs, id, t0, w = 5) => { tw(vs.A[id].path, { 'a_stroke-width': w + 4 }, t0, .3); tw(vs.A[id].path, { 'a_stroke-width': w }, t0 + .7, .4); };
+// A placed arrow ('dw', 'cv1') drawn first at the origin, then slid without turning until its tail sits on `tail`.
+const slideIn = (vs, id, tail, t0, dur = 1.6) => {
+ const a = vs.A[id], u = vs.P.u;
+ put(a.g, { x: -tail[0] * u, y: tail[1] * u, o: 0 });
+ tw(a.g, { o: 1 }, t0, .3); tw(a.g, { x: 0, y: 0 }, t0 + .4, dur);
+ show(a.lab, t0 + .4 + dur, .4);
+};
+// A dot that makes a trip along a list of plane points, one leg after another.
+const travel = (p, P, pts, t0, leg = 1.4, color = COL.task) => {
+ const d = G(p, { o: 0 });
+ mk('circle', { r: 10, fill: color, stroke: COL.board, 'stroke-width': 2 }, d);
+ put(d, { x: P.PX(pts[0][0]), y: P.PY(pts[0][1]) });
+ show(d, t0 - .3, .3);
+ for (let i = 1; i < pts.length; i++) {
+ const [a, b] = [pts[i - 1], pts[i]];
+ prog(q => put(d, { x: P.PX(a[0] + (b[0] - a[0]) * q), y: P.PY(a[1] + (b[1] - a[1]) * q) }), t0 + (i - 1) * leg, leg * .9, io);
+ }
+ return d;
+};
+// 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 },
+ '=', { col: 'sum', fixed: true }], { x, y, size, o });
+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' });
+ show(g, t0, .4);
+ return g;
+};
+const lightUp = (e, t0, base = COL.chalk) => { tw(e, { c_color: COL.task }, t0, .25); tw(e, { c_color: base }, t0 + 1.2, .6); };
+// A curved arrow from one number to another, arched over (up) or under the row: "this one goes there".
+const centre = e => { const b = e.getBBox(); return [b.x + b.width / 2, b.y + b.height / 2, b.height]; };
+const curve = (p, a, b, t0, { color = COL.task, up = true, dur = .7 } = {}) => {
+ const [ax, ay, ah] = centre(a), [bx, by, bh] = centre(b), sy = up ? -1 : 1;
+ const y0 = ay + sy * ah * .6, y1 = by + sy * bh * .6, top = (up ? Math.min(y0, y1) : Math.max(y0, y1)) + sy * 36;
+ const e = path(p, `M${ax} ${y0}C${ax} ${top} ${bx} ${top} ${bx} ${y1}`, { stroke: color, 'stroke-width': 3, fill: 'none', 'stroke-linecap': 'round', 'stroke-dasharray': '2 0' }, { d: 0 });
+ draw(e, t0, dur);
+ return e;
+};
+const boxAround = (p, els, t0, color = COL.task) => {
+ const bs = els.map(e => e.getBBox()), x = Math.min(...bs.map(b => b.x)) - 10, y = Math.min(...bs.map(b => b.y)) - 6;
+ const w = Math.max(...bs.map(b => b.x + b.width)) + 10 - x, hh = Math.max(...bs.map(b => b.y + b.height)) + 6 - y;
+ const r = path(p, `M${x + 10} ${y}H${x + w - 10}Q${x + w} ${y} ${x + w} ${y + 10}V${y + hh - 10}Q${x + w} ${y + hh} ${x + w - 10} ${y + hh}H${x + 10}Q${x} ${y + hh} ${x} ${y + hh - 10}V${y + 10}Q${x} ${y} ${x + 10} ${y}Z`, { stroke: color, 'stroke-width': 3, fill: 'none' }, { d: 0 });
+ draw(r, t0, .8);
+ return r;
+};
+const pairStr = (x, y) => `(${num(x)}, ${num(y)})`;
+
+/* ---------- practice data (every answer computed here, and checked by hand in chapters/ch05.md) ---------- */
+const ADDQ = [[[2, 3], [4, 1]], [[5, -2], [-1, 6]], [[-3, -4], [-2, 7]], [[0, 5], [6, -5]], [[-7, 2], [7, 2]], [[1, -1], [-1, 1]]].map(([a, b]) => ({
+ q: [hcol(...a, GREEN), ' + ', hcol(...b, VIOLET)], ans: [a[0] + b[0], a[1] + b[1]],
+ why: `Top: ${num(a[0])} + ${b[0] < 0 ? `(${num(b[0])})` : b[0]} = ${num(a[0] + b[0])}. Bottom: ${num(a[1])} + ${b[1] < 0 ? `(${num(b[1])})` : b[1]} = ${num(a[1] + b[1])}.`,
+ hint: 'Add the two top numbers for the top, and the two bottom numbers for the bottom. A negative number added means going back.',
+}));
+const MULQ = [
+ { c: 3, a: [2, -1] }, { c: -2, a: [4, 3] }, { c: F(1, 2), cn: .5, a: [6, -8] }, { c: 0, a: [5, 9] }, { c: -1, a: [-3, 7] },
+].map(({ c, cn = c, a }) => ({
+ q: [$m(...(typeof c === 'number' ? [num(c)] : ['', c])), ' · ', hcol(...a, GREEN)], ans: [cn * a[0] || 0, cn * a[1] || 0],
+ why: `Multiply both numbers by ${typeof c === 'number' ? num(c) : '1/2'}: ${num(cn * a[0] || 0)} and ${num(cn * a[1] || 0)}.`,
+ hint: 'Multiply the top number by c, and the bottom number by c too. Minus times minus is plus.',
+}));
+const SUBQ = [[[6, 4], [2, 1]], [[3, -2], [5, 1]], [[-1, 0], [-4, -3]]].map(([a, b]) => ({
+ q: [hcol(...a, GREEN), ' − ', hcol(...b, VIOLET)], ans: [a[0] - b[0], a[1] - b[1]],
+ why: `Top: ${num(a[0])} − ${b[0] < 0 ? `(${num(b[0])})` : b[0]} = ${num(a[0] - b[0])}. Bottom: ${num(a[1])} − ${b[1] < 0 ? `(${num(b[1])})` : b[1]} = ${num(a[1] - b[1])}.`,
+ hint: 'Subtract top from top and bottom from bottom. Taking away a negative number adds.',
+}));
+const CQ = [
+ { c: '3', ans: ['long'], why: '3 is bigger than 1: three times as long, same way.' },
+ { c: '1/3', ans: ['short'], why: 'One third of the length, same way.' },
+ { c: '−1', ans: ['flip'], why: 'Same length, the opposite way.' },
+ { c: '0', ans: ['zero'], why: 'Every number becomes 0: the zero vector.' },
+ { c: '−2', ans: ['long', 'flip'], why: 'Twice as long, and the opposite way.' },
+ { c: '−1/2', ans: ['short', 'flip'], why: 'Half as long, and the opposite way.' },
+].map(r => ({ parts: [$m(`c = ${r.c}`)], ans: r.ans, why: r.why }));
+const CCOLS = [['long', 'longer', null, '1'], ['short', 'shorter', null, '2'], ['flip', 'flipped', null, '3'], ['zero', 'the zero vector', null, '4']];
+
+/* ---------- beats: [id, title, run(m, D), { ask }?] ---------- */
+const BEATS = [
+ ['intro', 'Adding and stretching', (m, D) => {
+ const g = G(scene, { o: 0, y: 24 });
+ T(g, 'Unit 1, Chapter 5', { x: 800, y: 300, size: 28, fill: COL.dim, anchor: 'middle' });
+ T(g, 'Adding and Stretching Vectors', { x: 800, y: 410, size: 76, weight: 600, anchor: 'middle' });
+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);
+ const r = text(scene, 'v + w, and c times v: with the numbers and with the arrows', 800, 510, m('sub'), { size: 34, fill: COL.dim, anchor: 'middle' });
+ // a small tip-to-tail sum, drawn as the narration says "picture"
+ const pic = G(scene, { o: 0 }), o = [690, 780];
+ const ar = (d, c, t0) => draw(path(pic, d, { stroke: c, 'stroke-width': 6, 'stroke-linecap': 'round', fill: 'none' }, { d: 0 }), t0, .7);
+ ar(`M${o[0]} ${o[1]}l120 -30`, GREEN, m('both') + .2);
+ ar(`M${o[0] + 120} ${o[1] - 30}l40 -80`, VIOLET, m('both') + .9);
+ ar(`M${o[0]} ${o[1]}l160 -110`, COL.task, m('both') + 1.6);
+ ar(`M${o[0] + 260} ${o[1]}l90 -45`, GREEN, m('both') + 2.2);
+ ar(`M${o[0] + 260} ${o[1]}l180 -90`, GREEN, m('both') + 2.8);
+ show(pic, m('both'), .3);
+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(pic, D - .9, .8);
+ }],
+
+ ['add', 'Adding with numbers', (m) => {
+ const p = panel(0);
+ text(p, 'Adding two vectors: top plus top, bottom plus bottom', 60, 110, .2, { size: 40, weight: 600 });
+ const A = vecs(p, { vecs: { v: [3, 1], w: [1, 2] }, hidePlane: true }), B = vecs(p, { vecs: { v: [2, -1], w: [-4, 3] }, hidePlane: true });
+ const ra = sumRow(A, 90, 330, { size: 50 }), rb = sumRow(B, 90, 650, { size: 50 });
+ showRow(ra, m('v') - .2, 0, 1); showRow(ra, m('v'), 4, 5); showRow(ra, m('w') - .2, 1, 4); showRow(ra, m('w'), 5, 7);
+ showRow(ra, m('tops'), 7, 9); const [ft, fb] = A.num('fn'); put(fb, { o: 0 });
+ A.flash('v0', m('tops') + .3); A.flash('w0', m('tops') + 1.3);
+ showRow(ra, m('tops') + 2.6, 9, 11); const [st0] = A.num('sum0'), [st1] = A.num('sum1'); put(st1, { o: 0 });
+ show(fb, m('bots')); A.flash('v1', m('bots') + .3); A.flash('w1', m('bots') + 1.3); show(st1, m('bots') + 2.6);
+ A.flash('sum0', m('res') + .3); A.flash('sum1', m('res') + .3);
+ const lk = G(p, {});
+ curve(lk, A.num('v0')[0], ft, m('tops') + .3, { color: GREEN }); curve(lk, A.num('w0')[0], ft, m('tops') + 1.3, { color: VIOLET });
+ curve(lk, A.num('v1')[0], fb, m('bots') + .3, { color: GREEN, up: false }); curve(lk, A.num('w1')[0], fb, m('bots') + 1.3, { color: VIOLET, up: false });
+ boxAround(lk, [st0, st1], m('res') + .2);
+ hide(lk, m('ex2') - .3, .4);
+ const n = G(p, { o: 0 });
+ T(n, 'tops add to tops, bottoms add to bottoms: they never mix', { x: 90, y: 480, size: 30, weight: 600, fill: COL.task });
+ show(n, m('never'));
+ lightUp(ft, m('never') + 2.4); lightUp(st0, m('never') + 2.4, COL.task); lightUp(fb, m('never') + 4.6); lightUp(st1, m('never') + 4.6, COL.task);
+ showRow(rb, m('ex2'), 0, 7);
+ showRow(rb, m('t2'), 7, 9); const [, fb2] = B.num('fn'); put(fb2, { o: 0 });
+ B.flash('v0', m('t2') + .2); B.flash('w0', m('t2') + 1);
+ showRow(rb, m('t2') + 2.4, 9, 11); const [, s21] = [B.num('sum0')[0], B.num('sum1')[0]]; put(s21, { o: 0 });
+ show(fb2, m('b2')); B.flash('v1', m('b2') + .2); B.flash('w1', m('b2') + 1); show(s21, m('b2') + 2.4);
+ B.flash('sum0', m('r2') + .4); B.flash('sum1', m('r2') + .4);
+ }],
+
+ ['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: [] });
+ 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 });
+ vs.show(['v', 'w'], m('arrows'), .6);
+ vs.dim('w', m('slide') + .2, .25); hide(vs.A.w.lab, m('slide') + .2, .3);
+ slideIn(vs, 'dw', [3, 1], m('slide') + .2, 2);
+ vs.legs('dw', m('same') + .2); vs.legs('dw', m('trip') - .2, false);
+ const tr = travel(p, vs.P, [[0, 0], [3, 1]], m('trip') + .3, 1.6);
+ prog(q => put(tr, { x: vs.P.PX(3 + q), y: vs.P.PY(1 + 2 * q) }), m('then') + .3, 1.4, io);
+ hide(tr, m('sum') + .4, .3);
+ const end = G(p, {});
+ vs.P.dot(4, 3, COL.task, m('end') + .2, { r: 9, label: '(4, 3)', dx: 18, dy: 38, into: end });
+ vs.show('sum', m('sum'), .6);
+ 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.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);
+ vs.flash('sum0', m('read') + .4); vs.flash('sum1', m('read') + .4);
+ }],
+
+ ['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'] });
+ 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 });
+ vs.P.g.insertBefore(par, vs.P.g.lastChild);
+ tw(par, { o: .14 }, m('para'), .8);
+ vs.show('dw0', m('wv'), .6);
+ vs.show('cv1', m('route') + 1.6, .6);
+ const tr = travel(p, vs.P, [[0, 0], [1, 2], [4, 3]], m('route') + .2, 1.5);
+ hide(tr, m('para'), .3);
+ const end = vs.P.dot(4, 3, COL.task, m('land'), { r: 10, label: '(4, 3)', dx: 18, dy: 38 }); pulse(end, m('land') + .5);
+ const vw = vs.row([{ t: 'v', fill: GREEN }, '+', { t: 'w', fill: VIOLET }, '=', { fn: () => ['3 + 1', '1 + 2'], w: 160 }, '=', { col: 'sum', fixed: true }], { x: 90, y: 300, o: 0 });
+ const wv = vs.row([{ t: 'w', fill: VIOLET }, '+', { t: 'v', fill: GREEN }, '=', { fn: () => ['1 + 3', '2 + 1'], w: 160 }, '=', { col: 'sum', fixed: true }], { x: 90, y: 520, o: 0 });
+ showRow(vw, .4); showRow(wv, m('nums'));
+ vs.flash('sum0', m('nums') + 1); vs.flash('sum1', m('nums') + 4.4);
+ const [a0, a1] = vw.parts[4].querySelectorAll('g[color]'), [b0, b1] = wv.parts[4].querySelectorAll('g[color]');
+ const bx = G(p, {});
+ boxAround(bx, [a0], m('nums') + .6); boxAround(bx, [b0], m('nums') + 1.4);
+ boxAround(bx, [a1], m('nums') + 4.2, VIOLET); boxAround(bx, [b1], m('nums') + 5, VIOLET);
+ say(p, ['v + w = w + v'], 90, 730, m('rule'), { size: 54, fill: COL.task });
+ }],
+
+ ['q1', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ S.vs = vecs(p, { vecs: { v: [4, -1], w: [-1, 3] } });
+ S.vs.label('sum', ['v + w']);
+ }, { ask: done => quiz(CARD, [{
+ id: 'c-add', prompt: ['Add the two vectors: top plus top, bottom plus bottom.'],
+ build: vcolBlanks([{ q: [hcol(4, -1, GREEN), ' + ', hcol(-1, 3, VIOLET)], ans: [3, 2], why: 'Top: 4 + (−1) = 3. Bottom: −1 + 3 = 2.', hint: 'Add the tops: 4 + (−1). Then add the bottoms: −1 + 3.',
+ fx: () => { fx(S.vs.A.dw.g, { o: 1 }, 0, .5); fx(S.vs.A.dw.lab, { o: 1 }, 0, .5); fx(S.vs.A.sum.g, { o: 1 }, .6, .5); fx(S.vs.A.sum.lab, { o: 1 }, .6, .5); } }]),
+ }], done) }],
+
+ ['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'] });
+ 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 });
+ const { PX, PY } = vs.P, hand = G(p, { o: 0 });
+ mk('circle', { r: 20, fill: COL.task, 'fill-opacity': .25, stroke: COL.task, 'stroke-width': 3 }, hand);
+ put(hand, { x: PX(4), y: PY(3) });
+ show(hand, m('grab') + .6, .4);
+ prog(q => { // the tip of w snaps from grid point to grid point, as it does for the reader
+ const x = 4 + (5 - 4) * q, y = 3 + (-1 - 3) * q;
+ put(hand, { x: PX(x), y: PY(y) });
+ vs.set({ w0: Math.round(x) - 3, w1: Math.round(y) - 1 });
+ }, m('pull'), 2.6, io);
+ hide(hand, m('rule'), .4);
+ vs.flash('w0', m('pull') + .5); vs.flash('w1', m('pull') + .5); vs.flash('sum0', m('sum')); vs.flash('sum1', m('sum'));
+ const ce = G(p, { x: PX(5), y: PY(-1), o: 0 });
+ mk('circle', { r: 18, fill: 'none', stroke: COL.task, 'stroke-width': 4 }, ce);
+ show(ce, m('rule'), .3); pulse(ce, m('rule') + .6, 1.4); pulse(ce, m('rule') + 2, 1.4); hide(ce, m('scrub'), .3);
+ text(p, 'v + w ends where w ends', 90, 770, m('rule'), { size: 28, fill: COL.task, weight: 600 });
+ vs.to({ v0: 3, v1: 1, w0: 2, w1: -2 }, m('rule') - .1, .01); // the plan catches up with the hand
+ vs.to({ v0: 1 }, m('move'), 1.6); vs.flash('v0', m('scrub') + 1.6);
+ vs.flash('sum0', m('sum2') + .3);
+ }],
+
+ ['q2', 'Your turn', () => {
+ const p = panel(0);
+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
+ S.vs = vecs(p, { vecs: { v: [2, 1], w: [1, 1] }, show: ['v', 'dw', 'sum'] });
+ S.vs.label('sum', ['v + w']);
+ 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 });
+ ringAt(S.vs.P, -1, 4, .5, p);
+ }, { ask: done => quiz(CARD, [{
+ id: 'c-target', prompt: ['Move ', $m('w'), ' (drag its tip, or change its numbers) so that ', $m('v + w'), ' lands on ', $m('(−1, 4)'), '.'],
+ build: vsTask(S.vs, v => v.w0 === -3 && v.w1 === 3, ['w = ', hcol(-3, 3, VIOLET), ': 2 + (−3) = −1 and 1 + 3 = 4.'],
+ (v, k) => `v + w is at ${pairStr(k.sum[0], k.sum[1])}. From there, the target is ${num(-1 - k.sum[0])} across and ${num(4 - k.sum[1])} up: change w by that much.`,
+ () => S.vs.set({ w0: -3, w1: 3 }), { drag: ['dw'], move: true }),
+ }], done) }],
+
+ ['scale', 'Multiplying by a number', (m) => {
+ const p = panel(0);
+ text(p, 'Multiplying a vector by a number', 60, 110, .2, { size: 40, weight: 600 });
+ const vs = vecs(p, { vecs: { v: [2, 1] }, c: 2, show: [] });
+ vs.label('v', ['v'], 'tip', [-34, 30]);
+ vRow(vs, 'v', GREEN, 250).parts.forEach(e => show(e, m('v')));
+ vs.show('v', m('v') + .3, .6);
+ const vv = vs.row([{ t: 'v + v', fill: GREEN }, '=', { fn: () => ['2 + 2', '1 + 1'], w: 160 }, '=', { col: 'cv', fixed: true }], { x: 90, y: 430, o: 0 });
+ 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(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.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 });
+ 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'));
+ }],
+
+ ['shrink', 'Shrink, flip, vanish', (m) => {
+ const p = panel(0);
+ text(p, 'Shrink, flip, vanish', 60, 110, .2, { size: 40, weight: 600 });
+ const vs = vecs(p, { vecs: { v: [2, 1] }, c: 3, show: ['v', 'cv'] });
+ vs.dim('v', .3, .35);
+ 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: 250 });
+ const note = (str, y, t0, fill = COL.task) => text(p, str, 90, y, t0, { size: 30, fill, weight: 600 });
+ vs.to({ c: .5 }, m('half') + .2, 1.4); vs.flash('c', m('half') + .2);
+ vs.flash('cv0', m('th') + .2); vs.flash('cv1', m('th') + 1.5);
+ note('c = ½: half as long', 420, m('short'));
+ vs.to({ c: -1 }, m('neg') + .2, 1.6); vs.flash('c', m('neg') + .2);
+ vs.flash('cv0', m('tn') + 1); vs.flash('cv1', m('tn') + 3);
+ note('c = −1: flipped, the same length (−v)', 475, m('flip'));
+ vs.to({ c: -2 }, m('neg2'), 1.2);
+ note('c = −2: flipped and twice as long', 530, m('neg2') + .4);
+ vs.to({ c: 0 }, m('zero') + .4, 1.4);
+ note('c = 0: the zero vector', 585, m('dot'));
+ // sweep c from −3 to 3: the tip runs along one line; every whole c leaves a dot
+ const trail = G(p, {});
+ [-3, -2, -1, 0, 1, 2, 3].forEach(k => {
+ const t = m('line') + .6 + (k + 3) / 6 * 4;
+ vs.P.dot(2 * k, k, COL.task, t, { r: 6, into: trail, label: k >= -1 && k !== 2 && k !== -1 ? undefined : k === -1 ? "−v" : `${num(k)}v`, dx: 12, dy: 26 });
+ });
+ vs.to({ c: -3 }, m('line'), .6);
+ vs.to({ c: 3 }, m('line') + .6, 4, lin);
+ vs.P.line(-6, -3, 6, 3, COL.task, m('all'), { dash: '10 10', w: 3, into: trail });
+ note('every multiple of v: on the line through v', 670, m('all') + .4, COL.chalk);
+ }],
+
+ ['more', 'Two more examples', (m) => {
+ const p = panel(0);
+ text(p, 'Two more: multiply both numbers by c', 60, 110, .2, { size: 40, weight: 600 });
+ const vs = vecs(p, { vecs: { v: [-1, 2] }, c: 3, show: [] });
+ vs.label('cv', v => [...vs.parts(v.c), 'v'], 'tip', [36, -10]);
+ const r = 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: 170 }, '=', { col: 'cv' }], { x: 90, y: 300, o: 0 });
+ 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);
+ 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 });
+ thick(vs, 'cv', m('br') + .6); thick(vs, 'v', m('br') + 2.4);
+ text(p, 'twice as long, the opposite way', 90, 580, m('br') + 1, { size: 30, fill: COL.dim });
+ }],
+
+ ['q3', 'Your turn', () => {
+ const p = panel(0);
+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
+ S.vs = vecs(p, { vecs: { v: [2, 1] }, show: ['v', 'cv'] });
+ S.vs.dim('v', 0, .35);
+ S.vs.row([{ key: 'c' }, { t: 'v', fill: GREEN }, '=', { key: 'c' }, { col: 'v', fixed: true }, '=', { col: 'cv', fixed: true }], { x: 90, y: 230 });
+ }, { ask: done => quiz(CARD, [{
+ id: 'c-scale', prompt: ['Change ', $m('c'), ' (or drag the tip of ', $m('cv'), ') until ', $m('cv'), ' = ', hcol(-4, -2, GREEN), '.'],
+ build: vsTask(S.vs, v => v.c === -2, 'c = −2: −2·2 = −4 and −2·1 = −2. Flipped and twice as long.',
+ v => v.c === 2 ? 'Right length, wrong way: the numbers must turn negative. Try a negative c.' : `c = ${num(v.c)} gives ${num(2 * v.c)} on top. Which c turns 2 into −4?`,
+ () => S.vs.set({ c: -2 }), { drag: ['cv'] }),
+ }], done) }],
+
+ ['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 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);
+ 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);
+ 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);
+ text(p, 'flip w: −w', 90, 500, m('flip') + .8, { size: 30, fill: VIOLET, weight: 600 });
+ vs.hide('dw0', m('ride') + .2, .4);
+ slideIn(vs, 'dw', [3, 1], m('ride') + .1, 1.4);
+ vs.show('sum', m('end'), .6);
+ const gap = G(p, {});
+ vs.P.arrow(1, 2, 3, 1, COL.task, m('gap') + .6, { into: gap });
+ text(p, 'from the tip of w to the tip of v', 90, 600, m('gap') + .6, { size: 28, fill: COL.task, weight: 600 });
+ travel(p, vs.P, [[0, 0], [1, 2], [3, 1]], m('why') + .4, 1.3);
+ say(p, ['w + (v − w) = v'], 90, 680, m('why') + 1, { size: 40 });
+ }],
+
+ ['q4', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ S.vs = vecs(p, { vecs: { v: [5, 2], w: [1, 4] }, d: -1 });
+ S.vs.label('sum', ['v − w']);
+ }, { ask: done => quiz(CARD, [{
+ id: 'c-sub', prompt: ['Subtract: top minus top, bottom minus bottom.'],
+ build: vcolBlanks([{ q: [hcol(5, 2, GREEN), ' − ', hcol(1, 4, VIOLET)], ans: [4, -2], why: 'Top: 5 − 1 = 4. Bottom: 2 − 4 = −2.', hint: 'Top minus top: 5 − 1. Bottom minus bottom: 2 − 4 (that one is negative).',
+ fx: () => { fx(S.vs.A.dw.g, { o: 1 }, 0, .5); fx(S.vs.A.dw.lab, { o: 1 }, 0, .5); fx(S.vs.A.sum.g, { o: 1 }, .6, .5); fx(S.vs.A.sum.lab, { o: 1 }, .6, .5); } }]),
+ }], done) }],
+
+ ['wrap', 'Summary', (m) => {
+ const p = panel(0);
+ [['To add, add the tops and add the bottoms.', 'w1'], ['Arrows: tail of w on the tip of v; v + w = w + v.', 'w2'],
+ ['c·v: multiply both numbers by c (stretch, shrink, flip, vanish).', 'w3'], ['v − w = v + (−1)·w.', '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);
+ T(dg, String(i + 1), { x: 0, y: 11, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });
+ const tl = T(g, str, { x: 210, size: 36, weight: 600 });
+ tw(g, { o: 1, x: 0 }, m(mark), .6);
+ pulse(dg, m('end') + i * .3, 1.25);
+ const next = ['w2', 'w3', 'w4', 'end'][i], ul = path(g, `M210 16H${210 + tl.getComputedTextLength()}`, { stroke: COL.task, 'stroke-width': 3, 'stroke-opacity': .6 }, { d: 0 });
+ draw(ul, m(mark) + .5, Math.max(1, m(next) - m(mark) - 1), lin);
+ });
+ }],
+ ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
+ 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-sub', prompt: ['Subtract. Top minus top, bottom minus bottom.'], build: vcolBlanks(SUBQ),
+ }], done, 'Chapter practice · set 2 of 4') }],
+ ['final3', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
+ id: 'p-c', prompt: ['What does multiplying by c do to an arrow? Pick every word that fits.'],
+ build: grid(CQ, CCOLS, { multi: true, text: true }),
+ }], done, 'Chapter practice · set 3 of 4') }],
+ ['final4', 'Chapter practice', () => {
+ const p = panel(0);
+ text(p, 'Make it happen', 60, 110, .2, { size: 40, weight: 600 });
+ S.vs = vecs(p, { vecs: { v: [1, 2], w: [1, 1] }, show: ['v', 'dw', 'sum'] });
+ 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') }],
+ ['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],
+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
+
+// Hands-on practice: targets for v + w (w moves), then for c·v (c moves).
+const MAKE5 = [
+ ...[[4, 0], [-3, 5], [1, -4], [0, 0], [6, 6]].map(([x, y], i) => ({
+ id: `p-sum${i + 1}`, prompt: ['Move ', $m('w'), ' so that ', $m('v + w'), ' lands on ', $m(pairStr(x, y)), '.'],
+ setup: () => { S.vs.set({ v0: 1, v1: 2, w0: 1, w1: 1, c: 1, d: 1 }); S.q5?.remove(); S.q5 = ringAt(S.vs.P, x, y, 0, S.vs.stage); fx(S.q5, { o: 1 }, 0, .3); },
+ test: v => v.w0 === x - 1 && v.w1 === y - 2, why: ['w = ', hcol(x - 1, y - 2, VIOLET), `: 1 + ${(x - 1) < 0 ? `(${num(x - 1)})` : x - 1} = ${num(x)} and 2 + ${(y - 2) < 0 ? `(${num(y - 2)})` : y - 2} = ${num(y)}.`],
+ hint: (v, k) => `v + w is at ${pairStr(k.sum[0], k.sum[1])}; the target is ${num(x - k.sum[0])} across and ${num(y - k.sum[1])} up from there.`,
+ show: () => S.vs.set({ w0: x - 1, w1: y - 2 }), opts: { drag: ['dw'], move: true },
+ })),
+];
+
+boot();
+</script>
+</body>
+</html>
diff --git a/site/linear-algebra/ch06/audio/en/count.mp3 b/site/linear-algebra/ch06/audio/en/count.mp3
new file mode 100644
index 0000000..d0cae83
Binary files /dev/null and b/site/linear-algebra/ch06/audio/en/count.mp3 differ
diff --git a/site/linear-algebra/ch06/audio/en/ex2.mp3 b/site/linear-algebra/ch06/audio/en/ex2.mp3
new file mode 100644
index 0000000..be69a1d
Binary files /dev/null and b/site/linear-algebra/ch06/audio/en/ex2.mp3 differ
diff --git a/site/linear-algebra/ch06/audio/en/final1.mp3 b/site/linear-algebra/ch06/audio/en/final1.mp3
new file mode 100644
index 0000000..c34868f
Binary files /dev/null and b/site/linear-algebra/ch06/audio/en/final1.mp3 differ
diff --git a/site/linear-algebra/ch06/audio/en/final2.mp3 b/site/linear-algebra/ch06/audio/en/final2.mp3
new file mode 100644
index 0000000..a012138
Binary files /dev/null and b/site/linear-algebra/ch06/audio/en/final2.mp3 differ
diff --git a/site/linear-algebra/ch06/audio/en/final3.mp3 b/site/linear-algebra/ch06/audio/en/final3.mp3
new file mode 100644
index 0000000..89c4965
Binary files /dev/null and b/site/linear-algebra/ch06/audio/en/final3.mp3 differ
diff --git a/site/linear-algebra/ch06/audio/en/final4.mp3 b/site/linear-algebra/ch06/audio/en/final4.mp3
new file mode 100644
index 0000000..6ea56c7
Binary files /dev/null and b/site/linear-algebra/ch06/audio/en/final4.mp3 differ
diff --git a/site/linear-algebra/ch06/audio/en/finish.mp3 b/site/linear-algebra/ch06/audio/en/finish.mp3
new file mode 100644
index 0000000..d6ab030
Binary files /dev/null and b/site/linear-algebra/ch06/audio/en/finish.mp3 differ
diff --git a/site/linear-algebra/ch06/audio/en/intro.mp3 b/site/linear-algebra/ch06/audio/en/intro.mp3
new file mode 100644
index 0000000..ff977c8
Binary files /dev/null and b/site/linear-algebra/ch06/audio/en/intro.mp3 differ
diff --git a/site/linear-algebra/ch06/audio/en/lattice.mp3 b/site/linear-algebra/ch06/audio/en/lattice.mp3
new file mode 100644
index 0000000..c1fd89c
Binary files /dev/null and b/site/linear-algebra/ch06/audio/en/lattice.mp3 differ
diff --git a/site/linear-algebra/ch06/audio/en/name.mp3 b/site/linear-algebra/ch06/audio/en/name.mp3
new file mode 100644
index 0000000..abd5067
Binary files /dev/null and b/site/linear-algebra/ch06/audio/en/name.mp3 differ
diff --git a/site/linear-algebra/ch06/audio/en/parallel.mp3 b/site/linear-algebra/ch06/audio/en/parallel.mp3
new file mode 100644
index 0000000..099bd32
Binary files /dev/null and b/site/linear-algebra/ch06/audio/en/parallel.mp3 differ
diff --git a/site/linear-algebra/ch06/audio/en/q1.mp3 b/site/linear-algebra/ch06/audio/en/q1.mp3
new file mode 100644
index 0000000..0022404
Binary files /dev/null and b/site/linear-algebra/ch06/audio/en/q1.mp3 differ
diff --git a/site/linear-algebra/ch06/audio/en/q2.mp3 b/site/linear-algebra/ch06/audio/en/q2.mp3
new file mode 100644
index 0000000..7f92a03
Binary files /dev/null and b/site/linear-algebra/ch06/audio/en/q2.mp3 differ
diff --git a/site/linear-algebra/ch06/audio/en/q3.mp3 b/site/linear-algebra/ch06/audio/en/q3.mp3
new file mode 100644
index 0000000..66f2330
Binary files /dev/null and b/site/linear-algebra/ch06/audio/en/q3.mp3 differ
diff --git a/site/linear-algebra/ch06/audio/en/reach.mp3 b/site/linear-algebra/ch06/audio/en/reach.mp3
new file mode 100644
index 0000000..b8eaab0
Binary files /dev/null and b/site/linear-algebra/ch06/audio/en/reach.mp3 differ
diff --git a/site/linear-algebra/ch06/audio/en/scrub.mp3 b/site/linear-algebra/ch06/audio/en/scrub.mp3
new file mode 100644
index 0000000..0760c5d
Binary files /dev/null and b/site/linear-algebra/ch06/audio/en/scrub.mp3 differ
diff --git a/site/linear-algebra/ch06/audio/en/special.mp3 b/site/linear-algebra/ch06/audio/en/special.mp3
new file mode 100644
index 0000000..892ddaa
Binary files /dev/null and b/site/linear-algebra/ch06/audio/en/special.mp3 differ
diff --git a/site/linear-algebra/ch06/audio/en/timings.js b/site/linear-algebra/ch06/audio/en/timings.js
new file mode 100644
index 0000000..ee8b996
--- /dev/null
+++ b/site/linear-algebra/ch06/audio/en/timings.js
@@ -0,0 +1,610 @@
+window.TIMINGS = {
+ "intro": {
+ "dur": 8.976,
+ "marks": {
+ "sub": 3.008,
+ "big": 5.69
+ },
+ "cues": [
+ [
+ 0.104,
+ "Chapter six."
+ ],
+ [
+ 1.38,
+ "Linear combinations."
+ ],
+ [
+ 3.008,
+ "Stretch two vectors, then add them."
+ ],
+ [
+ 5.69,
+ "This one idea runs through all of linear algebra."
+ ]
+ ]
+ },
+ "name": {
+ "dur": 58.176,
+ "marks": {
+ "both": 3.893,
+ "vw": 5.573,
+ "cd": 11.003,
+ "ex": 17.93,
+ "cv": 21.068,
+ "dw": 24.492,
+ "add": 27.891,
+ "addb": 32.344,
+ "res": 36.198,
+ "pic": 39.766,
+ "pic2": 42.617,
+ "end": 44.818,
+ "name": 47.201,
+ "keep": 51.927
+ },
+ "cues": [
+ [
+ 0.104,
+ "In chapter five we stretched vectors, and we added them."
+ ],
+ [
+ 3.893,
+ "Now we do both at once."
+ ],
+ [
+ 5.573,
+ "Take v equals two, minus one, and w equals minus one, two."
+ ],
+ [
+ 11.003,
+ "Pick two numbers, c and d."
+ ],
+ [
+ 13.477,
+ "Stretch v by c, stretch w by d, then add."
+ ],
+ [
+ 17.93,
+ "Let's try c equals one and d equals two."
+ ],
+ [
+ 21.068,
+ "One times v is still two, minus one."
+ ],
+ [
+ 24.492,
+ "Two times w is minus two, four."
+ ],
+ [
+ 27.891,
+ "Now add."
+ ],
+ [
+ 28.828,
+ "The tops, two plus minus two, give zero."
+ ],
+ [
+ 32.344,
+ "The bottoms, minus one plus four, give three."
+ ],
+ [
+ 36.198,
+ "So one v plus two w is zero, three."
+ ],
+ [
+ 39.766,
+ "In the picture: one v from the origin, then two w from its tip, and the trip ends at zero, three."
+ ],
+ [
+ 47.201,
+ "c v plus d w is called a linear combination of v and w."
+ ],
+ [
+ 51.927,
+ "Remember these numbers: v, w, and zero, three."
+ ],
+ [
+ 57.083,
+ "They'll come back."
+ ]
+ ]
+ },
+ "ex2": {
+ "dur": 36.384,
+ "marks": {
+ "c2": 1.341,
+ "t": 4.18,
+ "b": 10.234,
+ "r": 17.422,
+ "c3": 20.911,
+ "t3": 24.661,
+ "b3": 28.724,
+ "r3": 31.51,
+ "same": 33.438
+ },
+ "cues": [
+ [
+ 0.104,
+ "Another choice: c equals two, d equals one."
+ ],
+ [
+ 4.18,
+ "Top: two times two, plus one times minus one."
+ ],
+ [
+ 8.073,
+ "Four minus one is three."
+ ],
+ [
+ 10.234,
+ "Bottom: two times minus one, plus one times two."
+ ],
+ [
+ 14.349,
+ "Minus two plus two is zero."
+ ],
+ [
+ 17.422,
+ "So two v plus w is three, zero."
+ ],
+ [
+ 20.911,
+ "And c equals minus one, d equals one."
+ ],
+ [
+ 24.661,
+ "Top: minus two, minus one: minus three."
+ ],
+ [
+ 28.724,
+ "Bottom: one plus two: three."
+ ],
+ [
+ 31.51,
+ "Minus three, three."
+ ],
+ [
+ 33.438,
+ "Each choice of c and d lands on one point."
+ ]
+ ]
+ },
+ "special": {
+ "dur": 22.848,
+ "marks": {
+ "sum": 2.161,
+ "diff": 6.445,
+ "onlyv": 10.143,
+ "zero": 12.904,
+ "all": 17.083
+ },
+ "cues": [
+ [
+ 0.104,
+ "You've met some combinations already."
+ ],
+ [
+ 2.161,
+ "c and d both one: that's v plus w."
+ ],
+ [
+ 6.445,
+ "c one, d minus one: v minus w."
+ ],
+ [
+ 10.143,
+ "d zero: just c times v."
+ ],
+ [
+ 12.904,
+ "And c and d both zero: the zero vector."
+ ],
+ [
+ 17.083,
+ "Sums, differences, multiples: all of them are linear combinations."
+ ]
+ ]
+ },
+ "q1": {
+ "dur": 2.76,
+ "marks": {},
+ "cues": [
+ [
+ 0.091,
+ "Quick check."
+ ],
+ [
+ 1.107,
+ "Work out this combination."
+ ]
+ ]
+ },
+ "scrub": {
+ "dur": 19.176,
+ "marks": {
+ "c": 2.409,
+ "cpath": 6.458,
+ "d": 9.922,
+ "dpath": 12.93,
+ "both": 15.651
+ },
+ "cues": [
+ [
+ 0.104,
+ "Now let's move c and d, and watch."
+ ],
+ [
+ 2.409,
+ "Change c, and only the first arrow stretches."
+ ],
+ [
+ 6.458,
+ "The tip slides along the direction of v."
+ ],
+ [
+ 9.922,
+ "Change d, and the second arrow stretches."
+ ],
+ [
+ 12.93,
+ "The tip slides along the direction of w."
+ ],
+ [
+ 15.651,
+ "Change both, and you can steer the tip wherever you like."
+ ]
+ ]
+ },
+ "reach": {
+ "dur": 43.56,
+ "marks": {
+ "target": 1.771,
+ "ask": 5.013,
+ "start": 6.979,
+ "up": 10.781,
+ "d1": 14.102,
+ "d2": 15.065,
+ "hit": 16.185,
+ "turn": 22.031,
+ "drag": 25.651,
+ "p30": 27.747,
+ "p11": 32.474,
+ "p10": 34.635,
+ "frac": 40.091
+ },
+ "cues": [
+ [
+ 0.104,
+ "Now turn the question around."
+ ],
+ [
+ 1.771,
+ "Here is a target: zero, three."
+ ],
+ [
+ 5.013,
+ "Which c and d reach it?"
+ ],
+ [
+ 6.979,
+ "Start at c zero, d zero: the origin."
+ ],
+ [
+ 10.781,
+ "Raise c to one: we're at the tip of v."
+ ],
+ [
+ 14.102,
+ "Raise d to one, then two."
+ ],
+ [
+ 16.185,
+ "There: c equals one, d equals two, the combination we began with."
+ ],
+ [
+ 22.031,
+ "It works the other way too."
+ ],
+ [
+ 23.646,
+ "Drag the tip of the combination, and c and d follow."
+ ],
+ [
+ 27.747,
+ "At three, zero, c is two and d is one."
+ ],
+ [
+ 32.474,
+ "At one, one, both are one."
+ ],
+ [
+ 34.635,
+ "And at one, zero, c is two thirds and d is one third."
+ ],
+ [
+ 40.091,
+ "Sometimes the numbers you need are fractions, and that's fine."
+ ]
+ ]
+ },
+ "q2": {
+ "dur": 6.072,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn."
+ ],
+ [
+ 1.055,
+ "Change c and d until the combination lands on the target, four, one."
+ ]
+ ]
+ },
+ "lattice": {
+ "dur": 26.784,
+ "marks": {
+ "dots": 1.458,
+ "grid": 5.26,
+ "gaps": 10.391,
+ "roam": 14.128,
+ "plane": 18.789
+ },
+ "cues": [
+ [
+ 0.104,
+ "Here's a big idea."
+ ],
+ [
+ 1.458,
+ "Mark every point you can reach with whole numbers c and d."
+ ],
+ [
+ 5.26,
+ "They make a slanted grid: lines along v, and lines along w."
+ ],
+ [
+ 10.391,
+ "With fractions, you fill in everything between the lines."
+ ],
+ [
+ 14.128,
+ "Drag the tip anywhere, and there's always a c and a d."
+ ],
+ [
+ 18.789,
+ "So the combinations of v and w fill the whole plane."
+ ],
+ [
+ 23.203,
+ "Every point is some c v plus d w."
+ ]
+ ]
+ },
+ "count": {
+ "dur": 36.672,
+ "marks": {
+ "t": 3.49,
+ "sv": 5.247,
+ "sw": 7.526,
+ "there": 11.615,
+ "read": 12.435,
+ "check": 18.984,
+ "t2": 27.487,
+ "s2": 29.948,
+ "s3": 31.745,
+ "r2": 33.867
+ },
+ "cues": [
+ [
+ 0.104,
+ "The slanted grid also tells you c and d."
+ ],
+ [
+ 3.49,
+ "Take the target one, four."
+ ],
+ [
+ 5.247,
+ "Walk along v: one, two steps."
+ ],
+ [
+ 7.526,
+ "Then along w: one, two, three steps."
+ ],
+ [
+ 11.615,
+ "We're there."
+ ],
+ [
+ 12.435,
+ "Two steps along v, three along w: c is two, and d is three."
+ ],
+ [
+ 18.984,
+ "Check with the numbers."
+ ],
+ [
+ 20.521,
+ "Top: four, minus three, is one."
+ ],
+ [
+ 23.646,
+ "Bottom: minus two, plus six, is four."
+ ],
+ [
+ 27.487,
+ "One more: minus one, five."
+ ],
+ [
+ 29.948,
+ "One step along v, then three steps along w."
+ ],
+ [
+ 33.867,
+ "c is one, and d is three."
+ ]
+ ]
+ },
+ "parallel": {
+ "dur": 29.736,
+ "marks": {
+ "turn": 1.458,
+ "squash": 6.719,
+ "par": 10.43,
+ "line": 12.773,
+ "miss": 15.521,
+ "rule": 22.109
+ },
+ "cues": [
+ [
+ 0.117,
+ "But not always."
+ ],
+ [
+ 1.458,
+ "Let w turn, slowly, until it points along v."
+ ],
+ [
+ 6.719,
+ "Watch the grid: it squashes flatter and flatter."
+ ],
+ [
+ 10.43,
+ "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."
+ ],
+ [
+ 22.109,
+ "Two vectors that point along different lines fill the plane."
+ ],
+ [
+ 26.107,
+ "Two that point along the same line only fill a line."
+ ]
+ ]
+ },
+ "q3": {
+ "dur": 3.864,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.172,
+ "Can the combinations reach every point?"
+ ]
+ ]
+ },
+ "wrap": {
+ "dur": 26.136,
+ "marks": {
+ "w1": 0.964,
+ "w2": 7.734,
+ "w3": 15.664,
+ "w4": 20.0,
+ "end": 23.776
+ },
+ "cues": [
+ [
+ 0.104,
+ "To sum up."
+ ],
+ [
+ 0.964,
+ "A linear combination is c v plus d w: stretch each vector, then add."
+ ],
+ [
+ 7.734,
+ "Each choice of c and d gives one point."
+ ],
+ [
+ 10.612,
+ "You can go from c and d to the point, or from the point back to c and d."
+ ],
+ [
+ 15.664,
+ "Two vectors that point different ways reach every point of the plane."
+ ],
+ [
+ 20.0,
+ "Two vectors along the same line only reach that line."
+ ],
+ [
+ 23.776,
+ "Now try the chapter practice."
+ ]
+ ]
+ },
+ "final1": {
+ "dur": 3.312,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Chapter practice."
+ ],
+ [
+ 1.497,
+ "Work out each combination."
+ ]
+ ]
+ },
+ "final2": {
+ "dur": 3.12,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Now find c and d for each target."
+ ]
+ ]
+ },
+ "final3": {
+ "dur": 2.784,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Can the combinations reach every point?"
+ ]
+ ]
+ },
+ "final4": {
+ "dur": 4.08,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Last set."
+ ],
+ [
+ 1.263,
+ "Steer the combination onto each target."
+ ]
+ ]
+ },
+ "finish": {
+ "dur": 10.872,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Well done."
+ ],
+ [
+ 1.133,
+ "That's the end of chapter six, linear combinations."
+ ],
+ [
+ 4.675,
+ "Next: the column picture, where a whole system of equations turns into one combination."
+ ]
+ ]
+ }
+};
diff --git a/site/linear-algebra/ch06/audio/en/wrap.mp3 b/site/linear-algebra/ch06/audio/en/wrap.mp3
new file mode 100644
index 0000000..4550c71
Binary files /dev/null and b/site/linear-algebra/ch06/audio/en/wrap.mp3 differ
diff --git a/site/linear-algebra/ch06/index.html b/site/linear-algebra/ch06/index.html
new file mode 100644
index 0000000..671dd46
--- /dev/null
+++ b/site/linear-algebra/ch06/index.html
@@ -0,0 +1,371 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>Linear Combinations</title>
+<link rel="stylesheet" href="../lib/engine.css">
+<link rel="expect" href="#bar" blocking="render"><!-- hold the first frame until the player exists, so the page transition can run -->
+</head>
+<body>
+<script src="../lib/engine.js"></script>
+<script src="../lib/math.js"></script>
+<script src="../lib/linsys.js"></script>
+<script src="../lib/vecs.js"></script>
+<script src="audio/en/timings.js"></script>
+<script>
+'use strict';
+const CHAPTER = { number: 6, title: 'Linear Combinations', minutes: 10, language: 'en' };
+
+/* ---------- chapter drawing helpers ---------- */
+const [GREEN, VIOLET] = VS_COL; // v green, w violet; the combination amber (it will be b)
+const LV = [2, -1], LW = [-1, 2]; // the lecture's two columns, not named columns yet
+const CARD = { x: 40, y: 320, w: 720, cls: 'side' };
+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));
+const thick = (vs, id, t0, w = 5) => { tw(vs.A[id].path, { 'a_stroke-width': w + 4 }, t0, .3); tw(vs.A[id].path, { 'a_stroke-width': w }, t0 + .7, .4); };
+const pairStr = (x, y) => `(${num(x)}, ${num(y)})`;
+// "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;
+ if (!v.c && !v.d) return ['0'];
+ if (!v.d) return [term(v.c, 'v')];
+ if (!v.c) return [term(v.d, 'w')];
+ return [`${term(v.c, 'v')} ${v.d < 0 ? '−' : '+'} ${term(Math.abs(v.d), 'w')}`];
+};
+// c v + d w = c [v] + d [w] (first line), and = [c v] + [d w] = [sum] or = [c·v0 + d·w0, …] = [sum] (second line).
+const line1 = (vs, y, o = 0, size = 42) => vs.row([{ key: 'c' }, { t: 'v', fill: GREEN }, { key: 'd', signed: true }, { t: 'w', fill: VIOLET }, '=', { key: 'c' }, { col: 'v', fixed: true }, { key: 'd', signed: true }, { col: 'w', fixed: true }], { x: 70, y, size, o });
+const line2 = (vs, y, o = 0, size = 42) => vs.row(['=', { col: 'cv', fixed: true }, '+', { col: 'dw', fixed: true }, '=', { col: 'sum', fixed: true }], { x: 160, y, size, o });
+const line2x = (vs, y, o = 0, size = 42) => vs.row(['=', { fn: v => [`${vs.fmt(v.c)}·${vs.paren(v.v0)} + ${vs.fmt(v.d)}·${vs.paren(v.w0)}`, `${vs.fmt(v.c)}·${vs.paren(v.v1)} + ${vs.fmt(v.d)}·${vs.paren(v.w1)}`], w: 360 }, '=', { col: 'sum', fixed: true }], { x: 160, y, size, o });
+const lecture = (p, o = {}) => { const vs = vecs(p, { vecs: { v: LV, w: LW }, ...o }); vs.label('sum', comboLabel(vs)); return vs; };
+const slideIn = (vs, id, tail, t0, dur = 1.6) => {
+ const a = vs.A[id], u = vs.P.u;
+ put(a.g, { x: -tail[0] * u, y: tail[1] * u, o: 0 });
+ 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 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' });
+ show(g, t0, .4);
+ return g;
+};
+// A hand that drags the combination's tip through plane points (solve mode): the tip snaps to grid points,
+// c and d are found at each one, as they are for the reader.
+const handPath = (p, vs, pts, t0, leg = 1.6) => {
+ const { PX, PY } = vs.P, hand = G(p, { o: 0 });
+ mk('circle', { r: 20, fill: COL.task, 'fill-opacity': .25, stroke: COL.task, 'stroke-width': 3 }, hand);
+ put(hand, { x: PX(pts[0][0]), y: PY(pts[0][1]) });
+ show(hand, t0 - .4, .3);
+ pts.slice(1).forEach((b, i) => {
+ const a = pts[i];
+ prog(q => {
+ const x = a[0] + (b[0] - a[0]) * q, y = a[1] + (b[1] - a[1]) * q;
+ put(hand, { x: PX(x), y: PY(y) });
+ vs.set(vs.solveFor(Math.round(x), Math.round(y)));
+ }, t0 + i * leg, leg * .85, io);
+ });
+ hide(hand, t0 + (pts.length - 1) * leg + .2, .3);
+ return hand;
+};
+
+/* ---------- practice data ---------- */
+const COMBQ = [
+ [2, [1, 3], 1, [2, -1]], [3, [1, 0], 2, [0, 1]], [1, [4, 1], -2, [1, 1]], [-1, [2, 5], 3, [1, 2]], [2, [3, -1], 2, [-3, 1]], [.5, [4, 2], 3, [0, 1]],
+].map(([c, a, d, b]) => {
+ const cs = c === .5 ? $m('', F(1, 2)) : c === 1 ? '' : c === -1 ? '−' : $m(num(c));
+ const ds = d === 1 ? ' + ' : d === -1 ? ' − ' : d < 0 ? [' − ', $m(num(-d))] : [' + ', $m(num(d))];
+ const ans = [c * a[0] + d * b[0], c * a[1] + d * b[1]];
+ return { q: [cs, hcol(...a, GREEN), ...[].concat(ds), hcol(...b, VIOLET)], ans,
+ why: `Stretch first: [${num(c * a[0])}, ${num(c * a[1])}] and [${num(d * b[0])}, ${num(d * b[1])}]. Then add: ${num(ans[0])} and ${num(ans[1])}.`,
+ hint: 'Multiply each column by its number first, then add tops and add bottoms.' };
+});
+// c and d for targets, with v = [2, −1], w = [−1, 2]: 2c − d = x, −c + 2d = y.
+const FINDQ = [[3, 0, 2, 1], [-3, 3, -1, 1], [0, 3, 1, 2], [4, 1, 3, 2], [1, -2, 0, -1], [1, 0, F(2, 3), F(1, 3)]].map(([x, y, c, d]) => {
+ const cv = typeof c === 'number' ? c : 2 / 3, dv = typeof d === 'number' ? d : 1 / 3;
+ 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.' };
+});
+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.'],
+ [[2, 3], [0, 0], 'n', 'The zero vector adds nothing: only the multiples of the first, one line.']].map(([a, b, ans, why]) => ({ parts: [hcol(...a, GREEN), ' and ', hcol(...b, VIOLET)], ans: [ans], why }));
+const STEER = [[3, 0], [-3, 3], [5, -1], [0, -3], [-1, 5]];
+
+/* ---------- beats: [id, title, run(m, D), { ask }?] ---------- */
+const BEATS = [
+ ['intro', 'Linear combinations', (m, D) => {
+ const g = G(scene, { o: 0, y: 24 });
+ T(g, 'Unit 1, Chapter 6', { x: 800, y: 300, size: 28, fill: COL.dim, anchor: 'middle' });
+ T(g, 'Linear Combinations', { x: 800, y: 410, size: 88, weight: 600, anchor: 'middle' });
+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);
+ const r = text(scene, 'c v + d w: stretch two vectors, then add', 800, 510, m('sub'), { size: 36, fill: COL.dim, anchor: 'middle' });
+ const pic = G(scene, { o: 0 }), o = [740, 790];
+ const ar = (d, c, t0) => draw(path(pic, d, { stroke: c, 'stroke-width': 6, 'stroke-linecap': 'round', fill: 'none' }, { d: 0 }), t0, .7);
+ ar(`M${o[0]} ${o[1]}l80 40`, GREEN, m('sub') + 1.2); ar(`M${o[0] + 80} ${o[1] + 40}l-80 -160`, VIOLET, m('sub') + 1.9); ar(`M${o[0]} ${o[1]}l0 -120`, COL.task, m('sub') + 2.6);
+ show(pic, m('sub') + 1, .3);
+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(pic, D - .9, .8);
+ }],
+
+ ['name', 'Stretch, then add', (m) => {
+ 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.show(['v', 'w'], m('vw'), .6);
+ const r1 = line1(vs, 240), r2 = line2(vs, 420);
+ showRow(r1, m('cd'), 0, 4); showRow(r1, m('ex') - .2, 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);
+ showRow(r2, m('add'), 4, 6);
+ const [s0] = vs.num('sum0'), [s1] = vs.num('sum1');
+ put(s1, { o: 0 }); show(s1, m('addb') + 1.4);
+ vs.flash('cv0', m('add') + .6); vs.flash('dw0', m('add') + 1.4); vs.flash('sum0', m('add') + 2.4);
+ 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);
+ vs.dim(['v', 'w'], m('pic'), .25);
+ vs.show('cv', m('pic') + .2, .6);
+ 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 });
+ 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'));
+ text(p, 'keep in mind: v = [2, −1], w = [−1, 2], 1v + 2w = [0, 3]', 70, 660, m('keep'), { size: 26, fill: COL.dim });
+ void s0;
+ }],
+
+ ['ex2', 'More choices', (m) => {
+ 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'] });
+ line1(vs, 240, 1); line2x(vs, 420, 1);
+ const dots = G(p, {});
+ vs.P.dot(0, 3, COL.task, .4, { r: 8, into: dots });
+ vs.to({ c: 2, d: 1 }, m('c2'), 1.4); vs.flash('c', m('c2')); vs.flash('d', m('c2') + .6);
+ const [f0, f1] = vs.num('fn');
+ lightUp(f0, m('t') + .2); vs.flash('sum0', m('t') + 4.2);
+ lightUp(f1, m('b') + .2); vs.flash('sum1', m('b') + 4.4);
+ vs.P.dot(3, 0, COL.task, m('r'), { r: 8, into: dots });
+ vs.to({ c: -1, d: 1 }, m('c3'), 1.4); vs.flash('c', m('c3')); vs.flash('d', m('c3') + .6);
+ 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); });
+ }],
+
+ ['special', 'Combinations you know', (m) => {
+ const p = panel(0);
+ text(p, 'Old friends are combinations too', 60, 110, .2, { size: 40, weight: 600 });
+ const vs = lecture(p, { c: -1, d: 1, show: ['cv', 'dw', 'sum'] });
+ line1(vs, 240, 1);
+ const note = (str, y, t0) => text(p, str, 70, y, t0, { size: 32, fill: COL.task, weight: 600 });
+ vs.to({ c: 1, d: 1 }, m('sum'), 1.2); note('c = 1, d = 1: v + w', 400, m('sum') + .6);
+ vs.to({ c: 1, d: -1 }, m('diff'), 1.2); note('c = 1, d = −1: v − w', 460, m('diff') + .6);
+ vs.to({ c: 2, d: 0 }, m('onlyv'), 1.2); note('d = 0: just c v', 520, m('onlyv') + .6);
+ vs.to({ c: 0, d: 0 }, m('zero'), 1.2); note('c = d = 0: the zero vector', 580, m('zero') + .6);
+ vs.to({ c: 1, d: 2 }, m('all') + .4, 1.6);
+ text(p, 'sums, differences, multiples: all linear combinations', 70, 660, m('all'), { size: 28, fill: COL.chalk, weight: 600 });
+ }],
+
+ ['q1', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ S.vs = vecs(p, { vecs: { v: [1, 2], w: [2, -1] }, c: 2, d: -1, show: ['v', 'w'] });
+ S.vs.label('sum', comboLabel(S.vs));
+ }, { ask: done => quiz(CARD, [{
+ id: 'c-comb', prompt: ['Work out the combination: stretch each vector, then add.'],
+ build: vcolBlanks([{ q: [$m('2'), hcol(1, 2, GREEN), ' − ', hcol(2, -1, VIOLET)], ans: [0, 5], why: '2·[1, 2] = [2, 4]; then [2, 4] − [2, −1] = [0, 5].',
+ hint: 'Stretch first: 2 times [1, 2] is [2, 4]. Then take away [2, −1]: top minus top, bottom minus bottom.',
+ fx: () => ['cv', 'dw', 'sum'].forEach((id, i) => { fx(S.vs.A[id].g, { o: 1 }, i * .5, .5); fx(S.vs.A[id].lab, { o: 1 }, i * .5, .5); }) }]),
+ }], done) }],
+
+ ['scrub', 'Steering with c and d', (m) => {
+ 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.dim(['v', 'w'], .3, .25);
+ line1(vs, 240, 1);
+ const tr = G(p, {});
+ vs.to({ c: 3 }, m('c') + .3, 1.2); vs.to({ c: -1 }, m('c') + 1.7, 1.8); vs.to({ c: 1 }, m('cpath') + 1.8, 1.2);
+ vs.flash('c', m('c') + .3);
+ vs.P.line(-1, 2, 1, 1, GREEN, m('cpath') - .2, { dash: '8 9', w: 3, into: tr });
+ text(p, 'c changes: the tip slides along v', 70, 420, m('cpath'), { size: 30, fill: GREEN, weight: 600 });
+ vs.to({ d: 3 }, m('d') + .3, 1.2); vs.to({ d: -1 }, m('d') + 1.7, 1.8); vs.to({ d: 1 }, m('dpath') + 1.8, 1.2);
+ vs.flash('d', m('d') + .3);
+ 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);
+ text(p, 'both: anywhere you steer', 70, 530, m('both') + .3, { size: 30, fill: COL.task, weight: 600 });
+ }],
+
+ ['reach', 'Reaching a target', (m) => {
+ const p = panel(0);
+ text(p, 'Which c and d reach the target?', 60, 110, .2, { size: 40, weight: 600 });
+ 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) : []);
+ line1(vs, 240, 1); line2(vs, 420, 1);
+ const ring = ringAt(vs.P, 0, 3, m('target'), p);
+ vs.P.dot(0, 0, COL.task, m('start'), { r: 8 });
+ vs.to({ c: 1 }, m('up'), 1.2); vs.flash('c', m('up'));
+ vs.to({ d: 1 }, m('d1'), 1); vs.flash('d', m('d1'));
+ vs.to({ d: 2 }, m('d2'), 1); vs.flash('d', m('d2'));
+ pulse(ring, m('hit') + .2, 1.5); vs.flash('c', m('hit') + .6); vs.flash('d', m('hit') + .6);
+ hide(ring, m('drag'), .4);
+ vs.solve(true);
+ handPath(p, vs, [[0, 3], [3, 0]], m('drag'), 2.2);
+ vs.flash('c', m('p30') + .2); vs.flash('d', m('p30') + .2);
+ handPath(p, vs, [[3, 0], [1, 1]], m('p11') - 1.2, 1.4);
+ vs.flash('c', m('p11') + .6); vs.flash('d', m('p11') + .6);
+ handPath(p, vs, [[1, 1], [1, 0]], m('p10') - .4, 1.2);
+ vs.flash('c', m('p10') + 2); vs.flash('d', m('p10') + 3.6);
+ text(p, 'c and d can be fractions', 70, 600, m('frac'), { size: 30, fill: COL.task, weight: 600 });
+ }],
+
+ ['q2', 'Your turn', () => {
+ const p = panel(0);
+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
+ S.vs = lecture(p, { c: 1, d: 1, show: ['cv', 'dw', 'sum'] });
+ line1(S.vs, 230, 1);
+ ringAt(S.vs.P, 4, 1, .5, p);
+ }, { ask: done => quiz(CARD, [{
+ id: 'c-reach', prompt: ['Change ', $m('c'), ' and ', $m('d'), ' (or drag the tips of the two stretched arrows) until the combination lands on ', $m('(4, 1)'), '.'],
+ build: vsTask(S.vs, (v, k) => k.sum[0] === 4 && k.sum[1] === 1, 'c = 3, d = 2: 3·[2, −1] + 2·[−1, 2] = [6 − 2, −3 + 4] = [4, 1].',
+ (v, k) => `You are at ${pairStr(k.sum[0], k.sum[1])}. Raising c moves the tip 2 right and 1 down; raising d moves it 1 left and 2 up.`,
+ () => S.vs.set({ c: 3, d: 2 }), { drag: ['cv', 'dw'] }),
+ }], done) }],
+
+ ['lattice', 'They fill the plane', (m) => {
+ const p = panel(0);
+ 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);
+ 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 });
+ hide(ax, m('gaps'), .5);
+ // fractions: the half-way points appear between the lines
+ const half = G(p, { o: 0 }); let d = '';
+ for (let c = -8; c <= 8; c += .5) for (let dd = -8; dd <= 8; dd += .5) {
+ if (Number.isInteger(c) && Number.isInteger(dd)) continue;
+ const x = 2 * c - dd, y = -c + 2 * dd;
+ if (Math.abs(x) <= 6 && Math.abs(y) <= 6) d += `M${vs.P.PX(x)} ${vs.P.PY(y)}h0`;
+ }
+ path(half, d, { stroke: COL.task, 'stroke-width': 5, 'stroke-linecap': 'round', 'stroke-opacity': .55, fill: 'none' });
+ show(half, m('gaps') + .3, 1.2);
+ 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]], m('roam') + .2, 1.6);
+ 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);
+ text(p, 'c v + d w reaches every point of the plane', 70, 420, m('plane'), { size: 30, fill: COL.task, weight: 600 });
+ }],
+
+ ['count', 'Reading c and d off the grid', (m) => {
+ const p = panel(0);
+ text(p, 'Count the steps: along v, then along w', 60, 110, .2, { size: 40, weight: 600 });
+ const vs = lecture(p, { c: 0, d: 0, show: ['cv', 'dw', 'sum'] });
+ vs.lattice(.3, true, .6);
+ 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);
+ 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;
+ };
+ const m1 = G(p, {});
+ const r1 = go(1, 4, 2, 3, m('t'), m('sv') + .9, m('sw') + .9, m1);
+ pulse(r1, m('there') + .2, 1.5);
+ vs.flash('c', m('read') + .6); vs.flash('d', m('read') + 2.2);
+ vs.flash('sum0', m('check') + .4); vs.flash('sum1', m('check') + 3.4);
+ hide(m1, m('t2') - .2, .4);
+ 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);
+ }],
+
+ ['parallel', 'Unless they line up', (m) => {
+ const p = panel(0);
+ text(p, 'When the two vectors line up', 60, 110, .2, { size: 40, weight: 600 });
+ const vs = lecture(p, { c: 1, d: 1, show: ['v', 'w'] });
+ 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);
+ say(p, ['w = 2v'], 70, 420, m('par'), { size: 44, fill: VIOLET });
+ 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);
+ 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 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'));
+ }],
+
+ ['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 }),
+ }], done) }],
+
+ ['wrap', 'Summary', (m) => {
+ const p = panel(0);
+ [['c v + d w: stretch each vector, then add.', 'w1'], ['Each c, d gives one point; from a point we can find c and d.', 'w2'],
+ ['Two vectors in different directions reach every point.', 'w3'], ['Two vectors on one line reach only that line.', '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);
+ T(dg, String(i + 1), { x: 0, y: 11, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });
+ const tl = T(g, str, { x: 210, size: 36, weight: 600 });
+ tw(g, { o: 1, x: 0 }, m(mark), .6);
+ pulse(dg, m('end') + i * .3, 1.25);
+ const next = ['w2', 'w3', 'w4', 'end'][i], ul = path(g, `M210 16H${210 + tl.getComputedTextLength()}`, { stroke: COL.task, 'stroke-width': 3, 'stroke-opacity': .6 }, { d: 0 });
+ draw(ul, m(mark) + .5, Math.max(1, m(next) - m(mark) - 1), lin);
+ });
+ }],
+ ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
+ id: 'p-comb', prompt: ['Work out each combination: stretch, then add.'], build: vcolBlanks(COMBQ),
+ }], done, 'Chapter practice · set 1 of 4') }],
+ ['final2', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
+ id: 'p-find', prompt: ['With ', $m('v'), ' = ', hcol(2, -1, GREEN), ' and ', $m('w'), ' = ', hcol(-1, 2, VIOLET), ', find ', $m('c'), ' and ', $m('d'), ' so that ', $m('c v + d w'), ' is the target.'],
+ build: blanks(FINDQ),
+ }], done, 'Chapter practice · set 2 of 4') }],
+ ['final3', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
+ id: 'p-span', prompt: ['Do the combinations of the two vectors reach every point of the plane?'],
+ build: grid(SPANQ, [['y', 'Every point', null, 'Y'], ['n', 'Only a line', null, 'N']], { multi: false, text: true }),
+ }], done, 'Chapter practice · set 3 of 4') }],
+ ['final4', 'Chapter practice', () => {
+ const p = panel(0);
+ text(p, 'Steer the combination', 60, 110, .2, { size: 40, weight: 600 });
+ S.vs = lecture(p, { c: 1, d: 1, show: ['cv', 'dw', 'sum'] });
+ line1(S.vs, 230, 1);
+ }, { ask: done => quiz(CARD, STEER.map(([x, y], i) => ({
+ id: `p-steer${i + 1}`, prompt: ['Change ', $m('c'), ' and ', $m('d'), ' until ', $m('c v + d w'), ' lands on ', $m(pairStr(x, y)), '.'],
+ build: (body, api) => {
+ S.vs.set({ c: 1, d: 1 }); S.q6?.remove(); S.q6 = ringAt(S.vs.P, x, y, 0, S.vs.stage); fx(S.q6, { o: 1 }, 0, .3);
+ const s = S.vs.solveFor(x, y);
+ return vsTask(S.vs, (v, k) => k.sum[0] === x && k.sum[1] === y, `c = ${num(s.c)}, d = ${num(s.d)}.`,
+ (v, k) => `You are at ${pairStr(k.sum[0], k.sum[1])}. c moves the tip along v (2 right, 1 down), d along w (1 left, 2 up).`,
+ () => S.vs.set(s), { drag: ['cv', 'dw'] })(body, api);
+ },
+ })), done, 'Chapter practice · set 4 of 4') }],
+ ['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],
+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
+
+const lightUp = (e, t0, base = COL.chalk) => { tw(e, { c_color: COL.task }, t0, .25); tw(e, { c_color: base }, t0 + 1.2, .6); };
+
+boot();
+</script>
+</body>
+</html>
diff --git a/site/linear-algebra/ch08/audio/en/back.mp3 b/site/linear-algebra/ch08/audio/en/back.mp3
new file mode 100644
index 0000000..d090262
Binary files /dev/null and b/site/linear-algebra/ch08/audio/en/back.mp3 differ
diff --git a/site/linear-algebra/ch08/audio/en/entry.mp3 b/site/linear-algebra/ch08/audio/en/entry.mp3
new file mode 100644
index 0000000..1deb2af
Binary files /dev/null and b/site/linear-algebra/ch08/audio/en/entry.mp3 differ
diff --git a/site/linear-algebra/ch08/audio/en/final1.mp3 b/site/linear-algebra/ch08/audio/en/final1.mp3
new file mode 100644
index 0000000..9f77a88
Binary files /dev/null and b/site/linear-algebra/ch08/audio/en/final1.mp3 differ
diff --git a/site/linear-algebra/ch08/audio/en/final2.mp3 b/site/linear-algebra/ch08/audio/en/final2.mp3
new file mode 100644
index 0000000..4758da6
Binary files /dev/null and b/site/linear-algebra/ch08/audio/en/final2.mp3 differ
diff --git a/site/linear-algebra/ch08/audio/en/final3.mp3 b/site/linear-algebra/ch08/audio/en/final3.mp3
new file mode 100644
index 0000000..21020a3
Binary files /dev/null and b/site/linear-algebra/ch08/audio/en/final3.mp3 differ
diff --git a/site/linear-algebra/ch08/audio/en/final4.mp3 b/site/linear-algebra/ch08/audio/en/final4.mp3
new file mode 100644
index 0000000..2d8b688
Binary files /dev/null and b/site/linear-algebra/ch08/audio/en/final4.mp3 differ
diff --git a/site/linear-algebra/ch08/audio/en/finish.mp3 b/site/linear-algebra/ch08/audio/en/finish.mp3
new file mode 100644
index 0000000..ac4df69
Binary files /dev/null and b/site/linear-algebra/ch08/audio/en/finish.mp3 differ
diff --git a/site/linear-algebra/ch08/audio/en/intro.mp3 b/site/linear-algebra/ch08/audio/en/intro.mp3
new file mode 100644
index 0000000..83a0683
Binary files /dev/null and b/site/linear-algebra/ch08/audio/en/intro.mp3 differ
diff --git a/site/linear-algebra/ch08/audio/en/name.mp3 b/site/linear-algebra/ch08/audio/en/name.mp3
new file mode 100644
index 0000000..193b335
Binary files /dev/null and b/site/linear-algebra/ch08/audio/en/name.mp3 differ
diff --git a/site/linear-algebra/ch08/audio/en/q1.mp3 b/site/linear-algebra/ch08/audio/en/q1.mp3
new file mode 100644
index 0000000..31d96e6
Binary files /dev/null and b/site/linear-algebra/ch08/audio/en/q1.mp3 differ
diff --git a/site/linear-algebra/ch08/audio/en/q2.mp3 b/site/linear-algebra/ch08/audio/en/q2.mp3
new file mode 100644
index 0000000..56c0266
Binary files /dev/null and b/site/linear-algebra/ch08/audio/en/q2.mp3 differ
diff --git a/site/linear-algebra/ch08/audio/en/q3.mp3 b/site/linear-algebra/ch08/audio/en/q3.mp3
new file mode 100644
index 0000000..4d52795
Binary files /dev/null and b/site/linear-algebra/ch08/audio/en/q3.mp3 differ
diff --git a/site/linear-algebra/ch08/audio/en/q4.mp3 b/site/linear-algebra/ch08/audio/en/q4.mp3
new file mode 100644
index 0000000..9fafe2b
Binary files /dev/null and b/site/linear-algebra/ch08/audio/en/q4.mp3 differ
diff --git a/site/linear-algebra/ch08/audio/en/recap.mp3 b/site/linear-algebra/ch08/audio/en/recap.mp3
new file mode 100644
index 0000000..cf420e5
Binary files /dev/null and b/site/linear-algebra/ch08/audio/en/recap.mp3 differ
diff --git a/site/linear-algebra/ch08/audio/en/rowscols.mp3 b/site/linear-algebra/ch08/audio/en/rowscols.mp3
new file mode 100644
index 0000000..c7fc731
Binary files /dev/null and b/site/linear-algebra/ch08/audio/en/rowscols.mp3 differ
diff --git a/site/linear-algebra/ch08/audio/en/scrub.mp3 b/site/linear-algebra/ch08/audio/en/scrub.mp3
new file mode 100644
index 0000000..a79c42d
Binary files /dev/null and b/site/linear-algebra/ch08/audio/en/scrub.mp3 differ
diff --git a/site/linear-algebra/ch08/audio/en/sizes.mp3 b/site/linear-algebra/ch08/audio/en/sizes.mp3
new file mode 100644
index 0000000..d1e5edc
Binary files /dev/null and b/site/linear-algebra/ch08/audio/en/sizes.mp3 differ
diff --git a/site/linear-algebra/ch08/audio/en/table.mp3 b/site/linear-algebra/ch08/audio/en/table.mp3
new file mode 100644
index 0000000..47e471f
Binary files /dev/null and b/site/linear-algebra/ch08/audio/en/table.mp3 differ
diff --git a/site/linear-algebra/ch08/audio/en/tidy.mp3 b/site/linear-algebra/ch08/audio/en/tidy.mp3
new file mode 100644
index 0000000..8e9d045
Binary files /dev/null and b/site/linear-algebra/ch08/audio/en/tidy.mp3 differ
diff --git a/site/linear-algebra/ch08/audio/en/timings.js b/site/linear-algebra/ch08/audio/en/timings.js
new file mode 100644
index 0000000..e1f8cf8
--- /dev/null
+++ b/site/linear-algebra/ch08/audio/en/timings.js
@@ -0,0 +1,769 @@
+window.TIMINGS = {
+ "intro": {
+ "dur": 14.76,
+ "marks": {
+ "sub": 4.323,
+ "move": 10.143
+ },
+ "cues": [
+ [
+ 0.091,
+ "Chapter eight."
+ ],
+ [
+ 1.12,
+ "Matrices, and A x equals b."
+ ],
+ [
+ 4.323,
+ "In this chapter we lift the numbers out of a system and put them in a table, called a matrix."
+ ],
+ [
+ 10.143,
+ "Same system, shorter to write, and much easier to think about."
+ ]
+ ]
+ },
+ "recap": {
+ "dur": 50.232,
+ "marks": {
+ "eq": 1.406,
+ "rows": 6.771,
+ "check": 12.448,
+ "cols": 19.701,
+ "c1": 23.385,
+ "c2": 25.846,
+ "c3": 29.023,
+ "mix": 31.38,
+ "letters": 36.914,
+ "numbers": 42.812
+ },
+ "cues": [
+ [
+ 0.104,
+ "Here's our old friend."
+ ],
+ [
+ 1.406,
+ "Two x minus y equals zero, and minus x plus two y equals three."
+ ],
+ [
+ 6.771,
+ "In the row picture, each equation is a line, and the two lines meet at one, two."
+ ],
+ [
+ 12.448,
+ "Check it: two times one, minus two, is zero."
+ ],
+ [
+ 16.315,
+ "Minus one, plus two times two, is three."
+ ],
+ [
+ 19.701,
+ "And in chapter seven we read the same system down its columns: x times the column two, minus one, plus y times the column minus one, two, has to equal zero, three."
+ ],
+ [
+ 31.38,
+ "One of the first column plus two of the second lands exactly on zero, three."
+ ],
+ [
+ 36.914,
+ "Now notice something."
+ ],
+ [
+ 38.164,
+ "Every time we write this system, we write x and y again, and again."
+ ],
+ [
+ 42.812,
+ "But the letters never change."
+ ],
+ [
+ 44.857,
+ "The only thing that makes this system different from any other system is its numbers."
+ ]
+ ]
+ },
+ "table": {
+ "dur": 51.864,
+ "marks": {
+ "r1": 2.018,
+ "one": 7.669,
+ "r2": 14.141,
+ "box": 21.719,
+ "xcol": 29.036,
+ "bcol": 35.13,
+ "read": 41.003,
+ "same": 46.042
+ },
+ "cues": [
+ [
+ 0.104,
+ "So let's keep just the numbers."
+ ],
+ [
+ 2.018,
+ "From the first equation, take the number in front of x, two, and the number in front of y."
+ ],
+ [
+ 7.669,
+ "Careful here: minus y means minus one times y."
+ ],
+ [
+ 11.888,
+ "So that number is minus one."
+ ],
+ [
+ 14.141,
+ "From the second equation: minus x is minus one times x, so minus one, and then two."
+ ],
+ [
+ 21.719,
+ "Put square brackets around the four numbers."
+ ],
+ [
+ 24.974,
+ "This table is called a matrix, and we give it a capital letter: A."
+ ],
+ [
+ 29.036,
+ "The unknowns, x and y, go into a column of their own: x on top, y below."
+ ],
+ [
+ 35.13,
+ "And the two right sides, zero and three, go into a third column."
+ ],
+ [
+ 39.948,
+ "We call it b."
+ ],
+ [
+ 41.003,
+ "Now the whole system fits in one short line: A times x equals b."
+ ],
+ [
+ 46.042,
+ "Nothing was lost."
+ ],
+ [
+ 47.383,
+ "Every number of the two equations is still there, in its place."
+ ]
+ ]
+ },
+ "name": {
+ "dur": 45.312,
+ "marks": {
+ "A": 1.68,
+ "x": 8.919,
+ "b": 15.417,
+ "r1": 19.401,
+ "r2": 28.646,
+ "next": 35.508,
+ "short": 40.391
+ },
+ "cues": [
+ [
+ 0.104,
+ "Let's look at each piece."
+ ],
+ [
+ 1.68,
+ "A is the matrix: the numbers in front of the unknowns, kept in the same places they had in the equations."
+ ],
+ [
+ 8.919,
+ "x is the column of unknowns."
+ ],
+ [
+ 11.693,
+ "It's a vector, just like the columns of numbers in chapter four."
+ ],
+ [
+ 15.417,
+ "And b is the column of right sides: another vector."
+ ],
+ [
+ 19.401,
+ "Read A x equals b one row at a time."
+ ],
+ [
+ 22.214,
+ "The first row of A, with x and y, and the first number of b, give the first equation."
+ ],
+ [
+ 28.646,
+ "The second row of A, with x and y, and the second number of b, give the second equation."
+ ],
+ [
+ 35.508,
+ "Exactly how A times x gives back the left sides is the next chapter."
+ ],
+ [
+ 40.391,
+ "For now, A x equals b is simply a short name for the whole system."
+ ]
+ ]
+ },
+ "rowscols": {
+ "dur": 46.632,
+ "marks": {
+ "rows": 2.63,
+ "row2": 8.737,
+ "lines": 13.958,
+ "cols": 19.583,
+ "col2": 25.846,
+ "arrows": 30.807,
+ "size": 38.659,
+ "first": 43.841
+ },
+ "cues": [
+ [
+ 0.078,
+ "A matrix has rows and columns."
+ ],
+ [
+ 2.63,
+ "Rows go across."
+ ],
+ [
+ 4.076,
+ "Row one is two, minus one: the numbers of the first equation."
+ ],
+ [
+ 8.737,
+ "Row two is minus one, two: the numbers of the second equation."
+ ],
+ [
+ 13.958,
+ "So each row is one equation, and in the picture, each row is one line."
+ ],
+ [
+ 19.583,
+ "Columns go down."
+ ],
+ [
+ 20.924,
+ "Column one is two, minus one: everything that multiplies x."
+ ],
+ [
+ 25.846,
+ "Column two is minus one, two: everything that multiplies y."
+ ],
+ [
+ 30.807,
+ "And those are exactly the two arrows of the column picture from chapter seven: green for column one, violet for column two."
+ ],
+ [
+ 38.659,
+ "This matrix has two rows and two columns."
+ ],
+ [
+ 42.24,
+ "We say it's two by two."
+ ],
+ [
+ 43.841,
+ "Always rows first, then columns."
+ ]
+ ]
+ },
+ "entry": {
+ "dur": 56.184,
+ "marks": {
+ "a21": 5.195,
+ "where": 11.771,
+ "a12": 16.224,
+ "a11": 26.953,
+ "a22": 31.81,
+ "rule": 37.526,
+ "sub": 42.656,
+ "try": 50.43
+ },
+ "cues": [
+ [
+ 0.078,
+ "Every number in a matrix has an address: its row, and its column."
+ ],
+ [
+ 5.195,
+ "Row two, column one."
+ ],
+ [
+ 6.888,
+ "Go down to the second row, then across to the first column: minus one."
+ ],
+ [
+ 11.771,
+ "Where is it in the equations?"
+ ],
+ [
+ 13.451,
+ "In the second equation, in front of x."
+ ],
+ [
+ 16.224,
+ "Row one, column two: first row, second column."
+ ],
+ [
+ 20.573,
+ "It's minus one again, but a different minus one: it sits in the first equation, in front of y."
+ ],
+ [
+ 26.953,
+ "Row one, column one is two, in front of x in the first equation."
+ ],
+ [
+ 31.81,
+ "And row two, column two is two, in front of y in the second equation."
+ ],
+ [
+ 37.526,
+ "So the row tells you which equation, and the column tells you which unknown."
+ ],
+ [
+ 42.656,
+ "Many books write the entry in row two, column one as a, two, one: row number first, then column number."
+ ],
+ [
+ 50.43,
+ "Point at any number, in the matrix or in the equations, and its partner lights up."
+ ]
+ ]
+ },
+ "q1": {
+ "dur": 5.616,
+ "marks": {},
+ "cues": [
+ [
+ 0.091,
+ "Quick check."
+ ],
+ [
+ 1.081,
+ "A new system."
+ ],
+ [
+ 2.383,
+ "Click the entry in row two, column one."
+ ]
+ ]
+ },
+ "scrub": {
+ "dur": 51.072,
+ "marks": {
+ "pick": 6.589,
+ "flip": 10.859,
+ "both": 12.305,
+ "turn": 17.474,
+ "col": 23.854,
+ "b": 30.039,
+ "slide": 33.841,
+ "meet": 38.438
+ },
+ "cues": [
+ [
+ 0.104,
+ "Because the matrix and the equations hold the same numbers, changing one changes the other."
+ ],
+ [
+ 6.589,
+ "Take the entry in row two, column one, the minus one."
+ ],
+ [
+ 10.859,
+ "Change it to plus one."
+ ],
+ [
+ 12.305,
+ "The equation changes with it: minus x becomes plus x."
+ ],
+ [
+ 17.474,
+ "And the second line turns, just as in chapter one, where a number in front of x or y turned the line."
+ ],
+ [
+ 23.854,
+ "In the column picture, column one changes too: its arrow swings over to two, one."
+ ],
+ [
+ 30.039,
+ "Now change the second number of b, from three to five."
+ ],
+ [
+ 33.841,
+ "The second line slides."
+ ],
+ [
+ 35.794,
+ "The right side only ever slides a line."
+ ],
+ [
+ 38.438,
+ "And look where the lines meet now: back at one, two."
+ ],
+ [
+ 41.562,
+ "One plus two times two is five."
+ ],
+ [
+ 44.531,
+ "One number in the matrix, one place in the equations, one line in the picture: it is all the same number."
+ ]
+ ]
+ },
+ "q2": {
+ "dur": 6.48,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn."
+ ],
+ [
+ 1.003,
+ "Change the numbers in the matrix until A x equals b says this system."
+ ]
+ ]
+ },
+ "sizes": {
+ "dur": 62.736,
+ "marks": {
+ "three": 2.8,
+ "rows3": 11.849,
+ "cols2": 14.596,
+ "lines3": 21.875,
+ "xb": 27.943,
+ "two3": 35.247,
+ "A23": 41.667,
+ "x3": 48.88,
+ "rule": 54.245
+ },
+ "cues": [
+ [
+ 0.104,
+ "Not every matrix is two by two."
+ ],
+ [
+ 2.8,
+ "Here are three equations with two unknowns: x plus y equals three, x minus y equals one, and two x plus y equals five."
+ ],
+ [
+ 11.849,
+ "Three equations give three rows."
+ ],
+ [
+ 14.596,
+ "Two unknowns give two columns."
+ ],
+ [
+ 17.201,
+ "So this A is three by two: three rows, two columns."
+ ],
+ [
+ 21.875,
+ "In the row picture that's three lines, and these three happen to pass through one point: two, one."
+ ],
+ [
+ 27.943,
+ "x still has two entries, one for each unknown."
+ ],
+ [
+ 32.018,
+ "b has three, one for each equation."
+ ],
+ [
+ 35.247,
+ "Now the other way round: two equations with three unknowns, x, y and z."
+ ],
+ [
+ 41.667,
+ "Two equations, two rows."
+ ],
+ [
+ 44.167,
+ "Three unknowns, three columns."
+ ],
+ [
+ 47.057,
+ "So A is two by three."
+ ],
+ [
+ 48.88,
+ "Now x has three entries, x, y and z, and b has two."
+ ],
+ [
+ 54.245,
+ "The rule never changes."
+ ],
+ [
+ 56.341,
+ "One row for each equation, one column for each unknown, and rows come first."
+ ]
+ ]
+ },
+ "q3": {
+ "dur": 3.696,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.133,
+ "How big is each matrix?"
+ ]
+ ]
+ },
+ "back": {
+ "dur": 49.368,
+ "marks": {
+ "given": 4.518,
+ "r1": 11.576,
+ "r1b": 19.831,
+ "r2": 23.711,
+ "zero": 29.154,
+ "lines": 37.305,
+ "meet": 43.021
+ },
+ "cues": [
+ [
+ 0.104,
+ "Now let's go the other way: from the matrix back to the equations."
+ ],
+ [
+ 4.518,
+ "Here A is one, four in the first row, two, zero in the second, and b is nine, two."
+ ],
+ [
+ 11.576,
+ "Read the first row with x and y: one times x, plus four times y, equals the first number of b, nine."
+ ],
+ [
+ 19.831,
+ "So x plus four y equals nine."
+ ],
+ [
+ 22.318,
+ "We don't write the one."
+ ],
+ [
+ 23.711,
+ "The second row: two times x, plus zero times y, equals two."
+ ],
+ [
+ 29.154,
+ "A zero means that letter is missing, just as in chapter one."
+ ],
+ [
+ 33.073,
+ "So the second equation is simply two x equals two."
+ ],
+ [
+ 37.305,
+ "Here are the two lines."
+ ],
+ [
+ 38.932,
+ "The second one stands straight up, at x equals one."
+ ],
+ [
+ 43.021,
+ "They meet at one, two."
+ ],
+ [
+ 44.375,
+ "Check: one plus four times two is nine, and two times one is two."
+ ]
+ ]
+ },
+ "tidy": {
+ "dur": 46.416,
+ "marks": {
+ "eq": 2.773,
+ "rule": 8.164,
+ "e1": 18.464,
+ "e1b": 22.435,
+ "e2": 24.688,
+ "e2b": 28.424,
+ "mat": 31.536,
+ "meet": 39.766
+ },
+ "cues": [
+ [
+ 0.104,
+ "Sometimes a system isn't lined up yet."
+ ],
+ [
+ 2.773,
+ "Look at this one: y equals three minus x, and two x equals y."
+ ],
+ [
+ 8.164,
+ "Before the numbers can go into a matrix, line up each equation: the x term first, then the y term, then the equals sign, then the plain number."
+ ],
+ [
+ 18.464,
+ "y equals three minus x."
+ ],
+ [
+ 20.872,
+ "Add x to both sides: x plus y equals three."
+ ],
+ [
+ 24.688,
+ "Two x equals y."
+ ],
+ [
+ 26.445,
+ "Take y away from both sides: two x minus y equals zero."
+ ],
+ [
+ 31.536,
+ "Now read off the numbers."
+ ],
+ [
+ 33.568,
+ "A has rows one, one and two, minus one, and b is three, zero."
+ ],
+ [
+ 39.766,
+ "The lines meet at one, two."
+ ],
+ [
+ 41.966,
+ "One plus two is three, and two minus two is zero."
+ ]
+ ]
+ },
+ "q4": {
+ "dur": 4.416,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.12,
+ "Write the equations that this matrix form stands for."
+ ]
+ ]
+ },
+ "wrap": {
+ "dur": 34.776,
+ "marks": {
+ "w1": 1.003,
+ "w2": 10.391,
+ "w3": 15.794,
+ "w4": 22.057,
+ "end": 32.513
+ },
+ "cues": [
+ [
+ 0.104,
+ "To sum up."
+ ],
+ [
+ 1.003,
+ "A system can be written as A x equals b: A holds the numbers in front of the unknowns, x the unknowns, b the right sides."
+ ],
+ [
+ 10.391,
+ "Each row of A is one equation."
+ ],
+ [
+ 12.669,
+ "Each column of A belongs to one unknown."
+ ],
+ [
+ 15.794,
+ "Size: rows first, then columns."
+ ],
+ [
+ 18.841,
+ "Three rows and two columns is three by two."
+ ],
+ [
+ 22.057,
+ "The entry in row two, column one is the number in the second equation, in front of the first unknown."
+ ],
+ [
+ 29.245,
+ "Change it in one place, and it changes in the other."
+ ],
+ [
+ 32.513,
+ "Now try the chapter practice."
+ ]
+ ]
+ },
+ "final1": {
+ "dur": 4.728,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Chapter practice."
+ ],
+ [
+ 1.51,
+ "Write each system as A x equals b."
+ ]
+ ]
+ },
+ "final2": {
+ "dur": 2.568,
+ "marks": {},
+ "cues": [
+ [
+ 0.091,
+ "Next, sizes and addresses."
+ ]
+ ]
+ },
+ "final3": {
+ "dur": 4.392,
+ "marks": {},
+ "cues": [
+ [
+ 0.091,
+ "Now go back: from A x equals b to the equations."
+ ]
+ ]
+ },
+ "final4": {
+ "dur": 3.552,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Last set."
+ ],
+ [
+ 1.237,
+ "Make the system with your hands."
+ ]
+ ]
+ },
+ "finish": {
+ "dur": 10.176,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Well done."
+ ],
+ [
+ 1.094,
+ "That's the end of chapter eight, matrices and A x equals b."
+ ],
+ [
+ 6.523,
+ "Next: what A times x really means, worked out two ways."
+ ]
+ ]
+ }
+};
diff --git a/site/linear-algebra/ch08/audio/en/wrap.mp3 b/site/linear-algebra/ch08/audio/en/wrap.mp3
new file mode 100644
index 0000000..df99e43
Binary files /dev/null and b/site/linear-algebra/ch08/audio/en/wrap.mp3 differ
diff --git a/site/linear-algebra/ch08/index.html b/site/linear-algebra/ch08/index.html
new file mode 100644
index 0000000..d6f8463
--- /dev/null
+++ b/site/linear-algebra/ch08/index.html
@@ -0,0 +1,634 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>Matrices and Ax = b</title>
+<link rel="stylesheet" href="../lib/engine.css">
+<link rel="expect" href="#bar" blocking="render"><!-- hold the first frame until the player exists, so the page transition can run -->
+</head>
+<body>
+<script src="../lib/engine.js"></script>
+<script src="../lib/math.js"></script>
+<script src="../lib/linsys.js"></script>
+<script src="audio/en/timings.js"></script>
+<script>
+'use strict';
+const CHAPTER = { number: 8, title: 'Matrices and Ax = b', minutes: 10, language: 'en' };
+
+/* ---------- layout and colours ---------- */
+const EQ = [90, 190], MAT = [150, 420]; // equations top left, matrix form under them
+const ROWC = [COL.whole, COL.nat, COL.int], COLC = [COL.irr, COL.real, COL.rat];
+const SIDE = { x: 820, y: 170, w: 720, cls: 'side' }; // question card on the right, plane hidden
+const LOW = { x: 40, y: 610, w: 740, cls: 'side' }; // question card under the matrix, plane kept
+// Where linsys draws the matrix form for MAT (its layout: columns 92 apart, rows 74 apart).
+const MX = { col: [MAT[0] + 56, MAT[0] + 148], row: [MAT[1], MAT[1] + 74], xcol: MAT[0] + 259, eq: MAT[0] + 334, bcol: MAT[0] + 424 };
+
+/* ---------- chapter drawing helpers ---------- */
+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 flash = (sys, key, t0, col = COL.task) => sys.num(key).forEach(e => { const c0 = e.getAttribute('fill'); tw(e, { c_fill: col }, t0, .25); tw(e, { c_fill: c0 }, t0 + 1.2, .6); });
+const keyColor = key => key[0] === 'b' ? COL.task : COLC[+key[2]];
+const where = key => key[0] === 'b' ? `b, row ${+key[1] + 1}` : `row ${+key[1] + 1}, column ${+key[2] + 1}`;
+// A text's box on the stage (T places text by its transform, which getBBox leaves out).
+const boxOf = e => { const b = e.getBBox(), s = st(e); return [b.x + s.x, b.y + s.y, b.width, b.height]; };
+const union = bs => { bs = bs.filter(b => b[2] > 0); const x = Math.min(...bs.map(b => b[0])), y = Math.min(...bs.map(b => b[1])); return [x, y, Math.max(...bs.map(b => b[0] + b[2])) - x, Math.max(...bs.map(b => b[1] + b[3])) - y]; };
+// The two copies of one number: in the matrix, and in the equations (with its letter and, in front of y, its sign).
+const matText = (sys, key) => sys.num(key).find(t => sys.M.contains(t));
+const eqText = (sys, key) => sys.num(key).find(t => sys.E.contains(t));
+const termBox = (sys, key) => {
+ const t = eqText(sys, key), parts = [boxOf(t)];
+ const l = t.nextElementSibling;
+ if (l && l.tagName === 'text' && /^[xy]$/.test(l.textContent)) parts.push(boxOf(l));
+ if (key[0] === 'a' && key[2] === '1') parts.push(boxOf(sys.eqRows[+key[1]].sign));
+ return union(parts);
+};
+// Rounded frames around both copies of a number; redrawn while shown, so they follow a number that changes width.
+function rings(sys, key, into, t0, t1, { tag = true } = {}) {
+ const g = G(into, { o: 0 }), c = keyColor(key);
+ const r1 = mk('rect', { rx: 12, fill: c, 'fill-opacity': .14, stroke: c, 'stroke-width': 3 }, g);
+ const r2 = mk('rect', { rx: 12, fill: c, 'fill-opacity': .14, stroke: c, 'stroke-width': 3 }, g);
+ const lab = tag ? T(g, where(key), { size: 24, fill: c, weight: 600, anchor: 'middle' }) : null;
+ const fit = () => {
+ const [ax, ay, aw, ah] = boxOf(matText(sys, key)), [ex, ey, ew, eh] = termBox(sys, key);
+ const set = (r, x, y, w, hh) => { for (const [k, v] of Object.entries({ x: x - 10, y: y - 6, width: w + 20, height: hh + 12 })) r.setAttribute(k, v); };
+ set(r1, ax - Math.max(0, 40 - aw) / 2, ay, Math.max(aw, 40), ah); set(r2, ex, ey, ew, eh);
+ if (lab) put(lab, { x: ax + aw / 2, y: key[1] === '0' ? ay - 18 : MX.row[1] + 124 });
+ };
+ fit();
+ if (t0 !== undefined) { sys.onChange(fit); prog(fit, t0, Math.max(.1, (t1 ?? t0 + 3) - t0), lin); show(g, t0, .3); if (t1 !== undefined) hide(g, t1, .3); }
+ return { g, fit };
+}
+// Pointing at a number (in the matrix or the equations) lights up its partner: the reader's own way to see the link.
+function link(sys, into) {
+ let cur = null, on = null;
+ const over = e => {
+ const k = e.target.getAttribute?.('aria-label');
+ if (!/^(a[01][01]|b[01])$/.test(k || '') || k === cur) return;
+ on?.g.remove(); cur = k; on = rings(sys, k, into); put(on.g, { o: 1 });
+ };
+ const out = e => { if (e.target.getAttribute?.('aria-label') === cur) { on?.g.remove(); on = cur = null; } };
+ [sys.E, sys.M].forEach(g => { g.addEventListener('pointerover', over); g.addEventListener('pointerout', out); });
+ sys.onChange(() => on?.fit());
+}
+// Pull some of a group's children into a subgroup of their own (to show them separately), chosen by where they sit.
+function pick(group, test) {
+ const sub = G(group, { o: 0 });
+ [...group.children].filter(c => c !== sub && test(...(() => { const [x, y, w, hh] = boxOf(c); return [x + w / 2, y + hh / 2, c]; })())).forEach(c => sub.append(c));
+ return sub;
+}
+// The equations of a linsys, one group per row (so a beat can bring them in one at a time).
+const eqRowGroups = sys => [pick(sys.E, (x, y) => y < EQ[1] + 46 - 20), pick(sys.E, (x, y) => y >= EQ[1] + 26)];
+// The pieces of the matrix form: A's bracket and label, the x column, '=', b's bracket and label (entries stay put).
+function matParts(sys) {
+ const entries = new Set(['a00', 'a01', 'a10', 'a11', 'b0', 'b1'].map(k => matText(sys, k)));
+ const not = c => !entries.has(c) && c.tagName !== 'rect';
+ return {
+ A: pick(sys.M, (x, y, c) => not(c) && x < MX.xcol - 40),
+ x: pick(sys.M, (x, y, c) => not(c) && x >= MX.xcol - 40 && x < MX.eq - 25),
+ eq: pick(sys.M, (x, y, c) => not(c) && x >= MX.eq - 25 && x < MX.eq + 25),
+ b: pick(sys.M, (x, y, c) => not(c) && x >= MX.eq + 25),
+ };
+}
+// Soft bands behind a row or a column of the matrix, and behind the matching terms of the equations.
+const band = (p, x, y, w, hh, c, t0, t1, o = .2) => { const r = mk('rect', { x, y, width: w, height: hh, rx: 14, fill: c }, p); put(r, { o: 0 }); tw(r, { o }, t0, .4); if (t1 !== undefined) tw(r, { o: 0 }, t1, .4); return r; };
+const rowBand = (p, i, t0, t1, { eq = true, mat = true, b = false } = {}) => {
+ if (mat) band(p, MAT[0] + 6, MX.row[i] - 46, 196, 62, ROWC[i], t0, t1);
+ if (b) band(p, MX.bcol - 44, MX.row[i] - 46, 88, 62, ROWC[i], t0, t1);
+ if (eq) band(p, EQ[0] - 44, EQ[1] + i * 92 - 50, 530, 68, ROWC[i], t0, t1);
+};
+const colBand = (p, j, t0, t1) => {
+ band(p, MX.col[j] - 42, MX.row[0] - 50, 84, 140, COLC[j], t0, t1);
+ band(p, j ? EQ[0] + 168 : EQ[0] + 24, EQ[1] - 50, j ? 130 : 120, 160, COLC[j], t0, t1);
+};
+const frame = (p, x, y, w, hh, c, t0, t1) => { const r = mk('rect', { x, y, width: w, height: hh, rx: 14, fill: 'none', stroke: c, 'stroke-width': 3 }, p); put(r, { o: 0 }); show(r, t0, .4); if (t1 !== undefined) hide(r, t1, .4); return r; };
+// A linsys in this chapter's layout, its numbers linked by pointing.
+const sysOf = (p, A, b, o = {}) => { const s = linsys(p, { A, b, eq: EQ, mat: MAT, sol: false, ...o }); link(s, p); return s; };
+
+// A matrix drawn as a picture (for sizes the 2 × 2 component does not cover): brackets, entries coloured by column.
+function mtx(p, rows, x, y, { size = 42, cw = 78, rh = 62, colored = true, o = 1, fill = COL.chalk } = {}) {
+ const g = G(p, { o }), n = rows[0].length, w = cw * n + 20, top = y - size * .95, bot = y + rh * (rows.length - 1) + size * .4;
+ path(g, `M${x + 14} ${top}H${x}V${bot}H${x + 14}M${x + w - 14} ${top}H${x + w}V${bot}H${x + w - 14}`, { stroke: COL.chalk, 'stroke-width': 3 });
+ const cells = rows.map((r, i) => r.map((v, j) => T(g, typeof v === 'number' ? num(v) : v, { x: x + 10 + cw * (j + .5), y: y + rh * i, size, fill: colored && typeof v === 'number' ? COLC[j] : fill, font: MATH, anchor: 'middle' })));
+ cells.flat().forEach(t => { if (/^[a-z]$/.test(t.textContent)) t.setAttribute('font-style', 'italic'); });
+ return { g, cells, w, x, y, top, bot };
+}
+// The same matrix as inline SVG for a question card.
+function matEl(rows, { size = 30, colored = true, letters = false } = {}) {
+ const n = rows[0].length, cw = size * 1.8, rh = size * 1.3, w = cw * n + 16, hh = rh * rows.length + size * .3;
+ const svg = mk('svg', { class: 'm', viewBox: `0 0 ${w} ${hh}`, width: w, height: hh });
+ svg.style.verticalAlign = 'middle';
+ path(svg, `M12 2H3V${hh - 2}H12M${w - 12} 2H${w - 3}V${hh - 2}H${w - 12}`, { stroke: 'currentColor', 'stroke-width': 2.5 });
+ rows.forEach((r, i) => r.forEach((v, j) => {
+ const t = T(svg, typeof v === 'number' ? num(v) : v, { x: 8 + cw * (j + .5), y: rh * (i + .5) + size * .5, size, fill: colored && typeof v === 'number' ? COLC[j] : 'currentColor', font: MATH, anchor: 'middle' });
+ if (letters || typeof v !== 'number') t.setAttribute('font-style', 'italic');
+ }));
+ return svg;
+}
+// "A x = b" as one inline picture: the matrix, the unknowns, the right sides.
+const formEl = (A, b, vars = ['x', 'y', 'z'].slice(0, A[0].length)) => {
+ const s = h('span', '', [matEl(A), ' ', matEl(vars.map(v => [v]), { colored: false }), ' = ', matEl(b.map(v => [v]), { colored: false })]);
+ s.style.whiteSpace = 'nowrap';
+ s.lastChild.style.color = COL.task;
+ return s;
+};
+// An equation from its numbers, written the way the book writes it: 1 and −1 without the 1, 0 terms left out.
+const eqStr = (row, c, vars = ['x', 'y', 'z']) => {
+ let s = '';
+ row.forEach((a, j) => {
+ if (!a) return;
+ const k = Math.abs(a) === 1 ? '' : num(Math.abs(a));
+ s += s ? (a < 0 ? ' − ' : ' + ') + k + vars[j] : (a < 0 ? '−' : '') + k + vars[j];
+ });
+ return `${s || '0'} = ${num(c)}`;
+};
+// A whole row (a, b, c) is right when it is a nonzero multiple of the wanted one.
+const prop = (want, got) => got.some(v => v !== 0) && want.every((w, i) => want.every((u, j) => w * got[j] === u * got[i]));
+
+/* ---------- practice data ---------- */
+const SYS1 = [
+ { A: [[1, 2], [3, -1]], b: [7, 0] },
+ { A: [[-2, 1], [1, 5]], b: [4, -3] },
+ { A: [[4, 0], [1, -1]], b: [8, 1], note: '4x = 8 has no y: its y-number is 0.' },
+ { A: [[-2, 1], [1, 1]], b: [1, 7], shown: ['y = 2x + 1', 'x + y = 7'], note: 'Line it up first: y = 2x + 1 becomes −2x + y = 1.' },
+];
+const SYS3 = [
+ { A: [[2, 3], [1, -1]], b: [12, 1] },
+ { A: [[0, 1], [5, 2]], b: [-4, 6], note: 'A 0 in front of x: the first equation is just y = −4.' },
+ { A: [[1, 0], [0, 1]], b: [3, -2], note: 'x = 3 and y = −2: this A hands the answer straight back.' },
+ { A: [[1, 1], [2, -1], [0, 3]], b: [4, 5, 3], note: 'Three rows, three equations: x + y = 4, 2x − y = 5, 3y = 3.' },
+];
+const eqRow = (r, c, i) => ({ parts: [`equation ${i + 1}: `, { box: String(r[0]) }, 'x + ', { box: String(r[1]) }, 'y = ', { box: String(c) }],
+ test: v => prop([r[0], r[1], c], v), why: eqStr(r, c), hint: `Row ${i + 1} of A gives the numbers in front of x and y; row ${i + 1} of b gives the right side.` });
+const toMat = (r, c, i) => ({ parts: [`row ${i + 1} of A: `, { box: String(r[0]) }, ' ', { box: String(r[1]) }, ` b: `, { box: String(c) }],
+ test: v => prop([r[0], r[1], c], v), why: `row ${i + 1} of A is ${num(r[0])}, ${num(r[1])} and b has ${num(c)}`, hint: 'The number in front of x first, then the one in front of y. x alone is 1, −y is −1, a missing letter is 0.' });
+
+/* ---------- beats: [id, title, run(m, D), { ask }?] ---------- */
+const BEATS = [
+ ['intro', 'Matrices and Ax = b', (m, D) => {
+ const g = G(scene, { o: 0, y: 24 });
+ T(g, 'Unit 1, Chapter 8', { x: 800, y: 300, size: 28, fill: COL.dim, anchor: 'middle' });
+ T(g, 'Matrices and Ax = b', { x: 800, y: 410, size: 88, weight: 600, anchor: 'middle' });
+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);
+ const r = text(scene, 'the numbers of a system, in one table', 800, 520, m('sub'), { size: 36, fill: COL.dim, anchor: 'middle' });
+ // two equations whose numbers lift into a bracketed table
+ const eqs = G(scene, { o: 0 });
+ M(eqs, ['2x − y = 0'], { x: 560, y: 640, size: 40, anchor: 'middle' });
+ M(eqs, ['−x + 2y = 3'], { x: 560, y: 700, size: 40, anchor: 'middle' });
+ show(eqs, m('sub') + 1, .5);
+ const arr = path(scene, 'M690 668H790M774 656L790 668L774 680', { stroke: COL.dim, 'stroke-width': 3 }, { d: 0 });
+ draw(arr, m('move'), .5);
+ const t = mtx(scene, [[2, -1], [-1, 2]], 840, 650, { size: 40, cw: 70, rh: 56, o: 0 });
+ tw(t.g, { o: 1 }, m('move') + .4, .6);
+ t.cells.flat().forEach((c, i) => { put(c, { y: st(c).y + 30 }); tw(c, { y: st(c).y - 30 }, m('move') + .4 + i * .15, .6, back); });
+ tw(g, { o: 0, y: -24 }, D - .9, .8); [r, eqs, arr, t.g].forEach(e => hide(e, D - .9, .8));
+ }],
+
+ ['recap', 'The system we know', (m) => {
+ const p = panel(0);
+ text(p, 'Two equations, two unknowns', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = linsys(p, { eq: EQ, mat: null, hidePlane: true, sol: false, t0: m('eq') - .3 });
+ show(sys.stage, m('rows') - .4, .6);
+ pulse(sys.meet, m('rows') + 2.5);
+ say(p, ['2·1 − 2 = 0'], 90, 420, m('check') + .3, { size: 36 });
+ text(p, '✓', 330, 420, m('check') + 2.4, { size: 34, fill: COL.good, weight: 700 });
+ say(p, ['−1 + 2·2 = 3'], 90, 480, m('check') + 3.4, { size: 36 });
+ text(p, '✓', 330, 480, m('check') + 5.6, { size: 34, fill: COL.good, weight: 700 });
+ // the column picture of chapter 7, written out and drawn
+ sys.view('both', m('cols'), .8);
+ sys.labels(['col 1', 'col 2', 'b']);
+ const ce = G(p, { o: 0 });
+ M(ce, ['x'], { x: 90, y: 640, size: 40, anchor: 'start' });
+ mtx(ce, [[2], [-1]], 122, 618, { size: 36, cw: 64, rh: 50 });
+ M(ce, ['+ y'], { x: 222, y: 640, size: 40, anchor: 'start' });
+ const c2 = mtx(ce, [[-1], [2]], 292, 618, { size: 36, cw: 64, rh: 50 }); c2.cells.flat().forEach(c => c.setAttribute('fill', COLC[1]));
+ M(ce, ['='], { x: 396, y: 640, size: 40, anchor: 'start' });
+ const bb = mtx(ce, [[0], [3]], 436, 618, { size: 36, cw: 64, rh: 50 }); bb.cells.flat().forEach(c => c.setAttribute('fill', COL.task));
+ show(ce, m('cols') + .4, .6);
+ const thick = (e, t) => { tw(e, { 'a_stroke-width': 10 }, t, .3); tw(e, { 'a_stroke-width': 5 }, t + 1.6, .5); };
+ frame(p, 80, 572, 134, 96, COLC[0], m('c1'), m('c2')); thick(sys.cols[0], m('c1') + .3);
+ frame(p, 214, 572, 168, 96, COLC[1], m('c2'), m('c3')); thick(sys.cols[1], m('c2') + .3);
+ frame(p, 428, 572, 98, 96, COL.task, m('c3'), m('mix')); thick(sys.bArrow, m('c3') + .3);
+ say(p, ['1·col 1 + 2·col 2 = b'], 90, 760, m('mix') + .3, { size: 34, fill: COL.task });
+ // the letters, again and again; then only the numbers matter
+ const letters = [...sys.E.querySelectorAll('text')].filter(t => /^[xy]$/.test(t.textContent));
+ letters.forEach((t, i) => { tw(t, { c_fill: COL.task }, m('letters') + 1 + i * .25, .25); tw(t, { c_fill: COL.chalk }, m('numbers') - .2, .4); });
+ ['a00', 'a01', 'a10', 'a11', 'b0', 'b1'].forEach((k, i) => flash(sys, k, m('numbers') + 1.2 + i * .3));
+ }],
+
+ ['table', 'Keep only the numbers', (m) => {
+ const p = S.p = panel(0);
+ text(p, 'Keep only the numbers', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = sysOf(p, [[2, -1], [-1, 2]], [0, 3], { t0: .1 });
+ const parts = matParts(sys);
+ const keys = ['a00', 'a01', 'a10', 'a11', 'b0', 'b1'];
+ keys.forEach(k => put(matText(sys, k), { o: 0 }));
+ // a number leaves its equation and lands in its place in the table
+ const fly = (key, str, from, t0, color) => {
+ const [tx, ty] = [key[0] === 'b' ? MX.bcol : MX.col[+key[2]], MX.row[+key[1]]];
+ const f = M(p, [str], { x: from[0], y: from[1], size: 54, fill: color, anchor: 'middle', o: 0 });
+ tw(f, { o: 1 }, t0, .2); tw(f, { x: tx, y: ty, s: .85 }, t0 + .2, 1, io); hide(f, t0 + 1.25, .2);
+ tw(matText(sys, key), { o: 1 }, t0 + 1.15, .25);
+ };
+ const mid = (k) => { const [x, , w] = termBox(sys, k); return x + w / 2; };
+ fly('a00', '2', [mid('a00') - 10, EQ[1]], m('r1') + .4, COLC[0]);
+ text(p, '−y = −1·y', 590, EQ[1], m('one') + .2, { size: 30, fill: COL.task, weight: 600 });
+ frame(p, ...(([x, y, w, hh]) => [x - 8, y - 6, w + 16, hh + 12])(termBox(sys, 'a01')), COL.task, m('one'), m('r2'));
+ fly('a01', '−1', [mid('a01'), EQ[1]], m('one') + 2.6, COLC[1]);
+ text(p, '−x = −1·x', 590, EQ[1] + 92, m('r2') + .4, { size: 30, fill: COL.task, weight: 600 });
+ fly('a10', '−1', [mid('a10'), EQ[1] + 92], m('r2') + 2, COLC[0]);
+ fly('a11', '2', [mid('a11') - 10, EQ[1] + 92], m('r2') + 4.2, COLC[1]);
+ show(parts.A, m('box'), .5);
+ pulse(parts.A, m('box') + 3.5);
+ const nm = text(p, 'a matrix', MX.col[0] + 46, 620, m('box') + 2.5, { size: 28, fill: COL.chalk, anchor: 'middle', weight: 600 });
+ hide(nm, m('read') - .3, .3);
+ // the letters go down into their own column
+ const lx = [...sys.E.querySelectorAll('text')].filter(t => /^[xy]$/.test(t.textContent));
+ [['x', lx[0], 0], ['y', lx[1], 1]].forEach(([n, t, i]) => {
+ const [x, y] = boxOf(t), f = M(p, [n], { x: x + 14, y: EQ[1], size: 54, anchor: 'middle', o: 0 });
+ tw(f, { o: 1 }, m('xcol') + .5 + i * .6, .2); tw(f, { x: MX.xcol, y: MX.row[i], s: .85 }, m('xcol') + .7 + i * .6, 1); hide(f, m('xcol') + 1.8 + i * .6, .2);
+ });
+ show(parts.x, m('xcol') + 1.6, .4);
+ fly('b0', '0', [mid('b0'), EQ[1]], m('bcol') + .4, COL.task);
+ fly('b1', '3', [mid('b1'), EQ[1] + 92], m('bcol') + 1, COL.task);
+ show(parts.eq, m('bcol') + 2, .4); show(parts.b, m('bcol') + 2, .4);
+ const big = say(p, ['Ax = b'], 90, 700, m('read'), { size: 60 });
+ say(p, ['the whole system in one line'], 290, 700, m('read') + 1.4, { size: 28, fill: COL.dim });
+ keys.forEach((k, i) => flash(sys, k, m('same') + .6 + i * .25));
+ sys.lines.forEach((l, i) => { tw(l.l, { 'a_stroke-width': 9 }, m('same') + 2 + i * .4, .3); tw(l.l, { 'a_stroke-width': 5 }, m('same') + 2.8 + i * .4, .5); });
+ }],
+
+ ['name', 'A, x and b', (m) => {
+ const p = panel(0);
+ text(p, 'Ax = b: three pieces', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = sysOf(p, [[2, -1], [-1, 2]], [0, 3]);
+ frame(p, MAT[0] - 10, MAT[1] - 56, 224, 200, COL.chalk, m('A'), m('x'));
+ text(p, 'the matrix', MAT[0] + 102, 620, m('A') + .4, { size: 26, fill: COL.chalk, anchor: 'middle', weight: 600 });
+ ['a00', 'a01', 'a10', 'a11'].forEach((k, i) => flash(sys, k, m('A') + 2.6 + i * .5));
+ frame(p, MX.xcol - 44, MAT[1] - 56, 88, 200, COL.chalk, m('x'), m('b'));
+ text(p, 'the unknowns', MX.xcol, 660, m('x') + .4, { size: 26, fill: COL.chalk, anchor: 'middle', weight: 600 });
+ frame(p, MX.bcol - 58, MAT[1] - 56, 116, 200, COL.task, m('b'), m('r1'));
+ text(p, 'the right sides', MX.bcol + 20, 620, m('b') + .4, { size: 26, fill: COL.task, anchor: 'middle', weight: 600 });
+ [0, 1].forEach(i => {
+ const t = m(`r${i + 1}`), t1 = i ? m('next') : m('r2');
+ rowBand(p, i, t, t1, { b: true });
+ frame(p, MX.xcol - 44, MAT[1] - 56, 88, 200, COL.chalk, t + 1.4, t1);
+ tw(sys.lines[i].l, { 'a_stroke-width': 10 }, t + 3, .35); tw(sys.lines[i].l, { 'a_stroke-width': 5 }, t + 4.2, .6);
+ });
+ text(p, 'how A times x works: chapter 9', 90, 760, m('next') + .5, { size: 28, fill: COL.dim });
+ frame(p, EQ[0] - 50, EQ[1] - 56, 540, 160, COL.task, m('short') + .6);
+ frame(p, MAT[0] - 14, MAT[1] - 60, 500, 200, COL.task, m('short') + 1.6);
+ text(p, '=', 600, 340, m('short') + 2.4, { size: 54, fill: COL.task, anchor: 'middle' });
+ ['a00', 'a01', 'a10', 'a11', 'b0', 'b1'].forEach((k, i) => flash(sys, k, m('short') + 3 + i * .35));
+ }],
+
+ ['rowscols', 'Rows and columns', (m) => {
+ const p = panel(0);
+ text(p, 'Rows go across, columns go down', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = sysOf(p, [[2, -1], [-1, 2]], [0, 3]);
+ rowBand(p, 0, m('rows'), m('cols'));
+ text(p, 'row 1', MAT[0] - 16, MX.row[0] - 6, m('rows') + .3, { size: 24, fill: ROWC[0], anchor: 'end', weight: 600 });
+ rowBand(p, 1, m('row2'), m('cols'));
+ text(p, 'row 2', MAT[0] - 16, MX.row[1] - 6, m('row2') + .3, { size: 24, fill: ROWC[1], anchor: 'end', weight: 600 });
+ sys.lines.forEach((l, i) => { tw(l.l, { 'a_stroke-width': 10 }, m('lines') + i * .9, .35); tw(l.l, { 'a_stroke-width': 5 }, m('lines') + 1.2 + i * .9, .6); });
+ text(p, 'one row = one equation = one line', 90, 680, m('lines') + .3, { size: 30, weight: 600 });
+ colBand(p, 0, m('cols'), m('size'));
+ text(p, 'column 1', MX.col[0], MX.row[0] - 68, m('cols') + .3, { size: 22, fill: COLC[0], anchor: 'middle', weight: 600 });
+ colBand(p, 1, m('col2'), m('size'));
+ text(p, 'column 2', MX.col[1] + 20, MX.row[0] - 68, m('col2') + .3, { size: 22, fill: COLC[1], anchor: 'middle', weight: 600 });
+ sys.view('both', m('arrows'), .8);
+ sys.labels(['col 1', 'col 2', 'b']);
+ tw(sys.cols[0], { 'a_stroke-width': 10 }, m('arrows') + 3.4, .3); tw(sys.cols[0], { 'a_stroke-width': 5 }, m('arrows') + 4.8, .5);
+ tw(sys.cols[1], { 'a_stroke-width': 10 }, m('arrows') + 5.4, .3); tw(sys.cols[1], { 'a_stroke-width': 5 }, m('arrows') + 6.8, .5);
+ text(p, 'one column = one unknown = one arrow', 90, 730, m('arrows') + .3, { size: 30, weight: 600, fill: COLC[0] });
+ const sz = G(p, { o: 0 });
+ M(sz, ['2 by 2'], { x: 90, y: 810, size: 44, fill: COL.task });
+ T(sz, '2 rows, 2 columns', { x: 260, y: 808, size: 28, fill: COL.dim });
+ show(sz, m('size') + .4);
+ text(p, 'rows first', 520, 808, m('first') + .2, { size: 28, fill: COL.task, weight: 600 });
+ }],
+
+ ['entry', 'Every number has an address', (m) => {
+ const p = panel(0);
+ text(p, 'Every number has an address', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = sysOf(p, [[2, -1], [-1, 2]], [0, 3]);
+ // row names on the left, column names on top, and two markers that slide to each address in turn
+ [0, 1].forEach(i => text(p, `row ${i + 1}`, MAT[0] - 46, MX.row[i] - 6, 1.2 + i * .4, { size: 24, fill: ROWC[i], anchor: 'end', weight: 600 }));
+ [0, 1].forEach(j => text(p, `column ${j + 1}`, MX.col[j] + (j ? 22 : -6), MX.row[0] - 88, 2.6 + j * .4, { size: 22, fill: COLC[j], anchor: 'middle', weight: 600 }));
+ const rm = G(p, { o: 0, x: MAT[0] - 28, y: MX.row[0] - 16 }), cm = G(p, { o: 0, x: MX.col[0], y: MX.row[0] - 68 });
+ path(rm, 'M-12 -10L4 0L-12 10Z', { fill: COL.task });
+ path(cm, 'M-10 -12L0 4L10 -12Z', { fill: COL.task });
+ const go = (i, j, t) => { tw(rm, { y: MX.row[i] - 16 }, t, .7); tw(cm, { x: MX.col[j] }, t + .8, .7); };
+ show(rm, m('a21') + .6, .3); show(cm, m('a21') + .6, .3);
+ go(1, 0, m('a21') + 1.4);
+ rings(sys, 'a10', p, m('a21') + 3.4, m('a12'), { tag: false });
+ rowBand(p, 1, m('where'), m('where') + 3.5, { mat: false });
+ go(0, 1, m('a12') + .2);
+ rings(sys, 'a01', p, m('a12') + 1.8, m('a11'), { tag: false });
+ rowBand(p, 0, m('a12') + 5, m('a12') + 8.5, { mat: false });
+ go(0, 0, m('a11') - .2);
+ rings(sys, 'a00', p, m('a11') + 1.4, m('a22'), { tag: false });
+ go(1, 1, m('a22') - .2);
+ rings(sys, 'a11', p, m('a22') + 1.4, m('rule'), { tag: false });
+ hide(rm, m('rule'), .3); hide(cm, m('rule'), .3);
+ const rule = G(p, { o: 0 });
+ T(rule, 'row', { x: 90, y: 690, size: 32, fill: ROWC[0], weight: 600 });
+ T(rule, '→ which equation', { x: 170, y: 690, size: 32, weight: 600 });
+ T(rule, 'column', { x: 90, y: 740, size: 32, fill: COLC[0], weight: 600 });
+ T(rule, '→ which unknown', { x: 210, y: 740, size: 32, weight: 600 });
+ show(rule, m('rule') + .3);
+ rowBand(p, 1, m('rule') + .3, m('rule') + 3);
+ colBand(p, 0, m('rule') + 2.2, m('sub'));
+ const sub = G(p, { o: 0 });
+ M(sub, ['a₂₁ = −1'], { x: 90, y: 815, size: 40, fill: COL.task });
+ T(sub, 'row 2, column 1', { x: 290, y: 812, size: 28, fill: COL.dim });
+ show(sub, m('sub') + 1);
+ rings(sys, 'a10', p, m('sub') + 1, m('try'));
+ text(p, 'point at any number', 520, 690, m('try') + .3, { size: 28, fill: COL.task, weight: 600 });
+ text(p, 'in the matrix or the equations', 520, 730, m('try') + .6, { size: 24, fill: COL.dim });
+ // a pointer that visits two numbers, the way the reader can
+ const ptr = G(p, { o: 0 });
+ path(ptr, 'M0 0L0 30L8 22L14 36L20 33L14 20L25 20Z', { fill: COL.chalk, stroke: COL.board, 'stroke-width': 2 });
+ put(ptr, { x: 640, y: 600 });
+ show(ptr, m('try') + 1, .3);
+ tw(ptr, { x: MX.col[1] + 6, y: MX.row[0] - 10 }, m('try') + 1.2, .9);
+ rings(sys, 'a01', p, m('try') + 2.1, m('try') + 3.4);
+ tw(ptr, { x: MX.bcol + 6, y: MX.row[1] - 10 }, m('try') + 3.4, .9);
+ rings(sys, 'b1', p, m('try') + 4.3, m('try') + 5.6);
+ hide(ptr, m('try') + 5.6, .3);
+ }],
+
+ ['q1', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ S.sys = sysOf(p, [[1, 3], [4, -2]], [5, 6], { hidePlane: true });
+ }, { ask: done => quiz(SIDE, [{
+ id: 'c-entry', prompt: ['Click the entry of ', $m('A'), ' in row 2, column 1.'],
+ build: (body, api) => {
+ const sys = S.sys, ks = ['a00', 'a01', 'a10', 'a11'];
+ const items = ks.map(k => { const [x, y, w, hh] = boxOf(matText(sys, k)); return { el: matText(sys, k), box: [x + w / 2 - 40, y - 8, 80, hh + 16], label: where(k) }; });
+ const no = ['That is row 1, column 1. Go down to the second row first.',
+ 'That is row 1, column 2: you went across first. Rows come first: down to row 2, then to column 1.',
+ '', 'That is row 2, column 2. Column 1 is the first column: the numbers in front of x.'];
+ return pickEls(items, 2, 'Row 2, column 1 is 4: the number in front of x in the second equation, 4x − 2y = 6.', i => no[i],
+ () => { const r = rings(sys, 'a10', S.q); put(r.g, { o: 0 }); fx(r.g, { o: 1 }, .1, .4); })(body, api);
+ },
+ }], done) }],
+
+ ['scrub', 'Change it once, it changes everywhere', (m) => {
+ const p = panel(0);
+ text(p, 'One number, two places', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = sysOf(p, [[2, -1], [-1, 2]], [0, 3], { view: 'both' });
+ sys.labels(['col 1', 'col 2', 'b']);
+ rings(sys, 'a10', p, m('pick'), m('turn') + 2);
+ const ghost = sys.P.line(0, 1.5, 3, 3, LS_ROW[1], m('flip'), { dash: '10 10', w: 3, into: p }); tw(ghost, { o: .35 }, m('flip') + .6, .4);
+ sys.to({ a10: 1 }, m('flip'), 1.2);
+ flash(sys, 'a10', m('both'));
+ text(p, '−x becomes +x', 590, EQ[1] + 92, m('both') + .4, { size: 30, fill: COL.task, weight: 600 });
+ tw(sys.lines[1].l, { 'a_stroke-width': 10 }, m('turn') + .3, .35); tw(sys.lines[1].l, { 'a_stroke-width': 5 }, m('turn') + 1.5, .6);
+ tw(sys.cols[0], { 'a_stroke-width': 10 }, m('col') + .4, .35); tw(sys.cols[0], { 'a_stroke-width': 5 }, m('col') + 1.8, .6);
+ colBand(p, 0, m('col') + .2, m('b'));
+ rings(sys, 'b1', p, m('b'), m('meet'));
+ const ghost2 = sys.P.line(-3, 3, 3, 0, LS_ROW[1], m('b') + .2, { dash: '10 10', w: 3, into: p }); tw(ghost2, { o: .3 }, m('b') + .8, .4);
+ hide(ghost, m('b') + .2, .4);
+ sys.to({ b1: 5 }, m('b') + .6, 1.4);
+ flash(sys, 'b1', m('b') + .8);
+ pulse(sys.meet, m('meet') + 1.4); pulse(sys.meet, m('meet') + 2.6);
+ say(p, ['1 + 2·2 = 5'], 90, 690, m('meet') + 3, { size: 36 });
+ text(p, '✓', 300, 690, m('meet') + 4.6, { size: 34, fill: COL.good, weight: 700 });
+ rings(sys, 'a10', p, m('meet') + 6.5, m('meet') + 13);
+ }],
+
+ ['q2', 'Your turn', () => {
+ const p = panel(0);
+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = sysOf(p, [[1, 0], [0, 1]], [1, 1]);
+ // the wanted lines, dashed: the reader's lines land on them when the numbers are right
+ sys.P.line(0, 5, 2, -1, LS_ROW[0], .3, { dash: '8 10', w: 3, into: p });
+ sys.P.line(-3, 0, 1, 2, LS_ROW[1], .3, { dash: '8 10', w: 3, into: p });
+ }, { ask: done => quiz(LOW, [{
+ id: 'c-make', prompt: ['Make ', $m('Ax = b'), ' say ', $m('3x + y = 5'), ' and ', $m('x − 2y = −3'), '.'],
+ build: lsTask(S.sys, v => {
+ const r0 = [v.a00, v.a01, v.b0], r1 = [v.a10, v.a11, v.b1], w0 = [3, 1, 5], w1 = [1, -2, -3];
+ return (prop(w0, r0) && prop(w1, r1)) || (prop(w1, r0) && prop(w0, r1));
+ }, 'A has rows 3, 1 and 1, −2; b is 5, −3. The lines meet at (1, 2).',
+ 'Row 1 of A holds the numbers in front of x and y in the first equation: 3 and 1 (y alone is 1). In the second, −2y gives −2. Then b holds the right sides.',
+ () => S.sys.set({ a00: 3, a01: 1, a10: 1, a11: -2, b0: 5, b1: -3 })),
+ }], done) }],
+
+ ['sizes', 'Other sizes', (m) => {
+ const p = panel(0);
+ text(p, 'Not every matrix is 2 by 2', 60, 110, .2, { size: 40, weight: 600 });
+ const P2 = plane(p, { cx: 1160, cy: 450, u: 52, t0: m('lines3') - .4 });
+ const A1 = G(p, {});
+ ['x + y = 3', 'x − y = 1', '2x + y = 5'].forEach((s, i) => {
+ say(A1, [s], 90, 190 + i * 70, m('three') + 1 + i * 2.2, { size: 46 });
+ const r = mk('rect', { x: 52, y: 190 + i * 70 - 38, width: 8, height: 44, rx: 4, fill: ROWC[i] }, A1); put(r, { o: 0 }); show(r, m('three') + 1 + i * 2.2);
+ });
+ const A = mtx(A1, [[1, 1], [1, -1], [2, 1]], 150, 440, { o: 0 });
+ show(A.g, m('rows3'));
+ [0, 1, 2].forEach(i => band(A1, 156, 440 + i * 62 - 42, 156, 58, ROWC[i], m('rows3') + .2 + i * .4, m('cols2')));
+ [0, 1].forEach(j => band(A1, 160 + 78 * j + 3, 395, 72, 186, COLC[j], m('cols2') + .2 + j * .4, m('lines3')));
+ const sz = G(A1, { o: 0 }); M(sz, ['3 by 2'], { x: 150, y: 640, size: 40, fill: COL.task }); T(sz, '3 rows, 2 columns', { x: 150, y: 690, size: 26, fill: COL.dim }); show(sz, m('cols2') + 1.5);
+ const xv = mtx(A1, [['x'], ['y']], 350, 471, { o: 0 }), eqs = M(A1, ['='], { x: 470, y: 516, size: 42, o: 0 }), bv = mtx(A1, [[3], [1], [5]], 505, 440, { o: 0 });
+ bv.cells.flat().forEach(c => c.setAttribute('fill', COL.task));
+ show(xv.g, m('xb') + .2); show(eqs, m('xb') + .2); show(bv.g, m('xb') + 1.6);
+ text(A1, '2 entries', 389, 590, m('xb') + .6, { size: 22, fill: COL.dim, anchor: 'middle' });
+ text(A1, '3 entries', 554, 640, m('xb') + 2, { size: 22, fill: COL.dim, anchor: 'middle' });
+ [[0, 3, 3, 0], [1, 0, 3, 2], [0, 5, 2, 1]].forEach(([xa, ya, xb, yb], i) => P2.line(xa, ya, xb, yb, ROWC[i], m('lines3') + .2 + i * .6, { into: A1 }));
+ P2.dot(2, 1, COL.chalk, m('lines3') + 3, { label: '(2, 1)', into: A1 });
+ // two equations, three unknowns
+ hide(A1, m('two3') - .4, .4); hide(P2.g, m('two3') - .4, .5);
+ const A2 = G(p, {});
+ ['x + 2y + z = 4', '3x − y + 2z = 1'].forEach((s, i) => {
+ say(A2, [s], 90, 190 + i * 70, m('two3') + .6 + i * 1, { size: 46 });
+ const r = mk('rect', { x: 52, y: 190 + i * 70 - 38, width: 8, height: 44, rx: 4, fill: ROWC[i] }, A2); put(r, { o: 0 }); show(r, m('two3') + .6 + i);
+ });
+ const B = mtx(A2, [[1, 2, 1], [3, -1, 2]], 150, 440, { o: 0 });
+ show(B.g, m('A23'));
+ [0, 1].forEach(i => band(A2, 156, 440 + i * 62 - 42, 234, 58, ROWC[i], m('A23') + .2 + i * .4, m('A23') + 3));
+ [0, 1, 2].forEach(j => band(A2, 160 + 78 * j + 3, 395, 72, 124, COLC[j], m('A23') + 3 + j * .4, m('x3')));
+ const sz2 = G(A2, { o: 0 }); M(sz2, ['2 by 3'], { x: 150, y: 640, size: 40, fill: COL.task }); T(sz2, '2 rows, 3 columns', { x: 150, y: 690, size: 26, fill: COL.dim }); show(sz2, m('A23') + 4);
+ const xv2 = mtx(A2, [['x'], ['y'], ['z']], 430, 409, { o: 0 }), eq2 = M(A2, ['='], { x: 550, y: 485, size: 42, o: 0 }), bv2 = mtx(A2, [[4], [1]], 585, 440, { o: 0 });
+ bv2.cells.flat().forEach(c => c.setAttribute('fill', COL.task));
+ show(xv2.g, m('x3')); show(eq2, m('x3')); show(bv2.g, m('x3') + 1.5);
+ text(A2, 'three unknowns live in space: chapter 11', 1160, 450, m('two3') + 2, { size: 28, fill: COL.dim, anchor: 'middle' });
+ const rule = G(A2, { o: 0 });
+ T(rule, 'one row for each equation,', { x: 90, y: 770, size: 30, weight: 600, fill: ROWC[0] });
+ T(rule, 'one column for each unknown', { x: 90, y: 815, size: 30, weight: 600, fill: COLC[0] });
+ show(rule, m('rule') + .4);
+ [0, 1].forEach(i => band(A2, 156, 440 + i * 62 - 42, 234, 58, ROWC[i], m('rule') + 1.4 + i * .5, m('rule') + 4.4));
+ [0, 1, 2].forEach(j => band(A2, 160 + 78 * j + 3, 395, 72, 124, COLC[j], m('rule') + 4.6 + j * .5, m('rule') + 8.4));
+ }],
+
+ ['q3', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ M(p, ['A ='], { x: 90, y: 250, size: 40 }); mtx(p, [[1, 0, 4], [2, 5, -1]], 180, 230, { size: 38, cw: 70, rh: 56 });
+ M(p, ['B ='], { x: 90, y: 420, size: 40 }); mtx(p, [[3, 1], [0, -2], [7, 6]], 180, 380, { size: 38, cw: 70, rh: 56 });
+ M(p, ['C ='], { x: 90, y: 660, size: 40 }); mtx(p, [[2, 0, 1], [1, 1, 0], [4, -3, 5]], 180, 610, { size: 38, cw: 70, rh: 56 });
+ }, { ask: done => quiz(SIDE, [{
+ id: 'c-size', prompt: ['How big is each matrix? Rows first.'],
+ build: blanks([
+ { parts: ['A is ', { box: '2' }, ' by ', { box: '3' }], why: '2 rows across, 3 columns down.', hint: 'Count the rows (going across) first, then the columns (going down).' },
+ { parts: ['B is ', { box: '3' }, ' by ', { box: '2' }], why: '3 rows, 2 columns.', hint: 'B has 3 rows. How many numbers in each row?' },
+ { parts: ['C is ', { box: '3' }, ' by ', { box: '3' }], why: '3 rows, 3 columns: a square matrix.', hint: 'Count the rows, then the numbers in one row.' },
+ { parts: ['5 equations, 2 unknowns: ', { box: '5' }, ' by ', { box: '2' }], why: 'One row for each equation, one column for each unknown.', hint: 'One row for each equation, one column for each unknown.' },
+ ]),
+ }], done) }],
+
+ ['back', 'From the matrix to the equations', (m) => {
+ const p = panel(0);
+ text(p, 'From A, x, b back to the equations', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = sysOf(p, [[1, 4], [2, 0]], [9, 2], { t0: m('given') - .4 });
+ const [g0, g1] = eqRowGroups(sys);
+ put(sys.ROWV, { o: 0 });
+ // row 1 read with x and y, written out in full first
+ rowBand(p, 0, m('r1'), m('r2'), { eq: false, b: true });
+ frame(p, MX.xcol - 44, MAT[1] - 56, 88, 200, COL.chalk, m('r1') + 1.2, m('r2'));
+ [['a00', 'a01'], ['a10', 'a11'], ['b0', 'b1']].forEach((ks, i) => ks.forEach(k => flash(sys, k, m('given') + 1.2 + i * 2.2)));
+ rowBand(p, 0, m('given') + 1, m('given') + 3, { eq: false }); rowBand(p, 1, m('given') + 3.2, m('given') + 5.2, { eq: false });
+ frame(p, MX.bcol - 50, MAT[1] - 56, 100, 140, COL.task, m('given') + 5.4, m('r1'));
+ const full1 = say(p, ['1·x + 4·y = 9'], EQ[0], EQ[1], m('r1') + 1, { size: 54 });
+ hide(full1, m('r1b'), .4); show(g0, m('r1b') + .2);
+ text(p, 'the 1 is not written', 590, EQ[1], m('r1b') + .6, { size: 26, fill: COL.dim });
+ rowBand(p, 1, m('r2'), m('lines'), { eq: false, b: true });
+ frame(p, MX.xcol - 44, MAT[1] - 56, 88, 200, COL.chalk, m('r2') + 1, m('lines'));
+ const full2 = say(p, ['2·x + 0·y = 2'], EQ[0], EQ[1] + 92, m('r2') + .8, { size: 54 });
+ hide(full2, m('zero') - .2, .4); show(g1, m('zero'));
+ text(p, '0y is nothing: 2x = 2', 590, EQ[1] + 92, m('zero') + 1.4, { size: 28, fill: COL.task, weight: 600 });
+ rings(sys, 'a11', p, m('zero') + .3, m('zero') + 3, { tag: false });
+ { const [x, y, w, hh] = termBox(sys, 'a11'); const k = path(p, `M${x - 6} ${y + hh * .55}L${x + w + 6} ${y + hh * .45}`, { stroke: COL.task, 'stroke-width': 4 }, { d: 0 }); tw(k, { d: 1 }, m('zero') + 3.4, .5); }
+ show(sys.ROWV, m('lines'), .8);
+ tw(sys.lines[1].l, { 'a_stroke-width': 10 }, m('lines') + 2.2, .35); tw(sys.lines[1].l, { 'a_stroke-width': 5 }, m('lines') + 3.6, .6);
+ say(p, ['x = 1'], 1160 + 52 + 12, 450 + 52 * 5, m('lines') + 2.6, { size: 30, fill: LS_ROW[1] });
+ pulse(sys.meet, m('meet') + .3);
+ say(p, ['1 + 4·2 = 9, 2·1 = 2'], 90, 690, m('meet') + 2, { size: 34 });
+ text(p, '✓', 470, 690, m('meet') + 5, { size: 34, fill: COL.good, weight: 700 });
+ }],
+
+ ['tidy', 'Line it up first', (m) => {
+ const p = panel(0);
+ text(p, 'Line it up first', 60, 110, .2, { size: 40, weight: 600 });
+ const steps = G(p, {});
+ say(steps, ['y = 3 − x'], 90, 200, m('eq') + .2, { size: 48 });
+ say(steps, ['2x = y'], 470, 200, m('eq') + 2.4, { size: 48 });
+ const rule = G(steps, { o: 0 });
+ [['x term', COLC[0]], ['y term', COLC[1]], ['=', COL.chalk], ['number', COL.task]].forEach(([s, c], i) => text(rule, s, 90 + [0, 150, 300, 360][i], 300, m('rule') + 1.4 + i * 1.3, { size: 28, fill: c, weight: 600 }));
+ put(rule, { o: 1 });
+ text(steps, '+ x on both sides', 90, 380, m('e1'), { size: 26, fill: COL.dim });
+ say(steps, ['x + y = 3'], 90, 440, m('e1b'), { size: 48, fill: COL.task });
+ text(steps, '− y on both sides', 470, 380, m('e2'), { size: 26, fill: COL.dim });
+ say(steps, ['2x − y = 0'], 470, 440, m('e2b'), { size: 48, fill: COL.task });
+ hide(steps, m('mat') - .2, .4);
+ const sys = S.sys = sysOf(p, [[1, 1], [2, -1]], [3, 0], { t0: m('mat') });
+ ['a00', 'a01', 'a10', 'a11', 'b0', 'b1'].forEach((k, i) => flash(sys, k, m('mat') + 1.5 + i * .5));
+ pulse(sys.meet, m('meet') + .4);
+ say(p, ['1 + 2 = 3, 2 − 2 = 0'], 90, 690, m('meet') + 1.4, { size: 34 });
+ text(p, '✓', 450, 690, m('meet') + 4.4, { size: 34, fill: COL.good, weight: 700 });
+ }],
+
+ ['q4', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ const A = mtx(p, [[3, -1], [0, 2]], 150, 330, { size: 46, cw: 92, rh: 74 });
+ mtx(p, [['x'], ['y']], 400, 330, { size: 46, cw: 50, rh: 74 });
+ M(p, ['='], { x: 500, y: 377, size: 46 });
+ mtx(p, [[7], [4]], 540, 330, { size: 46, cw: 70, rh: 74 }).cells.flat().forEach(c => c.setAttribute('fill', COL.task));
+ M(p, ['A'], { x: 252, y: 490, size: 34, fill: COL.dim, anchor: 'middle' });
+ }, { ask: done => quiz(SIDE, [{
+ id: 'c-back', prompt: ['Write the two equations. Type the number in front of each letter, sign included.'],
+ build: blanks([eqRow([3, -1], 7, 0), { ...eqRow([0, 2], 4, 1), why: '0x + 2y = 4, which is simply 2y = 4.' }]),
+ }], done) }],
+
+ ['wrap', 'Summary', (m) => {
+ const p = panel(0);
+ [['Ax = b is the system: A the numbers, x the unknowns, b the right sides.', 'w1'], ['Each row of A is one equation; each column belongs to one unknown.', 'w2'],
+ ['Size: rows first, then columns. 3 rows, 2 columns: 3 by 2.', 'w3'], ['Row 2, column 1: the second equation, in front of x. One number, two places.', 'w4']].forEach(([str, mark], i) => {
+ const g = G(p, { x: -16, y: 150 + i * 105, o: 0 });
+ mk('circle', { cx: 150, cy: -12, r: 26, fill: COL.task }, g);
+ T(g, String(i + 1), { x: 150, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });
+ T(g, str, { x: 210, size: 34, weight: 600 });
+ tw(g, { o: 1, x: 0 }, m(mark), .6);
+ });
+ // the chapter's system, small, lit up point by point
+ const pic = G(p, { o: 0 });
+ show(pic, m('w1') + .4, .6);
+ const eqs = [M(pic, ['2x − y = 0'], { x: 460, y: 640, size: 40, anchor: 'middle' }), M(pic, ['−x + 2y = 3'], { x: 460, y: 710, size: 40, anchor: 'middle' })];
+ const A = mtx(pic, [[2, -1], [-1, 2]], 820, 640, { size: 40, cw: 74, rh: 70 });
+ const xv = mtx(pic, [['x'], ['y']], 1010, 640, { size: 40, cw: 50, rh: 70 });
+ M(pic, ['='], { x: 1110, y: 690, size: 40 });
+ const bv = mtx(pic, [[0], [3]], 1150, 640, { size: 40, cw: 60, rh: 70 }); bv.cells.flat().forEach(c => c.setAttribute('fill', COL.task));
+ const fr = (x, y, w, hh, c, t0, t1) => frame(pic, x, y, w, hh, c, t0, t1);
+ fr(810, 590, 188, 170, COL.chalk, m('w1') + 2, m('w1') + 4); fr(1000, 590, 90, 170, COL.chalk, m('w1') + 4, m('w1') + 6); fr(1140, 590, 100, 170, COL.task, m('w1') + 6, m('w2'));
+ [0, 1].forEach(i => { band(pic, 816, 640 + 70 * i - 44, 176, 62, ROWC[i], m('w2') + .5 + i * 1.2, m('w2') + 4); band(pic, 330, 640 + 70 * i - 44, 260, 62, ROWC[i], m('w2') + .5 + i * 1.2, m('w2') + 4); });
+ [0, 1].forEach(j => band(pic, 830 + 74 * j, 590, 66, 170, COLC[j], m('w3') - 1.6 + j * .8, m('w3')));
+ const sz = text(pic, '2 by 2', 1300, 690, m('w3') + 1.5, { size: 40, fill: COL.task, weight: 600 }); hide(sz, m('w4'), .3);
+ fr(816, 670, 70, 60, COLC[0], m('w4') + .6, m('end'));
+ fr(460 - eqs[1]._w / 2 - 10, 664, 62, 64, COLC[0], m('w4') + 1.6, m('end'));
+ // change it in one place: both places change
+ const c = A.cells[1][0], c2 = T(pic, '1', { x: st(c).x, y: st(c).y, size: 40, fill: COLC[0], font: MATH, anchor: 'middle', o: 0 });
+ hide(c, m('w4') + 5.6, .3); show(c2, m('w4') + 5.8, .3);
+ const e2 = M(pic, ['x + 2y = 3'], { x: 460, y: 710, size: 40, anchor: 'middle', o: 0 });
+ hide(eqs[1], m('w4') + 5.6, .3); show(e2, m('w4') + 5.8, .3);
+ }],
+ ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, SYS1.map((s, k) => ({
+ id: `p-form${k + 1}`, prompt: ['Write the system as ', $m('Ax = b'), ': ', $m((s.shown || s.A.map((r, i) => eqStr(r, s.b[i])))[0]), ', ', $m((s.shown || s.A.map((r, i) => eqStr(r, s.b[i])))[1]), s.shown ? ' (line it up first)' : ''],
+ build: blanks(s.A.map((r, i) => ({ ...toMat(r, s.b[i], i), why: (!i && s.note) || toMat(r, s.b[i], i).why }))),
+ })), done, 'Chapter practice · set 1 of 4') }],
+ ['final2', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
+ id: 'p-addr1', prompt: [$m('B'), ' = ', matEl([[4, -2, 0], [1, 7, 3]])],
+ build: blanks([
+ { parts: ['B is ', { box: '2' }, ' by ', { box: '3' }], why: '2 rows, 3 columns.', hint: 'Rows first: how many rows go across?' },
+ { parts: ['row 2, column 3: ', { box: '3' }], why: 'Second row, third number: 3.', hint: 'Go down to row 2, then across to the third number.' },
+ { parts: ['row 1, column 2: ', { box: '-2' }], why: 'First row, second number: −2.', hint: 'Row 1 is the top row. Its second number?' },
+ { parts: ['the 7 is in row ', { box: '2' }, ', column ', { box: '2' }], why: '7 is the second number of the second row.', hint: 'Which row is 7 in? Then count across in that row.' },
+ ]),
+ }, {
+ id: 'p-addr2', prompt: [$m('C'), ' = ', matEl([[5, 1], [0, -3], [2, 6]])],
+ build: blanks([
+ { parts: ['C is ', { box: '3' }, ' by ', { box: '2' }], why: '3 rows, 2 columns.', hint: 'Count the rows first.' },
+ { parts: ['row 3, column 1: ', { box: '2' }], why: 'Bottom row, first number: 2.', hint: 'Row 3 is the bottom row.' },
+ { parts: ['row 2, column 2: ', { box: '-3' }], why: 'Middle row, second number: −3.', hint: 'Row 2 is the middle row.' },
+ ]),
+ }, {
+ id: 'p-sizes', prompt: ['Sizes from systems.'],
+ build: blanks([
+ { parts: ['3 equations, 4 unknowns: A is ', { box: '3' }, ' by ', { box: '4' }], why: 'A row for each equation, a column for each unknown.', hint: 'Rows = equations, columns = unknowns.' },
+ { parts: ['A is 2 by 5: ', { box: '2' }, ' equations, ', { box: '5' }, ' unknowns'], why: '2 rows: 2 equations. 5 columns: 5 unknowns.', hint: 'The first number counts rows, that is equations.' },
+ { parts: ['A is 4 by 3: x has ', { box: '3' }, ' entries, b has ', { box: '4' }], why: 'x has one entry per unknown (3), b one per equation (4).', hint: 'x lists the unknowns (one per column); b lists the right sides (one per row).' },
+ ]),
+ }], done, 'Chapter practice · set 2 of 4') }],
+ ['final3', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, SYS3.map((s, k) => ({
+ id: `p-back${k + 1}`, prompt: ['Write the equations of ', formEl(s.A, s.b)],
+ build: blanks(s.A.map((r, i) => ({ ...eqRow(r, s.b[i], i), ...(i === s.A.length - 1 && s.note ? { why: s.note } : {}) }))),
+ })), done, 'Chapter practice · set 3 of 4') }],
+ ['final4', 'Chapter practice', () => {
+ const p = panel(0);
+ text(p, 'Make the system', 60, 110, .2, { size: 40, weight: 600 });
+ S.sys = sysOf(p, [[1, 0], [0, 1]], [0, 0]);
+ }, { ask: done => {
+ const from = (start, f) => (body, api) => { S.sys.set(start); return f(body, api); };
+ const both = (v, w0, w1) => { const r0 = [v.a00, v.a01, v.b0], r1 = [v.a10, v.a11, v.b1]; return (prop(w0, r0) && prop(w1, r1)) || (prop(w1, r0) && prop(w0, r1)); };
+ quiz(LOW, [{
+ id: 'p-make1', prompt: ['Make ', $m('Ax = b'), ' say ', $m('x − y = 1'), ' and ', $m('2x + y = 8'), '.'],
+ build: from({ a00: 1, a01: 0, a10: 0, a11: 1, b0: 0, b1: 0 }, lsTask(S.sys, v => both(v, [1, -1, 1], [2, 1, 8]), 'A has rows 1, −1 and 2, 1; b is 1, 8. The lines meet at (3, 2).',
+ 'Row 1: the numbers in front of x and y in x − y = 1, that is 1 and −1. Row 2 from 2x + y = 8. Then b.', () => S.sys.set({ a00: 1, a01: -1, a10: 2, a11: 1, b0: 1, b1: 8 }))),
+ }, {
+ id: 'p-make2', prompt: ['Make the equations say ', $m('2x = 6'), ' and ', $m('y = −1'), '.'],
+ build: from({ a00: 1, a01: 1, a10: 1, a11: 1, b0: 2, b1: 2 }, lsTask(S.sys, v => both(v, [2, 0, 6], [0, 1, -1]), 'A has rows 2, 0 and 0, 1: each 0 is a missing letter. The lines meet at (3, −1).',
+ 'A missing letter is a 0 in the matrix. 2x = 6 is 2x + 0y = 6.', () => S.sys.set({ a00: 2, a01: 0, a10: 0, a11: 1, b0: 6, b1: -1 }))),
+ }, {
+ id: 'p-make3', prompt: ['Change only the entry in row 1, column 2, so that the lines meet at ', $m('(1, 1)'), '.'],
+ build: from({ a00: 1, a01: -3, a10: 1, a11: -1, b0: 3, b1: 0 }, lsTask(S.sys, v => v.a01 === 2 && v.a00 === 1 && v.a10 === 1 && v.a11 === -1 && v.b0 === 3 && v.b1 === 0,
+ 'Row 1, column 2 = 2: x + 2y = 3, and (1, 1) gives 1 + 2 = 3.',
+ 'Leave every other number as it was. (1, 1) must solve the first equation: 1 + (row 1, column 2)·1 = 3.', () => S.sys.set({ a01: 2 }))),
+ }], done, 'Chapter practice · set 4 of 4');
+ } }],
+ ['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],
+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
+
+boot();
+</script>
+</body>
+</html>
diff --git a/site/linear-algebra/ch09/audio/en/bigger.mp3 b/site/linear-algebra/ch09/audio/en/bigger.mp3
new file mode 100644
index 0000000..0014366
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/bigger.mp3 differ
diff --git a/site/linear-algebra/ch09/audio/en/cols.mp3 b/site/linear-algebra/ch09/audio/en/cols.mp3
new file mode 100644
index 0000000..efd74a3
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/cols.mp3 differ
diff --git a/site/linear-algebra/ch09/audio/en/cols2.mp3 b/site/linear-algebra/ch09/audio/en/cols2.mp3
new file mode 100644
index 0000000..ba490d5
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/cols2.mp3 differ
diff --git a/site/linear-algebra/ch09/audio/en/final1.mp3 b/site/linear-algebra/ch09/audio/en/final1.mp3
new file mode 100644
index 0000000..deaa7e1
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/final1.mp3 differ
diff --git a/site/linear-algebra/ch09/audio/en/final2.mp3 b/site/linear-algebra/ch09/audio/en/final2.mp3
new file mode 100644
index 0000000..8f542c9
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/final2.mp3 differ
diff --git a/site/linear-algebra/ch09/audio/en/final3.mp3 b/site/linear-algebra/ch09/audio/en/final3.mp3
new file mode 100644
index 0000000..12561ea
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/final3.mp3 differ
diff --git a/site/linear-algebra/ch09/audio/en/final4.mp3 b/site/linear-algebra/ch09/audio/en/final4.mp3
new file mode 100644
index 0000000..5580925
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/final4.mp3 differ
diff --git a/site/linear-algebra/ch09/audio/en/finish.mp3 b/site/linear-algebra/ch09/audio/en/finish.mp3
new file mode 100644
index 0000000..1c653f8
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/finish.mp3 differ
diff --git a/site/linear-algebra/ch09/audio/en/intro.mp3 b/site/linear-algebra/ch09/audio/en/intro.mp3
new file mode 100644
index 0000000..7be099a
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/intro.mp3 differ
diff --git a/site/linear-algebra/ch09/audio/en/match.mp3 b/site/linear-algebra/ch09/audio/en/match.mp3
new file mode 100644
index 0000000..6486d44
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/match.mp3 differ
diff --git a/site/linear-algebra/ch09/audio/en/q1.mp3 b/site/linear-algebra/ch09/audio/en/q1.mp3
new file mode 100644
index 0000000..c41401b
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/q1.mp3 differ
diff --git a/site/linear-algebra/ch09/audio/en/q2.mp3 b/site/linear-algebra/ch09/audio/en/q2.mp3
new file mode 100644
index 0000000..00c48ec
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/q2.mp3 differ
diff --git a/site/linear-algebra/ch09/audio/en/q3.mp3 b/site/linear-algebra/ch09/audio/en/q3.mp3
new file mode 100644
index 0000000..2c8cc15
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/q3.mp3 differ
diff --git a/site/linear-algebra/ch09/audio/en/q4.mp3 b/site/linear-algebra/ch09/audio/en/q4.mp3
new file mode 100644
index 0000000..2c47406
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/q4.mp3 differ
diff --git a/site/linear-algebra/ch09/audio/en/rows.mp3 b/site/linear-algebra/ch09/audio/en/rows.mp3
new file mode 100644
index 0000000..b85a44b
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/rows.mp3 differ
diff --git a/site/linear-algebra/ch09/audio/en/rows2.mp3 b/site/linear-algebra/ch09/audio/en/rows2.mp3
new file mode 100644
index 0000000..324572d
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/rows2.mp3 differ
diff --git a/site/linear-algebra/ch09/audio/en/setup.mp3 b/site/linear-algebra/ch09/audio/en/setup.mp3
new file mode 100644
index 0000000..1298c15
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/setup.mp3 differ
diff --git a/site/linear-algebra/ch09/audio/en/system.mp3 b/site/linear-algebra/ch09/audio/en/system.mp3
new file mode 100644
index 0000000..a6a440a
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/system.mp3 differ
diff --git a/site/linear-algebra/ch09/audio/en/tall.mp3 b/site/linear-algebra/ch09/audio/en/tall.mp3
new file mode 100644
index 0000000..adb8aa1
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/tall.mp3 differ
diff --git a/site/linear-algebra/ch09/audio/en/timings.js b/site/linear-algebra/ch09/audio/en/timings.js
new file mode 100644
index 0000000..59e47a9
--- /dev/null
+++ b/site/linear-algebra/ch09/audio/en/timings.js
@@ -0,0 +1,721 @@
+window.TIMINGS = {
+ "intro": {
+ "dur": 16.752,
+ "marks": {
+ "sub": 3.776,
+ "move": 10.703
+ },
+ "cues": [
+ [
+ 0.104,
+ "Chapter nine."
+ ],
+ [
+ 1.159,
+ "Matrix times vector, two ways."
+ ],
+ [
+ 3.776,
+ "In chapter eight we wrote A x equals b, and promised to say what A times x really means."
+ ],
+ [
+ 10.703,
+ "There are two ways to work it out: by columns, and by rows."
+ ],
+ [
+ 14.74,
+ "And they always give the same answer."
+ ]
+ ]
+ },
+ "setup": {
+ "dur": 16.536,
+ "marks": {
+ "A": 1.497,
+ "x": 6.81,
+ "q": 9.336,
+ "plan": 12.878
+ },
+ "cues": [
+ [
+ 0.117,
+ "Here's a matrix."
+ ],
+ [
+ 1.497,
+ "A is two, five in the first row, and one, three in the second."
+ ],
+ [
+ 6.81,
+ "And here's a vector x: one, two."
+ ],
+ [
+ 9.336,
+ "A times x will be a new vector, with two numbers."
+ ],
+ [
+ 12.878,
+ "Let's find them."
+ ],
+ [
+ 13.984,
+ "First by columns, then by rows."
+ ]
+ ]
+ },
+ "cols": {
+ "dur": 47.592,
+ "marks": {
+ "c1": 6.263,
+ "c2": 13.49,
+ "add": 21.38,
+ "ans": 29.779,
+ "pic": 32.331,
+ "land": 38.216,
+ "same": 40.273
+ },
+ "cues": [
+ [
+ 0.104,
+ "By columns, A times x is a mix of the columns of A, and x says how much of each."
+ ],
+ [
+ 6.263,
+ "The first number of x is one."
+ ],
+ [
+ 8.438,
+ "It multiplies column one: one times two, one is just two, one."
+ ],
+ [
+ 13.49,
+ "The second number of x is two."
+ ],
+ [
+ 15.859,
+ "It multiplies column two: two times five, three is ten, six."
+ ],
+ [
+ 21.38,
+ "Now add the two vectors, top with top and bottom with bottom: two plus ten is twelve, one plus six is seven."
+ ],
+ [
+ 29.779,
+ "So A times x is twelve, seven."
+ ],
+ [
+ 32.331,
+ "In the picture: one green column, then two violet columns, tip to tail, and we land on twelve, seven."
+ ],
+ [
+ 40.273,
+ "This is exactly a linear combination from chapter six."
+ ],
+ [
+ 44.193,
+ "The numbers of x play the part of c and d."
+ ]
+ ]
+ },
+ "cols2": {
+ "dur": 35.232,
+ "marks": {
+ "A": 2.305,
+ "x": 7.122,
+ "c1": 9.115,
+ "c2": 13.711,
+ "add": 23.737,
+ "ans": 28.294,
+ "pic": 31.029
+ },
+ "cues": [
+ [
+ 0.117,
+ "One more, with a minus sign."
+ ],
+ [
+ 2.305,
+ "A is one, minus one in the first row, two, one in the second."
+ ],
+ [
+ 7.122,
+ "x is two, minus one."
+ ],
+ [
+ 9.115,
+ "Two times column one: two times one, two is two, four."
+ ],
+ [
+ 13.711,
+ "Minus one times column two: minus one times minus one, one is one, minus one."
+ ],
+ [
+ 20.208,
+ "A minus sign means: go backwards along that column."
+ ],
+ [
+ 23.737,
+ "Add: two plus one is three, four minus one is three."
+ ],
+ [
+ 28.294,
+ "A times x is three, three."
+ ],
+ [
+ 31.029,
+ "Two greens forward, one violet backwards, and we're at three, three."
+ ]
+ ]
+ },
+ "q1": {
+ "dur": 3.216,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.12,
+ "Work out A times x by columns."
+ ]
+ ]
+ },
+ "rows": {
+ "dur": 49.464,
+ "marks": {
+ "r1": 8.359,
+ "m1": 16.094,
+ "s1": 20.742,
+ "r2": 23.763,
+ "m2": 29.388,
+ "s2": 32.279,
+ "same": 34.557,
+ "dot": 38.021
+ },
+ "cues": [
+ [
+ 0.104,
+ "Now the second way: by rows."
+ ],
+ [
+ 2.682,
+ "Back to A equals two, five, one, three, and x equals one, two."
+ ],
+ [
+ 8.359,
+ "For the first number of A x, take the first row of A, two, five, and lay it beside x, one, two."
+ ],
+ [
+ 16.094,
+ "Multiply number by number: two times one, and five times two."
+ ],
+ [
+ 20.742,
+ "Then add: two plus ten is twelve."
+ ],
+ [
+ 23.763,
+ "For the second number, take the second row, one, three, with the same x."
+ ],
+ [
+ 29.388,
+ "One times one, and three times two."
+ ],
+ [
+ 32.279,
+ "One plus six is seven."
+ ],
+ [
+ 34.557,
+ "Twelve, seven."
+ ],
+ [
+ 35.951,
+ "The same answer as by columns."
+ ],
+ [
+ 38.021,
+ "A row times a column, multiplied number by number and then added, is called a dot product."
+ ],
+ [
+ 44.284,
+ "Each number of A x is one dot product: one row of A, with x."
+ ]
+ ]
+ },
+ "rows2": {
+ "dur": 40.2,
+ "marks": {
+ "A": 2.969,
+ "r1": 10.104,
+ "s1": 16.68,
+ "r2": 18.789,
+ "s2": 23.997,
+ "ans": 26.12,
+ "chk": 28.151,
+ "add": 34.922
+ },
+ "cues": [
+ [
+ 0.117,
+ "One more by rows, with a minus sign."
+ ],
+ [
+ 2.969,
+ "A is three, minus two in the first row, one, two in the second, and x is two, one."
+ ],
+ [
+ 10.104,
+ "Row one with x: three times two is six."
+ ],
+ [
+ 13.685,
+ "Minus two times one is minus two."
+ ],
+ [
+ 16.68,
+ "Six minus two is four."
+ ],
+ [
+ 18.789,
+ "Row two with x: one times two is two, and two times one is two."
+ ],
+ [
+ 23.997,
+ "Two plus two is four."
+ ],
+ [
+ 26.12,
+ "So A x is four, four."
+ ],
+ [
+ 28.151,
+ "Check it by columns: two of column one is six, two."
+ ],
+ [
+ 32.161,
+ "One of column two is minus two, two."
+ ],
+ [
+ 34.922,
+ "Six minus two is four, two plus two is four."
+ ],
+ [
+ 38.841,
+ "Four, four again."
+ ]
+ ]
+ },
+ "why": {
+ "dur": 37.056,
+ "marks": {
+ "grid": 2.617,
+ "colway": 9.688,
+ "rowway": 18.516,
+ "same": 24.258,
+ "use": 29.466
+ },
+ "cues": [
+ [
+ 0.104,
+ "Why do the two ways always agree?"
+ ],
+ [
+ 2.617,
+ "Look at the four products we made: two times one, five times two, one times one, three times two."
+ ],
+ [
+ 9.688,
+ "By columns, we stacked them by column: two and one from column one, ten and six from column two, and added the two stacks."
+ ],
+ [
+ 18.516,
+ "By rows, we added them along each row: two plus ten, one plus six."
+ ],
+ [
+ 24.258,
+ "The same four products, added up in a different order."
+ ],
+ [
+ 27.461,
+ "That's why the answer can't change."
+ ],
+ [
+ 29.466,
+ "So pick whichever way is easier."
+ ],
+ [
+ 31.628,
+ "By hand, rows are often quicker."
+ ],
+ [
+ 34.154,
+ "To see what's going on, columns are often clearer."
+ ]
+ ]
+ },
+ "system": {
+ "dur": 45.672,
+ "marks": {
+ "A": 2.891,
+ "r1": 12.383,
+ "r2": 18.906,
+ "b": 22.617,
+ "c": 33.451,
+ "one": 42.109
+ },
+ "cues": [
+ [
+ 0.104,
+ "And now A x equals b makes sense."
+ ],
+ [
+ 2.891,
+ "Take the system from chapter seven."
+ ],
+ [
+ 5.182,
+ "A is two, minus one, minus one, two, and this time x is the unknowns, x and y."
+ ],
+ [
+ 12.383,
+ "Row one times x: two times x, plus minus one times y."
+ ],
+ [
+ 16.914,
+ "That's two x minus y."
+ ],
+ [
+ 18.906,
+ "Row two times x: minus x plus two y."
+ ],
+ [
+ 22.617,
+ "So A x equals b says: two x minus y equals zero, and minus x plus two y equals three."
+ ],
+ [
+ 30.286,
+ "Our two equations: that's the row picture."
+ ],
+ [
+ 33.451,
+ "By columns, A x equals b says: x times column one, plus y times column two, equals b."
+ ],
+ [
+ 40.599,
+ "That's the column picture."
+ ],
+ [
+ 42.109,
+ "One product, two ways to read it, two pictures."
+ ]
+ ]
+ },
+ "q2": {
+ "dur": 4.176,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn."
+ ],
+ [
+ 0.977,
+ "Move x until A x lands on the amber target."
+ ]
+ ]
+ },
+ "bigger": {
+ "dur": 51.72,
+ "marks": {
+ "A": 3.034,
+ "r1": 9.349,
+ "r2": 19.635,
+ "r3": 27.891,
+ "ans": 35.404,
+ "c": 38.294,
+ "sum": 44.792
+ },
+ "cues": [
+ [
+ 0.104,
+ "The same two ways work for bigger matrices."
+ ],
+ [
+ 3.034,
+ "Here A is three by three, and x has three numbers: one, two, three."
+ ],
+ [
+ 9.349,
+ "By rows."
+ ],
+ [
+ 10.417,
+ "Row one: one times one, plus zero times two, plus two times three."
+ ],
+ [
+ 16.367,
+ "One plus zero plus six is seven."
+ ],
+ [
+ 19.635,
+ "Row two: zero, plus three times two, plus one times three."
+ ],
+ [
+ 24.961,
+ "Zero plus six plus three is nine."
+ ],
+ [
+ 27.891,
+ "Row three: two times one, plus one times two, plus zero."
+ ],
+ [
+ 33.281,
+ "Two plus two is four."
+ ],
+ [
+ 35.404,
+ "A x is seven, nine, four."
+ ],
+ [
+ 38.294,
+ "By columns: one of column one, plus two of column two, plus three of column three."
+ ],
+ [
+ 44.792,
+ "One, zero, two, plus zero, six, two, plus six, three, zero."
+ ],
+ [
+ 49.987,
+ "Seven, nine, four again."
+ ]
+ ]
+ },
+ "tall": {
+ "dur": 34.368,
+ "marks": {
+ "A": 2.188,
+ "x": 6.771,
+ "rows": 11.263,
+ "cols": 18.268,
+ "sizes": 25.938
+ },
+ "cues": [
+ [
+ 0.091,
+ "Now a matrix that isn't square."
+ ],
+ [
+ 2.188,
+ "This A is three by two: three rows, two columns."
+ ],
+ [
+ 6.771,
+ "So x has two numbers, one for each column: four and one."
+ ],
+ [
+ 11.263,
+ "By rows: four plus two is six."
+ ],
+ [
+ 14.154,
+ "Zero plus one is one."
+ ],
+ [
+ 15.911,
+ "Twelve minus one is eleven."
+ ],
+ [
+ 18.268,
+ "By columns: four times column one, plus one times column two, gives the same: six, one, eleven."
+ ],
+ [
+ 25.938,
+ "Notice the sizes."
+ ],
+ [
+ 27.5,
+ "Two columns in A, so x has two numbers."
+ ],
+ [
+ 30.82,
+ "Three rows in A, so A x has three numbers."
+ ]
+ ]
+ },
+ "match": {
+ "dur": 30.312,
+ "marks": {
+ "try": 1.966,
+ "cols": 6.328,
+ "rows": 12.474,
+ "no": 19.57,
+ "rule": 21.875
+ },
+ "cues": [
+ [
+ 0.104,
+ "So the sizes must fit."
+ ],
+ [
+ 1.966,
+ "What if we try this three by two A with an x of three numbers?"
+ ],
+ [
+ 6.328,
+ "By columns: the third number of x would need a third column to multiply, and there isn't one."
+ ],
+ [
+ 12.474,
+ "By rows: each row has two numbers, but x has three."
+ ],
+ [
+ 16.576,
+ "The last number is left without a partner."
+ ],
+ [
+ 19.57,
+ "A times x is not defined."
+ ],
+ [
+ 21.875,
+ "The rule: x needs exactly as many numbers as A has columns."
+ ],
+ [
+ 26.263,
+ "And A x comes out with as many numbers as A has rows."
+ ]
+ ]
+ },
+ "q3": {
+ "dur": 3.12,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.12,
+ "Work out A times x by rows."
+ ]
+ ]
+ },
+ "q4": {
+ "dur": 2.472,
+ "marks": {},
+ "cues": [
+ [
+ 0.091,
+ "Quick check."
+ ],
+ [
+ 1.081,
+ "Do the sizes fit?"
+ ]
+ ]
+ },
+ "wrap": {
+ "dur": 22.944,
+ "marks": {
+ "w1": 1.003,
+ "w2": 6.862,
+ "w3": 12.331,
+ "w4": 15.925,
+ "end": 20.742
+ },
+ "cues": [
+ [
+ 0.091,
+ "To sum up."
+ ],
+ [
+ 1.003,
+ "By columns: A x is a combination of the columns of A, using the numbers of x."
+ ],
+ [
+ 6.862,
+ "By rows: each number of A x is a row of A times x, a dot product."
+ ],
+ [
+ 12.331,
+ "Both ways use the same products, so they always agree."
+ ],
+ [
+ 15.925,
+ "x needs one number for each column of A; A x gets one number for each row."
+ ],
+ [
+ 20.742,
+ "Now try the chapter practice."
+ ]
+ ]
+ },
+ "final1": {
+ "dur": 3.744,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Chapter practice."
+ ],
+ [
+ 1.523,
+ "Work out A times x by columns."
+ ]
+ ]
+ },
+ "final2": {
+ "dur": 1.872,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Next, by rows."
+ ]
+ ]
+ },
+ "final3": {
+ "dur": 1.872,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Now check the sizes."
+ ]
+ ]
+ },
+ "final4": {
+ "dur": 3.048,
+ "marks": {},
+ "cues": [
+ [
+ 0.078,
+ "Last set."
+ ],
+ [
+ 1.185,
+ "Make A x land where you're told."
+ ]
+ ]
+ },
+ "finish": {
+ "dur": 9.432,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Well done."
+ ],
+ [
+ 1.094,
+ "That's the end of chapter nine, matrix times vector, two ways."
+ ],
+ [
+ 5.638,
+ "Next: what A does to every point of the plane at once."
+ ]
+ ]
+ }
+};
diff --git a/site/linear-algebra/ch09/audio/en/why.mp3 b/site/linear-algebra/ch09/audio/en/why.mp3
new file mode 100644
index 0000000..df4a3aa
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/why.mp3 differ
diff --git a/site/linear-algebra/ch09/audio/en/wrap.mp3 b/site/linear-algebra/ch09/audio/en/wrap.mp3
new file mode 100644
index 0000000..6f9850a
Binary files /dev/null and b/site/linear-algebra/ch09/audio/en/wrap.mp3 differ
diff --git a/site/linear-algebra/ch09/index.html b/site/linear-algebra/ch09/index.html
new file mode 100644
index 0000000..7e56cae
--- /dev/null
+++ b/site/linear-algebra/ch09/index.html
@@ -0,0 +1,569 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>Matrix Times Vector, Two Ways</title>
+<link rel="stylesheet" href="../lib/engine.css">
+<link rel="expect" href="#bar" blocking="render"><!-- hold the first frame until the player exists, so the page transition can run -->
+</head>
+<body>
+<script src="../lib/engine.js"></script>
+<script src="../lib/math.js"></script>
+<script src="../lib/linsys.js"></script>
+<script src="../lib/grid2.js"></script>
+<script src="audio/en/timings.js"></script>
+<script>
+'use strict';
+const CHAPTER = { number: 9, title: 'Matrix Times Vector, Two Ways', minutes: 9, language: 'en' };
+
+/* ---------- layout and colours ---------- */
+const DISP = [90, 230]; // A x = Ax in brackets, top left
+const BIG = { cx: 900, cy: 780, u: 46, x0: -1, x1: 13, y0: -1, y1: 8 }; // a plane that reaches (12, 7)
+const ROWC = [COL.whole, COL.nat, COL.int], COLC = [COL.irr, COL.real, COL.rat];
+const SIDE = { x: 820, y: 170, w: 720, cls: 'side' }; // question card on the right, plane hidden
+const LOW = { x: 40, y: 430, w: 720, cls: 'side' }; // question card under the matrix, plane kept
+
+/* ---------- chapter drawing helpers ---------- */
+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 pulseAll = (els, t, gap = .45, k = 1.3) => els.forEach((e, i) => pulse(e, t + i * gap, k));
+const paren = n => n < 0 ? `(${num(n)})` : num(n);
+const flashEl = (e, t0, col = COL.task) => { const c0 = e.getAttribute('fill'); tw(e, { c_fill: col }, t0, .25); tw(e, { c_fill: c0 }, t0 + 1.2, .6); };
+const frame = (p, x, y, w, hh, c, t0, t1) => { const r = mk('rect', { x, y, width: w, height: hh, rx: 14, fill: 'none', stroke: c, 'stroke-width': 3 }, p); put(r, { o: 0 }); show(r, t0, .4); if (t1 !== undefined) hide(r, t1, .4); return r; };
+const band = (p, x, y, w, hh, c, t0, t1, o = .2) => { const r = mk('rect', { x, y, width: w, height: hh, rx: 14, fill: c }, p); put(r, { o: 0 }); tw(r, { o }, t0, .4); if (t1 !== undefined) tw(r, { o: 0 }, t1, .4); return r; };
+// A matrix drawn as a picture: brackets and entries (coloured by column unless fill is given).
+function mtx(p, rows, x, y, { size = 42, cw = 78, rh = 62, fill = null, o = 1 } = {}) {
+ const g = G(p, { o }), n = rows[0].length, w = cw * n + 20, top = y - size * .95, bot = y + rh * (rows.length - 1) + size * .4;
+ path(g, `M${x + 14} ${top}H${x}V${bot}H${x + 14}M${x + w - 14} ${top}H${x + w}V${bot}H${x + w - 14}`, { stroke: COL.chalk, 'stroke-width': 3 });
+ const cells = rows.map((r, i) => r.map((v, j) => {
+ const t = T(g, typeof v === 'number' ? num(v) : v, { x: x + 10 + cw * (j + .5), y: y + rh * i, size, fill: fill || (typeof v === 'number' ? COLC[j] : COL.chalk), font: MATH, anchor: 'middle' });
+ if (typeof v !== 'number') t.setAttribute('font-style', 'italic');
+ return t;
+ }));
+ return { g, cells, w, x, y, top, bot, at: (i, j) => [x + 10 + cw * (j + .5), y + rh * i] };
+}
+// Pieces laid out left to right on one baseline: strings (math) and column vectors { v: [...], fill }.
+// Every piece starts hidden; returns them with .at(k) for the k-th piece.
+function lineUp(p, items, x0, y, { size = 40, gap = 14, rh = size * 1.25, lineH = size * 3.2 } = {}) {
+ let x = x0;
+ return items.map(it => {
+ if (it === '\n') { x = x0 + 40; y += lineH; return { e: G(p, { o: 0 }), x, w: 0 }; }
+ if (typeof it === 'string') { const e = M(p, [it], { x, y, size, anchor: 'start', o: 0 }); const r = { e, x, w: e._w }; x += e._w + gap; return r; }
+ const n = it.v.length, c = y - size * .3, y1 = c - (n - 1) * rh / 2 + size * .35;
+ const m = mtx(p, it.v.map(v => [v]), x, y1, { size, cw: size * 1.55, rh, fill: it.fill || COL.chalk, o: 0 });
+ const r = { e: m.g, x, w: m.w, m }; x += m.w + gap; return r;
+ });
+}
+// The column way: k₁·[col 1] + k₂·[col 2] (+ …) = [k₁·col 1] + … = [Ax], each part shown at its own time.
+// wrap: the products and the sum go on a second line.
+function colWork(p, ks, cols, x0, y, times, { size = 36, wrap = false } = {}) {
+ const prod = cols.map((c, j) => c.map(v => ks[j] * v)), sum = cols[0].map((_, i) => prod.reduce((s, c) => s + c[i], 0));
+ const items = [], at = [];
+ const add = (it, t) => { items.push(it); at.push(t); };
+ ks.forEach((k, j) => { add((j ? '+ ' : '') + (j && k < 0 ? `(${num(k)})·` : `${num(k)}·`), times.terms[j]); add({ v: cols[j], fill: COLC[j] }, times.terms[j]); });
+ if (wrap) add('\n');
+ add('=', times.prod);
+ prod.forEach((c, j) => { if (j) add('+', times.prod + j * .5); add({ v: c, fill: COLC[j] }, times.prod + .2 + j * .5); });
+ add('=', times.sum); add({ v: sum, fill: COL.task }, times.sum + .2);
+ const parts = lineUp(p, items, x0, y, { size, lineH: cols[0].length * size * 1.25 + size * 1.3 });
+ parts.forEach((r, k) => { if (at[k] !== undefined) show(r.e, at[k], .4); });
+ return { parts, sum };
+}
+// The row way for one row: a₁·x₁ + a₂·x₂ (+ …) = products = result. The numbers fly in from where they sit.
+function rowWork(p, a, xs, x0, y, { from = null, xFrom = null, tm, ts, tr = ts + 1.4, size = 40, color = COL.chalk } = {}) {
+ const pr = a.map((v, j) => v * xs[j]), r = pr.reduce((s, v) => s + v, 0);
+ const items = [];
+ a.forEach((v, j) => { if (j) items.push(' + '); items.push({ t: paren(v), fill: COLC[j] }, '·', paren(xs[j])); });
+ items.push(' = ', pr.map((v, j) => j ? (v < 0 ? ` − ${num(-v)}` : ` + ${num(v)}`) : num(v)).join(''), ' = ', { t: num(r), fill: COL.task });
+ const row = tokens(p, items, { x: x0, y, size, fill: color });
+ row.forEach(e => put(e, { o: 0 }));
+ a.forEach((v, j) => {
+ const ea = row[j * 4], ex = row[j * 4 + 2], t = tm + j * .9;
+ if (from) { put(ea, { x: from[j][0], y: from[j][1] }); tw(ea, { x: ea._px, y }, t, .8); }
+ if (xFrom) { put(ex, { x: xFrom[j][0], y: xFrom[j][1] }); tw(ex, { x: ex._px, y }, t + .25, .8); }
+ show(ea, t, .2); show(ex, t + .25, .2); show(row[j * 4 + 1], t + .6, .3); if (j) show(row[j * 4 - 1], t, .3);
+ });
+ const k = a.length * 4 - 1;
+ show(row[k], ts, .3); show(row[k + 1], ts + .2, .4); show(row[k + 2], tr, .3); show(row[k + 3], tr + .2, .4);
+ return { row, r };
+}
+// A grid2 in this chapter's layout (no moved grid: the columns, x·col 1 + y·col 2 and Ax only).
+const g2Of = (p, A, x, o = {}) => grid2(p, { A, x, mat: DISP, grid: false, square: false, units: false, ...o });
+const hideX = g => { put(g.xRing, { o: 0 }); put(g.xLab, { o: 0 }); };
+// Hide the product Ax (numbers in the brackets) behind question marks until t, or for good.
+function hideRes(g, p, t) {
+ const q = [0, 1].map(i => { const e = g.res(i), s = st(e); put(e, { o: 0 }); return T(p, '?', { x: s.x, y: s.y, size: 54, fill: COL.task, font: MATH, anchor: 'middle' }); });
+ if (t !== undefined) { q.forEach(e => hide(e, t, .3)); [0, 1].forEach(i => show(g.res(i), t + .2, .4)); }
+ return q;
+}
+const hideAx = g => [g.axArrow, g.axDot, g.axLab, ...g.combo].forEach(e => put(e, { o: 0 }));
+// Positions in the A x = Ax display (from grid2's layout).
+const aAt = (g, i, j) => [g.lay.A[0][j], g.lay.A[1][i]], xAt = (g, i) => [g.lay.x, g.lay.A[1][i]], rAt = (g, i) => [g.lay.r, g.lay.A[1][i]];
+const rowBandA = (p, g, i, t0, t1) => band(p, DISP[0] + 6, g.lay.A[1][i] - 48, 192, 64, ROWC[i], t0, t1);
+const xBand = (p, g, t0, t1) => band(p, g.lay.x - 40, DISP[1] - 52, 80, 140, COL.chalk, t0, t1, .12);
+const target = (P2, [x, y], into, t0 = .3) => {
+ const g = G(into, { x: P2.PX(x), y: P2.PY(y), o: 0 });
+ mk('circle', { r: 17, fill: 'none', stroke: COL.task, 'stroke-width': 3, 'stroke-dasharray': '5 5' }, g);
+ T(g, `target (${num(x)}, ${num(y)})`, { x: 22, y: -18, size: 22, fill: COL.task, font: MATH });
+ show(g, t0, .4);
+ return g;
+};
+const vecStr = v => `(${v.map(num).join(', ')})`;
+// Inline matrix for a card prompt.
+function matEl(rows, { size = 30, fill = null } = {}) {
+ const n = rows[0].length, cw = size * 1.8, rh = size * 1.3, w = cw * n + 16, hh = rh * rows.length + size * .3;
+ const svg = mk('svg', { class: 'm', viewBox: `0 0 ${w} ${hh}`, width: w, height: hh });
+ svg.style.verticalAlign = 'middle';
+ path(svg, `M12 2H3V${hh - 2}H12M${w - 12} 2H${w - 3}V${hh - 2}H${w - 12}`, { stroke: 'currentColor', 'stroke-width': 2.5 });
+ rows.forEach((r, i) => r.forEach((v, j) => T(svg, num(v), { x: 8 + cw * (j + .5), y: rh * (i + .5) + size * .5, size, fill: fill || COLC[j], font: MATH, anchor: 'middle' })));
+ return svg;
+}
+const prodEl = (A, x) => { const s = h('span', '', [$m('A'), ' = ', matEl(A), ' ', $m('x'), ' = ', matEl(x.map(v => [v]), { fill: 'currentColor' })]); s.style.whiteSpace = 'pre'; return s; };
+
+/* ---------- practice data ---------- */
+const COLQ = [
+ { A: [[1, 2], [3, 1]], x: [2, 3] },
+ { A: [[4, -1], [0, 2]], x: [1, -2], note: 'A minus number of a column: go backwards along it.' },
+ { A: [[2, 0], [1, 5]], x: [3, 0], note: 'x = (3, 0) takes 3 of column 1 and none of column 2.' },
+ { A: [[-1, 3], [2, 2]], x: [-2, 1] },
+];
+const ROWQ = [
+ { A: [[2, 5], [1, 3]], x: [3, 1] },
+ { A: [[1, -2], [4, 3]], x: [2, -1] },
+ { A: [[1, 1, 1], [2, 0, -1], [0, 3, 1]], x: [2, 1, 4] },
+ { A: [[2, 1], [0, -1], [5, 2]], x: [1, 3] },
+];
+const mul = (A, x) => A.map(r => r.reduce((s, v, j) => s + v * x[j], 0));
+const colRows = ({ A, x, note }) => {
+ const c = j => A.map(r => r[j]), pr = j => c(j).map(v => v * x[j]), ax = mul(A, x);
+ return [
+ { parts: [`${num(x[0])} · column 1 = (`, { box: String(pr(0)[0]) }, ', ', { box: String(pr(0)[1]) }, ')'], why: `${num(x[0])}·${vecStr(c(0))} = ${vecStr(pr(0))}`, hint: `Multiply both numbers of column 1, ${vecStr(c(0))}, by ${num(x[0])}.` },
+ { parts: [`${num(x[1])} · column 2 = (`, { box: String(pr(1)[0]) }, ', ', { box: String(pr(1)[1]) }, ')'], why: `${num(x[1])}·${vecStr(c(1))} = ${vecStr(pr(1))}`, hint: `Multiply both numbers of column 2, ${vecStr(c(1))}, by ${num(x[1])}.` },
+ { parts: ['Ax = (', { box: String(ax[0]) }, ', ', { box: String(ax[1]) }, ')'], why: note || `${vecStr(pr(0))} + ${vecStr(pr(1))} = ${vecStr(ax)}`, hint: 'Add the two vectors: top with top, bottom with bottom.' },
+ ];
+};
+const rowRows = ({ A, x }) => A.map((r, i) => ({
+ parts: [`row ${i + 1} · x = `, { box: String(mul([r], x)[0]) }],
+ why: r.map((v, j) => `${paren(v)}·${paren(x[j])}`).join(' + ') + ` = ${num(mul([r], x)[0])}`,
+ hint: `Row ${i + 1} is ${r.map(num).join(', ')}. Multiply each by the matching number of x, then add.`,
+}));
+const FITQ = [
+ { parts: ['A is 2 by 3, x has 3 numbers'], ans: ['y'], why: 'A has 3 columns and x has 3 numbers: it fits. Ax has 2 numbers.' },
+ { parts: ['A is 3 by 2, x has 3 numbers'], ans: ['n'], why: 'A has only 2 columns, so x needs exactly 2 numbers.' },
+ { parts: ['A is 2 by 2, x has 2 numbers'], ans: ['y'], why: '2 columns, 2 numbers. Ax has 2 numbers.' },
+ { parts: ['A is 1 by 4, x has 4 numbers'], ans: ['y'], why: '4 columns, 4 numbers: one row, so Ax is one number (a single dot product).' },
+ { parts: ['A is 3 by 3, x has 2 numbers'], ans: ['n'], why: '3 columns need 3 numbers in x.' },
+ { parts: ['A is 2 by 4, x has 2 numbers'], ans: ['n'], why: 'Count columns, not rows: A has 4 columns, so x needs 4 numbers.' },
+];
+
+/* ---------- beats: [id, title, run(m, D), { ask }?] ---------- */
+const BEATS = [
+ ['intro', 'Matrix times vector, two ways', (m, D) => {
+ const g = G(scene, { o: 0, y: 24 });
+ T(g, 'Unit 1, Chapter 9', { x: 800, y: 290, size: 28, fill: COL.dim, anchor: 'middle' });
+ T(g, 'Matrix Times Vector, Two Ways', { x: 800, y: 400, size: 80, weight: 600, anchor: 'middle' });
+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);
+ const r = text(scene, 'what A times x means', 800, 500, m('sub'), { size: 36, fill: COL.dim, anchor: 'middle' });
+ const pic = G(scene, { o: 0 });
+ const A = mtx(pic, [[2, 5], [1, 3]], 600, 640, { size: 40, cw: 66, rh: 56 });
+ mtx(pic, [[1], [2]], 762, 640, { size: 40, cw: 52, rh: 56, fill: COL.chalk });
+ M(pic, ['='], { x: 870, y: 682, size: 40 });
+ const q = M(pic, ['?'], { x: 940, y: 682, size: 52, fill: COL.task });
+ show(pic, m('sub') + 1, .5);
+ // the two readings: down the columns, across the rows
+ const cg = G(scene, { o: 0 }), rg = G(scene, { o: 0 });
+ [0, 1].forEach(j => band(cg, A.at(0, j)[0] - 30, 596, 60, 118, COLC[j], m('move') + .6 + j * .5, D - 1, .25));
+ T(cg, 'by columns', { x: 666, y: 790, size: 28, fill: COLC[0], anchor: 'middle', weight: 600 });
+ [0, 1].forEach(i => band(rg, 606, A.at(i, 0)[1] - 40, 140, 54, ROWC[i], m('move') + 3 + i * .5, D - 1, .25));
+ T(rg, 'by rows', { x: 580, y: 668, size: 28, fill: ROWC[0], anchor: 'end', weight: 600 });
+ show(cg, m('move') + .6, .4); show(rg, m('move') + 3, .4);
+ pulse(q, m('move') + 5.5);
+ tw(g, { o: 0, y: -24 }, D - .9, .8); [r, pic, cg, rg].forEach(e => hide(e, D - .9, .8));
+ }],
+
+ ['setup', 'A matrix and a vector', (m) => {
+ const p = panel(0);
+ text(p, 'A times x', 60, 110, .2, { size: 40, weight: 600 });
+ const g = S.g = g2Of(p, [[2, 5], [1, 3]], [1, 2], { plane: BIG, hidePlane: true, t0: m('A') - .4 });
+ hideX(g);
+ const q = hideRes(g, p);
+ q.forEach(e => put(e, { o: 0 }));
+ ['a00', 'a01', 'a10', 'a11'].forEach((k, i) => g.num(k).forEach(e => flashEl(e, m('A') + .6 + i * .5)));
+ ['x0', 'x1'].forEach((k, i) => g.num(k).forEach(e => flashEl(e, m('x') + .4 + i * .6)));
+ pulseAll(['a00', 'a01', 'a10', 'a11'].map(k => g.num(k)[0]), m('A') + .6, .9);
+ pulseAll(['x0', 'x1'].map(k => g.num(k)[0]), m('x') + .4, .8);
+ q.forEach((e, i) => { show(e, m('q') + .3 + i * .3, .3); pulse(e, m('q') + 1.6 + i * .3); });
+ text(p, 'two numbers to find', g.lay.r, 430, m('q') + 1, { size: 26, fill: COL.task, anchor: 'middle', weight: 600 });
+ const plan = G(p, { o: 0 });
+ T(plan, '1. by columns', { x: 90, y: 560, size: 34, weight: 600, fill: COLC[0] });
+ T(plan, '2. by rows', { x: 90, y: 615, size: 34, weight: 600, fill: ROWC[0] });
+ show(plan, m('plan') + .3);
+ }],
+
+ ['cols', 'By columns', (m) => {
+ const p = panel(0);
+ text(p, 'By columns: a mix of the columns', 60, 110, .2, { size: 40, weight: 600 });
+ const g = S.g = g2Of(p, [[2, 5], [1, 3]], [1, 2], { plane: BIG });
+ hideX(g); hideAx(g); hideRes(g, p, m('ans'));
+ g.labels(['col 1', 'col 2']);
+ put(g.parts.cols, { o: 0 }); show(g.parts.cols, m('c1') - .2, .4);
+ put(g.cols[1], { o: 0 }); show(g.cols[1], m('c2'), .5);
+ // x's first number goes with column 1, its second with column 2
+ band(p, g.lay.A[0][0] - 40, DISP[1] - 52, 80, 140, COLC[0], m('c1'), m('c2'));
+ g.num('x0').forEach(e => flashEl(e, m('c1') + .2));
+ band(p, g.lay.A[0][1] - 40, DISP[1] - 52, 80, 140, COLC[1], m('c2'), m('add'));
+ g.num('x1').forEach(e => flashEl(e, m('c2') + .2));
+ colWork(p, [1, 2], [[2, 1], [5, 3]], 70, 500, { terms: [m('c1') + 1.5, m('c2') + 1.5], prod: m('c2') + 4.5, sum: m('add') + 3 });
+ show(g.combo[0], m('pic') + .2, .5); show(g.combo[1], m('pic') + 1.8, .6);
+ [g.axArrow, g.axDot, g.axLab].forEach(e => show(e, m('land'), .5));
+ pulse(g.axDot, m('land') + .6);
+ const lc = G(p, { o: 0 });
+ M(lc, ['c·v + d·w'], { x: 90, y: 690, size: 38, anchor: 'start' });
+ T(lc, 'chapter 6, with c = 1 and d = 2', { x: 300, y: 688, size: 28, fill: COL.dim });
+ show(lc, m('same') + 1);
+ [['c', 'x0', 0], ['d', 'x1', 1]].forEach(([n, k, i]) => {
+ const [x, y] = xAt(g, i), t = text(p, `= ${n}`, x + 40, y, m('same') + 3 + i * 1.4, { size: 34, fill: COL.task, weight: 600 });
+ pulse(g.num(k)[0], m('same') + 3 + i * 1.4);
+ });
+ }],
+
+ ['cols2', 'By columns, with a minus', (m) => {
+ const p = panel(0);
+ text(p, 'By columns: a minus sign goes backwards', 60, 110, .2, { size: 40, weight: 600 });
+ const g = S.g = g2Of(p, [[1, -1], [2, 1]], [2, -1], { t0: m('A') - .4 });
+ hideX(g); hideAx(g); hideRes(g, p, m('ans'));
+ g.labels(['col 1', 'col 2']);
+ put(g.M, { o: 0 }); show(g.M, m('A') - .2, .4);
+ ['x0', 'x1'].forEach((k, i) => g.num(k).forEach(e => flashEl(e, m('x') + .3 + i * .7)));
+ pulseAll(['a00', 'a01', 'a10', 'a11'].map(k => g.num(k)[0]), m('A') + .3, .9);
+ pulseAll(['x0', 'x1'].map(k => g.num(k)[0]), m('x') + .3, .7);
+ band(p, g.lay.A[0][0] - 40, DISP[1] - 52, 80, 140, COLC[0], m('c1'), m('c2'));
+ band(p, g.lay.A[0][1] - 40, DISP[1] - 52, 80, 140, COLC[1], m('c2'), m('add'));
+ colWork(p, [2, -1], [[1, 2], [-1, 1]], 70, 500, { terms: [m('c1') + .5, m('c2') + .5], prod: m('c2') + 3.5, sum: m('add') + 2.5 });
+ text(p, '−1 of column 2: backwards along it', 90, 650, m('c2') + 6, { size: 28, fill: COLC[1], weight: 600 });
+ show(g.combo[0], m('pic') + .2, .5); show(g.combo[1], m('pic') + 1.6, .6);
+ [g.axArrow, g.axDot, g.axLab].forEach(e => show(e, m('pic') + 2.6, .5));
+ // the backwards step: the violet arrow, flipped, from the tip of 2·col 1
+ pulse(g.axDot, m('pic') + 3.2);
+ }],
+
+ ['q1', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ const g = S.g = g2Of(p, [[3, 1], [1, 2]], [2, 1], { hidePlane: true });
+ hideX(g); S.q1 = hideRes(g, p);
+ text(p, 'by columns: 2 · column 1 + 1 · column 2', 90, 480, .6, { size: 30, fill: COL.dim });
+ }, { ask: done => quiz(SIDE, [{
+ id: 'c-cols', prompt: ['Work out ', $m('Ax'), ' by columns.'],
+ build: blanks(colRows({ A: [[3, 1], [1, 2]], x: [2, 1] }).map((r, i) => i < 2 ? r : { ...r, fx: () => { S.q1.forEach(e => fx(e, { o: 0 }, 0, .3)); [0, 1].forEach(k => fx(S.g.res(k), { o: 1 }, .2, .4)); } })),
+ }], done) }],
+
+ ['rows', 'By rows', (m) => {
+ const p = panel(0);
+ text(p, 'By rows: a row times x', 60, 110, .2, { size: 40, weight: 600 });
+ const g = S.g = g2Of(p, [[2, 5], [1, 3]], [1, 2], { plane: BIG });
+ hideX(g); hideAx(g);
+ g.labels(['col 1', 'col 2']);
+ put(g.parts.cols, { o: .35 });
+ [0, 1].forEach(i => put(g.res(i), { o: 0 }));
+ pulseAll(['a00', 'a01', 'a10', 'a11'].map(k => g.num(k)[0]), 3.4, .5);
+ pulseAll(['x0', 'x1'].map(k => g.num(k)[0]), 6, .6);
+ [0, 1].forEach(i => {
+ const r = m(`r${i + 1}`), mm = m(`m${i + 1}`), s = m(`s${i + 1}`);
+ rowBandA(p, g, i, r, i ? m('same') : m('r2'));
+ xBand(p, g, r + .8, i ? m('same') : m('r2'));
+ const w = rowWork(p, i ? [1, 3] : [2, 5], [1, 2], 70, 500 + i * 80, { from: [aAt(g, i, 0), aAt(g, i, 1)], xFrom: [xAt(g, 0), xAt(g, 1)], tm: mm - .4, ts: s, tr: s + 1.2 });
+ const res = w.row[w.row.length - 1];
+ const fl = M(p, [String(w.r)], { x: res._px, y: 500 + i * 80, size: 40, fill: COL.task, o: 0 });
+ show(fl, s + 1.8, .1); tw(fl, { x: rAt(g, i)[0], y: rAt(g, i)[1], s: 1.3 }, s + 1.9, .8); hide(fl, s + 2.7, .1);
+ show(g.res(i), s + 2.6, .3);
+ });
+ [g.axArrow, g.axDot, g.axLab].forEach(e => show(e, m('same') + .4, .5));
+ pulse(g.axDot, m('same') + 1);
+ const dot = G(p, { o: 0 });
+ T(dot, 'dot product', { x: 90, y: 700, size: 32, weight: 600, fill: COL.task });
+ T(dot, 'a row times a column: multiply, then add', { x: 90, y: 745, size: 28, fill: COL.dim });
+ show(dot, m('dot') + 1);
+ say(p, ['(2, 5) · (1, 2) = 12'], 90, 800, m('dot') + 5, { size: 34, fill: ROWC[0] });
+ rowBandA(p, g, 0, m('dot') + 5, m('dot') + 8);
+ say(p, ['(1, 3) · (1, 2) = 7'], 450, 800, m('dot') + 8, { size: 34, fill: ROWC[1] });
+ rowBandA(p, g, 1, m('dot') + 8, m('dot') + 11);
+ }],
+
+ ['rows2', 'By rows, with a minus', (m) => {
+ const p = panel(0);
+ text(p, 'By rows, then check by columns', 60, 110, .2, { size: 40, weight: 600 });
+ const g = S.g = g2Of(p, [[3, -2], [1, 2]], [2, 1], { t0: m('A') - .4 });
+ hideX(g); hideAx(g);
+ g.labels(['col 1', 'col 2']);
+ put(g.M, { o: 0 }); show(g.M, m('A') - .2, .4);
+ put(g.parts.cols, { o: .35 });
+ [0, 1].forEach(i => put(g.res(i), { o: 0 }));
+ pulseAll(['a00', 'a01', 'a10', 'a11'].map(k => g.num(k)[0]), m('A') + .6, .8);
+ pulseAll(['x0', 'x1'].map(k => g.num(k)[0]), m('A') + 5, .6);
+ [0, 1].forEach(i => {
+ const r = m(`r${i + 1}`), s = m(`s${i + 1}`);
+ rowBandA(p, g, i, r, i ? m('ans') : m('r2'));
+ xBand(p, g, r + .5, i ? m('ans') : m('r2'));
+ rowWork(p, i ? [1, 2] : [3, -2], [2, 1], 70, 490 + i * 75, { from: [aAt(g, i, 0), aAt(g, i, 1)], xFrom: [xAt(g, 0), xAt(g, 1)], tm: r + .3, ts: s, tr: s + 1 });
+ show(g.res(i), s + 1.4, .4);
+ });
+ tw(g.parts.cols, { o: 1 }, m('chk'), .4);
+ colWork(p, [2, 1], [[3, 1], [-2, 2]], 70, 700, { terms: [m('chk') + .3, m('chk') + 3.2], prod: m('chk') + 4.5, sum: m('add') + 1.5 }, { size: 34 });
+ show(g.combo[0], m('chk') + .5, .5); show(g.combo[1], m('chk') + 3.4, .6);
+ [g.axArrow, g.axDot, g.axLab].forEach(e => show(e, m('add') + 1.5, .5));
+ }],
+
+ ['why', 'Why the two ways agree', (m) => {
+ const p = panel(0);
+ text(p, 'The same four products', 60, 110, .2, { size: 40, weight: 600 });
+ const A = mtx(p, [[2, 5], [1, 3]], 90, 250, { size: 50, cw: 90, rh: 70 });
+ mtx(p, [[1], [2]], 310, 250, { size: 50, cw: 70, rh: 70, fill: COL.chalk });
+ // the four products in a 2 × 2 table: column j holds x_j · column j, row i adds up to the i-th number of Ax
+ const cx = [860, 1110], cy = [330, 430], cells = [];
+ [[2, 1, 5, 2], [1, 1, 3, 2]].forEach(([a, x, b, y], i) => [[a, x], [b, y]].forEach(([u, w], j) => {
+ const e = M(p, [`${u}·${w} = ${u * w}`], { x: cx[j], y: cy[i], size: 46, anchor: 'middle', fill: COLC[j], o: 0 });
+ show(e, m('grid') + .6 + (i * 2 + j) * .9); cells.push(e);
+ }));
+ frame(p, cx[0] - 120, cy[0] - 58, 240, 190, COLC[0], m('colway'), m('rowway'));
+ frame(p, cx[1] - 130, cy[0] - 58, 260, 190, COLC[1], m('colway') + 1.5, m('rowway'));
+ const cw = lineUp(p, [{ v: [2, 1], fill: COLC[0] }, '+', { v: [10, 6], fill: COLC[1] }, '=', { v: [12, 7], fill: COL.task }], 820, 610, { size: 42 });
+ cw.forEach((r, k) => show(r.e, m('colway') + 3 + k * .5, .4));
+ text(p, 'columns, then add', 1420, 600, m('colway') + 5, { size: 26, fill: COLC[0], weight: 600, anchor: 'middle' });
+ [0, 1].forEach(i => {
+ frame(p, cx[0] - 130, cy[i] - 50, 520, 70, ROWC[i], m('rowway') + i * 1.6, m('same') + 2);
+ say(p, [`→ ${i ? '1 + 6 = 7' : '2 + 10 = 12'}`], 1270, cy[i], m('rowway') + .8 + i * 1.6, { size: 40, fill: COL.task });
+ });
+ text(p, 'rows, added across', 1420, 500, m('rowway') + 4, { size: 26, fill: ROWC[0], weight: 600, anchor: 'middle' });
+ cells.forEach((e, k) => pulse(e, m('same') + .5 + k * .3, 1.25));
+ const use = G(p, { o: 0 });
+ T(use, 'by hand: rows are often quicker', { x: 90, y: 720, size: 32, weight: 600, fill: ROWC[0] });
+ T(use, 'to see it: columns are often clearer', { x: 90, y: 775, size: 32, weight: 600, fill: COLC[0] });
+ show(use, m('use') + 2);
+ flashEl(A.cells[0][0], m('grid') + .6); flashEl(A.cells[0][1], m('grid') + 1.5); flashEl(A.cells[1][0], m('grid') + 2.4); flashEl(A.cells[1][1], m('grid') + 3.3);
+ }],
+
+ ['system', 'Ax = b, read two ways', (m) => {
+ const p = panel(0);
+ text(p, 'Ax = b, read two ways', 60, 110, .2, { size: 40, weight: 600 });
+ const A = mtx(p, [[2, -1], [-1, 2]], 90, 230, { size: 50, cw: 90, rh: 68, o: 0 });
+ const X = mtx(p, [['x'], ['y']], 310, 230, { size: 50, cw: 60, rh: 68, o: 0 });
+ const eq = M(p, ['='], { x: 420, y: 280, size: 50, o: 0 });
+ const B = mtx(p, [[0], [3]], 460, 230, { size: 50, cw: 70, rh: 68, fill: COL.task, o: 0 });
+ [A.g, X.g, eq].forEach(e => show(e, m('A') + .3, .5)); show(B.g, m('b'), .5);
+ pulseAll(A.cells.flat(), m('A') + 4, .6); pulseAll(X.cells.flat(), m('A') + 7.5, .7);
+ // each row times (x, y): the letters fly in from x
+ const lineRow = (i, a, y, t, res) => {
+ const w = tokens(p, [{ t: paren(a[0]), fill: COLC[0] }, '·', 'x', ' + ', { t: paren(a[1]), fill: COLC[1] }, '·', 'y', ' = ', res], { x: 70, y, size: 40 });
+ w.forEach(e => put(e, { o: 0 }));
+ [[0, A.at(i, 0)], [4, A.at(i, 1)], [2, X.at(0, 0)], [6, X.at(1, 0)]].forEach(([k, [fx_, fy]], n) => { const e = w[k]; put(e, { x: fx_, y: fy }); show(e, t + n * .4, .2); tw(e, { x: e._px, y }, t + n * .4, .8); });
+ [1, 3, 5].forEach(k => show(w[k], t + .8, .3)); show(w[7], t + 2.4, .3); show(w[8], t + 2.8, .4);
+ band(p, 96, A.at(i, 0)[1] - 50, 196, 68, ROWC[i], t, t + 4);
+ };
+ lineRow(0, [2, -1], 470, m('r1') + .2, '2x − y');
+ lineRow(1, [-1, 2], 545, m('r2') + .2, '−x + 2y');
+ // the rows: our two lines (linsys draws the equations and the row picture), then the columns
+ const sys = S.sys = linsys(p, { eq: [90, 660], mat: null, size: 44, sol: false, t0: m('b') + 1 });
+ sys.view('both', m('c') + .5, .8);
+ sys.labels(['col 1', 'col 2', 'b']);
+ text(p, 'row picture', 560, 690, m('b') + 4, { size: 26, fill: ROWC[0], weight: 600 });
+ const cw = lineUp(p, ['x', { v: [2, -1], fill: COLC[0] }, '+ y', { v: [-1, 2], fill: COLC[1] }, '=', { v: [0, 3], fill: COL.task }], 90, 845, { size: 34, rh: 40 });
+ cw.forEach((r, k) => show(r.e, m('c') + 1 + k * .4, .4));
+ text(p, 'column picture', 560, 840, m('c') + 4, { size: 26, fill: COLC[0], weight: 600 });
+ pulse(sys.meet, m('one') + 1);
+ frame(p, 50, 610, 470, 160, ROWC[0], m('one') + .3, m('one') + 2.6);
+ sys.lines.forEach(l => { tw(l.l, { 'a_stroke-width': 9 }, m('one') + .4, .3); tw(l.l, { 'a_stroke-width': 5 }, m('one') + 2, .5); });
+ frame(p, 70, 790, 400, 100, COLC[0], m('one') + 2.8);
+ sys.cols.forEach(c => { tw(c, { 'a_stroke-width': 9 }, m('one') + 3, .3); tw(c, { 'a_stroke-width': 5 }, m('one') + 4.6, .5); });
+ }],
+
+ ['q2', 'Your turn', () => {
+ const p = panel(0);
+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
+ const g = S.g = g2Of(p, [[1, 1], [1, -1]], [1, 0]);
+ g.labels(['col 1', 'col 2']);
+ target(g.P, [4, 2], p);
+ }, { ask: done => quiz(LOW, [{
+ id: 'c-land', prompt: ['Drag the point ', $m('x'), ' (or change its numbers) until ', $m('Ax'), ' lands on ', $m('(4, 2)'), '.'],
+ build: g2Task(S.g, v => v.x0 + v.x1 === 4 && v.x0 - v.x1 === 2, 'x = (3, 1): 3·(1, 1) + 1·(1, −1) = (4, 2). By rows: 3 + 1 = 4 and 3 − 1 = 2.',
+ 'By rows: the first row says x₁ + x₂ = 4, the second x₁ − x₂ = 2. Which two numbers add to 4 and differ by 2?', () => S.g.set({ x0: 3, x1: 1 }), ['x']),
+ }], done) }],
+
+ ['bigger', 'A 3 by 3 matrix', (m) => {
+ const p = panel(0);
+ text(p, 'Three by three: the same two ways', 60, 110, .2, { size: 40, weight: 600 });
+ const A = mtx(p, [[1, 0, 2], [0, 3, 1], [2, 1, 0]], 90, 230, { size: 46, cw: 76, rh: 64, o: 0 });
+ const X = mtx(p, [[1], [2], [3]], 350, 230, { size: 46, cw: 60, rh: 64, fill: COL.chalk, o: 0 });
+ const eq = M(p, ['='], { x: 460, y: 295, size: 46, o: 0 });
+ const R = mtx(p, [[''], [''], ['']], 500, 230, { size: 46, cw: 70, rh: 64, o: 0 });
+ [A.g, X.g, R.g, eq].forEach(e => show(e, m('A') + .3, .5));
+ const res = [7, 9, 4].map((v, i) => T(p, String(v), { x: 545, y: 230 + 64 * i, size: 46, fill: COL.task, font: MATH, anchor: 'middle', o: 0 }));
+ const rows = [[1, 0, 2], [0, 3, 1], [2, 1, 0]];
+ rows.forEach((r, i) => {
+ const t = m(`r${i + 1}`);
+ band(p, 96, 230 + 64 * i - 44, 236, 60, ROWC[i], t, i < 2 ? m(`r${i + 2}`) : m('ans'));
+ rowWork(p, r, [1, 2, 3], 70, 470 + i * 72, { from: [0, 1, 2].map(j => A.at(i, j)), xFrom: [0, 1, 2].map(j => X.at(j, 0)), tm: t + .3, ts: t + 4.5, tr: t + 6, size: 36 });
+ show(res[i], t + 7, .4);
+ });
+ [0, 1, 2].forEach(j => band(p, 90 + 10 + 76 * j + 4, 186, 68, 186, COLC[j], m('c') + .4 + j * .8, m('sum') + 6));
+ const cw = colWork(p, [1, 2, 3], [[1, 0, 2], [0, 3, 1], [2, 1, 0]], 830, 300, { terms: [m('c') + .4, m('c') + 1.2, m('c') + 2], prod: m('sum') + .3, sum: m('sum') + 4 }, { size: 32, wrap: true });
+ text(p, 'by columns', 830, 200, m('c'), { size: 28, fill: COLC[0], weight: 600 });
+ text(p, 'by rows', 70, 420, m('r1'), { size: 28, fill: ROWC[0], weight: 600 });
+ }],
+
+ ['tall', 'A 3 by 2 matrix', (m) => {
+ const p = panel(0);
+ text(p, 'A matrix that is not square', 60, 110, .2, { size: 40, weight: 600 });
+ const A = mtx(p, [[1, 2], [0, 1], [3, -1]], 90, 230, { size: 46, cw: 76, rh: 64, o: 0 });
+ show(A.g, m('A') + .2, .5);
+ const X = mtx(p, [[4], [1]], 290, 262, { size: 46, cw: 60, rh: 64, fill: COL.chalk, o: 0 });
+ show(X.g, m('x') + .2, .5);
+ show(M(p, ['='], { x: 400, y: 312, size: 46, o: 0 }), m('rows'));
+ const res = [6, 1, 11].map((v, i) => T(p, String(v), { x: 490, y: 230 + 64 * i, size: 46, fill: COL.task, font: MATH, anchor: 'middle', o: 0 }));
+ const R = mtx(p, [[''], [''], ['']], 440, 230, { size: 46, cw: 80, rh: 64, o: 0 }); show(R.g, m('rows'));
+ [0, 1].forEach(j => band(p, 104 + 76 * j, 186, 68, 186, COLC[j], m('A') + 2 + j * .6, m('x') + 3));
+ [[1, 2], [0, 1], [3, -1]].forEach((r, i) => {
+ const t = m('rows') + i * 2.3;
+ rowWork(p, r, [4, 1], 70, 480 + i * 70, { from: [A.at(i, 0), A.at(i, 1)], xFrom: [X.at(0, 0), X.at(1, 0)], tm: t, ts: t + 1.2, tr: t + 1.8, size: 36 });
+ show(res[i], t + 2.2, .3);
+ });
+ colWork(p, [4, 1], [[1, 0, 3], [2, 1, -1]], 830, 300, { terms: [m('cols') + .3, m('cols') + 1.4], prod: m('cols') + 2.6, sum: m('cols') + 4.6 }, { size: 34 });
+ // sizes: 2 columns ↔ 2 numbers in x; 3 rows ↔ 3 numbers in Ax
+ frame(p, 96, 180, 168, 190, COLC[0], m('sizes') + .3, m('sizes') + 4.5);
+ frame(p, 284, 214, 72, 124, COLC[0], m('sizes') + 1.2, m('sizes') + 4.5);
+ frame(p, 90, 180, 186, 190, ROWC[0], m('sizes') + 4.6);
+ frame(p, 438, 180, 102, 190, ROWC[0], m('sizes') + 5.4);
+ const note = G(p, { o: 0 });
+ T(note, '2 columns → x has 2 numbers', { x: 830, y: 640, size: 32, weight: 600, fill: COLC[0] });
+ T(note, '3 rows → Ax has 3 numbers', { x: 830, y: 690, size: 32, weight: 600, fill: ROWC[0] });
+ show(note, m('sizes') + 1.5);
+ }],
+
+ ['match', 'The sizes must fit', (m) => {
+ const p = panel(0);
+ text(p, 'When the sizes do not fit', 60, 110, .2, { size: 40, weight: 600 });
+ const A = mtx(p, [[1, 2], [0, 1], [3, -1]], 90, 230, { size: 46, cw: 76, rh: 64 });
+ const X = mtx(p, [[4], [1], [2]], 290, 230, { size: 46, cw: 60, rh: 64, fill: COL.chalk, o: 0 });
+ show(X.g, m('try') + .3, .5);
+ pulse(X.cells[2][0], m('try') + 2);
+ // by columns: x's numbers pair with columns; the third has none
+ const pairs = G(p, { o: 0 });
+ [['4', '· column 1', COLC[0]], ['1', '· column 2', COLC[1]], ['2', '· column 3 ?', COL.bad]].forEach(([k, s, c], i) => {
+ T(pairs, k, { x: 860, y: 260 + i * 60, size: 38, fill: COL.chalk, font: MATH, anchor: 'end' });
+ T(pairs, s, { x: 875, y: 258 + i * 60, size: 32, fill: c, weight: 600 });
+ });
+ show(pairs, m('cols') + .5);
+ frame(p, 284, 154 + 128, 72, 64, COL.bad, m('cols') + 2);
+ text(p, 'by columns', 860, 200, m('cols'), { size: 28, fill: COLC[0], weight: 600 });
+ // by rows: row 1 has two numbers, x has three
+ text(p, 'by rows', 860, 470, m('rows'), { size: 28, fill: ROWC[0], weight: 600 });
+ const w = tokens(p, [{ t: '1', fill: COLC[0] }, '·', '4', ' + ', { t: '2', fill: COLC[1] }, '·', '1', ' + ', { t: '?', fill: COL.bad }, '·', '2'], { x: 860, y: 540, size: 40 });
+ w.forEach((e, k) => { put(e, { o: 0 }); show(e, m('rows') + 1 + k * .25, .3); });
+ band(p, 96, 230 - 44, 168, 60, ROWC[0], m('rows') + .5, m('no'));
+ const no = G(p, { o: 0 });
+ T(no, 'Ax is not defined', { x: 860, y: 640, size: 40, weight: 600, fill: COL.bad });
+ show(no, m('no'));
+ const rule = G(p, { o: 0 });
+ T(rule, 'x: one number for each column of A', { x: 90, y: 700, size: 32, weight: 600, fill: COLC[0] });
+ T(rule, 'Ax: one number for each row of A', { x: 90, y: 750, size: 32, weight: 600, fill: ROWC[0] });
+ show(rule, m('rule') + .5);
+ frame(p, 96, 180, 168, 190, COLC[0], m('rule') + 2, m('rule') + 5); frame(p, 284, 180, 72, 190, COLC[0], m('rule') + 2.6, m('rule') + 5);
+ frame(p, 90, 180, 186, 190, ROWC[0], m('rule') + 5.4);
+ tw(X.cells[2][0], { c_fill: COL.bad }, m('cols') + 2, .4);
+ }],
+
+ ['q3', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ M(p, ['A ='], { x: 90, y: 300, size: 44, anchor: 'start' }); mtx(p, [[2, 0, 1], [1, 3, -1]], 180, 270, { size: 44, cw: 76, rh: 66 });
+ M(p, ['x ='], { x: 90, y: 520, size: 44, anchor: 'start' }); mtx(p, [[1], [2], [4]], 180, 456, { size: 44, cw: 60, rh: 56, fill: COL.chalk });
+ }, { ask: done => quiz(SIDE, [{
+ id: 'c-rows', prompt: ['Work out ', $m('Ax'), ' by rows.'],
+ build: blanks(rowRows({ A: [[2, 0, 1], [1, 3, -1]], x: [1, 2, 4] })),
+ }], done) }],
+
+ ['q4', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ M(p, ['A ='], { x: 90, y: 330, size: 44, anchor: 'start' }); mtx(p, [[5, 1], [2, 0], [-1, 3]], 180, 270, { size: 44, cw: 76, rh: 62 });
+ }, { ask: done => quiz(SIDE, [{
+ id: 'c-fit', prompt: ['This ', $m('A'), ' is 3 by 2. Which ', $m('x'), ' can it multiply?'],
+ build: choice([['x with 2 numbers'], ['x with 3 numbers'], ['either one']], 0, 'One number of x for each column of A: 2 columns, 2 numbers.',
+ ['', 'Count the columns, not the rows: A has 2 columns, so x needs 2 numbers.', 'Only one fits: x needs exactly one number per column.']),
+ }, {
+ id: 'c-out', prompt: ['And how many numbers does ', $m('Ax'), ' have?'],
+ build: blanks([{ parts: ['Ax has ', { box: '3' }, ' numbers'], why: 'One for each row: 3.', hint: 'Each row of A makes one number of Ax.' }]),
+ }], done) }],
+
+ ['wrap', 'Summary', (m) => {
+ const p = panel(0);
+ [['By columns: Ax = x₁·(column 1) + x₂·(column 2) + …', 'w1'], ['By rows: each number of Ax is a row of A times x (a dot product).', 'w2'],
+ ['Both ways use the same products, so they always agree.', 'w3'], ['x: one number per column of A. Ax: one number per row.', 'w4']].forEach(([str, mark], i) => {
+ const g = G(p, { x: -16, y: 160 + i * 105, o: 0 });
+ mk('circle', { cx: 150, cy: -12, r: 26, fill: COL.task }, g);
+ T(g, String(i + 1), { x: 150, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });
+ T(g, str, { x: 210, size: 34, weight: 600 });
+ tw(g, { o: 1, x: 0 }, m(mark), .6);
+ });
+ // the lecture example, both ways, small
+ const A = mtx(p, [[2, 5], [1, 3]], 300, 660, { size: 40, cw: 66, rh: 56, o: 0 });
+ const X = mtx(p, [[1], [2]], 462, 660, { size: 40, cw: 52, rh: 56, fill: COL.chalk, o: 0 });
+ const R = mtx(p, [[12], [7]], 610, 660, { size: 40, cw: 60, rh: 56, fill: COL.task, o: 0 });
+ const e = M(p, ['='], { x: 572, y: 700, size: 40, o: 0 });
+ [A.g, X.g, R.g, e].forEach(x => show(x, m('w1') + .5));
+ [0, 1].forEach(j => band(p, 300 + 10 + 66 * j + 3, 616, 60, 112, COLC[j], m('w1') + 1.5 + j * .7, m('w2')));
+ [0, 1].forEach(i => band(p, 306, 660 + 56 * i - 38, 136, 52, ROWC[i], m('w2') + .6 + i * .7, m('w3')));
+ say(p, ['1·(2, 1) + 2·(5, 3) = (12, 7)'], 800, 680, m('w1') + 2.5, { size: 34, fill: COLC[0] });
+ say(p, ['2·1 + 5·2 = 12, 1·1 + 3·2 = 7'], 800, 740, m('w2') + 1.5, { size: 34, fill: ROWC[0] });
+ frame(p, 780, 630, 560, 140, COL.task, m('w3') + .5, m('w4'));
+ [0, 1].forEach(j => band(p, 300 + 10 + 66 * j + 3, 616, 60, 112, COLC[j], m('w4') + .5, m('w4') + 2.5)); band(p, 462, 616, 72, 112, COLC[0], m('w4') + 1, m('w4') + 2.5, .15);
+ [0, 1].forEach(i => band(p, 306, 660 + 56 * i - 38, 136, 52, ROWC[i], m('w4') + 2.8 + i * .3, m('end'))); band(p, 610, 616, 80, 112, ROWC[0], m('w4') + 3.4, m('end'), .15);
+ }],
+ ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, COLQ.map((q, k) => ({
+ id: `p-cols${k + 1}`, prompt: ['By columns: ', prodEl(q.A, q.x)], build: blanks(colRows(q)),
+ })), done, 'Chapter practice · set 1 of 4') }],
+ ['final2', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, ROWQ.map((q, k) => ({
+ id: `p-rows${k + 1}`, prompt: ['By rows: ', prodEl(q.A, q.x)], build: blanks(rowRows(q)),
+ })), done, 'Chapter practice · set 2 of 4') }],
+ ['final3', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
+ id: 'p-fit', prompt: ['Can ', $m('A'), ' multiply this ', $m('x'), '?'],
+ build: grid(FITQ, [['y', 'Yes', COL.good, 'Y'], ['n', 'No', COL.bad, 'N']], { multi: false, text: true }),
+ }, {
+ id: 'p-out', prompt: ['How many numbers?'],
+ build: blanks([
+ { parts: ['A is 3 by 5: x has ', { box: '5' }, ', Ax has ', { box: '3' }], why: 'x: one per column (5). Ax: one per row (3).', hint: 'x matches the columns (the second number), Ax the rows (the first).' },
+ { parts: ['A is 1 by 2: Ax has ', { box: '1' }, ' number'], why: 'One row, one number: a single dot product.', hint: 'One number of Ax for each row of A.' },
+ { parts: ['A is 4 by 4: Ax has ', { box: '4' }, ' numbers'], why: 'Four rows, four numbers.', hint: 'One number of Ax for each row of A.' },
+ ]),
+ }], done, 'Chapter practice · set 3 of 4') }],
+ ['final4', 'Chapter practice', () => {
+ const p = panel(0);
+ text(p, 'Make Ax land', 60, 110, .2, { size: 40, weight: 600 });
+ S.g = g2Of(p, [[2, 1], [1, 1]], [0, 0]);
+ S.g.labels(['col 1', 'col 2']);
+ S.tg = G(p, {});
+ }, { ask: done => {
+ const from = (A, x, tgt, f) => (body, api) => { S.g.set({ a00: A[0][0], a01: A[0][1], a10: A[1][0], a11: A[1][1], x0: x[0], x1: x[1] }); S.tg.replaceChildren(); target(S.g.P, tgt, S.tg, 0); put(S.tg.lastChild, { o: 1 }); return f(body, api); };
+ const at = (v, [a, b]) => { const [p, q] = [v.a00 * v.x0 + v.a01 * v.x1, v.a10 * v.x0 + v.a11 * v.x1]; return p === a && q === b; };
+ quiz(LOW, [{
+ id: 'p-land1', prompt: ['Move ', $m('x'), ' until ', $m('Ax'), ' lands on ', $m('(5, 3)'), '.'],
+ build: from([[2, 1], [1, 1]], [0, 0], [5, 3], g2Task(S.g, v => at(v, [5, 3]), 'x = (2, 1): 2·(2, 1) + 1·(1, 1) = (5, 3).',
+ 'Rows: 2x₁ + x₂ = 5 and x₁ + x₂ = 3. Subtract: x₁ = 2.', () => S.g.set({ x0: 2, x1: 1 }), ['x'])),
+ }, {
+ id: 'p-land2', prompt: ['Now ', $m('x = (1, 1)'), ' stays. Change ', $m('A'), ' (drag a column, or its numbers) so that ', $m('Ax = (3, 1)'), '.'],
+ build: from([[1, 0], [0, 1]], [1, 1], [3, 1], g2Task(S.g, v => at(v, [3, 1]), 'x = (1, 1) means one of each column: column 1 + column 2 = (3, 1). Many matrices do it, for example columns (2, 0) and (1, 1).',
+ 'With x = (1, 1), Ax is column 1 + column 2. Make the two columns add up to (3, 1).', () => S.g.set({ a00: 2, a01: 1, a10: 0, a11: 1 }), ['A', 'cols'])),
+ }, {
+ id: 'p-land3', prompt: ['Now ', $m('x = (0, 2)'), '. Change ', $m('A'), ' so that ', $m('Ax = (−2, 4)'), '.'],
+ build: from([[1, 0], [0, 1]], [0, 2], [-2, 4], g2Task(S.g, v => at(v, [-2, 4]), 'x = (0, 2) takes no column 1 and two of column 2: column 2 must be (−1, 2). Column 1 can be anything.',
+ 'x = (0, 2) means 0 of column 1 plus 2 of column 2. So 2 · column 2 = (−2, 4).', () => S.g.set({ a01: -1, a11: 2 }), ['A', 'cols'])),
+ }], done, 'Chapter practice · set 4 of 4');
+ } }],
+ ['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],
+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
+
+boot();
+</script>
+</body>
+</html>
diff --git a/site/linear-algebra/ch11/audio/en/cloud.mp3 b/site/linear-algebra/ch11/audio/en/cloud.mp3
new file mode 100644
index 0000000..5c8ed05
Binary files /dev/null and b/site/linear-algebra/ch11/audio/en/cloud.mp3 differ
diff --git a/site/linear-algebra/ch11/audio/en/cross.mp3 b/site/linear-algebra/ch11/audio/en/cross.mp3
new file mode 100644
index 0000000..376e17e
Binary files /dev/null and b/site/linear-algebra/ch11/audio/en/cross.mp3 differ
diff --git a/site/linear-algebra/ch11/audio/en/final1.mp3 b/site/linear-algebra/ch11/audio/en/final1.mp3
new file mode 100644
index 0000000..5f7171a
Binary files /dev/null and b/site/linear-algebra/ch11/audio/en/final1.mp3 differ
diff --git a/site/linear-algebra/ch11/audio/en/final2.mp3 b/site/linear-algebra/ch11/audio/en/final2.mp3
new file mode 100644
index 0000000..136fa99
Binary files /dev/null and b/site/linear-algebra/ch11/audio/en/final2.mp3 differ
diff --git a/site/linear-algebra/ch11/audio/en/final3.mp3 b/site/linear-algebra/ch11/audio/en/final3.mp3
new file mode 100644
index 0000000..3f12441
Binary files /dev/null and b/site/linear-algebra/ch11/audio/en/final3.mp3 differ
diff --git a/site/linear-algebra/ch11/audio/en/final4.mp3 b/site/linear-algebra/ch11/audio/en/final4.mp3
new file mode 100644
index 0000000..b925d96
Binary files /dev/null and b/site/linear-algebra/ch11/audio/en/final4.mp3 differ
diff --git a/site/linear-algebra/ch11/audio/en/finish.mp3 b/site/linear-algebra/ch11/audio/en/finish.mp3
new file mode 100644
index 0000000..f3c495f
Binary files /dev/null and b/site/linear-algebra/ch11/audio/en/finish.mp3 differ
diff --git a/site/linear-algebra/ch11/audio/en/intro.mp3 b/site/linear-algebra/ch11/audio/en/intro.mp3
new file mode 100644
index 0000000..128be8a
Binary files /dev/null and b/site/linear-algebra/ch11/audio/en/intro.mp3 differ
diff --git a/site/linear-algebra/ch11/audio/en/missing.mp3 b/site/linear-algebra/ch11/audio/en/missing.mp3
new file mode 100644
index 0000000..3482023
Binary files /dev/null and b/site/linear-algebra/ch11/audio/en/missing.mp3 differ
diff --git a/site/linear-algebra/ch11/audio/en/off.mp3 b/site/linear-algebra/ch11/audio/en/off.mp3
new file mode 100644
index 0000000..aea3713
Binary files /dev/null and b/site/linear-algebra/ch11/audio/en/off.mp3 differ
diff --git a/site/linear-algebra/ch11/audio/en/point.mp3 b/site/linear-algebra/ch11/audio/en/point.mp3
new file mode 100644
index 0000000..b3213c2
Binary files /dev/null and b/site/linear-algebra/ch11/audio/en/point.mp3 differ
diff --git a/site/linear-algebra/ch11/audio/en/q1.mp3 b/site/linear-algebra/ch11/audio/en/q1.mp3
new file mode 100644
index 0000000..fd26a87
Binary files /dev/null and b/site/linear-algebra/ch11/audio/en/q1.mp3 differ
diff --git a/site/linear-algebra/ch11/audio/en/q2.mp3 b/site/linear-algebra/ch11/audio/en/q2.mp3
new file mode 100644
index 0000000..e74331f
Binary files /dev/null and b/site/linear-algebra/ch11/audio/en/q2.mp3 differ
diff --git a/site/linear-algebra/ch11/audio/en/q3.mp3 b/site/linear-algebra/ch11/audio/en/q3.mp3
new file mode 100644
index 0000000..4fda5ef
Binary files /dev/null and b/site/linear-algebra/ch11/audio/en/q3.mp3 differ
diff --git a/site/linear-algebra/ch11/audio/en/slide.mp3 b/site/linear-algebra/ch11/audio/en/slide.mp3
new file mode 100644
index 0000000..c3699ab
Binary files /dev/null and b/site/linear-algebra/ch11/audio/en/slide.mp3 differ
diff --git a/site/linear-algebra/ch11/audio/en/space.mp3 b/site/linear-algebra/ch11/audio/en/space.mp3
new file mode 100644
index 0000000..a95d1d4
Binary files /dev/null and b/site/linear-algebra/ch11/audio/en/space.mp3 differ
diff --git a/site/linear-algebra/ch11/audio/en/third.mp3 b/site/linear-algebra/ch11/audio/en/third.mp3
new file mode 100644
index 0000000..397371a
Binary files /dev/null and b/site/linear-algebra/ch11/audio/en/third.mp3 differ
diff --git a/site/linear-algebra/ch11/audio/en/tilt.mp3 b/site/linear-algebra/ch11/audio/en/tilt.mp3
new file mode 100644
index 0000000..31a5b98
Binary files /dev/null and b/site/linear-algebra/ch11/audio/en/tilt.mp3 differ
diff --git a/site/linear-algebra/ch11/audio/en/timings.js b/site/linear-algebra/ch11/audio/en/timings.js
new file mode 100644
index 0000000..89225f3
--- /dev/null
+++ b/site/linear-algebra/ch11/audio/en/timings.js
@@ -0,0 +1,791 @@
+window.TIMINGS = {
+ "intro": {
+ "dur": 17.544,
+ "marks": {
+ "sub": 4.635,
+ "move": 11.68
+ },
+ "cues": [
+ [
+ 0.104,
+ "Chapter eleven."
+ ],
+ [
+ 1.315,
+ "Three unknowns: a plane in space."
+ ],
+ [
+ 4.635,
+ "So far every equation had two unknowns, x and y, and every equation was a line."
+ ],
+ [
+ 11.68,
+ "Add a third unknown, and the line becomes a flat sheet, floating in space."
+ ]
+ ]
+ },
+ "third": {
+ "dur": 69.672,
+ "marks": {
+ "r0": 1.471,
+ "rp": 5.664,
+ "rl": 7.852,
+ "eq": 10.286,
+ "q": 16.185,
+ "x1": 19.727,
+ "z1": 26.784,
+ "ok1": 28.438,
+ "tri": 32.005,
+ "r2": 41.263,
+ "r3": 48.646,
+ "r4": 53.49,
+ "many": 59.076
+ },
+ "cues": [
+ [
+ 0.104,
+ "In chapter one, x plus y equals four had endlessly many solutions."
+ ],
+ [
+ 5.664,
+ "Each one was a pair of numbers, and the pairs made a line."
+ ],
+ [
+ 10.286,
+ "Now here is an equation with three unknowns: x plus y plus z equals three."
+ ],
+ [
+ 16.185,
+ "A solution has to give a number to each of the three letters."
+ ],
+ [
+ 19.727,
+ "Try x equals one and y equals one."
+ ],
+ [
+ 23.086,
+ "Then one plus one plus z has to be three, so z must be one."
+ ],
+ [
+ 28.438,
+ "One plus one plus one is three."
+ ],
+ [
+ 30.977,
+ "It works."
+ ],
+ [
+ 32.005,
+ "We write this solution as three numbers in brackets: one, one, one."
+ ],
+ [
+ 37.643,
+ "x first, then y, then z."
+ ],
+ [
+ 39.948,
+ "We call it a triple."
+ ],
+ [
+ 41.263,
+ "Here is another: three, zero, zero."
+ ],
+ [
+ 45.456,
+ "Three plus zero plus zero is three."
+ ],
+ [
+ 48.646,
+ "Zero, two, one: zero plus two plus one is three."
+ ],
+ [
+ 53.49,
+ "Negative numbers are allowed too: two plus two plus negative one is three."
+ ],
+ [
+ 59.076,
+ "Again there are endlessly many solutions, and each one is three numbers."
+ ],
+ [
+ 64.596,
+ "So where do they live?"
+ ],
+ [
+ 65.924,
+ "A pair was a point on a flat plane."
+ ],
+ [
+ 67.956,
+ "A triple needs more room."
+ ]
+ ]
+ },
+ "space": {
+ "dur": 38.088,
+ "marks": {
+ "flat": 0.117,
+ "xr": 3.568,
+ "yu": 4.701,
+ "pt": 5.703,
+ "lay": 8.151,
+ "back": 12.5,
+ "up": 17.669,
+ "floor": 22.656,
+ "turn": 28.932
+ },
+ "cues": [
+ [
+ 0.117,
+ "Here is the flat x y plane from chapter one."
+ ],
+ [
+ 3.568,
+ "x goes to the right, y goes up, and the pair two, one is a point on it."
+ ],
+ [
+ 8.151,
+ "Now lay this plane down flat, like a sheet of paper on a table."
+ ],
+ [
+ 12.5,
+ "x still goes to the right."
+ ],
+ [
+ 14.102,
+ "But y now points away from you, into the picture."
+ ],
+ [
+ 17.669,
+ "A third number needs a third direction: straight up."
+ ],
+ [
+ 20.977,
+ "That is the z axis."
+ ],
+ [
+ 22.656,
+ "The sheet we laid down is the floor, and everywhere on the floor, z is zero."
+ ],
+ [
+ 28.932,
+ "Watch the picture turn."
+ ],
+ [
+ 30.352,
+ "The floor stays flat and the z axis stays upright."
+ ],
+ [
+ 33.906,
+ "Whenever depth is hard to see, the turning shows it."
+ ]
+ ]
+ },
+ "point": {
+ "dur": 50.472,
+ "marks": {
+ "o": 2.982,
+ "x": 6.706,
+ "y": 9.18,
+ "z": 12.812,
+ "here": 14.648,
+ "shadow": 16.914,
+ "turn": 25.586,
+ "ex2": 30.247,
+ "x2": 34.036,
+ "y2": 36.875,
+ "z2": 38.451,
+ "here2": 43.359
+ },
+ "cues": [
+ [
+ 0.104,
+ "So how do we find a point like two, one, three?"
+ ],
+ [
+ 2.982,
+ "Start at the origin, where all three axes meet."
+ ],
+ [
+ 6.706,
+ "Go two steps along x, to the right."
+ ],
+ [
+ 9.18,
+ "Then one step in the y direction, away from you."
+ ],
+ [
+ 12.812,
+ "Then three steps straight up."
+ ],
+ [
+ 14.648,
+ "That is the point two, one, three."
+ ],
+ [
+ 16.914,
+ "Right under it, on the floor, is its shadow, the point two, one."
+ ],
+ [
+ 21.432,
+ "The third number says how high above the floor the point floats."
+ ],
+ [
+ 25.586,
+ "Turn the picture, and you can see it really is three steps above its shadow."
+ ],
+ [
+ 30.247,
+ "One more: negative one, two, negative two."
+ ],
+ [
+ 34.036,
+ "One step to the left, because x is negative."
+ ],
+ [
+ 36.875,
+ "Two steps away from you."
+ ],
+ [
+ 38.451,
+ "And two steps down, below the floor, because z is negative."
+ ],
+ [
+ 43.359,
+ "Every triple of numbers is exactly one point in space, and every point in space is one triple."
+ ]
+ ]
+ },
+ "cloud": {
+ "dur": 41.544,
+ "marks": {
+ "p1": 5.508,
+ "p2": 6.771,
+ "p3": 9.206,
+ "p4": 10.742,
+ "more": 12.435,
+ "look": 13.607,
+ "edge": 16.263,
+ "line": 18.021,
+ "plane": 24.31,
+ "rule": 28.945,
+ "name": 36.784
+ },
+ "cues": [
+ [
+ 0.104,
+ "Now let's put the solutions of x plus y plus z equals three into the picture."
+ ],
+ [
+ 5.508,
+ "One, one, one."
+ ],
+ [
+ 6.771,
+ "Three, zero, zero."
+ ],
+ [
+ 9.206,
+ "Zero, two, one."
+ ],
+ [
+ 10.742,
+ "Two, two, negative one."
+ ],
+ [
+ 12.435,
+ "And many more."
+ ],
+ [
+ 13.607,
+ "From here they look scattered, like a cloud."
+ ],
+ [
+ 16.263,
+ "But turn the picture just right, and every one of them lines up."
+ ],
+ [
+ 20.091,
+ "They all lie on one flat sheet, and we are looking at its edge."
+ ],
+ [
+ 24.31,
+ "Turn back, and there is the sheet."
+ ],
+ [
+ 26.562,
+ "A flat sheet like this is called a plane."
+ ],
+ [
+ 28.945,
+ "Every point on this plane is a solution of x plus y plus z equals three, and every solution is a point on it."
+ ],
+ [
+ 36.784,
+ "So in space, one equation in x, y and z is a plane."
+ ]
+ ]
+ },
+ "off": {
+ "dur": 25.632,
+ "marks": {
+ "p": 2.474,
+ "sum": 4.089,
+ "no": 7.617,
+ "above": 9.258,
+ "o": 13.086,
+ "o2": 17.305,
+ "below": 20.13,
+ "end": 21.536
+ },
+ "cues": [
+ [
+ 0.104,
+ "What about a point that is not on the plane?"
+ ],
+ [
+ 2.474,
+ "Take two, two, two."
+ ],
+ [
+ 4.089,
+ "Two plus two plus two is six, not three."
+ ],
+ [
+ 7.617,
+ "So it is not a solution."
+ ],
+ [
+ 9.258,
+ "It sits above the plane, on the side where the sum is too big."
+ ],
+ [
+ 13.086,
+ "Now take the origin, zero, zero, zero."
+ ],
+ [
+ 17.305,
+ "The sum is zero."
+ ],
+ [
+ 19.076,
+ "Too small."
+ ],
+ [
+ 20.13,
+ "It sits on the other side."
+ ],
+ [
+ 21.536,
+ "Only the points right on the plane add up to exactly three."
+ ]
+ ]
+ },
+ "q1": {
+ "dur": 4.536,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.198,
+ "Find the missing number, so that the point lies on the plane."
+ ]
+ ]
+ },
+ "cross": {
+ "dur": 67.896,
+ "marks": {
+ "eq": 9.753,
+ "xa": 13.047,
+ "px": 18.815,
+ "ya": 23.346,
+ "py": 28.477,
+ "za": 30.638,
+ "pz": 33.88,
+ "tri": 36.51,
+ "ex2": 44.271,
+ "a": 49.87,
+ "b": 54.297,
+ "c": 58.802,
+ "tri2": 63.503
+ },
+ "cues": [
+ [
+ 0.104,
+ "In chapter one, two points were enough to draw a line."
+ ],
+ [
+ 3.359,
+ "In space, three points pin down a plane, and the easiest three are where it crosses the axes."
+ ],
+ [
+ 9.753,
+ "Take x plus y plus z equals three."
+ ],
+ [
+ 13.047,
+ "On the x axis, y and z are both zero."
+ ],
+ [
+ 16.719,
+ "So x equals three, and the plane crosses the x axis at three, zero, zero."
+ ],
+ [
+ 23.346,
+ "On the y axis, x and z are zero, so y is three: zero, three, zero."
+ ],
+ [
+ 30.638,
+ "On the z axis, z is three: zero, zero, three."
+ ],
+ [
+ 36.51,
+ "Join the three points, and you get a triangle."
+ ],
+ [
+ 39.518,
+ "It is the corner of the plane where x, y and z are all positive."
+ ],
+ [
+ 44.271,
+ "A second example: three x plus two y plus two z equals six."
+ ],
+ [
+ 49.87,
+ "On the x axis, three x equals six, so x is two."
+ ],
+ [
+ 54.297,
+ "On the y axis, two y equals six, so y is three."
+ ],
+ [
+ 58.802,
+ "On the z axis, two z equals six, so z is three."
+ ],
+ [
+ 63.503,
+ "Three points, one triangle, and the whole plane goes through it."
+ ]
+ ]
+ },
+ "slide": {
+ "dur": 35.256,
+ "marks": {
+ "three": 3.034,
+ "one": 6.836,
+ "in": 9.193,
+ "zero": 15.612,
+ "origin": 17.279,
+ "neg": 24.219,
+ "par": 29.062
+ },
+ "cues": [
+ [
+ 0.104,
+ "Now let's change the numbers and watch the plane."
+ ],
+ [
+ 3.034,
+ "Here is x plus y plus z equals three again."
+ ],
+ [
+ 6.836,
+ "Change the three into a one."
+ ],
+ [
+ 9.193,
+ "The plane slides toward the origin."
+ ],
+ [
+ 11.966,
+ "It now crosses each axis at one instead of three."
+ ],
+ [
+ 15.612,
+ "Change it to zero, and the plane passes right through the origin, because zero plus zero plus zero is zero."
+ ],
+ [
+ 24.219,
+ "Make it negative two, and it slides past the origin, to the other side."
+ ],
+ [
+ 29.062,
+ "Just like a line in chapter one: changing the right side slides the plane."
+ ],
+ [
+ 33.919,
+ "It never tilts it."
+ ]
+ ]
+ },
+ "tilt": {
+ "dur": 57.696,
+ "marks": {
+ "three": 4.128,
+ "tilt": 10.729,
+ "why": 12.148,
+ "xa": 16.576,
+ "same": 23.685,
+ "zc": 32.826,
+ "zt": 38.685,
+ "minus": 44.206,
+ "neg": 48.177,
+ "sum": 52.07
+ },
+ "cues": [
+ [
+ 0.104,
+ "The numbers in front of x, y and z do something else."
+ ],
+ [
+ 4.128,
+ "Change x plus y plus z equals three into three x plus y plus z equals three."
+ ],
+ [
+ 10.729,
+ "The plane tilts."
+ ],
+ [
+ 12.148,
+ "Here is why."
+ ],
+ [
+ 13.125,
+ "On the x axis, y and z are zero, so three x equals three, and x is one."
+ ],
+ [
+ 20.182,
+ "The plane used to cross at three."
+ ],
+ [
+ 22.188,
+ "Now it crosses at one."
+ ],
+ [
+ 23.685,
+ "On the y axis and the z axis, nothing changed: they still cross at three."
+ ],
+ [
+ 29.896,
+ "So the plane swings, like a door on a hinge."
+ ],
+ [
+ 32.826,
+ "Now put the three in front of z instead: x plus y plus three z equals three."
+ ],
+ [
+ 38.685,
+ "This time the z crossing moves down to one, and the plane leans the other way."
+ ],
+ [
+ 44.206,
+ "And with negative x plus y plus z equals three, the x crossing jumps to negative three, behind the origin."
+ ],
+ [
+ 52.07,
+ "So the right side slides the plane, and the numbers in front of x, y and z tilt it."
+ ]
+ ]
+ },
+ "q2": {
+ "dur": 4.056,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.107,
+ "Where does this plane cross the three axes?"
+ ]
+ ]
+ },
+ "missing": {
+ "dur": 48.048,
+ "marks": {
+ "eq1": 1.602,
+ "zero": 3.203,
+ "floor": 11.276,
+ "eq2": 15.026,
+ "wall": 21.211,
+ "eq3": 23.711,
+ "line": 27.357,
+ "free": 32.526,
+ "rise": 40.247,
+ "sum": 42.435
+ },
+ "cues": [
+ [
+ 0.104,
+ "What if a letter is missing?"
+ ],
+ [
+ 1.602,
+ "Take z equals two."
+ ],
+ [
+ 3.203,
+ "That is really zero x plus zero y plus z equals two."
+ ],
+ [
+ 8.034,
+ "x and y can be anything, but z must be two."
+ ],
+ [
+ 11.276,
+ "So the plane is flat, like a floor, at height two."
+ ],
+ [
+ 15.026,
+ "x equals one works the same way: y and z are free, and x must be one."
+ ],
+ [
+ 21.211,
+ "That plane stands upright, like a wall."
+ ],
+ [
+ 23.711,
+ "Now something from chapter one: x plus y equals two."
+ ],
+ [
+ 27.357,
+ "On the floor, where z is zero, that is just the line from chapter one."
+ ],
+ [
+ 32.526,
+ "But z is missing, so z is free."
+ ],
+ [
+ 35.794,
+ "Every point straight above or below that line is a solution too."
+ ],
+ [
+ 40.247,
+ "The line rises into a wall."
+ ],
+ [
+ 42.435,
+ "A missing letter is a free letter, and the plane runs straight along that letter's axis."
+ ]
+ ]
+ },
+ "q3": {
+ "dur": 7.56,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn."
+ ],
+ [
+ 1.016,
+ "Change the numbers, or drag the plane, until it crosses all three axes at the marked points."
+ ]
+ ]
+ },
+ "wrap": {
+ "dur": 28.056,
+ "marks": {
+ "w1": 0.964,
+ "w2": 7.135,
+ "w3": 12.083,
+ "w4": 16.888,
+ "end": 25.99
+ },
+ "cues": [
+ [
+ 0.104,
+ "To sum up."
+ ],
+ [
+ 0.964,
+ "A point in space is a triple of numbers: x steps along, y steps back, z steps up."
+ ],
+ [
+ 7.135,
+ "The solutions of one equation in x, y and z make a flat plane."
+ ],
+ [
+ 12.083,
+ "Find where it crosses the three axes, and three points pin it down."
+ ],
+ [
+ 16.888,
+ "The right side slides the plane; the numbers in front of x, y and z tilt it; a missing letter makes it a floor or a wall."
+ ],
+ [
+ 25.99,
+ "Now try the chapter practice."
+ ]
+ ]
+ },
+ "final1": {
+ "dur": 2.856,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Chapter practice."
+ ],
+ [
+ 1.536,
+ "Is the point on the plane?"
+ ]
+ ]
+ },
+ "final2": {
+ "dur": 2.256,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Next, find the missing number."
+ ]
+ ]
+ },
+ "final3": {
+ "dur": 4.56,
+ "marks": {},
+ "cues": [
+ [
+ 0.078,
+ "Now find where each plane crosses the axes, and what kind of plane it is."
+ ]
+ ]
+ },
+ "final4": {
+ "dur": 3.024,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Last set."
+ ],
+ [
+ 1.185,
+ "Make the plane with your hands."
+ ]
+ ]
+ },
+ "finish": {
+ "dur": 12.456,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Well done."
+ ],
+ [
+ 1.146,
+ "That's the end of chapter eleven, three unknowns: a plane in space."
+ ],
+ [
+ 6.641,
+ "Next: three equations, three planes, and the one point where they all meet."
+ ]
+ ]
+ }
+};
diff --git a/site/linear-algebra/ch11/audio/en/wrap.mp3 b/site/linear-algebra/ch11/audio/en/wrap.mp3
new file mode 100644
index 0000000..7f9d40d
Binary files /dev/null and b/site/linear-algebra/ch11/audio/en/wrap.mp3 differ
diff --git a/site/linear-algebra/ch11/index.html b/site/linear-algebra/ch11/index.html
new file mode 100644
index 0000000..92cb2d8
--- /dev/null
+++ b/site/linear-algebra/ch11/index.html
@@ -0,0 +1,515 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>Three Unknowns: A Plane in Space</title>
+<link rel="stylesheet" href="../lib/engine.css">
+<link rel="expect" href="#bar" blocking="render"><!-- hold the first frame until the player exists, so the page transition can run -->
+</head>
+<body>
+<script src="../lib/engine.js"></script>
+<script src="../lib/math.js"></script>
+<script src="../lib/linsys.js"></script>
+<script src="../lib/space3.js"></script>
+<script src="audio/en/timings.js"></script>
+<script>
+'use strict';
+const CHAPTER = { number: 11, title: 'Three Unknowns: A Plane in Space', minutes: 12, language: 'en' };
+
+/* ---------- chapter drawing helpers ---------- */
+const BLUE = S3_ROW[0]; // the one equation's plane: blue, as row 1 everywhere in the book
+const AXC = [COL.whole, COL.nat, COL.int]; // the steps along x, y, z (as chapter 1's walk: x blue, y coral)
+const VIEW = { yaw: 30, pitch: 24 }; // x runs right and back, y left and back, z up: the origin's corner faces us
+const CARD = { x: 40, y: 290, w: 720, cls: 'side' }; // question card under the one equation, beside the space
+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 r1 = n => Math.round(n * 10) / 10;
+const tri = q => `(${q.map(c => num(r1(c))).join(', ')})`;
+// One equation a·x + b·y + c·z = d, top left, and its plane in space on the right.
+const onePlane = (p, a, b, c, d, { t0 = .1, view = VIEW } = {}) => lin3(p, { rows: 1, A: [[a, b, c], [0, 0, 0], [0, 0, 0]], b: [d, 0, 0], eq: [90, 200], size: 50, space: { ...view }, t0 });
+const flash = (sys, key, t0) => sys.num(key).forEach(e => { tw(e, { c_fill: COL.task }, t0, .25); tw(e, { c_fill: COL.chalk }, t0 + 1.2, .6); });
+const glowPl = (pl, t0) => { prog(q => pl.width(3 + 5 * Math.sin(Math.PI * q)), t0, 1.2, lin); };
+// Amber dots where the plane crosses the three axes, following the numbers; labels keep tick numbers away.
+const crossings = (sys, t0 = 0, { labels = true } = {}) => {
+ const V = sys.space, g = G(V.content, { o: 0 });
+ const dots = [0, 1, 2].map(() => V.point(null, { color: COL.task, r: 8, size: 24, into: g }));
+ sys.onChange(v => [0, 1, 2].forEach(j => {
+ const a = v[`a0${j}`], c = Math.abs(a) > 1e-6 ? v.b0 / a : null, ok = c !== null && Math.abs(c) <= V.R + 1e-6, q = [0, 0, 0];
+ if (ok) q[j] = c;
+ dots[j].set(ok ? q : null);
+ if (ok && labels) dots[j].label(tri(q));
+ }));
+ V.avoid(proj => dots.filter(d => d.pos && labels).flatMap(d => { const q = proj(d.pos); return [[q[0] + 30, q[1] - 22], [q[0] + 75, q[1] - 22]]; }));
+ show(g, t0, .4);
+ return g;
+};
+const legend = (p, t0s, y0 = 610) => [['x', 'to the right'], ['y', 'away from you'], ['z', 'up']].map(([n, s], j) => {
+ const g = G(p, { o: 0 });
+ M(g, [n], { x: 90, y: y0 + j * 52, size: 36, fill: AXC[j], anchor: 'start' });
+ T(g, s, { x: 130, y: y0 + j * 52, size: 28, fill: COL.dim });
+ show(g, t0s[j]);
+ return g;
+});
+
+/* ---------- practice data ---------- */
+const YN = [['y', 'Yes', null, 'Y'], ['n', 'No', null, 'N']];
+const ONQ = [
+ { parts: ['Is ', $m('(4, 0, 0)'), ' on ', $m('x + 2y − z = 4'), '?'], ans: ['y'], why: '4 + 0 − 0 = 4. Yes: it is where the plane crosses the x-axis.' },
+ { parts: ['Is ', $m('(1, 1, −1)'), ' on ', $m('x + 2y − z = 4'), '?'], ans: ['y'], why: '1 + 2 − (−1) = 1 + 2 + 1 = 4. Yes.' },
+ { parts: ['Is ', $m('(2, 1, 1)'), ' on ', $m('x + 2y − z = 4'), '?'], ans: ['n'], why: '2 + 2 − 1 = 3, not 4.' },
+ { parts: ['Is ', $m('(0, 0, 4)'), ' on ', $m('x + 2y − z = 4'), '?'], ans: ['n'], why: '0 + 0 − 4 = −4, not 4. Watch the minus in front of z.' },
+ { parts: ['Is ', $m('(3, 1, 1)'), ' on ', $m('x + 2y − z = 4'), '?'], ans: ['y'], why: '3 + 2 − 1 = 4. Yes.' },
+ { parts: ['Is ', $m('(1, 2, 0)'), ' on ', $m('x + 2y − z = 4'), '?'], ans: ['n'], why: '1 + 4 − 0 = 5, not 4. Order matters: the second number is y, and y is doubled.' },
+];
+const MISSQ = [
+ { parts: ['x + y + z = 5, x = 1, y = 3: z = ', { box: '1' }], why: '1 + 3 + z = 5, so z = 1.', hint: 'Put in x = 1 and y = 3: 4 + z = 5.' },
+ { parts: ['2x + y + z = 6, y = 0, z = 0: x = ', { box: '3' }], why: '2x = 6, so x = 3.', hint: 'With y and z both 0, only 2x is left: 2x = 6.' },
+ { parts: ['x − y + z = 2, x = 4, z = 0: y = ', { box: '2' }], why: '4 − y + 0 = 2, so y = 2.', hint: '4 − y = 2. What do you take away from 4 to leave 2?' },
+ { parts: ['x + 2y + 3z = 6, x = 0, y = 0: z = ', { box: '2' }], why: '3z = 6, so z = 2.', hint: 'Only 3z is left: 3z = 6.' },
+ { parts: ['x + y − z = 0, x = 2, y = 1: z = ', { box: '3' }], why: '2 + 1 − z = 0, so z = 3.', hint: '3 − z = 0. What must z be?' },
+ { parts: ['3x − y + 2z = 1, x = 1, z = −1: y = ', { box: '0' }], why: '3 − y − 2 = 1, so 1 − y = 1 and y = 0.', hint: '2 times −1 is −2. Then 3 − y − 2 = 1.' },
+];
+const CROSSQ = [
+ { parts: ['2x + y + z = 4: (', { box: '2' }, ', 0, 0), (0, ', { box: '4' }, ', 0), (0, 0, ', { box: '4' }, ')'], why: '2x = 4 gives x = 2; y = 4; z = 4.', hint: 'On each axis the other two letters are 0. On the x-axis: 2x = 4.' },
+ { parts: ['x + 3y + 3z = 3: (', { box: '3' }, ', 0, 0), (0, ', { box: '1' }, ', 0), (0, 0, ', { box: '1' }, ')'], why: 'x = 3; 3y = 3 gives y = 1; 3z = 3 gives z = 1.', hint: 'On the y-axis, x and z are 0: 3y = 3.' },
+ { parts: ['−x + 2y + z = 2: (', { box: '-2' }, ', 0, 0), (0, ', { box: '1' }, ', 0), (0, 0, ', { box: '2' }, ')'], why: '−x = 2 gives x = −2; 2y = 2 gives y = 1; z = 2.', hint: 'On the x-axis: −x = 2. So x is negative.' },
+];
+const KINDQ = [
+ { parts: [$m('z = −1')], ans: ['f'], why: 'Only z is there: x and y are free. A floor at height −1.' },
+ { parts: [$m('x = 2')], ans: ['w'], why: 'z is missing, so z is free: the plane stands upright.' },
+ { parts: [$m('x + y = 1')], ans: ['w'], why: 'No z: it is the floor line x + y = 1, stood up into a wall.' },
+ { parts: [$m('x + z = 2')], ans: ['t'], why: 'z is there, and so is x: the plane leans, like a ramp. (It runs along y, the missing letter.)' },
+ { parts: [$m('2z = 6')], ans: ['f'], why: 'Only z: z = 3, a floor at height 3.' },
+ { parts: [$m('y − 2z = 0')], ans: ['t'], why: 'Both y and z are there: a tilted plane, running along x.' },
+];
+const KINDS = [['f', 'Floor', null, 'F'], ['w', 'Wall', null, 'W'], ['t', 'Tilted', null, 'T']];
+
+/* ---------- beats: [id, title, run(m, D), { ask }?] ---------- */
+const BEATS = [
+ ['intro', 'Three unknowns: a plane in space', (m, D) => {
+ const g = G(scene, { o: 0, y: 24 });
+ T(g, 'Unit 1, Chapter 11', { x: 800, y: 320, size: 28, fill: COL.dim, anchor: 'middle' });
+ T(g, 'Three Unknowns: A Plane in Space', { x: 800, y: 430, size: 80, weight: 600, anchor: 'middle' });
+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);
+ const r = text(scene, 'one equation in x, y and z is a flat sheet in space', 800, 560, m('sub'), { size: 36, fill: COL.dim, anchor: 'middle' });
+ // a line (two unknowns) that opens into a tilted sheet (three)
+ const lg = G(scene, { x: 800, y: 690, o: 0 }), sh = path(lg, '', { stroke: BLUE, 'stroke-width': 5, fill: BLUE, 'fill-opacity': .22, 'stroke-linejoin': 'round' });
+ const sheet = q => { const w = 160, h = 70 * q, sk = 60 * q; return `M${-w + sk} ${-h}L${w + sk} ${-h}L${w - sk} ${h}L${-w - sk} ${h}Z`; };
+ sh.setAttribute('d', sheet(0));
+ show(lg, m('sub') + 1.5, .4); tw(lg, { r: 8 }, m('sub') + 1.5, m('move') - m('sub') - 1, soft);
+ prog(q => sh.setAttribute('d', sheet(q)), m('move') + .6, 1.4, io);
+ tw(lg, { r: -8 }, m('move') + 2, 2.2, soft);
+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(lg, D - .9, .8);
+ }],
+
+ ['third', 'A third unknown', (m) => {
+ const p = S.p = panel(0);
+ text(p, 'One equation, three unknowns', 60, 110, .2, { size: 40, weight: 600 });
+ const recap = G(p, {});
+ say(recap, ['x + y = 4'], 90, 200, m('r0'), { size: 34, fill: COL.dim });
+ say(recap, ['→ pairs (1, 3), (2, 2), (4, 0) …'], 250, 200, m('rp'), { size: 34, fill: COL.dim });
+ const rl = G(recap, { x: 300, y: 280 });
+ const ld = path(rl, 'M-180 60L180 -60', { stroke: COL.whole, 'stroke-width': 5, 'stroke-linecap': 'round' }, { d: 0 });
+ draw(ld, m('rl'), 1);
+ [-120, -40, 40, 120].forEach((x, i) => { const c = mk('circle', { cx: x, cy: -x / 3, r: 8, fill: COL.chalk }, rl); put(c, { o: 0 }); show(c, m('rp') + .4 + i * .3, .3); });
+ say(recap, ['→ a line'], 520, 290, m('rl') + .3, { size: 34, fill: COL.whole });
+ hide(recap, m('eq') - .4, .4);
+ say(p, ['x + y + z = 3'], 90, 200, m('eq'), { size: 54, fill: BLUE });
+ const un = G(p, {});
+ text(un, 'three unknowns:', 420, 196, m('eq') + 2.2, { size: 28, fill: COL.dim });
+ ['x', 'y', 'z'].forEach((n, j) => { const e = say(un, [n], 668 + j * 44, 198, m('eq') + 2.8 + j * .5, { size: 36, fill: AXC[j], anchor: 'middle' }); pulse(e, m('eq') + 2.8 + j * .5); });
+ hide(un, m('q') + 2, .5);
+ const q = text(p, 'a solution gives a number to each letter', 90, 254, m('q'), { size: 28, fill: COL.dim });
+ hide(q, m('x1') - .4, .4);
+ const tx = [130, 230, 330, 500], ty = 300, rh = 64;
+ const head = G(p, { o: 0 });
+ ['x', 'y', 'z', 'x + y + z'].forEach((h, j) => M(head, [h], { x: tx[j], y: ty, size: 34, fill: j < 3 ? AXC[j] : COL.dim, anchor: 'middle' }));
+ path(head, `M70 ${ty + 18}H660`, { stroke: COL.faint, 'stroke-width': 2 });
+ show(head, m('q'));
+ const qs = G(p, {});
+ [0, 1, 2].forEach(j => { const e = M(qs, ['?'], { x: tx[j], y: ty + 66, size: 38, fill: COL.dim, anchor: 'middle', o: 0 }); show(e, m('q') + .5 + j * .3, .3); pulse(e, m('q') + 2 + j * .4); });
+ hide(qs, m('x1') - .2, .2);
+ const rows = [[1, 1, 1], [3, 0, 0], [0, 2, 1], [2, 2, -1]];
+ const at = [[m('x1'), m('x1') + .8, m('z1'), m('ok1')], ...[m('r2'), m('r3'), m('r4')].map(t => [t, t + .5, t + 1, t + 2])];
+ rows.forEach((r, i) => {
+ const yy = ty + 66 + i * rh;
+ r.forEach((c, j) => say(p, [num(c)], tx[j], yy, at[i][j], { size: 38, anchor: 'middle', fill: AXC[j] }));
+ say(p, [`${r.map((c, j) => j && c < 0 ? `(${num(c)})` : num(c)).join(' + ')} = 3`], tx[3], yy, at[i][3], { size: 32, anchor: 'middle' });
+ if (!i) { const w = say(p, ['1 + 1 + z = 3'], tx[3], yy, m('x1') + 3.2, { size: 32, anchor: 'middle', fill: COL.dim }); hide(w, at[0][3] - .2, .2); }
+ text(p, '✓', 640, yy, at[i][3] + .3, { size: 34, fill: COL.good, anchor: 'middle', weight: 700 });
+ });
+ text(p, 'solutions: triples', 1160, 250, m('tri') - .3, { size: 30, fill: COL.dim, anchor: 'middle' });
+ // each row's numbers fly into its chip as the row is checked
+ rows.forEach((r, i) => r.forEach((c, j) => {
+ const t = i ? at[i][3] + .2 : m('tri'), cx_ = 1030 + (i % 2) * 260, cy_ = 343 + Math.floor(i / 2) * 100;
+ const f = M(p, [num(c)], { x: tx[j], y: ty + 66 + i * rh, size: 38, fill: AXC[j], anchor: 'middle', o: 0 });
+ tw(f, { o: 1 }, t, .1); tw(f, { x: cx_ + (j - 1) * 34, y: cy_ }, t + .1 * j, .9); hide(f, t + 1.1, .2);
+ }));
+ rows.forEach((r, i) => {
+ const c = chip(p, [tri(r)], COL.chalk, { x: 1030 + (i % 2) * 260, y: 330 + Math.floor(i / 2) * 100, size: 38 });
+ put(c, { o: 0, s: .6 });
+ tw(c, { o: 1, s: 1 }, (i ? at[i][3] + .2 : m('tri')) + 1.1, .5, back);
+ });
+ text(p, 'x first, then y, then z', 1160, 486, m('tri') + 3, { size: 24, fill: COL.dim, anchor: 'middle' });
+ const tl = text(p, 'a triple', 1030, 400, m('r2') - 2.2, { size: 26, fill: COL.task, anchor: 'middle', weight: 600 });
+ hide(tl, m('r2') + 1.5, .4);
+ [[0, 0, 1], [1, 0, 2], [3, 1, -1], [0.5, 0.5, 2], [-1, 2, 2], [4, -2, 1]].forEach((r, i) => {
+ const c = chip(p, [tri(r)], COL.dim, { x: 990 + (i % 3) * 190, y: 540 + Math.floor(i / 3) * 70, size: 26 });
+ put(c, { o: 0, s: .5 }); tw(c, { o: .8, s: 1 }, m('many') + .6 + i * .45, .4, back);
+ });
+ text(p, '… and endlessly many more', 1180, 700, m('many') + 3.6, { size: 30, fill: COL.task, anchor: 'middle', weight: 600 });
+ text(p, 'a pair is a point on a flat plane. A triple?', 1180, 790, m('many') + 7, { size: 30, fill: COL.chalk, anchor: 'middle', weight: 600 });
+ }],
+
+ ['space', 'Space has three directions', (m) => {
+ const p = panel(0);
+ text(p, 'A third direction: up', 60, 110, .2, { size: 40, weight: 600 });
+ const V = S.V = space3(p, { yaw: 0, pitch: 90, t0: .1 });
+ put(V.axes[2], { o: 0 }); put(V.cube, { o: 0 });
+ const pt = V.point([2, 1, 0], { color: COL.task, label: '(2, 1)' });
+ // the walk of chapter 1, on the flat plane seen from above
+ V.walk([2, 1, 0], m('pt'), { dur: 1.4, dot: false, w: 4 });
+ say(p, ['(2, 1)'], 90, 210, m('pt') + .6, { size: 46, fill: COL.task });
+ put(pt.e, { o: 0 }); show(pt.e, m('pt') + 1.3, .3);
+ [[0, 'xr'], [1, 'yu']].forEach(([j, mk_]) => {
+ const a = V.line(null, null, { color: AXC[j], w: 7, into: V.content, head: true }), e = [0, 0, 0];
+ prog(q => { e[j] = 4.6 * q; a.set([0, 0, 0], [...e]); }, m(mk_), .9, io);
+ tw(a.e, { o: 0 }, m(mk_) + 1.6, .5);
+ });
+ V.turn({ pitch: VIEW.pitch, yaw: VIEW.yaw }, m('lay'), 2.6); // straight from above to the chapter's view: y and z never overlap on screen
+ const yl = V.line(null, null, { color: AXC[1], w: 7, into: V.content, head: true });
+ prog(q => yl.set([0, 0, 0], [0, 4.6 * q, 0]), m('back'), 1, io);
+ tw(yl.e, { o: 0 }, m('up') + 2, .6);
+ show(V.axes[2], m('up'), .5); show(V.cube, m('up') + .4, .8);
+ const zl = V.line(null, null, { color: AXC[2], w: 7, into: V.content, head: true });
+ prog(q => zl.set([0, 0, 0], [0, 0, 4.6 * q]), m('up'), 1.1, io);
+ tw(zl.e, { o: 0 }, m('floor') + 1.5, .6);
+ legend(p, [m('lay') + 1.4, m('back'), m('up')], 330);
+ const fl = G(p, { o: 0 });
+ T(fl, 'the floor: z = 0', { x: 90, y: 540, size: 34, weight: 600, fill: COL.chalk });
+ show(fl, m('floor'));
+ tw(V.floor, { 'a_stroke-opacity': .35 }, m('floor'), .4); tw(V.floor, { 'a_stroke-opacity': .09 }, m('floor') + 1.4, .8);
+ prog(() => { pt.label('(2, 1, 0)'); }, m('floor') + .5, 0, lin);
+ V.sway(4, 9, m('lay') + 2.6);
+ V.turn({ yaw: VIEW.yaw - 25, pitch: VIEW.pitch }, m('turn'), 3.2);
+ V.turn({ yaw: VIEW.yaw + 20 }, m('turn') + 3.2, 3.6);
+ V.turn({ yaw: VIEW.yaw }, m('turn') + 6.8, 2.4);
+ }],
+
+ ['point', 'Finding a point in space', (m) => {
+ const p = panel(0);
+ text(p, 'A point in space: three numbers', 60, 110, .2, { size: 40, weight: 600 });
+ const V = space3(p, { ...VIEW, t0: .1 });
+ V.sway(5, 11);
+ say(p, ['(2, 1, 3)'], 90, 210, .4, { size: 54, fill: COL.task });
+ const O = V.point(null, { color: COL.chalk, r: 7 });
+ prog(() => O.set([0, 0, 0]), m('o'), 0, lin); pulse(O.e, m('o'));
+ const w1 = V.walk([2, 1, 3], 0, { at: [m('x'), m('y'), m('z')], dur: 3, label: '(2, 1, 3)' });
+ const steps = [['2', 'steps along x'], ['1', 'step along y, away'], ['3', 'steps up']];
+ const st1 = G(p, {});
+ steps.forEach(([n, s], j) => { say(st1, [n], 110, 300 + j * 56, m(['x', 'y', 'z'][j]), { size: 40, fill: AXC[j], anchor: 'middle' }); text(st1, s, 150, 300 + j * 56, m(['x', 'y', 'z'][j]) + .2, { size: 28, fill: COL.dim }); });
+ const shd = V.point(null, { color: COL.dim, r: 7, label: '(2, 1, 0)', size: 22, dy: 26 });
+ prog(() => shd.set([2, 1, 0]), m('shadow'), 0, lin);
+ const sn = text(p, 'its shadow on the floor: (2, 1, 0)', 90, 500, m('shadow') + .4, { size: 28, fill: COL.dim });
+ pulse(w1.dot.e, m('here'));
+ V.turn({ yaw: VIEW.yaw + 55, pitch: 12 }, m('turn'), 3);
+ V.turn({ yaw: VIEW.yaw - 10, pitch: VIEW.pitch }, m('ex2') - .2, 2.2);
+ [st1, sn].forEach(e => hide(e, m('ex2') - .4, .4));
+ tw(w1.dot.e, { o: .5 }, m('ex2'), .4);
+ say(p, ['(−1, 2, −2)'], 360, 210, m('ex2'), { size: 54, fill: COL.int });
+ const w2 = V.walk([-1, 2, -2], 0, { at: [m('x2'), m('y2'), m('z2')], dur: 3, label: '(−1, 2, −2)', color: COL.int });
+ const steps2 = [['−1', 'step along x: to the left'], ['2', 'steps along y, away'], ['−2', 'steps: down, below the floor']];
+ steps2.forEach(([n, s], j) => { say(p, [n], 110, 300 + j * 56, m(['x2', 'y2', 'z2'][j]), { size: 40, fill: AXC[j], anchor: 'middle' }); text(p, s, 150, 300 + j * 56, m(['x2', 'y2', 'z2'][j]) + .2, { size: 28, fill: COL.dim }); });
+ pulse(w2.dot.e, m('here2'));
+ text(p, 'one triple = one point in space', 90, 560, m('here2'), { size: 34, weight: 600, fill: COL.task });
+ V.sway(8, 12, m('here2'));
+ }],
+
+ ['cloud', 'The solutions make a plane', (m) => {
+ const p = panel(0);
+ text(p, 'The solutions make a flat sheet', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = onePlane(p, 1, 1, 1, 3);
+ const V = sys.space, pl = sys.planes[0];
+ V.sway(5, 12);
+ pl.fade(0, 0, 0); pl.fade(1, m('plane') + .3, 1.2);
+ const cl = G(V.content, {});
+ const sols = [[1, 1, 1, 'p1'], [3, 0, 0, 'p2'], [0, 2, 1, 'p3'], [2, 2, -1, 'p4']];
+ sols.forEach(([x, y, z, mk_]) => { const d = V.point(null, { color: COL.task, label: tri([x, y, z]), size: 24, into: cl }); prog(() => d.set([x, y, z]), m(mk_), 0, lin); pulse(d.e, m(mk_)); hide(d.t, m('more'), .5); });
+ [[0, 3, 0], [0, 0, 3], [2, 1, 0], [1, 0, 2], [0, 1, 2], [2, 0, 1], [1, 2, 0], [-1, 2, 2], [3, 1, -1], [1, -1, 3], [2, -1, 2], [-1, 1, 3], [4, 0, -1], [0, 4, -1]].forEach((q, i) => {
+ const d = V.point(null, { color: COL.task, r: 7, into: cl });
+ prog(() => d.set(q), m('more') + i * .12, 0, lin);
+ });
+ // edge-on: the view direction (sin yaw, cos yaw, −tan pitch) lies in the plane when tan pitch = sin yaw + cos yaw
+ const edge = Math.atan(Math.sin(VIEW.yaw * Math.PI / 180) + Math.cos(VIEW.yaw * Math.PI / 180)) * 180 / Math.PI;
+ V.turn({ pitch: edge }, m('edge'), 2.4);
+ const ln = text(p, 'all in one line: a flat sheet seen edge-on', 90, 330, m('line'), { size: 30, fill: COL.task, weight: 600 });
+ hide(ln, m('plane'), .4);
+ V.turn({ pitch: VIEW.pitch }, m('plane'), 2.4);
+ tw(cl, { o: .55 }, m('rule') - .5, .5);
+ // a probe that wanders on the plane, adding up its coordinates
+ const probe = V.point(null, { color: COL.chalk, r: 10 });
+ const sum = G(p, { o: 0 }), st_ = T(sum, '', { x: 90, y: 400, size: 36, fill: COL.chalk, font: MATH });
+ T(sum, 'on the plane = a solution', { x: 90, y: 470, size: 34, weight: 600, fill: BLUE });
+ show(sum, m('rule'));
+ prog(q => {
+ const a = q * Math.PI * 2, x = r1(1 + 1.6 * Math.cos(a)), y = r1(1 + 1.6 * Math.sin(a)), z = r1(3 - x - y);
+ probe.set([x, y, z]);
+ const s = `${num(x)} + ${y < 0 ? `(${num(y)})` : num(y)} + ${z < 0 ? `(${num(z)})` : num(z)} = 3`;
+ if (st_.textContent !== s) st_.textContent = s;
+ }, m('rule'), m('name') - m('rule') + 1.5, lin);
+ glowPl(pl, m('name')); flash(sys, 'b0', m('name')); ['a00', 'a01', 'a02'].forEach(k => flash(sys, k, m('name')));
+ }],
+
+ ['off', 'Off the plane', (m) => {
+ const p = panel(0);
+ text(p, 'Off the plane', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = onePlane(p, 1, 1, 1, 3);
+ const V = sys.space;
+ V.sway(5, 12);
+ const a = V.point(null, { color: COL.nat, label: '(2, 2, 2)', stem: true });
+ prog(() => a.set([2, 2, 2]), m('p'), 0, lin); pulse(a.e, m('p'));
+ say(p, ['2 + 2 + 2 = 6'], 90, 330, m('sum'), { size: 38, fill: COL.nat });
+ text(p, 'not 3: not a solution', 360, 330, m('no'), { size: 28, fill: COL.nat, weight: 600 });
+ text(p, 'above the plane: sum too big', 90, 390, m('above'), { size: 28, fill: COL.nat, weight: 600 });
+ const o = V.point(null, { color: COL.whole, label: '(0, 0, 0)', dy: 32 });
+ prog(() => o.set([0, 0, 0]), m('o'), 0, lin); pulse(o.e, m('o'));
+ say(p, ['0 + 0 + 0 = 0'], 90, 480, m('o2'), { size: 38, fill: COL.whole });
+ text(p, 'below the plane: sum too small', 90, 540, m('below'), { size: 28, fill: COL.whole, weight: 600 });
+ // turn side-on, so the plane is a line and the two points sit on either side of it
+ const edge = Math.atan(Math.sin(VIEW.yaw * Math.PI / 180) + Math.cos(VIEW.yaw * Math.PI / 180)) * 180 / Math.PI;
+ V.turn({ pitch: edge - 6 }, m('above'), 2.4);
+ V.turn({ pitch: VIEW.pitch }, m('end'), 2.4);
+ glowPl(sys.planes[0], m('end') + .4);
+ }],
+
+ ['q1', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ S.sys = onePlane(p, 1, 1, 1, 3);
+ S.sys.space.sway(6, 14);
+ }, { ask: done => quiz(CARD, [{
+ id: 'c-miss', prompt: ['Find the missing number so that the point lies on ', $m('x + y + z = 3'), '.'],
+ build: blanks([
+ { parts: ['(2, 0, ', { box: '1' }, ')'], why: '2 + 0 + z = 3, so z = 1.', hint: 'Put x = 2 and y = 0 in: 2 + z = 3.',
+ fx: () => S.sys.space.point([2, 0, 1], { color: COL.good, label: '(2, 0, 1)', size: 24 }) },
+ { parts: ['(0, 4, ', { box: '-1' }, ')'], why: '0 + 4 + z = 3, so z = −1: a little below the floor.', hint: '4 + z = 3. z must be negative.',
+ fx: () => S.sys.space.point([0, 4, -1], { color: COL.good, label: '(0, 4, −1)', size: 24 }) },
+ { parts: ['(−1, ', { box: '1' }, ', 3)'], why: '−1 + y + 3 = 3, so y = 1.', hint: '−1 + 3 is 2. Then 2 + y = 3.',
+ fx: () => S.sys.space.point([-1, 1, 3], { color: COL.good, label: '(−1, 1, 3)', size: 24 }) },
+ ]),
+ }], done) }],
+
+ ['cross', 'Three points pin down a plane', (m) => {
+ const p = panel(0);
+ text(p, 'Drawing a plane: where it crosses the axes', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = onePlane(p, 1, 1, 1, 3);
+ const V = sys.space, pl = sys.planes[0];
+ V.sway(9, 16);
+ hide(sys.E, .3, 0); show(sys.E, m('eq') - .2, .5);
+ const rc = G(p, {});
+ text(rc, 'a line: 2 points', 90, 330, .5, { size: 32, fill: COL.dim });
+ text(rc, 'a plane: 3 points', 90, 390, 3.2, { size: 32, fill: BLUE, weight: 600 });
+ hide(rc, m('eq') - .4, .4);
+ pl.fade(.25, 0, 0);
+ const steps = G(p, {});
+ const cr = (lab, res, y, t, q, mk_) => {
+ say(steps, [lab], 90, y, t, { size: 30, fill: COL.dim });
+ say(steps, [res], 470, y, t + 1.2, { size: 36 });
+ const d = V.point(null, { color: COL.task, label: tri(q), size: 24, into: steps });
+ prog(() => d.set(q), m(mk_), 0, lin); pulse(d.e, m(mk_));
+ };
+ cr('on the x-axis, y = z = 0:', 'x = 3', 330, m('xa'), [3, 0, 0], 'px');
+ cr('on the y-axis, x = z = 0:', 'y = 3', 390, m('ya'), [0, 3, 0], 'py');
+ cr('on the z-axis, x = y = 0:', 'z = 3', 450, m('za'), [0, 0, 3], 'pz');
+ const t1 = V.poly([[3, 0, 0], [0, 3, 0], [0, 0, 3]], { color: COL.task, fo: .28, w: 4, into: steps });
+ tw(t1.e, { o: 0 }, 0, 0); show(t1.e, m('tri'), .8);
+ text(steps, 'the corner where x, y, z are all positive', 90, 520, m('tri') + 1.5, { size: 26, fill: COL.task });
+ pl.fade(.9, m('tri') + 3, 1.2);
+ hide(steps, m('ex2') - .5, .4);
+ pl.fade(.25, m('ex2') - .5, .4);
+ sys.to({ a00: 3, a01: 2, a02: 2, b0: 6 }, m('ex2'), 1.4);
+ ['a00', 'a01', 'a02', 'b0'].forEach(k => flash(sys, k, m('ex2') + .6));
+ const s2 = G(p, {});
+ const cr2 = (lab, res, y, t, q, dx, dy) => {
+ say(s2, [lab], 90, y, t, { size: 30, fill: COL.dim });
+ say(s2, [res], 470, y, t + 1.4, { size: 36 });
+ const d = V.point(null, { color: COL.irr, label: tri(q), size: 24, into: s2, dx, dy });
+ prog(() => d.set(q), t + 1.8, 0, lin); pulse(d.e, t + 1.8);
+ };
+ cr2('x-axis: 3x = 6', 'x = 2', 330, m('a'), [2, 0, 0], 14, 34);
+ cr2('y-axis: 2y = 6', 'y = 3', 390, m('b'), [0, 3, 0], -112, 30);
+ cr2('z-axis: 2z = 6', 'z = 3', 450, m('c'), [0, 0, 3], 14, -18);
+ const t2 = V.poly([[2, 0, 0], [0, 3, 0], [0, 0, 3]], { color: COL.irr, fo: .3, w: 4, into: s2 });
+ tw(t2.e, { o: 0 }, 0, 0); show(t2.e, m('tri2'), .6);
+ pl.fade(.9, m('tri2') + 1.5, 1.2);
+ }],
+
+ ['slide', 'The right side slides it', (m) => {
+ const p = panel(0);
+ text(p, 'Change the right side', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = onePlane(p, 1, 1, 1, 3);
+ const V = sys.space;
+ crossings(sys, m('three'));
+ const ghost = V.poly(null, { color: BLUE, fo: 0, w: 2, into: V.content });
+ ghost.e.setAttribute('stroke-dasharray', '8 8'); ghost.e.setAttribute('stroke-opacity', .5);
+ const keep = (d, t) => prog(() => ghost.set(S3_cut(1, 1, 1, d, V.R)), t, 0, lin);
+ keep(3, m('one'));
+ sys.to({ b0: 1 }, m('one'), 1.6); flash(sys, 'b0', m('one'));
+ keep(1, m('zero'));
+ sys.to({ b0: 0 }, m('zero'), 1.4); flash(sys, 'b0', m('zero'));
+ say(p, ['0 + 0 + 0 = 0'], 90, 330, m('origin'), { size: 38, fill: COL.task });
+ keep(0, m('neg'));
+ sys.to({ b0: -2 }, m('neg'), 1.4); flash(sys, 'b0', m('neg'));
+ const n = G(p, { o: 0 });
+ T(n, 'right side changes:', { x: 90, y: 460, size: 32, fill: COL.dim });
+ T(n, 'the plane slides, never tilts', { x: 90, y: 510, size: 36, weight: 600, fill: COL.task });
+ show(n, m('par'));
+ V.sway(10, 14, 0);
+ }],
+
+ ['tilt', 'The other numbers tilt it', (m) => {
+ const p = panel(0);
+ text(p, 'Change the numbers in front of x, y, z', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = onePlane(p, 1, 1, 1, 3);
+ const V = sys.space;
+ crossings(sys, .3);
+ const old = V.poly(S3_cut(1, 1, 1, 3, V.R), { color: BLUE, fo: 0, w: 2, into: V.content });
+ old.e.setAttribute('stroke-dasharray', '8 8'); tw(old.e, { o: 0 }, 0, 0); tw(old.e, { o: .5 }, m('three') + .4, .4);
+ sys.to({ a00: 3 }, m('three'), 1.6); flash(sys, 'a00', m('three'));
+ const w = G(p, {});
+ say(w, ['on the x-axis, y = z = 0:'], 90, 330, m('why'), { size: 30, fill: COL.dim });
+ say(w, ['3x = 3, x = 1'], 90, 385, m('xa'), { size: 40 });
+ const hinge = V.line(null, null, { color: COL.task, w: 5, into: V.content });
+ prog(() => hinge.set([0, 3, 0], [0, 0, 3]), m('same'), 0, lin);
+ text(w, 'y and z crossings stay: the hinge', 90, 450, m('same') + .5, { size: 28, fill: COL.task, weight: 600 });
+ hide(w, m('zc') - .3, .3); hide(hinge.e, m('zc') - .3, .3);
+ sys.to({ a00: 1, a02: 3 }, m('zc'), 1.8); flash(sys, 'a00', m('zc')); flash(sys, 'a02', m('zc'));
+ const w2 = say(p, ['on the z-axis: 3z = 3, z = 1'], 90, 385, m('zt'), { size: 36 });
+ hide(w2, m('minus') - .3, .3);
+ sys.to({ a00: -1, a02: 1 }, m('minus'), 1.8); flash(sys, 'a00', m('minus')); flash(sys, 'a02', m('minus'));
+ say(p, ['on the x-axis: −x = 3, x = −3'], 90, 385, m('neg'), { size: 36 });
+ const n = G(p, { o: 0 });
+ T(n, 'right side: slides the plane', { x: 90, y: 630, size: 34, weight: 600, fill: COL.task });
+ T(n, 'numbers in front of x, y, z: tilt it', { x: 90, y: 682, size: 34, weight: 600, fill: BLUE });
+ show(n, m('sum'));
+ V.sway(9, 15, 0);
+ }],
+
+ ['q2', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ S.sys = onePlane(p, 1, 2, 4, 4);
+ S.sys.space.sway(6, 14);
+ }, { ask: done => quiz(CARD, [{
+ id: 'c-cross', prompt: ['Where does ', $m('x + 2y + 4z = 4'), ' cross the three axes?'],
+ build: blanks([
+ { parts: ['x-axis (y = z = 0): (', { box: '4' }, ', 0, 0)'], why: 'x = 4.', hint: 'Put y = 0 and z = 0. What is left?',
+ fx: () => S.sys.space.point([4, 0, 0], { color: COL.good, label: '(4, 0, 0)', size: 24 }) },
+ { parts: ['y-axis (x = z = 0): (0, ', { box: '2' }, ', 0)'], why: '2y = 4, so y = 2.', hint: 'Put x = 0 and z = 0: 2y = 4.',
+ fx: () => S.sys.space.point([0, 2, 0], { color: COL.good, label: '(0, 2, 0)', size: 24 }) },
+ { parts: ['z-axis (x = y = 0): (0, 0, ', { box: '1' }, ')'], why: '4z = 4, so z = 1.', hint: 'Put x = 0 and y = 0: 4z = 4.',
+ fx: () => S.sys.space.point([0, 0, 1], { color: COL.good, label: '(0, 0, 1)', size: 24 }) },
+ ]),
+ }], done) }],
+
+ ['missing', 'A missing letter', (m) => {
+ const p = panel(0);
+ text(p, 'When a letter is missing', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = onePlane(p, 0, 0, 1, 2, { t0: m('eq1') });
+ const V = sys.space, pl = sys.planes[0];
+ V.sway(6, 13);
+ pl.fade(0, 0, 0); pl.fade(1, m('floor'), 1);
+ ['a00', 'a01'].forEach(k => flash(sys, k, m('zero') + .4));
+ const f1 = text(p, 'x and y free, z must be 2', 90, 300, m('zero') + 1.5, { size: 32, fill: COL.task, weight: 600 });
+ const fl = G(V.content, {});
+ [[-3, -2], [0, 0], [3, 1], [-1, 3]].forEach(([x, y], i) => { const d = V.point(null, { color: COL.task, r: 7, into: fl, stem: true }); prog(() => d.set([x, y, 2]), m('floor') + .5 + i * .25, 0, lin); });
+ V.turn({ pitch: 8 }, m('floor') + .4, 2); V.turn({ pitch: VIEW.pitch }, m('eq2') - .5, 1.5);
+ [f1, fl].forEach(e => hide(e, m('eq2') - .4, .3));
+ sys.to({ a00: 1, a02: 0, b0: 1 }, m('eq2'), 1.8);
+ ['a00', 'a02', 'b0'].forEach(k => flash(sys, k, m('eq2') + .8));
+ const f2 = text(p, 'y and z free, x must be 1', 90, 300, m('wall') - .4, { size: 32, fill: COL.task, weight: 600 });
+ V.turn({ yaw: VIEW.yaw + 40 }, m('wall'), 2.4); // nearer face-on to the wall x = 1
+ hide(f2, m('eq3') - .4, .3);
+ // x + y = 2: first the line on the floor, then the wall that rises from it
+ prog(() => { pl.visible = false; V.redraw(); }, m('eq3') - .3, 0, lin);
+ sys.to({ a01: 1, b0: 2 }, m('eq3'), .1);
+ flash(sys, 'a02', m('eq3') + .5);
+ const ln = V.line(null, null, { color: BLUE, w: 6, into: V.content });
+ prog(q => ln.set([4, -2, 0], [4 - 6 * q, -2 + 6 * q, 0]), m('line'), 1.2, io);
+ text(p, 'on the floor: the line x + y = 2', 90, 300, m('line'), { size: 30, fill: BLUE, weight: 600 });
+ text(p, 'z is free: up and down', 90, 350, m('free'), { size: 30, fill: COL.task, weight: 600 });
+ const wl = V.poly(null, { color: BLUE, fo: .22, w: 3, into: V.polys });
+ prog(q => { const h = V.R * q; wl.set(q ? [[4, -2, -h], [-2, 4, -h], [-2, 4, h], [4, -2, h]] : null); }, m('rise'), 2.2, io);
+ [-1, 1, 3].forEach((x, i) => { const d = V.point(null, { color: COL.task, r: 7, into: V.content }); prog(() => d.set([x, 2 - x, [3, -2, 1.5][i]]), m('free') + 1 + i * .3, 0, lin); });
+ V.turn({ yaw: VIEW.yaw - 20, pitch: 16 }, m('rise'), 3);
+ text(p, 'a missing letter = a free letter', 90, 690, m('sum'), { size: 32, weight: 600 });
+ }],
+
+ ['q3', 'Your turn', () => {
+ const p = panel(0);
+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = onePlane(p, 1, 2, 1, 4);
+ crossings(sys, .4, { labels: false });
+ [[2, 0, 0], [0, 2, 0], [0, 0, 2]].forEach(q => { const d = sys.space.point(q, { color: COL.task, r: 13, label: tri(q), size: 24 }); d.e.firstChild.setAttribute('fill', 'none'); d.e.firstChild.setAttribute('stroke', COL.task); d.e.firstChild.setAttribute('stroke-dasharray', '4 4'); });
+ sys.space.sway(5, 16);
+ }, { ask: done => quiz(CARD, [{
+ id: 'c-make', prompt: ['Make the plane cross the axes at ', $m('(2, 0, 0)'), ', ', $m('(0, 2, 0)'), ' and ', $m('(0, 0, 2)'), '. Drag a number sideways, or drag the plane by its edge.'],
+ build: lin3Task(S.sys, v => v.a00 !== 0 && v.a00 === v.a01 && v.a01 === v.a02 && v.b0 === 2 * v.a00,
+ 'x + y + z = 2 (or any multiple, like 2x + 2y + 2z = 4): each crossing point adds up to 2.',
+ 'Put each marked point into your equation: each must give the right side. (2, 0, 0) gives 2 times the x number. Try the same number in front of x, y and z.',
+ () => S.sys.set({ a00: 1, a01: 1, a02: 1, b0: 2 })),
+ }], done) }],
+
+ ['wrap', 'Summary', (m) => {
+ const p = panel(0);
+ [['A point in space is a triple (x, y, z): along x, back along y, up z.', 'w1'], ['The solutions of one equation in x, y, z make a flat plane.', 'w2'],
+ ['Where it crosses the three axes: three points pin it down.', 'w3'], ['Right side slides it; the numbers tilt it; a missing letter is free.', 'w4']].forEach(([str, mark], i) => {
+ const g = G(p, { x: -16, y: 230 + i * 130, o: 0 });
+ mk('circle', { cx: 150, cy: -12, r: 26, fill: COL.task }, g);
+ T(g, String(i + 1), { x: 150, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });
+ T(g, str, { x: 210, size: 34, weight: 600 });
+ tw(g, { o: 1, x: 0 }, m(mark), .6);
+ });
+ }],
+ ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
+ id: 'p-on', prompt: ['Is the point on the plane? Put x, y and z into the equation and check.'],
+ build: grid(ONQ, YN, { multi: false, text: true }),
+ }], done, 'Chapter practice · set 1 of 4') }],
+ ['final2', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
+ id: 'p-miss', prompt: ['Find the missing number so that the point is a solution.'],
+ build: blanks(MISSQ),
+ }], done, 'Chapter practice · set 2 of 4') }],
+ ['final3', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
+ id: 'p-cross', prompt: ['Where does each plane cross the x-, y- and z-axes?'],
+ build: blanks(CROSSQ),
+ }, {
+ id: 'p-kind', prompt: ['A floor (flat), a wall (upright) or tilted? Look at which letters are there.'],
+ build: grid(KINDQ, KINDS, { multi: false, text: true }),
+ }], done, 'Chapter practice · set 3 of 4') }],
+ ['final4', 'Chapter practice', () => {
+ const p = panel(0);
+ text(p, 'Make the plane', 60, 110, .2, { size: 40, weight: 600 });
+ S.sys = onePlane(p, 1, 1, 1, 1);
+ crossings(S.sys, .3, { labels: false });
+ S.sys.space.sway(5, 16);
+ }, { ask: done => quiz(CARD, [{
+ id: 'p-floor', prompt: ['Make a flat floor at height ', $m('z = −1'), ': every point on it has z = −1, whatever x and y are.'],
+ build: lin3Task(S.sys, v => v.a00 === 0 && v.a01 === 0 && v.a02 !== 0 && v.b0 === -v.a02, 'z = −1: 0 in front of x and y leaves them free.',
+ 'Put 0 in front of x and of y. Then make the right side say z = −1.', () => S.sys.set({ a00: 0, a01: 0, a02: 1, b0: -1 })),
+ }, {
+ id: 'p-cross', prompt: ['Make a plane that crosses the axes at ', $m('(4, 0, 0)'), ', ', $m('(0, 2, 0)'), ' and ', $m('(0, 0, 4)'), '.'],
+ build: lin3Task(S.sys, v => v.b0 !== 0 && 4 * v.a00 === v.b0 && 2 * v.a01 === v.b0 && 4 * v.a02 === v.b0, 'x + 2y + z = 4: (4, 0, 0) gives 4, (0, 2, 0) gives 2·2 = 4, (0, 0, 4) gives 4.',
+ 'All three points must give the same right side. (0, 2, 0) gives 2 times the y number, so y needs half of what x and z need.', () => S.sys.set({ a00: 1, a01: 2, a02: 1, b0: 4 })),
+ }, {
+ id: 'p-wall', prompt: ['Make an upright wall that stands on the floor line ', $m('x − y = 1'), '.'],
+ build: lin3Task(S.sys, v => v.a02 === 0 && v.a00 !== 0 && v.a01 === -v.a00 && v.b0 === v.a00, 'x − y + 0z = 1: z is missing, so z is free and the line stands up.',
+ 'A wall has no z: put 0 in front of z. Then the rest is the line x − y = 1.', () => S.sys.set({ a00: 1, a01: -1, a02: 0, b0: 1 })),
+ }], done, 'Chapter practice · set 4 of 4') }],
+ ['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],
+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
+
+boot();
+</script>
+</body>
+</html>
diff --git a/site/linear-algebra/ch12/audio/en/check.mp3 b/site/linear-algebra/ch12/audio/en/check.mp3
new file mode 100644
index 0000000..4d3299a
Binary files /dev/null and b/site/linear-algebra/ch12/audio/en/check.mp3 differ
diff --git a/site/linear-algebra/ch12/audio/en/corner.mp3 b/site/linear-algebra/ch12/audio/en/corner.mp3
new file mode 100644
index 0000000..baec96c
Binary files /dev/null and b/site/linear-algebra/ch12/audio/en/corner.mp3 differ
diff --git a/site/linear-algebra/ch12/audio/en/final1.mp3 b/site/linear-algebra/ch12/audio/en/final1.mp3
new file mode 100644
index 0000000..4cf1609
Binary files /dev/null and b/site/linear-algebra/ch12/audio/en/final1.mp3 differ
diff --git a/site/linear-algebra/ch12/audio/en/final2.mp3 b/site/linear-algebra/ch12/audio/en/final2.mp3
new file mode 100644
index 0000000..02c0432
Binary files /dev/null and b/site/linear-algebra/ch12/audio/en/final2.mp3 differ
diff --git a/site/linear-algebra/ch12/audio/en/final3.mp3 b/site/linear-algebra/ch12/audio/en/final3.mp3
new file mode 100644
index 0000000..341ec83
Binary files /dev/null and b/site/linear-algebra/ch12/audio/en/final3.mp3 differ
diff --git a/site/linear-algebra/ch12/audio/en/final4.mp3 b/site/linear-algebra/ch12/audio/en/final4.mp3
new file mode 100644
index 0000000..d3c3d95
Binary files /dev/null and b/site/linear-algebra/ch12/audio/en/final4.mp3 differ
diff --git a/site/linear-algebra/ch12/audio/en/finish.mp3 b/site/linear-algebra/ch12/audio/en/finish.mp3
new file mode 100644
index 0000000..fcf6374
Binary files /dev/null and b/site/linear-algebra/ch12/audio/en/finish.mp3 differ
diff --git a/site/linear-algebra/ch12/audio/en/intro.mp3 b/site/linear-algebra/ch12/audio/en/intro.mp3
new file mode 100644
index 0000000..464a6bc
Binary files /dev/null and b/site/linear-algebra/ch12/audio/en/intro.mp3 differ
diff --git a/site/linear-algebra/ch12/audio/en/line.mp3 b/site/linear-algebra/ch12/audio/en/line.mp3
new file mode 100644
index 0000000..255bac4
Binary files /dev/null and b/site/linear-algebra/ch12/audio/en/line.mp3 differ
diff --git a/site/linear-algebra/ch12/audio/en/move.mp3 b/site/linear-algebra/ch12/audio/en/move.mp3
new file mode 100644
index 0000000..6848061
Binary files /dev/null and b/site/linear-algebra/ch12/audio/en/move.mp3 differ
diff --git a/site/linear-algebra/ch12/audio/en/none.mp3 b/site/linear-algebra/ch12/audio/en/none.mp3
new file mode 100644
index 0000000..46ee677
Binary files /dev/null and b/site/linear-algebra/ch12/audio/en/none.mp3 differ
diff --git a/site/linear-algebra/ch12/audio/en/p1.mp3 b/site/linear-algebra/ch12/audio/en/p1.mp3
new file mode 100644
index 0000000..d4b7e3e
Binary files /dev/null and b/site/linear-algebra/ch12/audio/en/p1.mp3 differ
diff --git a/site/linear-algebra/ch12/audio/en/p2.mp3 b/site/linear-algebra/ch12/audio/en/p2.mp3
new file mode 100644
index 0000000..b2be747
Binary files /dev/null and b/site/linear-algebra/ch12/audio/en/p2.mp3 differ
diff --git a/site/linear-algebra/ch12/audio/en/p3.mp3 b/site/linear-algebra/ch12/audio/en/p3.mp3
new file mode 100644
index 0000000..d4ceb1b
Binary files /dev/null and b/site/linear-algebra/ch12/audio/en/p3.mp3 differ
diff --git a/site/linear-algebra/ch12/audio/en/q1.mp3 b/site/linear-algebra/ch12/audio/en/q1.mp3
new file mode 100644
index 0000000..431d8a5
Binary files /dev/null and b/site/linear-algebra/ch12/audio/en/q1.mp3 differ
diff --git a/site/linear-algebra/ch12/audio/en/q2.mp3 b/site/linear-algebra/ch12/audio/en/q2.mp3
new file mode 100644
index 0000000..581f2b4
Binary files /dev/null and b/site/linear-algebra/ch12/audio/en/q2.mp3 differ
diff --git a/site/linear-algebra/ch12/audio/en/q3.mp3 b/site/linear-algebra/ch12/audio/en/q3.mp3
new file mode 100644
index 0000000..d02ae8a
Binary files /dev/null and b/site/linear-algebra/ch12/audio/en/q3.mp3 differ
diff --git a/site/linear-algebra/ch12/audio/en/solve.mp3 b/site/linear-algebra/ch12/audio/en/solve.mp3
new file mode 100644
index 0000000..14893b9
Binary files /dev/null and b/site/linear-algebra/ch12/audio/en/solve.mp3 differ
diff --git a/site/linear-algebra/ch12/audio/en/system.mp3 b/site/linear-algebra/ch12/audio/en/system.mp3
new file mode 100644
index 0000000..3a0de21
Binary files /dev/null and b/site/linear-algebra/ch12/audio/en/system.mp3 differ
diff --git a/site/linear-algebra/ch12/audio/en/timings.js b/site/linear-algebra/ch12/audio/en/timings.js
new file mode 100644
index 0000000..b781073
--- /dev/null
+++ b/site/linear-algebra/ch12/audio/en/timings.js
@@ -0,0 +1,749 @@
+window.TIMINGS = {
+ "intro": {
+ "dur": 12.528,
+ "marks": {
+ "sub": 3.203,
+ "move": 8.099
+ },
+ "cues": [
+ [
+ 0.104,
+ "Chapter twelve."
+ ],
+ [
+ 1.458,
+ "Three planes, one point."
+ ],
+ [
+ 3.203,
+ "Three equations in x, y and z are three planes in space."
+ ],
+ [
+ 8.099,
+ "The point where all three meet is the one point that solves them all."
+ ]
+ ]
+ },
+ "system": {
+ "dur": 81.648,
+ "marks": {
+ "eq": 8.724,
+ "zero": 24.284,
+ "all": 30.013,
+ "try": 33.49,
+ "c1": 35.625,
+ "c2": 41.589,
+ "c3": 49.062,
+ "yes": 55.234,
+ "try2": 59.961,
+ "d1": 61.914,
+ "d2": 65.677,
+ "d3": 72.044,
+ "no": 76.758
+ },
+ "cues": [
+ [
+ 0.104,
+ "In chapter two, two equations had to be true at the same time."
+ ],
+ [
+ 4.336,
+ "Each one was a line, and the answer was the point where the lines crossed."
+ ],
+ [
+ 8.724,
+ "Now here are three equations with three unknowns."
+ ],
+ [
+ 12.435,
+ "Two x minus y equals zero."
+ ],
+ [
+ 15.091,
+ "Negative x plus two y minus z equals negative one."
+ ],
+ [
+ 20.156,
+ "And negative three y plus four z equals four."
+ ],
+ [
+ 24.284,
+ "The first one has no z: read it as plus zero z."
+ ],
+ [
+ 28.255,
+ "The third one has no x."
+ ],
+ [
+ 30.013,
+ "A solution has to make all three true at once."
+ ],
+ [
+ 33.49,
+ "Let's try zero, zero, one."
+ ],
+ [
+ 35.625,
+ "First equation: two times zero, minus zero, is zero."
+ ],
+ [
+ 40.807,
+ "True."
+ ],
+ [
+ 41.589,
+ "Second: negative zero, plus two times zero, minus one, is negative one."
+ ],
+ [
+ 48.229,
+ "True."
+ ],
+ [
+ 49.062,
+ "Third: negative three times zero, plus four times one, is four."
+ ],
+ [
+ 54.466,
+ "True."
+ ],
+ [
+ 55.234,
+ "All three work, so zero, zero, one is a solution."
+ ],
+ [
+ 59.961,
+ "Now try one, two, four."
+ ],
+ [
+ 61.914,
+ "First: two minus two is zero."
+ ],
+ [
+ 64.896,
+ "True."
+ ],
+ [
+ 65.677,
+ "Second: negative one, plus four, minus four, is negative one."
+ ],
+ [
+ 71.237,
+ "True."
+ ],
+ [
+ 72.044,
+ "Third: negative six plus sixteen is ten, not four."
+ ],
+ [
+ 76.758,
+ "Two out of three is not enough."
+ ],
+ [
+ 79.089,
+ "One, two, four is not a solution."
+ ]
+ ]
+ },
+ "p1": {
+ "dur": 29.952,
+ "marks": {
+ "eq1": 4.974,
+ "free": 8.477,
+ "floor": 14.648,
+ "rise": 22.161,
+ "pts": 24.779
+ },
+ "cues": [
+ [
+ 0.104,
+ "Now the picture."
+ ],
+ [
+ 1.25,
+ "Each equation is a plane, so let's draw them one at a time."
+ ],
+ [
+ 4.974,
+ "The first: two x minus y equals zero."
+ ],
+ [
+ 8.477,
+ "z is missing, so z is free, and the plane stands upright, like a wall."
+ ],
+ [
+ 14.648,
+ "On the floor it is the line two x minus y equals zero, the line through the origin from chapter one."
+ ],
+ [
+ 22.161,
+ "Stand it up, and there is the first plane."
+ ],
+ [
+ 24.779,
+ "Both points we tried are on it: zero, zero, one, and one, two, four."
+ ]
+ ]
+ },
+ "p2": {
+ "dur": 44.664,
+ "marks": {
+ "eq2": 0.117,
+ "cx": 6.315,
+ "cy": 13.75,
+ "cz": 19.935,
+ "show": 25.833,
+ "meet": 28.49,
+ "line": 30.638,
+ "both": 34.336,
+ "many": 38.477
+ },
+ "cues": [
+ [
+ 0.117,
+ "The second equation: negative x plus two y minus z equals negative one."
+ ],
+ [
+ 6.315,
+ "Where does it cross the axes?"
+ ],
+ [
+ 8.125,
+ "On the x axis, negative x equals negative one, so x is one."
+ ],
+ [
+ 13.75,
+ "On the y axis, two y equals negative one, so y is negative one half."
+ ],
+ [
+ 19.935,
+ "On the z axis, negative z equals negative one, so z is one."
+ ],
+ [
+ 25.833,
+ "Three points, and the plane through them."
+ ],
+ [
+ 28.49,
+ "Two planes meet in a line."
+ ],
+ [
+ 30.638,
+ "Every point on this line solves the first two equations."
+ ],
+ [
+ 34.336,
+ "Both of our points are on it."
+ ],
+ [
+ 35.846,
+ "That's why each one passed the first two checks."
+ ],
+ [
+ 38.477,
+ "Two equations in three unknowns leave a whole line of solutions."
+ ],
+ [
+ 43.555,
+ "We need the third."
+ ]
+ ]
+ },
+ "p3": {
+ "dur": 34.848,
+ "marks": {
+ "eq3": 0.104,
+ "nox": 5.156,
+ "cz": 11.172,
+ "cy": 13.62,
+ "show": 16.562,
+ "cut": 17.539,
+ "pt": 23.047,
+ "miss": 26.471,
+ "only": 30.625
+ },
+ "cues": [
+ [
+ 0.104,
+ "The third equation: negative three y plus four z equals four."
+ ],
+ [
+ 5.156,
+ "x is missing, so this plane runs straight along the x direction, like a ramp."
+ ],
+ [
+ 11.172,
+ "It crosses the z axis at one, and the y axis at negative four thirds."
+ ],
+ [
+ 16.562,
+ "Here it is."
+ ],
+ [
+ 17.539,
+ "Now watch the line where the first two planes meet."
+ ],
+ [
+ 20.742,
+ "The third plane cuts straight through it, at a single point: zero, zero, one."
+ ],
+ [
+ 26.471,
+ "One, two, four is on the line too, but the third plane misses it."
+ ],
+ [
+ 30.625,
+ "Only zero, zero, one is on all three planes."
+ ]
+ ]
+ },
+ "check": {
+ "dur": 27.24,
+ "marks": {
+ "f1": 2.07,
+ "f2": 5.547,
+ "f3": 6.992,
+ "lines": 8.385,
+ "thru": 12.318,
+ "ans": 15.3,
+ "name": 21.367
+ },
+ "cues": [
+ [
+ 0.104,
+ "Let's look at it from all sides."
+ ],
+ [
+ 2.07,
+ "The first plane, the wall, passes through the point."
+ ],
+ [
+ 5.547,
+ "So does the second."
+ ],
+ [
+ 6.992,
+ "And so does the third."
+ ],
+ [
+ 8.385,
+ "Each pair of planes meets in a line, three lines in all, and all three lines run through the same point."
+ ],
+ [
+ 15.3,
+ "That point is the solution: x equals zero, y equals zero, z equals one."
+ ],
+ [
+ 21.367,
+ "In space, the solution of three equations is the point where three planes meet."
+ ]
+ ]
+ },
+ "q1": {
+ "dur": 4.2,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.185,
+ "Which points solve all three equations?"
+ ]
+ ]
+ },
+ "corner": {
+ "dur": 27.0,
+ "marks": {
+ "eq": 2.292,
+ "wx": 6.732,
+ "wy": 8.646,
+ "fz": 12.891,
+ "pt": 17.031,
+ "read": 22.188
+ },
+ "cues": [
+ [
+ 0.104,
+ "Some systems are easier to see."
+ ],
+ [
+ 2.292,
+ "x equals one, y equals two, z equals three."
+ ],
+ [
+ 6.732,
+ "x equals one is a wall."
+ ],
+ [
+ 8.646,
+ "y equals two is another wall, standing across the first."
+ ],
+ [
+ 12.891,
+ "z equals three is flat, like a ceiling at height three."
+ ],
+ [
+ 17.031,
+ "They meet in one point, like the corner of a room: one, two, three."
+ ],
+ [
+ 22.188,
+ "When each equation names just one letter, you can read the answer straight off."
+ ]
+ ]
+ },
+ "solve": {
+ "dur": 50.88,
+ "marks": {
+ "eq": 0.117,
+ "s3": 9.036,
+ "s2": 12.995,
+ "s1": 18.372,
+ "s1b": 23.294,
+ "sy": 26.576,
+ "pt": 29.284,
+ "see": 31.328,
+ "w": 34.818,
+ "f": 38.724,
+ "chk": 42.786
+ },
+ "cues": [
+ [
+ 0.117,
+ "Here's one that takes a little more work."
+ ],
+ [
+ 2.617,
+ "x plus y plus z equals three, x minus y equals zero, and z equals one."
+ ],
+ [
+ 9.036,
+ "The third equation already says z is one."
+ ],
+ [
+ 12.995,
+ "The second says x minus y is zero, so x and y are the same number."
+ ],
+ [
+ 18.372,
+ "Put both into the first: x plus x plus one equals three."
+ ],
+ [
+ 23.294,
+ "So two x equals two, and x is one."
+ ],
+ [
+ 26.576,
+ "And y is the same as x: one."
+ ],
+ [
+ 29.284,
+ "The point is one, one, one."
+ ],
+ [
+ 31.328,
+ "In the picture: the tilted plane from chapter eleven, the upright wall through the line where x equals y, and the floor at height one, all meeting at one, one, one."
+ ],
+ [
+ 42.786,
+ "Check it in all three: one plus one plus one is three, one minus one is zero, and z is one."
+ ]
+ ]
+ },
+ "move": {
+ "dur": 31.8,
+ "marks": {
+ "b3": 1.784,
+ "slide": 5.117,
+ "along": 10.482,
+ "new": 14.622,
+ "old": 16.589,
+ "back": 27.24
+ },
+ "cues": [
+ [
+ 0.091,
+ "Back to our first system."
+ ],
+ [
+ 1.784,
+ "What if we change the third right side, from four to ten?"
+ ],
+ [
+ 5.117,
+ "Only the third plane moves."
+ ],
+ [
+ 7.122,
+ "It slides, and the first two planes stay where they are."
+ ],
+ [
+ 10.482,
+ "So their line stays too, and the meeting point slides along that line."
+ ],
+ [
+ 14.622,
+ "It stops at one, two, four."
+ ],
+ [
+ 16.589,
+ "Remember one, two, four?"
+ ],
+ [
+ 18.932,
+ "It failed only the third equation, because the right side was four."
+ ],
+ [
+ 23.411,
+ "Now it is ten, and negative six plus sixteen is ten."
+ ],
+ [
+ 27.24,
+ "Change it back to four, and the point slides back to zero, zero, one."
+ ]
+ ]
+ },
+ "q2": {
+ "dur": 6.408,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn."
+ ],
+ [
+ 1.042,
+ "Change only the right sides, until the three planes meet at the marked point."
+ ]
+ ]
+ },
+ "none": {
+ "dur": 48.384,
+ "marks": {
+ "eq": 3.594,
+ "two": 9.141,
+ "nosol": 15.964,
+ "eq2": 20.286,
+ "pairs": 28.646,
+ "end": 32.344,
+ "par": 33.88,
+ "alg": 39.193,
+ "none": 47.031
+ },
+ "cues": [
+ [
+ 0.169,
+ "Three planes do not always meet in one point."
+ ],
+ [
+ 3.594,
+ "Take z equals one, z equals three, and x equals zero."
+ ],
+ [
+ 9.141,
+ "The first two are floors, one above the other."
+ ],
+ [
+ 12.096,
+ "They never meet: z can't be one and three at once."
+ ],
+ [
+ 15.964,
+ "So no point lies on all three planes."
+ ],
+ [
+ 18.828,
+ "There is no solution."
+ ],
+ [
+ 20.286,
+ "Here's a sneakier one: x plus z equals two, negative x plus z equals two, and z equals zero."
+ ],
+ [
+ 28.646,
+ "Every two of these planes do meet, each pair in a line."
+ ],
+ [
+ 32.344,
+ "But look at them from the end."
+ ],
+ [
+ 33.88,
+ "The three lines run side by side, like the edges of a tent, and never meet."
+ ],
+ [
+ 39.193,
+ "The algebra agrees."
+ ],
+ [
+ 40.951,
+ "The first two together say z is two, and the third says z is zero."
+ ],
+ [
+ 47.031,
+ "No solution again."
+ ]
+ ]
+ },
+ "line": {
+ "dur": 31.536,
+ "marks": {
+ "eq": 0.104,
+ "spine": 7.396,
+ "pts": 13.633,
+ "many": 20.443,
+ "sum": 26.172
+ },
+ "cues": [
+ [
+ 0.104,
+ "One more: x minus y equals zero, y minus z equals zero, and x minus z equals zero."
+ ],
+ [
+ 7.396,
+ "These three planes all share one line, the way the pages of an open book share the spine."
+ ],
+ [
+ 13.633,
+ "One, one, one is on all three."
+ ],
+ [
+ 15.404,
+ "So is two, two, two, and negative one, negative one, negative one."
+ ],
+ [
+ 20.443,
+ "Every point on the spine solves all three: infinitely many solutions."
+ ],
+ [
+ 26.172,
+ "So three planes can meet in one point, in no point at all, or along a whole line."
+ ]
+ ]
+ },
+ "q3": {
+ "dur": 3.792,
+ "marks": {},
+ "cues": [
+ [
+ 0.091,
+ "Quick check."
+ ],
+ [
+ 1.12,
+ "One point, no point, or a whole line?"
+ ]
+ ]
+ },
+ "wrap": {
+ "dur": 24.96,
+ "marks": {
+ "w1": 1.016,
+ "w2": 7.904,
+ "w3": 12.734,
+ "w4": 19.089,
+ "end": 22.734
+ },
+ "cues": [
+ [
+ 0.104,
+ "To sum up."
+ ],
+ [
+ 1.016,
+ "A system of three equations in x, y and z asks for one triple that makes all three true."
+ ],
+ [
+ 7.904,
+ "Each equation is a plane."
+ ],
+ [
+ 9.883,
+ "Two planes usually meet in a line."
+ ],
+ [
+ 12.734,
+ "The third plane usually cuts that line at one point: the solution."
+ ],
+ [
+ 16.979,
+ "Check it in every equation."
+ ],
+ [
+ 19.089,
+ "But three planes can also share no point at all, or a whole line."
+ ],
+ [
+ 22.734,
+ "Now try the chapter practice."
+ ]
+ ]
+ },
+ "final1": {
+ "dur": 3.576,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Chapter practice."
+ ],
+ [
+ 1.523,
+ "Does the point solve the whole system?"
+ ]
+ ]
+ },
+ "final2": {
+ "dur": 1.92,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Next, find the meeting point."
+ ]
+ ]
+ },
+ "final3": {
+ "dur": 2.448,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "One point, no point, or a line?"
+ ]
+ ]
+ },
+ "final4": {
+ "dur": 3.24,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Last set."
+ ],
+ [
+ 1.237,
+ "Move the planes with your hands."
+ ]
+ ]
+ },
+ "finish": {
+ "dur": 12.528,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Well done."
+ ],
+ [
+ 1.107,
+ "That's the end of chapter twelve, three planes, one point."
+ ],
+ [
+ 5.026,
+ "Next: the same three equations read down the columns, as three arrows in space."
+ ]
+ ]
+ }
+};
diff --git a/site/linear-algebra/ch12/audio/en/wrap.mp3 b/site/linear-algebra/ch12/audio/en/wrap.mp3
new file mode 100644
index 0000000..9a1c3b8
Binary files /dev/null and b/site/linear-algebra/ch12/audio/en/wrap.mp3 differ
diff --git a/site/linear-algebra/ch12/index.html b/site/linear-algebra/ch12/index.html
new file mode 100644
index 0000000..6e9041a
--- /dev/null
+++ b/site/linear-algebra/ch12/index.html
@@ -0,0 +1,444 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>Three Planes, One Point</title>
+<link rel="stylesheet" href="../lib/engine.css">
+<link rel="expect" href="#bar" blocking="render"><!-- hold the first frame until the player exists, so the page transition can run -->
+</head>
+<body>
+<script src="../lib/engine.js"></script>
+<script src="../lib/math.js"></script>
+<script src="../lib/linsys.js"></script>
+<script src="../lib/space3.js"></script>
+<script src="audio/en/timings.js"></script>
+<script>
+'use strict';
+const CHAPTER = { number: 12, title: 'Three Planes, One Point', minutes: 14, language: 'en' };
+
+/* ---------- chapter drawing helpers ---------- */
+const LEC = { A: [[2, -1, 0], [-1, 2, -1], [0, -3, 4]], b: [0, -1, 4] }; // the lecture's system (OCW 18.06, lecture 1)
+const VIEW = { yaw: -35, pitch: 22 }; // all three lecture planes seen face-on enough to tell apart
+const CARD = { x: 40, y: 430, w: 720, cls: 'side' }; // under the three equations and their readout
+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 r1 = n => Math.round(n * 10) / 10;
+const tri = q => `(${q.map(c => num(r1(c))).join(', ')})`;
+// A 3 × 3 system: equations top left, its planes on the right, no matrix (chapter 13 brings it back).
+const three = (p, A, b, { t0 = .1, view = VIEW, sol = true } = {}) => lin3(p, { A, b, eq: [90, 180], mat: null, space: { ...view }, t0, sol });
+const flash = (sys, key, t0) => sys.num(key).forEach(e => { tw(e, { c_fill: COL.task }, t0, .25); tw(e, { c_fill: COL.chalk }, t0 + 1.2, .6); });
+const glowPl = (pl, t0) => prog(q => pl.width(3 + 5 * Math.sin(Math.PI * q)), t0, 1.2, lin);
+// Start with every plane, line and the meeting point hidden; reveal(i, t) brings plane i in.
+const hideAll = sys => { sys.shown = new Set(); sys.planes.forEach(pl => pl.fade(0, 0, 0)); tw(sys.meet.e, { o: 0 }, 0, 0); tw(sys.sol, { o: 0 }, 0, 0); };
+const reveal = (sys, i, t, dur = 1) => { sys.shown?.add(i); sys.planes[i].fade(1, t, dur); };
+// Light some equations (and their planes, if shown yet) and dim the rest; planes not yet revealed stay hidden.
+const lit = (sys, on, t, dur = .6) => {
+ const L = on === null ? [0, 1, 2] : [].concat(on);
+ [0, 1, 2].forEach(i => {
+ tw(sys.rows[i], { o: L.includes(i) ? 1 : .35 }, t, dur);
+ if (!sys.shown || sys.shown.has(i)) sys.planes[i].fade(L.includes(i) ? 1 : .18, t, dur);
+ });
+};
+const ring = (V, q, color = COL.task, label = tri(q)) => {
+ const d = V.point(q, { color, r: 14, label, size: 24 });
+ const c = d.e.firstChild; c.setAttribute('fill', 'none'); c.setAttribute('stroke', color); c.setAttribute('stroke-dasharray', '4 4'); c.setAttribute('stroke-width', 3);
+ return d;
+};
+// One checked line: "2·0 − 0 = 0" then a ✓ or ✗, appearing on a word.
+const chk = (p, str, ok, x, y, t, size = 30) => {
+ say(p, [str], x, y, t, { size });
+ return text(p, ok ? '✓' : '✗', x + mathW([str], size) + 18, y, t + 1.2, { size, fill: ok ? COL.good : COL.bad, weight: 700 });
+};
+// A wall rising from a line on the floor (a growing upright strip), then handed to the real plane.
+const rise = (sys, i, a, b, t, dur = 1.6) => {
+ const V = sys.space, R = V.R, wl = V.poly(null, { color: S3_ROW[i], fo: .2, w: 3, into: V.polys });
+ prog(q => { const h = R * q; wl.set(q ? [[a[0], a[1], -h], [b[0], b[1], -h], [b[0], b[1], h], [a[0], a[1], h]] : null); }, t, dur, io);
+ reveal(sys, i, t + dur, .3); hide(wl.e, t + dur + .2, .3);
+};
+const tickCross = (V, pts, t, color = COL.task, into) => pts.map(([q, lab, dx, dy], k) => {
+ const d = V.point(null, { color, r: 8, label: lab || tri(q), size: 24, dx, dy, into });
+ prog(() => d.set(q), t[k], 0, lin); pulse(d.e, t[k]);
+ return d;
+});
+
+/* ---------- practice data ---------- */
+const YN = [['y', 'Yes', null, 'Y'], ['n', 'No', null, 'N']];
+const KIND = [['o', 'One point', null, 'O'], ['n', 'No point', null, 'N'], ['l', 'A whole line', null, 'L']];
+const SYS_S = ['x + y + z = 6', '2x − y = 0', 'z = 3'], SYS_T = ['x = 2', 'y + z = 1', 'x + y = 0'];
+const sysParts = rows => rows.flatMap((r, i) => [i ? ', ' : '', $m(r)]);
+const SQ = [
+ { parts: [$m('(1, 2, 3)')], ans: ['y'], why: '1 + 2 + 3 = 6, 2 − 2 = 0, z = 3. All three.' },
+ { parts: [$m('(3, 0, 3)')], ans: ['n'], why: 'The first works (6), but 2·3 − 0 = 6, not 0.' },
+ { parts: [$m('(2, 4, 0)')], ans: ['n'], why: '2 + 4 + 0 = 6 and 4 − 4 = 0, but z is 0, not 3. Two out of three is not enough.' },
+ { parts: [$m('(1, 2, 0)')], ans: ['n'], why: '1 + 2 + 0 = 3, not 6.' },
+];
+const TQ = [
+ { parts: [$m('(2, −2, 3)')], ans: ['y'], why: 'x = 2; −2 + 3 = 1; 2 + (−2) = 0. All three.' },
+ { parts: [$m('(2, 0, 1)')], ans: ['n'], why: 'x = 2 and 0 + 1 = 1, but 2 + 0 = 2, not 0.' },
+ { parts: [$m('(2, −2, 1)')], ans: ['n'], why: '−2 + 1 = −1, not 1.' },
+ { parts: [$m('(0, 0, 1)')], ans: ['n'], why: 'x must be 2.' },
+];
+const MEETQ = [
+ { parts: ['x = 4, y = −1, z = 2: (', { box: '4' }, ', ', { box: '-1' }, ', ', { box: '2' }, ')'], why: 'Each equation names one letter: read them off.', hint: 'Each equation already says what its letter is.' },
+ { parts: ['z = 2, y = 3, x + y + z = 6: (', { box: '1' }, ', ', { box: '3' }, ', ', { box: '2' }, ')'], why: 'x + 3 + 2 = 6, so x = 1.', hint: 'Put y = 3 and z = 2 into the third: x + 5 = 6.' },
+ { parts: ['x = 1, x + y = 3, y + z = 5: (', { box: '1' }, ', ', { box: '2' }, ', ', { box: '3' }, ')'], why: 'x = 1, so y = 2; then 2 + z = 5, so z = 3.', hint: 'Start with x = 1. The second then gives y; the third gives z.' },
+ { parts: ['z = −1, y = 2z, x + y + z = 0: (', { box: '3' }, ', ', { box: '-2' }, ', ', { box: '-1' }, ')'], why: 'y = 2·(−1) = −2; x − 2 − 1 = 0, so x = 3.', hint: 'y is twice z, so y = −2. Then x − 2 − 1 = 0.' },
+ { parts: ['x − y = 0, z = 2, x + y + z = 8: (', { box: '3' }, ', ', { box: '3' }, ', ', { box: '2' }, ')'], why: 'x = y, so x + x + 2 = 8, 2x = 6, x = 3 and y = 3.', hint: 'x and y are the same number. Then x + x + 2 = 8.' },
+];
+const KINDQ = [
+ { parts: [$m('x = 1, y = 1, z = 1')], ans: ['o'], why: 'Two walls and a floor: one corner, (1, 1, 1).' },
+ { parts: [$m('z = 0, z = 2, x = 5')], ans: ['n'], why: 'z = 0 and z = 2 are two floors that never meet.' },
+ { parts: [$m('x = 0, y = 0, 2x + 3y = 0')], ans: ['l'], why: 'All three are walls through the z-axis: every (0, 0, z) works.' },
+ { parts: [$m('x + y + z = 2, x + y + z = 5, y = 1')], ans: ['n'], why: 'x + y + z cannot be 2 and 5 at once: the first two planes are parallel.' },
+ { parts: [$m('y = 0, z = 0, x + y + z = 4')], ans: ['o'], why: 'y = 0, z = 0, then x = 4: the point (4, 0, 0).' },
+ { parts: [$m('x − y = 0, y − z = 0, x − z = 0')], ans: ['l'], why: 'x = y = z: the line through (1, 1, 1), (2, 2, 2), …' },
+];
+
+/* ---------- beats: [id, title, run(m, D), { ask }?] ---------- */
+const BEATS = [
+ ['intro', 'Three planes, one point', (m, D) => {
+ const g = G(scene, { o: 0, y: 24 });
+ T(g, 'Unit 1, Chapter 12', { x: 800, y: 320, size: 28, fill: COL.dim, anchor: 'middle' });
+ T(g, 'Three Planes, One Point', { x: 800, y: 430, size: 88, weight: 600, anchor: 'middle' });
+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);
+ const r = text(scene, 'three equations in x, y, z: three planes, and the point they share', 800, 560, m('sub'), { size: 34, fill: COL.dim, anchor: 'middle' });
+ // three strokes that swing in and cross at one dot
+ const lg = G(scene, { x: 800, y: 700 });
+ S3_ROW.forEach((c, i) => {
+ const l = path(lg, 'M-150 0H150', { stroke: c, 'stroke-width': 6, 'stroke-linecap': 'round' });
+ put(l, { o: 0, r: 0 }); tw(l, { o: 1 }, m('sub') + 1 + i * .5, .4); tw(l, { r: [-35, 30, 85][i] }, m('sub') + 1 + i * .5, 1.6, soft);
+ });
+ tw(lg, { r: 25 }, m('sub') + 1, D - m('sub') - 1, soft);
+ const dt = mk('circle', { r: 11, fill: COL.chalk, stroke: COL.board, 'stroke-width': 3 }, lg);
+ put(dt, { o: 0, s: 0 }); pop(dt, m('move') + .5); pulse(dt, m('move') + 2);
+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(lg, D - .9, .8);
+ }],
+
+ ['system', 'Three equations at once', (m) => {
+ const p = S.p = panel(0);
+ text(p, 'Three equations, three unknowns', 60, 110, .2, { size: 40, weight: 600 });
+ const recap = G(p, {});
+ text(recap, 'chapter 2: two lines, one crossing point', 90, 220, .5, { size: 30, fill: COL.dim });
+ const sk = G(recap, { x: 330, y: 420 }); // chapter 2 in a sketch: two lines drawn on, crossing at a dot
+ [['M-180 90L180 -90', S3_ROW[0]], ['M-180 -60L180 60', S3_ROW[1]]].forEach(([d, c], i) => draw(path(sk, d, { stroke: c, 'stroke-width': 5, 'stroke-linecap': 'round' }, { d: 0 }), 1 + i * 1.6, 1.4));
+ const sd = mk('circle', { r: 10, fill: COL.chalk }, sk); put(sd, { o: 0, s: 0 }); pop(sd, 4.4); pulse(sd, 6);
+ hide(recap, m('eq') - .5, .4);
+ const sys = S.sys = three(p, LEC.A, LEC.b, { t0: m('eq') - .3 });
+ hideAll(sys);
+ put(sys.E, { o: 0 });
+ sys.rows.forEach((g, i) => { put(g, { o: 0 }); show(g, m('eq') + [0, 3.2, 8.4][i], .5); });
+ flash(sys, 'a02', m('zero')); flash(sys, 'a20', m('zero') + 2.2);
+ text(p, 'all three true at once', 90, 420, m('all'), { size: 30, fill: COL.task, weight: 600 });
+ const V = sys.space;
+ V.sway(6, 14);
+ // two tries, side by side
+ const P1 = V.point(null, { color: COL.chalk, label: '(0, 0, 1)', size: 26 }), P2 = V.point(null, { color: COL.chalk, label: '(1, 2, 4)', size: 26 });
+ prog(() => P1.set([0, 0, 1]), m('try'), 0, lin); pulse(P1.e, m('try'));
+ prog(() => P2.set([1, 2, 4]), m('try2'), 0, lin); pulse(P2.e, m('try2'));
+ S.P1 = P1; S.P2 = P2;
+ say(p, ['(0, 0, 1)'], 90, 490, m('try'), { size: 34, fill: COL.task });
+ chk(p, '2·0 − 0 = 0', true, 90, 545, m('c1'));
+ chk(p, '−0 + 2·0 − 1 = −1', true, 90, 595, m('c2'));
+ chk(p, '−3·0 + 4·1 = 4', true, 90, 645, m('c3'));
+ text(p, 'a solution', 90, 705, m('yes'), { size: 30, fill: COL.good, weight: 600 });
+ say(p, ['(1, 2, 4)'], 450, 490, m('try2'), { size: 34, fill: COL.task });
+ chk(p, '2 − 2 = 0', true, 450, 545, m('d1'));
+ chk(p, '−1 + 4 − 4 = −1', true, 450, 595, m('d2'));
+ chk(p, '−6 + 16 = 10', false, 450, 645, m('d3'));
+ text(p, 'not a solution', 450, 705, m('no'), { size: 30, fill: COL.bad, weight: 600 });
+ }],
+
+ ['p1', 'The first plane', (m) => {
+ const sys = S.sys, V = sys.space, p = S.p;
+ V.sway(5, 13);
+ // clear the checks (everything drawn on the panel after the equations' space) for the plane story
+ [...p.children].filter(e => e !== sys.E && e !== V.g && !e.textContent.startsWith('Three equations')).forEach(e => hide(e, .1, .4));
+ lit(sys, 0, .2);
+ const w = G(p, {});
+ text(w, 'z is missing: z is free', 90, 460, m('free'), { size: 30, fill: COL.task, weight: 600 });
+ text(w, 'on the floor: the line 2x − y = 0', 90, 510, m('floor'), { size: 30, fill: S3_ROW[0], weight: 600 });
+ text(w, 'stood up: a wall', 90, 560, m('rise'), { size: 30, fill: S3_ROW[0], weight: 600 });
+ S.w = w;
+ const ln = V.line(null, null, { color: S3_ROW[0], w: 6, into: V.content });
+ prog(q => ln.set([-2, -4, 0], [-2 + 4 * q, -4 + 8 * q, 0]), m('floor') + .3, 1.4, io);
+ hide(ln.e, m('rise') + 2, .4);
+ V.turn({ pitch: 55 }, m('floor'), 1.6); V.turn({ pitch: VIEW.pitch }, m('rise'), 1.6);
+ rise(sys, 0, [-2, -4], [2, 4], m('rise'));
+ pulse(S.P1.e, m('pts') + .3); pulse(S.P2.e, m('pts') + 1.6);
+ }],
+
+ ['p2', 'The second plane', (m) => {
+ const sys = S.sys, V = sys.space, p = S.p;
+ V.sway(5, 13);
+ hide(S.w, .1, .4);
+ lit(sys, 1, m('eq2') - .3);
+ const w = S.w = G(p, {});
+ const cr = tickCross(V, [[[1, 0, 0], '', 12, 30], [[0, -.5, 0], '(0, −½, 0)', -120, 4], [[0, 0, 1], '', -100, -14]], [m('cx') + 2.5, m('cy') + 2.8, m('cz') + 2.4], COL.task, w);
+ say(w, ['x-axis: −x = −1, x = 1'], 90, 460, m('cx') + 1, { size: 30 });
+ say(w, ['y-axis: 2y = −1, y = −', F(1, 2)], 90, 510, m('cy') + 1, { size: 30 });
+ say(w, ['z-axis: −z = −1, z = 1'], 90, 560, m('cz') + 1, { size: 30 });
+ reveal(sys, 1, m('show'), 1);
+ cr.forEach(d => hide(d.e, m('meet'), .4));
+ lit(sys, [0, 1], m('meet'));
+ prog(q => sys.lines[0].e.setAttribute('stroke-width', 2.5 + 4 * Math.sin(Math.PI * q)), m('meet') + .3, 1.4, lin);
+ hide(w, m('line') - .3, .3);
+ const w2 = G(p, {});
+ text(w2, 'on the dashed line: both equations true', 90, 460, m('line'), { size: 30, fill: COL.chalk, weight: 600 });
+ // a probe runs along the meeting line (t, 2t, 1 + 3t)
+ const pr = V.point(null, { color: COL.task, r: 9 });
+ prog(q => { const t = -1 + 1.8 * (1 - Math.cos(2 * Math.PI * q)) / 2; pr.set([t, 2 * t, 1 + 3 * t]); }, m('line') + .3, m('both') - m('line') - .4, lin);
+ hide(pr.e, m('both'), .3);
+ pulse(S.P1.e, m('both') + .5); pulse(S.P2.e, m('both') + 1.2);
+ text(w2, 'two equations: a whole line of solutions', 90, 520, m('many'), { size: 30, fill: COL.task, weight: 600 });
+ S.w = w2;
+ V.turn({ yaw: VIEW.yaw + 30 }, m('meet'), 3); V.turn({ yaw: VIEW.yaw }, m('many'), 2.5);
+ }],
+
+ ['p3', 'The third plane', (m) => {
+ const sys = S.sys, V = sys.space, p = S.p;
+ V.sway(5, 13);
+ hide(S.w, .1, .4);
+ lit(sys, 2, m('eq3') - .3);
+ const w = S.w = G(p, {});
+ text(w, 'x is missing: it runs along x', 90, 460, m('nox'), { size: 30, fill: COL.task, weight: 600 });
+ say(w, ['z-axis: 4z = 4, z = 1'], 90, 515, m('cz'), { size: 30 });
+ say(w, ['y-axis: −3y = 4, y = −', F(4, 3)], 90, 570, m('cy'), { size: 30 });
+ const cr = tickCross(V, [[[0, 0, 1], '', -100, -14], [[0, -4 / 3, 0], '(0, −4/3, 0)', -150, 4]], [m('cz') + .4, m('cy') + .6], COL.task, w);
+ reveal(sys, 2, m('show'), 1);
+ cr.forEach(d => hide(d.e, m('cut'), .4));
+ lit(sys, [0, 1], m('cut') - .2); // the line of the first two, bright; the third plane dim while we look at the line
+ prog(q => sys.lines[0].e.setAttribute('stroke-width', 2.5 + 4 * Math.sin(Math.PI * q)), m('cut'), 1.4, lin);
+ lit(sys, null, m('cut') + 2.4);
+ show(sys.meet.e, m('pt'), .3); pulse(sys.meet.e, m('pt')); pulse(sys.meet.e, m('pt') + 1);
+ show(sys.sol, m('pt') + .4, .5);
+ hide(w, m('miss') - .3, .3);
+ tw(S.P2.e, { o: 1 }, m('miss'), 0); tw(S.P2.e.firstChild, { c_fill: COL.bad }, m('miss'), .3); tw(S.P2.t, { c_fill: COL.bad }, m('miss'), .3);
+ text(p, '(1, 2, 4): on the line, off the third plane', 90, 470, m('miss'), { size: 28, fill: COL.bad, weight: 600 });
+ text(p, '(0, 0, 1): on all three planes', 90, 530, m('only'), { size: 30, fill: COL.good, weight: 600 });
+ V.turn({ yaw: VIEW.yaw - 25, pitch: 30 }, m('cut'), 3);
+ }],
+
+ ['check', 'From all sides', (m) => {
+ const sys = S.sys, V = sys.space;
+ hide(S.P2.e, .1, .5); hide(S.P1.e, .1, .3);
+ V.turn({ yaw: VIEW.yaw - 25 + 340, pitch: 26 }, .3, m('ans') - .3, lin); // once round, slowly
+ sys.focus(0, m('f1')); sys.focus(1, m('f2')); sys.focus(2, m('f3')); sys.focus(null, m('lines'));
+ [m('f1'), m('f2'), m('f3')].forEach(t => pulse(sys.meet.e, t + .4));
+ [0, 1, 2].forEach(i => prog(q => sys.lines[i].e.setAttribute('stroke-width', 2.5 + 3.5 * Math.sin(Math.PI * q)), m('lines') + i * .5, 1.2, lin));
+ pulse(sys.meet.e, m('thru') + .5);
+ tw(sys.sol, { s: 1.08 }, m('ans'), .3); tw(sys.sol, { s: 1 }, m('ans') + .5, .4);
+ const n = G(S.p, { o: 0 });
+ T(n, 'three planes meet → the solution', { x: 90, y: 610, size: 34, weight: 600, fill: COL.task });
+ show(n, m('name'));
+ V.sway(5, 12, m('ans'));
+ }],
+
+ ['q1', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ S.sys = three(p, LEC.A, LEC.b, { sol: false });
+ S.sys.space.sway(6, 14);
+ }, { ask: done => quiz(CARD, [{
+ id: 'c-all', prompt: ['Does the point solve all three equations?'],
+ build: grid([
+ { parts: [$m('(0, 0, 1)')], ans: ['y'], why: '0 = 0, −1 = −1, 4 = 4. It is the meeting point.' },
+ { parts: [$m('(1, 2, 4)')], ans: ['n'], why: 'The first two work, but the third gives −6 + 16 = 10, not 4.' },
+ { parts: [$m('(0, 0, 0)')], ans: ['n'], why: 'The first works, but the second gives 0, not −1.' },
+ { parts: [$m('(1, 2, 0)')], ans: ['n'], why: 'The first works (2 − 2 = 0), but the second gives −1 + 4 − 0 = 3, not −1.' },
+ ], YN, { multi: false, text: true }),
+ }], done) }],
+
+ ['corner', 'The corner of a room', (m) => {
+ const p = panel(0);
+ text(p, 'Two walls and a ceiling', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = three(p, [[1, 0, 0], [0, 1, 0], [0, 0, 1]], [1, 2, 3], { t0: m('eq') - .3, view: { yaw: 30, pitch: 22 } });
+ hideAll(sys);
+ const V = sys.space;
+ V.sway(6, 14);
+ reveal(sys, 0, m('wx')); lit(sys, 0, m('wx') - .2);
+ reveal(sys, 1, m('wy')); lit(sys, 1, m('wy') - .2);
+ reveal(sys, 2, m('fz')); lit(sys, 2, m('fz') - .2);
+ lit(sys, null, m('pt') - .2);
+ show(sys.meet.e, m('pt'), .3); pulse(sys.meet.e, m('pt') + .2); show(sys.sol, m('pt') + .6);
+ // the corner's three edges, from the point, along the three axes' directions
+ const e = [0, 1, 2].map(j => V.line(null, null, { color: COL.chalk, w: 3, dash: '2 6', into: V.content }));
+ prog(() => { e[0].set([1, 2, 3], [-4, 2, 3]); e[1].set([1, 2, 3], [1, -4, 3]); e[2].set([1, 2, 3], [1, 2, -4]); }, m('pt') + .6, 0, lin);
+ text(p, 'one letter per equation: read it off', 90, 480, m('read'), { size: 30, fill: COL.task, weight: 600 });
+ }],
+
+ ['solve', 'A little more work', (m) => {
+ const p = panel(0);
+ text(p, 'Finding the point step by step', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = three(p, [[1, 1, 1], [1, -1, 0], [0, 0, 1]], [3, 0, 1], { t0: m('eq') - .3, view: { yaw: 25, pitch: 20 } });
+ hideAll(sys);
+ const V = sys.space;
+ V.sway(6, 14);
+ const w = G(p, {});
+ say(w, ['z = 1'], 90, 470, m('s3'), { size: 34, fill: S3_ROW[2] });
+ say(w, ['x − y = 0, so x = y'], 90, 525, m('s2'), { size: 34, fill: S3_ROW[1] });
+ say(w, ['x + x + 1 = 3'], 90, 580, m('s1'), { size: 34, fill: S3_ROW[0] });
+ say(w, ['2x = 2, x = 1'], 90, 635, m('s1b'), { size: 34 });
+ say(w, ['y = x = 1'], 90, 690, m('sy'), { size: 34 });
+ lit(sys, 2, m('s3') - .2); lit(sys, 1, m('s2') - .2); lit(sys, 0, m('s1') - .2); lit(sys, null, m('pt') - .2);
+ show(sys.sol, m('pt') + .4);
+ reveal(sys, 0, m('see')); reveal(sys, 1, m('w')); reveal(sys, 2, m('f'));
+ show(sys.meet.e, m('f') + .6, .3); pulse(sys.meet.e, m('f') + .8);
+ tw(w, { o: .25 }, m('see'), .4);
+ V.turn({ yaw: 60, pitch: 26 }, m('see'), 4);
+ const c = G(p, {});
+ chk(c, '1 + 1 + 1 = 3', true, 430, 470, m('chk') + 1);
+ chk(c, '1 − 1 = 0', true, 430, 525, m('chk') + 3.6);
+ chk(c, 'z = 1', true, 430, 580, m('chk') + 5.2);
+ }],
+
+ ['move', 'Change a right side', (m) => {
+ const p = panel(0);
+ text(p, 'Change a right side', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = three(p, LEC.A, LEC.b);
+ const V = sys.space;
+ V.sway(5, 14);
+ flash(sys, 'b2', m('b3'));
+ sys.focus(2, m('slide') - .3);
+ sys.to({ b2: 10 }, m('slide'), m('new') - m('slide'), io);
+ flash(sys, 'b2', m('slide'));
+ prog(q => sys.lines[0].e.setAttribute('stroke-width', 2.5 + 4 * Math.sin(Math.PI * q)), m('along'), 1.4, lin);
+ sys.focus(null, m('along'));
+ const old = V.point([0, 0, 1], { color: COL.dim, r: 7 });
+ put(old.e, { o: 0 }); show(old.e, m('slide'), .3);
+ pulse(sys.meet.e, m('new'));
+ say(p, ['−3·2 + 4·4 = −6 + 16 = 10 ✓'], 90, 480, m('old') + 4, { size: 30, fill: COL.good });
+ sys.to({ b2: 4 }, m('back'), 2.2, io); flash(sys, 'b2', m('back'));
+ V.turn({ yaw: VIEW.yaw + 20, pitch: 28 }, m('slide'), 4);
+ }],
+
+ ['q2', 'Your turn', () => {
+ const p = panel(0);
+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = three(p, LEC.A, LEC.b);
+ ring(sys.space, [1, 1, 1]);
+ sys.space.sway(5, 16);
+ }, { ask: done => quiz(CARD, [{
+ id: 'c-meet', prompt: ['Change only the right sides until the three planes meet at ', $m('(1, 1, 1)'), '. Scrub a right side, or drag a plane by its edge.'],
+ build: lin3Task(S.sys, v => v.b0 === 1 && v.b1 === 0 && v.b2 === 1,
+ 'Right sides 1, 0, 1: put x = y = z = 1 into each left side. 2 − 1 = 1, −1 + 2 − 1 = 0, −3 + 4 = 1.',
+ 'Put x = 1, y = 1, z = 1 into each left side: what you get is the right side that plane needs.',
+ () => S.sys.set({ b0: 1, b1: 0, b2: 1 }), ['b0', 'b1', 'b2']),
+ }], done) }],
+
+ ['none', 'No point at all', (m) => {
+ const p = panel(0);
+ text(p, 'When there is no meeting point', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = three(p, [[0, 0, 1], [0, 0, 1], [1, 0, 0]], [1, 3, 0], { t0: m('eq') - .3, view: { yaw: 40, pitch: 16 } });
+ const V = sys.space;
+ V.sway(5, 14);
+ tw(sys.sol, { o: 0 }, 0, 0); show(sys.sol, m('nosol'), .4);
+ sys.focus([0, 1], m('two'));
+ const a = text(p, 'z = 1 and z = 3 at once? Never.', 90, 470, m('two') + 2, { size: 30, fill: COL.bad, weight: 600 });
+ sys.focus(null, m('nosol'));
+ tw(sys.sol, { s: 1.06 }, m('nosol'), .3); tw(sys.sol, { s: 1 }, m('nosol') + .5, .4);
+ hide(a, m('eq2') - .4, .3);
+ // switch to the tent: hide the planes, change the numbers, bring them back
+ sys.planes.forEach(pl => { pl.fade(0, m('eq2') - .4, .3); pl.fade(1, m('eq2') + .5, .8); });
+ sys.to({ a00: 1, a01: 0, a02: 1, a10: -1, a11: 0, a12: 1, a20: 0, a21: 0, a22: 1, b0: 2, b1: 2, b2: 0 }, m('eq2') - .1, .1, lin);
+ V.turn({ yaw: 30, pitch: 20 }, m('eq2') - .1, .1);
+ [0, 1, 2].forEach(i => prog(q => sys.lines[i].e.setAttribute('stroke-width', 2.5 + 3.5 * Math.sin(Math.PI * q)), m('pairs') + .6 + i * .6, 1.2, lin));
+ V.turn({ yaw: 14, pitch: 7 }, m('end'), 2.4); // nearly along y: the planes stand as a triangle, the three lines run side by side into the picture
+ const b = G(p, {});
+ text(b, 'every two meet in a line,', 90, 470, m('pairs'), { size: 30, fill: COL.chalk, weight: 600 });
+ text(b, 'but the three lines never meet', 90, 515, m('par'), { size: 30, fill: COL.bad, weight: 600 });
+ say(b, ['first two: z = 2. third: z = 0.'], 90, 580, m('alg'), { size: 30 });
+ V.turn({ yaw: 30, pitch: 22 }, m('none') - .6, 1.6);
+ }],
+
+ ['line', 'A whole line', (m) => {
+ const p = panel(0);
+ text(p, 'When the planes share a line', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = three(p, [[1, -1, 0], [0, 1, -1], [1, 0, -1]], [0, 0, 0], { t0: m('eq') - .3, view: { yaw: -20, pitch: 22 } });
+ const V = sys.space;
+ tw(sys.sol, { o: 0 }, 0, 0); show(sys.sol, m('many'), .4);
+ V.sway(6, 12);
+ const sp = V.line(null, null, { color: COL.task, w: 6, into: V.content });
+ prog(q => sp.set([-4, -4, -4], [-4 + 8 * q, -4 + 8 * q, -4 + 8 * q]), m('spine'), 1.4, io);
+ // look down the spine, like looking at a book from its end
+ V.turn({ yaw: -135, pitch: 35.3 }, m('spine') + 1.2, 3); V.turn({ yaw: -60, pitch: 24 }, m('pts') - .2, 2.6);
+ [[1, 1, 1], [2, 2, 2], [-1, -1, -1]].forEach((q, i) => {
+ const d = V.point(null, { color: COL.chalk, label: tri(q), size: 24 });
+ const t = m('pts') + [0, 1.6, 3.2][i];
+ prog(() => d.set(q), t, 0, lin); pulse(d.e, t);
+ });
+ say(p, ['1 − 1 = 0, 1 − 1 = 0, 1 − 1 = 0 ✓'], 90, 480, m('pts') + .4, { size: 28, fill: COL.good });
+ tw(sys.sol, { s: 1.06 }, m('many'), .3); tw(sys.sol, { s: 1 }, m('many') + .5, .4);
+ const n = G(p, { o: 0 });
+ T(n, 'one point · no point · a whole line', { x: 90, y: 600, size: 34, weight: 600, fill: COL.task });
+ show(n, m('sum'));
+ }],
+
+ ['q3', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ const V = space3(p, { ...VIEW, cx: 1330, size: 460 });
+ [[0, 0, 1, 1], [0, 0, 1, 3], [1, 0, 0, 0]].forEach((c, i) => V.plane(...c, { color: S3_ROW[i], fo: .14 }));
+ V.sway(6, 14);
+ }, { ask: done => quiz({ x: 40, y: 170, w: 1010, cls: 'side' }, [{
+ id: 'c-kind', prompt: ['Do the three planes meet in one point, in no point, or along a whole line?'],
+ build: grid([
+ { parts: [$m('x = 2, y = −1, z = 0')], ans: ['o'], why: 'Each names one letter: the point (2, −1, 0).' },
+ { parts: [$m('z = 1, z = 4, x + y = 0')], ans: ['n'], why: 'Two floors, z = 1 and z = 4, never meet.' },
+ { parts: [$m('x = 0, y = 0, x + y = 0')], ans: ['l'], why: 'Three walls through the z-axis: every (0, 0, z).' },
+ { parts: [$m('x + y + z = 3, x − y = 0, z = 1')], ans: ['o'], why: 'This was our example: (1, 1, 1).' },
+ ], KIND, { multi: false, text: true }),
+ }], done) }],
+
+ ['wrap', 'Summary', (m) => {
+ const p = panel(0);
+ [['Three equations, three unknowns: one triple must make all three true.', 'w1'], ['Each equation is a plane; two planes usually meet in a line.', 'w2'],
+ ['The third plane cuts that line at one point: the solution. Check it in each.', 'w3'], ['Three planes can also meet nowhere, or along a whole line.', 'w4']].forEach(([str, mark], i) => {
+ const g = G(p, { x: -16, y: 230 + i * 130, o: 0 });
+ mk('circle', { cx: 150, cy: -12, r: 26, fill: COL.task }, g);
+ T(g, String(i + 1), { x: 150, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });
+ T(g, str, { x: 210, size: 34, weight: 600 });
+ tw(g, { o: 1, x: 0 }, m(mark), .6);
+ });
+ }],
+ ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
+ id: 'p-s', prompt: ['System: ', ...sysParts(SYS_S), '. Does the point solve all three?'],
+ build: grid(SQ, YN, { multi: false, text: true }),
+ }, {
+ id: 'p-t', prompt: ['System: ', ...sysParts(SYS_T), '. Does the point solve all three?'],
+ build: grid(TQ, YN, { multi: false, text: true }),
+ }], done, 'Chapter practice · set 1 of 4') }],
+ ['final2', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
+ id: 'p-meet', prompt: ['Find the point where the three planes meet. Start with the equation that names one letter.'],
+ build: blanks(MEETQ),
+ }], done, 'Chapter practice · set 2 of 4') }],
+ ['final3', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
+ id: 'p-kind', prompt: ['One point, no point, or a whole line?'],
+ build: grid(KINDQ, KIND, { multi: false, text: true }),
+ }], done, 'Chapter practice · set 3 of 4') }],
+ ['final4', 'Chapter practice', () => {
+ const p = panel(0);
+ text(p, 'Move the planes', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = three(p, LEC.A, LEC.b);
+ sys.space.sway(5, 16);
+ }, { ask: done => quiz(CARD, [{
+ id: 'p-meet1', prompt: ['Change only the right sides so the planes meet at ', $m('(1, 0, 1)'), '.'],
+ build: lin3Task(S.sys, v => v.b0 === 2 && v.b1 === -2 && v.b2 === 4, 'Right sides 2, −2, 4: 2·1 − 0 = 2, −1 + 0 − 1 = −2, 0 + 4 = 4.',
+ 'Put x = 1, y = 0, z = 1 into each left side.', () => S.sys.set({ b0: 2, b1: -2, b2: 4 }), ['b0', 'b1', 'b2']),
+ }, {
+ id: 'p-meet2', prompt: ['Now make them meet at ', $m('(2, 1, 0)'), '.'],
+ build: lin3Task(S.sys, v => v.b0 === 3 && v.b1 === 0 && v.b2 === -3, 'Right sides 3, 0, −3: 4 − 1 = 3, −2 + 2 − 0 = 0, −3 + 0 = −3.',
+ 'Put x = 2, y = 1, z = 0 into each left side.', () => S.sys.set({ b0: 3, b1: 0, b2: -3 }), ['b0', 'b1', 'b2']),
+ }, {
+ id: 'p-none', prompt: ['Change only the numbers in front of x, y, z in the third equation, so that no point lies on all three planes.'],
+ build: lin3Task(S.sys, (v, s) => !!s.none && (v.a20 || v.a21 || v.a22), 'For example 2x − y + 0z on the third left side: the third plane is then parallel to the first. Both say 2x − y equals a number, but different numbers, so they never meet.',
+ 'Make the third plane parallel to the first: copy the first equation’s numbers in front of x, y and z. Then both say 2x − y equals something, but different somethings.',
+ () => S.sys.set({ a20: 2, a21: -1, a22: 0 }), ['a20', 'a21', 'a22']),
+ }], done, 'Chapter practice · set 4 of 4') }],
+ ['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],
+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
+
+boot();
+</script>
+</body>
+</html>
diff --git a/site/linear-algebra/lib/grid2.js b/site/linear-algebra/lib/grid2.js
new file mode 100644
index 0000000..b2e8147
--- /dev/null
+++ b/site/linear-algebra/lib/grid2.js
@@ -0,0 +1,249 @@
+// A 2 × 2 matrix A carrying the whole plane, drawn from one state: the matrix in brackets (and, when given, a vector x
+// and the product Ax beside it) and the plane, where every grid line, the unit square, a small shape and some points are
+// moved by A while the original grid stays faint behind. The columns of A are the green and violet arrows: their tips are
+// where [1, 0] and [0, 1] land. Drag a tip and the grid and the numbers follow; scrub a number and the grid follows.
+// The beat moves it with g.to(); a question turns the reader's hands on with g.live(true). Same shape as linsys.js.
+// Loads after engine.js and math.js (it uses plane()).
+const G2_COLS = [COL.irr, COL.real], G2_AX = COL.task;
+// A small flag: a pole and a pennant pointing right, so a flip or a turn shows at once.
+const G2_FLAG = [[.5, .5], [.8, .5], [.8, 2], [1.9, 2.4], [.8, 2.8], [.8, 3.2], [.5, 3.2]];
+
+function grid2(p, { A = [[1, 0], [0, 1]], x = null, mat = [90, 300], size = 54, plane: po = {}, grid = true, square = true, shape = false,
+ units = true, pts = [], t0 = .1, hidePlane = false, result = true } = {}) {
+ const v = { a00: A[0][0], a01: A[0][1], a10: A[1][0], a11: A[1][1], x0: x ? x[0] : 0, x1: x ? x[1] : 0 };
+ const RANGE = { a00: 9, a01: 9, a10: 9, a11: 9, x0: 9, x1: 9 }, K = 14; // grid lines k = −K … K
+ const holder = G(p, { o: hidePlane ? 0 : 1 });
+ const P2 = plane(holder, { cx: 1160, cy: 450, u: 52, x0: -6, x1: 6, y0: -6, y1: 6, t0, ...po });
+ const { PX, PY } = P2, box = [P2.x0 - .4, P2.x1 + .4, P2.y0 - .4, P2.y1 + .4];
+ const svg = $('stage'), listeners = [], slots = [], drags = [];
+ let live = false, plan = { ...v };
+ const fmt = n => { const r = Math.round(n * 10) / 10; return (r < 0 ? '−' : '') + (Number.isInteger(r) ? String(Math.abs(r)) : Math.abs(r).toFixed(1)); };
+ const setText = (e, s) => { if (e.textContent !== s) e.textContent = s; };
+ const setD = (e, d) => { if (e.getAttribute('d') !== d) e.setAttribute('d', d); };
+ const clamp = (k, n) => Math.max(-RANGE[k], Math.min(RANGE[k], n));
+ const pt = e => { const q = svg.createSVGPoint(); q.x = e.clientX; q.y = e.clientY; const w = q.matrixTransform(P2.g.getScreenCTM().inverse()); return [(w.x - P2.cx) / P2.u, (P2.cy - w.y) / P2.u]; };
+ const map = ([a, b]) => [v.a00 * a + v.a01 * b, v.a10 * a + v.a11 * b];
+ const XY = ([a, b]) => `${PX(a).toFixed(1)} ${PY(b).toFixed(1)}`;
+
+ /* ---------- numbers you can scrub ---------- */
+ function slot(g, key, x, y, fill) {
+ const bx = mk('rect', { x: x - 44, y: y - size * .85, width: 88, height: size * 1.1, rx: 10, fill: 'transparent' }, g);
+ const t = T(g, '', { x, y, size, fill, font: MATH, anchor: 'middle' });
+ t.style.pointerEvents = 'none';
+ bx.setAttribute('aria-label', key);
+ const s = { key, t, box: bx, set: () => setText(t, fmt(v[key])) };
+ let drag = null;
+ bx.addEventListener('pointerdown', e => { if (!live || !s.on) return; e.preventDefault(); drag = { x: e.clientX, from: Math.round(v[key]) }; bx.setPointerCapture(e.pointerId); });
+ bx.addEventListener('pointermove', e => { if (!drag) return; const k = svg.getScreenCTM().a; edit({ [key]: clamp(key, drag.from + Math.round((e.clientX - drag.x) / k / 22)) }); });
+ const end = () => { drag = null; };
+ bx.addEventListener('pointerup', end); bx.addEventListener('lostpointercapture', end);
+ bx.addEventListener('keydown', e => {
+ if (!live || !s.on) return;
+ if (e.key === 'Enter') { e.preventDefault(); e.stopPropagation(); bx.blur(); P.keys?.(e); return; }
+ const d = { ArrowUp: 1, ArrowRight: 1, ArrowDown: -1, ArrowLeft: -1 }[e.key];
+ if (!d) return;
+ e.preventDefault(); e.stopPropagation();
+ edit({ [key]: clamp(key, Math.round(v[key]) + d) });
+ });
+ slots.push(s);
+ return s;
+ }
+
+ /* ---------- the matrix (and x, Ax) in brackets ---------- */
+ const Mx = G(p, { o: 0 }), cw = size * 1.7, rh = size * 1.35;
+ const bracket = (x0, w, color = COL.chalk) => {
+ const top = mat[1] - size * .95, bot = mat[1] + rh + size * .35;
+ path(Mx, `M${x0 + 14} ${top}H${x0}V${bot}H${x0 + 14}M${x0 + w - 14} ${top}H${x0 + w}V${bot}H${x0 + w - 14}`, { stroke: color, 'stroke-width': 3, fill: 'none' });
+ };
+ const [mx, my] = mat || [0, 0], lay = {};
+ if (mat) {
+ bracket(mx, cw * 2 + 20);
+ lay.A = [[0, 1].map(j => mx + 10 + cw * (j + .5)), [my, my + rh]];
+ [0, 1].forEach(i => [0, 1].forEach(j => slot(Mx, `a${i}${j}`, lay.A[0][j], my + rh * i, G2_COLS[j])));
+ T(Mx, 'A', { x: mx + cw + 10, y: my + rh + size * 1.25, size: 34, fill: COL.dim, font: MATH, anchor: 'middle', weight: 700 });
+ if (x) {
+ const xa = mx + cw * 2 + 44, wx = cw * .95;
+ bracket(xa, wx);
+ [0, 1].forEach(i => slot(Mx, `x${i}`, xa + wx / 2, my + rh * i, COL.chalk));
+ T(Mx, 'x', { x: xa + wx / 2, y: my + rh + size * 1.25, size: 34, fill: COL.dim, font: MATH, anchor: 'middle' }).setAttribute('font-style', 'italic');
+ lay.x = xa + wx / 2;
+ if (result) {
+ T(Mx, '=', { x: xa + wx + 40, y: my + rh / 2 + size * .3, size, fill: COL.chalk, font: MATH, anchor: 'middle' });
+ const xr = xa + wx + 80, wr = cw * 1.25;
+ bracket(xr, wr);
+ lay.r = xr + wr / 2;
+ lay.res = [0, 1].map(i => T(Mx, '', { x: xr + wr / 2, y: my + rh * i, size, fill: G2_AX, font: MATH, anchor: 'middle' }));
+ const lab = T(Mx, 'Ax', { x: xr + wr / 2, y: my + rh + size * 1.25, size: 34, fill: COL.dim, font: MATH, anchor: 'middle' });
+ lab.setAttribute('font-style', 'italic');
+ }
+ }
+ }
+
+ /* ---------- the plane: the moved grid, square, shape, points; the columns; x and Ax ---------- */
+ const layer = (o = 1) => G(P2.g, { o });
+ const gridG = layer(grid ? 1 : 0), sqG = layer(square ? 1 : 0), shG = layer(shape ? 1 : 0), unG = layer(units ? 1 : 0);
+ const ptG = layer(), colG = layer(), xG = layer(x ? 1 : 0);
+ const gl = path(gridG, '', { stroke: COL.chalk, 'stroke-opacity': .32, 'stroke-width': 1.6, fill: 'none' });
+ const axs = G2_COLS.map(c => path(gridG, '', { stroke: c, 'stroke-opacity': .75, 'stroke-width': 3, fill: 'none' }));
+ const sq = path(sqG, '', { fill: COL.chalk, 'fill-opacity': .12, stroke: COL.chalk, 'stroke-opacity': .7, 'stroke-width': 2.5 });
+ const sh = path(shG, '', { fill: COL.task, 'fill-opacity': .55, stroke: COL.task, 'stroke-width': 2, 'stroke-linejoin': 'round' });
+ path(unG, `M${PX(0)} ${PY(0)}H${PX(1)}M${PX(0)} ${PY(0)}V${PY(1)}`, { stroke: COL.chalk, 'stroke-opacity': .45, 'stroke-width': 3, 'stroke-dasharray': '5 6' });
+ [[1, 0, '[1, 0]', 8, 30], [0, 1, '[0, 1]', -70, -12]].forEach(([a, b, s, dx, dy]) => T(unG, s, { x: PX(a) + dx, y: PY(b) + dy, size: 20, fill: COL.dim, font: MATH }));
+ const arrowD = (a, c, hl0 = 18) => {
+ const A1 = [PX(a[0]), PY(a[1])], C = [PX(c[0]), PY(c[1])], L = Math.hypot(C[0] - A1[0], C[1] - A1[1]);
+ if (L < 1) return '';
+ const ux = (C[0] - A1[0]) / L, uy = (C[1] - A1[1]) / L, hl = Math.min(hl0, L * .45);
+ return `M${A1[0]} ${A1[1]}L${C[0] - ux * hl * .6} ${C[1] - uy * hl * .6}M${C[0] - hl * ux - 9 * uy} ${C[1] - hl * uy + 9 * ux}L${C[0]} ${C[1]}L${C[0] - hl * ux + 9 * uy} ${C[1] - hl * uy - 9 * ux}Z`;
+ };
+ const arrow = (g, color, w = 5, dash) => path(g, '', { stroke: color, fill: color, 'stroke-width': w, 'stroke-linejoin': 'round', ...(dash ? { 'stroke-dasharray': dash, 'fill-opacity': .5 } : {}) });
+ const ptDots = pts.map(q => {
+ const g = G(ptG, {});
+ mk('circle', { r: 8, fill: COL.chalk, stroke: COL.board, 'stroke-width': 2 }, g);
+ const lab = q.label ? T(g, q.label, { x: 12, y: -12, size: 22, fill: COL.chalk, font: MATH }) : null;
+ return { g, q, lab };
+ });
+ const combo = [arrow(xG, G2_COLS[0], 4, '10 8'), arrow(xG, G2_COLS[1], 4, '10 8')]; // x·col 1, then y·col 2 from its tip
+ const axArrow = arrow(xG, G2_AX, 6);
+ const xRing = G(xG, {});
+ mk('circle', { r: 22, fill: 'transparent' }, xRing);
+ mk('circle', { r: 9, fill: COL.board, stroke: COL.chalk, 'stroke-width': 3 }, xRing);
+ const xLab = T(xG, '', { size: 24, fill: COL.chalk, font: MATH });
+ const axDot = G(xG, {});
+ mk('circle', { r: 10, fill: G2_AX, stroke: COL.board, 'stroke-width': 3 }, axDot);
+ const axLab = T(xG, '', { size: 26, fill: G2_AX, font: MATH, weight: 600 });
+ const cols = G2_COLS.map(c => arrow(colG, c));
+ const tips = G2_COLS.map(c => {
+ const g = G(colG, {});
+ mk('circle', { r: 24, fill: 'transparent' }, g);
+ const ring = mk('circle', { r: 14, fill: 'none', stroke: c, 'stroke-width': 3, 'stroke-dasharray': '4 4' }, g);
+ ring.style.opacity = 0;
+ g._ring = ring;
+ return g;
+ });
+ const tipLabels = [0, 1].map(() => G(colG, {}));
+
+ // Drag in the plane: a column tip or x follows the pointer (to a tenth), and lands on the nearest whole numbers when let go.
+ const dragIn = (el, keys, what) => {
+ let on = false;
+ const to = ([X, Y], snap) => { const r = n => snap ? Math.round(n) : Math.round(n * 10) / 10; edit({ [keys[0]]: clamp(keys[0], r(X)), [keys[1]]: clamp(keys[1], r(Y)) }); };
+ el.addEventListener('pointerdown', e => { if (!live || !drags.includes(what)) return; e.preventDefault(); on = true; el.setPointerCapture(e.pointerId); to(pt(e), false); });
+ el.addEventListener('pointermove', e => { if (on) to(pt(e), false); });
+ const end = () => { if (!on) return; on = false; to([v[keys[0]], v[keys[1]]], true); };
+ el.addEventListener('pointerup', end); el.addEventListener('lostpointercapture', end);
+ };
+ dragIn(tips[0], ['a00', 'a10'], 'cols'); dragIn(tips[1], ['a01', 'a11'], 'cols'); dragIn(xRing, ['x0', 'x1'], 'x');
+
+ /* ---------- one state, drawn everywhere ---------- */
+ // The part of the line P + s·d, s in [s0, s1], inside the box, as a path piece (Liang–Barsky).
+ const seg = (P0, d, s0, s1) => {
+ let a = s0, b = s1;
+ for (const [p0, dd, lo, hi] of [[P0[0], d[0], box[0], box[1]], [P0[1], d[1], box[2], box[3]]]) {
+ if (Math.abs(dd) < 1e-9) { if (p0 < lo || p0 > hi) return ''; continue; }
+ let t1 = (lo - p0) / dd, t2 = (hi - p0) / dd;
+ if (t1 > t2) [t1, t2] = [t2, t1];
+ a = Math.max(a, t1); b = Math.min(b, t2);
+ if (a > b) return '';
+ }
+ return `M${XY([P0[0] + a * d[0], P0[1] + a * d[1]])}L${XY([P0[0] + b * d[0], P0[1] + b * d[1]])}`;
+ };
+ function draw() {
+ slots.forEach(s => s.set());
+ const c0 = [v.a00, v.a10], c1 = [v.a01, v.a11], ax = map([v.x0, v.x1]);
+ if (lay.res) lay.res.forEach((t, i) => setText(t, fmt(ax[i])));
+ if (grid) {
+ let d = '';
+ for (let k = -K; k <= K; k++) {
+ if (!k) continue;
+ d += seg([k * c0[0], k * c0[1]], c1, -K, K); // the image of the line x = k
+ d += seg([k * c1[0], k * c1[1]], c0, -K, K); // the image of the line y = k
+ }
+ setD(gl, d);
+ setD(axs[0], seg([0, 0], c0, -K, K)); // the x-axis lands along column 1
+ setD(axs[1], seg([0, 0], c1, -K, K)); // the y-axis along column 2
+ }
+ if (square) setD(sq, `M${XY([0, 0])}L${XY(c0)}L${XY([c0[0] + c1[0], c0[1] + c1[1]])}L${XY(c1)}Z`);
+ if (shape) setD(sh, 'M' + G2_FLAG.map(q => XY(map(q))).join('L') + 'Z');
+ ptDots.forEach(({ g, lab }, i) => {
+ const [a, b] = map(ptDots[i].q.p);
+ put(g, { x: PX(a), y: PY(b) });
+ });
+ [c0, c1].forEach((c, j) => {
+ setD(cols[j], arrowD([0, 0], c));
+ put(tips[j], { x: PX(c[0]), y: PY(c[1]) });
+ const n = Math.hypot(...c) || 1;
+ put(tipLabels[j], { x: PX(c[0]) + c[0] / n * 30, y: PY(c[1]) - c[1] / n * 30 + 10 });
+ });
+ if (x) {
+ const m1 = [v.x0 * c0[0], v.x0 * c0[1]];
+ setD(combo[0], arrowD([0, 0], m1, 14));
+ setD(combo[1], arrowD(m1, ax, 14));
+ setD(axArrow, arrowD([0, 0], ax));
+ put(xRing, { x: PX(v.x0), y: PY(v.x1) });
+ put(xLab, { x: PX(v.x0) + 14, y: PY(v.x1) + 30 });
+ setText(xLab, `x = (${fmt(v.x0)}, ${fmt(v.x1)})`);
+ put(axDot, { x: PX(ax[0]), y: PY(ax[1]) });
+ const n = Math.hypot(...ax) || 1;
+ let lx = PX(ax[0]) + ax[0] / n * 26 + (ax[0] < 0 ? -150 : 8);
+ if (lx + 170 > 1590) lx = PX(ax[0]) - 180; // near the right edge: put the label on the left
+ put(axLab, { x: lx, y: PY(ax[1]) - ax[1] / n * 26 + (ax[1] < 0 ? 24 : -8) });
+ setText(axLab, `Ax = (${fmt(ax[0])}, ${fmt(ax[1])})`);
+ }
+ listeners.forEach(f => f(v));
+ }
+ function edit(to) {
+ let changed = false;
+ for (const k in to) if (v[k] !== to[k]) { v[k] = to[k]; changed = true; }
+ if (changed) draw();
+ }
+ draw();
+ if (mat) show(Mx, t0 + .3);
+
+ const api = {
+ v, P: P2, stage: holder, M: Mx, lay, cols, tips, combo, axArrow, axDot, xRing, xLab, axLab,
+ parts: { grid: gridG, square: sqG, shape: shG, units: unG, pts: ptG, cols: colG, x: xG },
+ // Move the numbers to new values over dur seconds, on the beat clock (deterministic, so seeking replays it).
+ to(next, at, dur = 1.2, ease = io) {
+ const from = { ...plan };
+ plan = { ...plan, ...next };
+ const goal = { ...plan };
+ prog(q => edit(Object.fromEntries(Object.keys(goal).map(k => [k, from[k] + (goal[k] - from[k]) * q]))), at, dur, ease);
+ },
+ // Hands on. what: which parts take the reader's hands: 'A' the matrix numbers, 'cols' the column tips, 'x' the point x and its numbers.
+ live(on, what = ['A', 'cols', 'x']) {
+ live = on;
+ drags.splice(0, drags.length, ...(on ? what : []));
+ for (const s of slots) {
+ s.on = on && what.includes(s.key[0] === 'a' ? 'A' : 'x');
+ s.box.style.cursor = s.on ? 'ew-resize' : '';
+ s.box.setAttribute('stroke', s.on ? COL.faint : 'none');
+ s.box.setAttribute('stroke-dasharray', '4 6');
+ if (s.on) s.box.setAttribute('tabindex', 0); else s.box.removeAttribute('tabindex');
+ }
+ const cOn = on && what.includes('cols'), xOn = on && what.includes('x');
+ tips.forEach(g => { g.style.cursor = cOn ? 'grab' : ''; g._ring.style.opacity = cOn ? 1 : 0; });
+ xRing.style.cursor = xOn ? 'grab' : '';
+ },
+ set: edit, // at once, for a reader's action or an answer shown
+ num: key => slots.filter(s => s.key === key).map(s => s.t), // the text that shows this value (to flash it)
+ res: i => lay.res?.[i],
+ onChange(f) { listeners.push(f); },
+ col: j => j ? [v.a01, v.a11] : [v.a00, v.a10],
+ Ax: () => map([v.x0, v.x1]),
+ map,
+ labels(names) { names.forEach((n, i) => { tipLabels[i].replaceChildren(); M(tipLabels[i], [n], { size: 28, fill: G2_COLS[i] }); }); },
+ };
+ return api;
+}
+
+// A question that is a task on the moved plane: the reader changes it until test(v) holds, then checks.
+// what: the parts the reader may move (see g.live).
+const g2Task = (g, test, why, hint, reveal, what) => (body, api) => {
+ g.live(true, what);
+ const parts = what || ['A', 'cols', 'x'];
+ return {
+ check: () => { const ok = test(g.v); api.grade(ok, ok ? why : hint); },
+ reveal: () => { reveal?.(); return why; },
+ lock: () => g.live(false),
+ hint: parts.includes('A') || parts.includes('x') ? [kbd('Tab'), 'pick a number', kbd('↑'), kbd('↓'), 'change it, or drag in the picture'] : ['drag in the picture'],
+ };
+};
diff --git a/site/linear-algebra/lib/linsys.js b/site/linear-algebra/lib/linsys.js
index 1dfe20e..9ab633c 100644
--- a/site/linear-algebra/lib/linsys.js
+++ b/site/linear-algebra/lib/linsys.js
@@ -12,10 +12,12 @@ function linsys(p, { A = [[2, -1], [-1, 2]], b = [0, 3], eq = [90, 250], mat = [
const RANGE = { a00: 9, a01: 9, a10: 9, a11: 9, b0: 30, b1: 30 };
// The plane sits in its own holder, so a beat can keep it hidden (hidePlane) and show sys.stage later.
const holder = G(p, { o: hidePlane ? 0 : 1 });
+ holder.style.userSelect = 'none'; // a drag that misses a line must not select the axis numbers
const P2 = plane(holder, { cx: 1160, cy: 450, u: 52, x0: -6, x1: 6, y0: -6, y1: 6, t0, ...po });
const { PX, PY } = P2, bx = [P2.x0, P2.x1], by = [P2.y0, P2.y1];
const svg = $('stage'), listeners = [], slots = [];
- let live = false, plan = { ...v };
+ let live = false, plan = { ...v }, allowed = null;
+ const can = k => live && (!allowed || allowed.has(k)); // live(true, { only }) unlocks only the named numbers
const fmt = (n, one = false) => {
const r = Math.round(n * 10) / 10, s = Number.isInteger(r) ? String(Math.abs(r)) : Math.abs(r).toFixed(1);
@@ -33,11 +35,17 @@ function linsys(p, { A = [[2, -1], [-1, 2]], b = [0, 3], eq = [90, 250], mat = [
const l = letter ? T(g, letter, { x: x + 3, y, size, fill, font: MATH }) : null;
l?.setAttribute('font-style', 'italic');
t.style.pointerEvents = 'none'; if (l) l.style.pointerEvents = 'none'; // the box under them takes the drag
- const s = { key, t, box, one, set: () => setText(t, fmt(v[key], one) || (one ? '' : '0')) };
+ // A number with a letter after it keeps its hit box tight around what shows: a hidden 1 leaves just the letter.
+ const fit = () => {
+ if (!letter || anchor !== 'end') return;
+ const tw0 = t.textContent ? t.getComputedTextLength() : 0, lw = l.getComputedTextLength() || size * .5, bx0 = x - tw0 - 10;
+ if (+box.getAttribute('x') !== bx0) { box.setAttribute('x', bx0); box.setAttribute('width', tw0 + lw + 23); }
+ };
+ const s = { key, t, l, box, one, fit, set: () => { setText(t, fmt(v[key], one) || (one ? '' : '0')); fit(); } };
box.setAttribute('aria-label', key);
let drag = null;
box.addEventListener('pointerdown', e => {
- if (!live) return;
+ if (!can(key)) return;
e.preventDefault();
drag = { x: e.clientX, from: Math.round(v[key]) };
box.setPointerCapture(e.pointerId);
@@ -51,7 +59,7 @@ function linsys(p, { A = [[2, -1], [-1, 2]], b = [0, 3], eq = [90, 250], mat = [
box.addEventListener('pointerup', end);
box.addEventListener('lostpointercapture', end);
box.addEventListener('keydown', e => {
- if (!live) return;
+ if (!can(key)) return;
if (e.key === 'Enter') { e.preventDefault(); e.stopPropagation(); box.blur(); P.keys?.(e); return; } // Enter checks, as in an answer box
const d = { ArrowUp: 1, ArrowRight: 1, ArrowDown: -1, ArrowLeft: -1 }[e.key];
if (!d) return;
@@ -65,22 +73,24 @@ function linsys(p, { A = [[2, -1], [-1, 2]], b = [0, 3], eq = [90, 250], mat = [
/* ---------- the equations ---------- */
const E = G(p, { o: 0 }), eqRows = [];
RI.forEach(i => {
- const y = eq[1] + i * 92, x = eq[0];
- const bar = mk('rect', { x: x - 34, y: y - size * .7, width: 8, height: size * .8, rx: 4, fill: LS_ROW[i] }, E);
- const a = slot(E, `a${i}0`, x + 110, y, { letter: 'x', one: true });
- const sign = T(E, '+', { x: x + 190, y, size, fill: COL.chalk, font: MATH, anchor: 'middle' });
- const bb = slot(E, `a${i}1`, x + 262, y, { letter: 'y', one: true });
- T(E, '=', { x: x + 330, y, size, fill: COL.chalk, font: MATH, anchor: 'middle' });
- const c = slot(E, `b${i}`, x + 368, y, { anchor: 'start' });
- eqRows.push({ bar, a, sign, bb, c });
+ const y = eq[1] + i * 92, x = eq[0], g = G(E, {}); // each row in its own group, so focus() can dim the other
+ const bar = mk('rect', { x: x - 34, y: y - size * .7, width: 8, height: size * .8, rx: 4, fill: LS_ROW[i] }, g);
+ const a = slot(g, `a${i}0`, x + 110, y, { letter: 'x', one: true });
+ const sign = T(g, '+', { x: x + 190, y, size, fill: COL.chalk, font: MATH, anchor: 'middle' });
+ const bb = slot(g, `a${i}1`, x + 270, y, { letter: 'y', one: true });
+ T(g, '=', { x: x + 338, y, size, fill: COL.chalk, font: MATH, anchor: 'middle' });
+ const c = slot(g, `b${i}`, x + 376, y, { anchor: 'start' });
+ eqRows.push({ g, bar, a, sign, bb, c });
});
- // The second term shows its size; the sign between carries its sign.
+ // The second term shows its size; the sign between carries its sign and sits halfway between the two terms,
+ // so "x + y", "2x + 3y" and "2.5x − 2.5y" are evenly spaced.
eqRows.forEach((r, i) => {
- const right = eq[0] + 262;
+ const right = eq[0] + 270, xEnd = eq[0] + 113 + (r.a.l.getComputedTextLength() || size * .5);
r.bb.set = () => {
setText(r.sign, v[`a${i}1`] < 0 ? '−' : '+');
setText(r.bb.t, fmt(Math.abs(v[`a${i}1`]), true));
- const x = Math.min(eq[0] + 200, right - (r.bb.t.textContent ? r.bb.t.getComputedTextLength() : 0) - size * .55); // a wide coefficient pushes the sign left
+ r.bb.fit();
+ const x = Math.round((xEnd + right - (r.bb.t.textContent ? r.bb.t.getComputedTextLength() : 0)) / 2);
if (st(r.sign).x !== x) put(r.sign, { x });
};
});
@@ -111,6 +121,9 @@ function linsys(p, { A = [[2, -1], [-1, 2]], b = [0, 3], eq = [90, 250], mat = [
/* ---------- the plane: rows as lines, columns as arrows ---------- */
const ROWV = G(P2.g, { o: view === 'col' ? 0 : 1 }), COLV = G(P2.g, { o: view === 'row' || rows === 1 ? 0 : 1 });
if (rows === 1) COLV.style.display = 'none';
+ // A hidden picture must not catch the pointer: the column arrows lie over the lines and would take their drags.
+ const hits = which => { ROWV.style.pointerEvents = which === 'col' ? 'none' : ''; COLV.style.pointerEvents = which === 'row' ? 'none' : ''; };
+ hits(view);
// The part of a·x + b·y = c inside the grid, as [x1, y1, x2, y2] in plane units, or null.
const clipLine = (a, b2, c) => {
const ps = [];
@@ -121,12 +134,21 @@ function linsys(p, { A = [[2, -1], [-1, 2]], b = [0, 3], eq = [90, 250], mat = [
return [...ps[0], ...ps[ps.length - 1]];
};
const lines = RI.map(i => {
- const hit = path(ROWV, '', { stroke: 'transparent', 'stroke-width': 30, fill: 'none' });
- const l = path(ROWV, '', { stroke: LS_ROW[i], 'stroke-width': 5, fill: 'none', 'stroke-linecap': 'round' });
+ const g = G(ROWV, {});
+ const hit = path(g, '', { stroke: 'transparent', 'stroke-width': 30, fill: 'none' });
+ const l = path(g, '', { stroke: LS_ROW[i], 'stroke-width': 5, fill: 'none', 'stroke-linecap': 'round' });
l.style.pointerEvents = 'none';
- return { hit, l };
+ return { g, hit, l };
});
- const meet = G(ROWV, { o: 0 });
+ // The meeting point's trail: dotted amber, under the point. A trail from to(…, { trail: true }) is its own path,
+ // drawn from the tween's progress, so seeking shows the same frame; sys.trail(true) records the reader's moves.
+ const trailG = G(ROWV, {});
+ const trailAttrs = { stroke: COL.task, 'stroke-width': 5, 'stroke-dasharray': '0 13', 'stroke-linecap': 'round', fill: 'none', opacity: .75 };
+ const liveTrail = path(trailG, '', trailAttrs);
+ let liveOn = false, livePts = [];
+ const meetBox = G(ROWV, {}); // the chapter can hide the point (meetBox) while draw() keeps setting meet itself
+ const meet = G(meetBox, { o: 0 });
+ meetBox.style.pointerEvents = trailG.style.pointerEvents = 'none'; // a drag at the crossing reaches the lines under it
mk('circle', { r: 11, fill: COL.chalk, stroke: COL.board, 'stroke-width': 3 }, meet);
const meetT = T(meet, '', { x: 18, y: -16, size: 30, fill: COL.chalk, font: MATH, weight: 600 });
@@ -157,9 +179,11 @@ function linsys(p, { A = [[2, -1], [-1, 2]], b = [0, 3], eq = [90, 250], mat = [
el.addEventListener('pointerup', () => { on = false; });
el.addEventListener('lostpointercapture', () => { on = false; });
};
- lines.forEach(({ hit }, i) => dragIn(hit, ([X, Y]) => edit({ [`b${i}`]: clamp(`b${i}`, Math.round(v[`a${i}0`] * X + v[`a${i}1`] * Y)) })));
+ lines.forEach(({ hit }, i) => dragIn(hit, ([X, Y]) => can(`b${i}`) && edit({ [`b${i}`]: clamp(`b${i}`, Math.round(v[`a${i}0`] * X + v[`a${i}1`] * Y)) })));
const grid = (n, lo, hi) => Math.max(lo, Math.min(hi, Math.round(n)));
+ const tipKeys = { b: ['b0', 'b1'], col0: ['a00', 'a10'], col1: ['a01', 'a11'] };
tips.forEach(({ g, k }) => dragIn(g, ([X, Y]) => {
+ if (!tipKeys[k].every(can)) return;
const x = grid(X, bx[0], bx[1]), y = grid(Y, by[0], by[1]);
edit(k === 'b' ? { b0: x, b1: y } : k === 'col0' ? { a00: x, a10: y } : { a01: x, a11: y });
}));
@@ -178,6 +202,10 @@ function linsys(p, { A = [[2, -1], [-1, 2]], b = [0, 3], eq = [90, 250], mat = [
const g = gcd(Math.abs(num), Math.abs(det)) || 1, nn = num / g * Math.sign(det), dd = Math.abs(det) / g;
return dd === 1 ? [fmt(nn)] : [nn < 0 ? '−' : '', F(Math.abs(nn), dd)];
};
+ const fracText = n => { // the same exact value as plain text, for the label beside the meeting point: 4/3
+ const f = frac(n);
+ return f.length === 1 ? f[0] : f[0] + f[1].f.join('/');
+ };
let solKey = '';
function draw() {
slots.forEach(s => s.set());
@@ -187,7 +215,7 @@ function linsys(p, { A = [[2, -1], [-1, 2]], b = [0, 3], eq = [90, 250], mat = [
});
const s = solve(), inGrid = s.x !== undefined && s.x >= bx[0] && s.x <= bx[1] && s.y >= by[0] && s.y <= by[1];
put(meet, { x: inGrid ? PX(s.x) : 0, y: inGrid ? PY(s.y) : 0, o: inGrid ? 1 : 0 });
- if (inGrid) setText(meetT, `(${fmt(s.x)}, ${fmt(s.y)})`);
+ setText(meetT, inGrid ? `(${fracText(s.x)}, ${fracText(s.y)})` : ''); // cleared off the grid, so a seek and a play leave the same page
const c0 = [v.a00, v.a10], c1 = [v.a01, v.a11], bb = [v.b0, v.b1];
[[cols[0], c0], [cols[1], c1], [bArrow, bb]].forEach(([e, [x, y]], i) => {
e.setAttribute('d', arrowD(0, 0, x, y));
@@ -207,8 +235,13 @@ function linsys(p, { A = [[2, -1], [-1, 2]], b = [0, 3], eq = [90, 250], mat = [
if (s.x !== undefined) M(sol, ['x = ', ...frac(s.x), ', y = ', ...frac(s.y)], { x: eq[0], y, size: 40, fill: COL.task, anchor: 'start' });
else T(sol, s.none ? 'parallel lines: no solution' : 'the same line: every point on it solves both', { x: eq[0], y: y - 4, size: 32, fill: COL.task, weight: 600 });
}
+ if (liveOn && inGrid) {
+ const q = livePts[livePts.length - 1];
+ if (!q || Math.hypot(q[0] - s.x, q[1] - s.y) > .15) { livePts.push([s.x, s.y]); liveTrail.setAttribute('d', trailD(livePts)); }
+ }
listeners.forEach(f => f(v, s));
}
+ const trailD = pts => pts.map(([x, y], i) => `${i ? 'L' : 'M'}${PX(x).toFixed(1)} ${PY(y).toFixed(1)}`).join('');
function edit(to) {
let changed = false;
for (const k in to) if (v[k] !== to[k]) { v[k] = to[k]; changed = true; }
@@ -217,31 +250,65 @@ function linsys(p, { A = [[2, -1], [-1, 2]], b = [0, 3], eq = [90, 250], mat = [
draw();
show(E, t0 + .2); show(Mx, t0 + .4);
+ const lsMix = (from, goal, q) => Object.fromEntries(Object.keys(goal).map(k => [k, from[k] + (goal[k] - from[k]) * q]));
+ // Where the lines of state w meet, or null (parallel, or off the grid).
+ const meetOf = w => {
+ const det = w.a00 * w.a11 - w.a01 * w.a10;
+ if (Math.abs(det) < 1e-9) return null;
+ const x = (w.b0 * w.a11 - w.a01 * w.b1) / det, y = (w.a00 * w.b1 - w.b0 * w.a10) / det;
+ return x >= bx[0] && x <= bx[1] && y >= by[0] && y <= by[1] ? [x, y] : null;
+ };
+
return {
- v, P: P2, stage: holder, E, M: Mx, lines, cols, bArrow, combo, meet, ROWV, COLV, solve,
+ v, P: P2, stage: holder, E, M: Mx, lines, cols, bArrow, combo, meet, meetBox, readout: sol, ROWV, COLV, solve,
// Move the numbers to new values over dur seconds, on the beat clock (deterministic, so seeking replays it).
- to(next, at, dur = 1.2, ease = io) {
+ // { trail: true } leaves the meeting point's dotted path for this move and returns it (hide it when done).
+ to(next, at, dur = 1.2, ease = io, { trail = false } = {}) {
const from = { ...plan };
plan = { ...plan, ...next };
const goal = { ...plan };
- prog(q => edit(Object.fromEntries(Object.keys(goal).map(k => [k, from[k] + (goal[k] - from[k]) * q]))), at, dur, ease);
+ const tr = trail ? path(trailG, '', { ...trailAttrs }) : null;
+ prog(q => {
+ edit(lsMix(from, goal, q));
+ if (!tr) return;
+ const pts = [], n = Math.ceil(60 * q);
+ for (let i = 0; i <= n; i++) { const p = meetOf(lsMix(from, goal, n ? q * i / n : 0)); if (p) pts.push(p); }
+ const d = trailD(pts);
+ if (tr.getAttribute('d') !== d) tr.setAttribute('d', d);
+ }, at, dur, ease);
+ return tr;
+ },
+ // Bring row i (0 or 1) forward: its equation and its line; the other row dims. focus(null, at) shows both again.
+ focus(i, at, dur = .5) {
+ RI.forEach(j => {
+ const on = i === null || i === j;
+ tw(eqRows[j].g, { o: on ? 1 : .28 }, at, dur);
+ tw(lines[j].g, { o: on ? 1 : .28 }, at, dur);
+ tw(lines[j].l, { 'a_stroke-width': i === j ? 8 : 5 }, at, dur);
+ });
},
+ // Record the meeting point's path while the reader moves the numbers (true), or clear it (false).
+ trail(on) { liveOn = on; livePts = []; liveTrail.setAttribute('d', ''); },
// Show the row picture, the column picture, or both.
view(which, at, dur = .6) {
+ hits(which); // the picture that ends up shown takes the pointer
tw(ROWV, { o: which === 'col' ? 0 : 1 }, at, dur);
tw(COLV, { o: which === 'row' ? 0 : 1 }, at, dur);
},
// Hands on: scrub numbers and drag in the plane. Turned off by sys.live(false) or by leaving the beat.
- live(on) {
+ // { only: ['b0', 'b1'] } unlocks only those numbers (and only the lines and tips they move); the rest stay put.
+ live(on, { only } = {}) {
live = on;
+ allowed = on && only ? new Set(only) : null;
for (const s of slots) {
- s.box.style.cursor = on ? 'ew-resize' : '';
- s.box.setAttribute('stroke', on ? COL.faint : 'none');
+ const ok = can(s.key);
+ s.box.style.cursor = ok ? 'ew-resize' : '';
+ s.box.setAttribute('stroke', ok ? COL.faint : 'none');
s.box.setAttribute('stroke-dasharray', '4 6');
- if (on) s.box.setAttribute('tabindex', 0); else s.box.removeAttribute('tabindex');
+ if (ok) s.box.setAttribute('tabindex', 0); else s.box.removeAttribute('tabindex');
}
- lines.forEach(({ hit }) => { hit.style.cursor = on ? 'move' : ''; });
- tips.forEach(({ g, ring }) => { g.style.cursor = on ? 'grab' : ''; ring.style.opacity = on ? 1 : 0; });
+ lines.forEach(({ hit }, i) => { hit.style.cursor = can(`b${i}`) ? 'move' : ''; });
+ tips.forEach(({ g, ring, k }) => { const ok = tipKeys[k].every(can); g.style.cursor = ok ? 'grab' : ''; ring.style.opacity = ok ? 1 : 0; });
},
set: edit, // at once, for a reader's action or an answer shown
num: key => slots.filter(s => s.key === key).map(s => s.t), // every text that shows this value (to flash it)
@@ -252,12 +319,14 @@ function linsys(p, { A = [[2, -1], [-1, 2]], b = [0, 3], eq = [90, 250], mat = [
}
// A question that is a task on the system: the reader changes it until test(v, s) holds, then checks.
-const lsTask = (sys, test, why, hint, reveal) => (body, api) => {
- sys.live(true);
+// opts.only names the numbers the reader may change (sys.live(true, { only })); opts.trail records the meeting point's path.
+const lsTask = (sys, test, why, hint, reveal, { only, trail = false } = {}) => (body, api) => {
+ sys.live(true, { only });
+ if (trail) sys.trail?.(true);
return {
check: () => { const ok = test(sys.v, sys.solve()); api.grade(ok, ok ? why : hint); },
reveal: () => { reveal?.(); return why; },
lock: () => sys.live(false),
- hint: [kbd('Tab'), 'pick a number', kbd('↑'), kbd('↓'), 'change it, or drag in the picture'],
+ hint: [kbd('Tab'), ' pick a number ', kbd('↑'), kbd('↓'), ' change it, or drag in the picture'],
};
};
diff --git a/site/linear-algebra/lib/space3.js b/site/linear-algebra/lib/space3.js
index f5f0928..b7f482b 100644
--- a/site/linear-algebra/lib/space3.js
+++ b/site/linear-algebra/lib/space3.js
@@ -1,10 +1,13 @@
// Space in three dimensions, drawn in SVG, and lin3: the 3 × 3 twin of linsys (equations, matrix form and space).
// World axes: x to the right, y into the page (depth), z up; the floor is z = 0. The camera turns about the z axis (yaw)
-// and looks down at the floor (pitch); the projection is orthographic with a gentle perspective, so the near side of
-// the cube is a little larger and depth reads in motion. Everything re-projects when the camera moves: a beat turns it
-// on the beat clock (view.turn, view.drift), so seeking replays it; the reader orbits it by dragging empty space while
-// it is live (an ask), as an offset of its own that the beat clock never touches and a rebuilt beat starts without.
-// Loads after engine.js (and linsys.js, whose lsTask works on lin3 as it is).
+// and looks down at the floor (pitch; 90 looks straight down, so x runs right and y up, as in a flat 2D plane); the
+// projection is orthographic with a gentle perspective, so the near side of the cube is a little larger and depth reads
+// in motion. Everything re-projects when the camera moves: a beat turns it on the beat clock (view.turn, view.drift), so
+// seeking replays it; the reader orbits it while it is live (an ask) by dragging empty space, or by focusing the view
+// (Tab) and pressing the arrow keys, as an offset of its own that the beat clock never touches.
+// Planes are cut along the lines where they meet each other and the pieces are painted far to near, so the plane in
+// front covers the one behind; plane.fade(k) and lin3's focus() light one plane and dim the others.
+// Loads after engine.js (and linsys.js, whose lsTask works on lin3 as it is; lin3Task adds the 3D keys to its hint).
const S3_ROW = [COL.whole, COL.nat, COL.int], S3_COLS = [COL.irr, COL.real, COL.rat], S3_B = COL.task;
const S3_DIST = 10; // camera distance in half-widths of the cube: larger is flatter
@@ -61,25 +64,46 @@ function S3_meet(P, Q, R) {
}
return hi - lo > 1e-9 ? [o.map((x, j) => x + u[j] * lo), o.map((x, j) => x + u[j] * hi)] : null;
}
+// The part of a convex polygon on one side (s = 1 or −1) of the plane n·p = d.
+function S3_half(poly, n, d, s) {
+ const out = [], f = p => s * (S3_dot(n, p) - d);
+ poly.forEach((P, i) => {
+ const Q = poly[(i + 1) % poly.length], fp = f(P), fq = f(Q);
+ if (fp >= -1e-9) out.push(P);
+ if ((fp > 1e-9 && fq < -1e-9) || (fp < -1e-9 && fq > 1e-9)) { const t = fp / (fp - fq); out.push(P.map((x, j) => x + (Q[j] - x) * t)); }
+ });
+ return out.length > 2 ? out : null;
+}
+// The segment a–b clipped to the cube ±R, or null.
+function S3_clipSeg(a, b, R) {
+ let lo = 0, hi = 1;
+ for (let j = 0; j < 3; j++) {
+ const d = b[j] - a[j];
+ if (Math.abs(d) < 1e-12) { if (Math.abs(a[j]) > R + 1e-9) return null; continue; }
+ const t1 = (-R - a[j]) / d, t2 = (R - a[j]) / d;
+ lo = Math.max(lo, Math.min(t1, t2)); hi = Math.min(hi, Math.max(t1, t2));
+ }
+ return hi - lo > 1e-9 ? [a.map((x, j) => x + (b[j] - x) * lo), a.map((x, j) => x + (b[j] - x) * hi)] : null;
+}
function space3(p, { cx = 1150, cy = 450, size = 640, range: R = 4, yaw = -30, pitch = 22, t0 = .1 } = {}) {
const g = G(p, { o: 0 }), svg = $('stage'), k = size / (3.4 * R), dist = S3_DIST * R;
- const cam = { yaw, pitch }, user = { yaw: 0, pitch: 0 }, drifts = [], items = [], sorted = [], hooks = [];
+ const cam = { yaw, pitch }, user = { yaw: 0, pitch: 0 }, drifts = [], items = [], sorted = [], hooks = [], avoids = [], planeItems = [];
let plan = { yaw, pitch }, live = false, queued = false, sortKey = '', ca = 1, sa = 0, cb = 1, sb = 0;
- const PITCH = [-15, 80];
+ const PITCH = [-15, 80]; // what the reader may reach; a beat may turn the camera up to 90 (straight down)
const proj = ([x, y, z]) => {
const xr = x * ca - y * sa, yr = x * sa + y * ca, up = z * cb + yr * sb, dep = yr * cb - z * sb, f = dist / (dist + dep);
return [cx + k * f * xr, cy - k * f * up, dep];
};
- // The world point shown at (sx, sy) at depth dep: a point dragged in the plane facing the reader keeps its depth.
+ // The world point shown at (sx, sy) at depth dep.
const unproj = (sx, sy, dep) => {
const f = dist / (dist + dep), xr = (sx - cx) / k / f, up = (cy - sy) / k / f, yr = up * sb + dep * cb, z = up * cb - dep * sb;
return [xr * ca + yr * sa, -xr * sa + yr * ca, z];
};
const n1 = n => Math.round(n * 10) / 10;
const D = pts => pts.map((q, i) => (i ? 'L' : 'M') + n1(q[0]) + ' ' + n1(q[1])).join('');
- const att = (e, key, val) => { if (e.getAttribute(key) !== val) e.setAttribute(key, val); };
+ const att = (e, key, val) => { if (e.getAttribute(key) !== String(val)) e.setAttribute(key, val); };
// An arrow in screen space; its head shrinks with the arrow, so a foreshortened arrow keeps its shape.
const arrowD = (a, c, w = 9) => {
const L = Math.hypot(c[0] - a[0], c[1] - a[1]);
@@ -92,18 +116,20 @@ function space3(p, { cx = 1150, cy = 450, size = 640, range: R = 4, yaw = -30, p
function redraw() {
queued = false;
const a = (cam.yaw + drifts.reduce((s, d) => s + d, 0) + user.yaw) * Math.PI / 180;
- const b = Math.max(PITCH[0], Math.min(PITCH[1], cam.pitch + user.pitch)) * Math.PI / 180;
+ const b = Math.max(PITCH[0], Math.min(90, cam.pitch + user.pitch)) * Math.PI / 180;
ca = Math.cos(a); sa = Math.sin(a); cb = Math.cos(b); sb = Math.sin(b);
+ planeItems.forEach(cutPlane);
items.forEach(f => f());
hooks.forEach(f => f(proj));
// Painter's order for the polygons: far first. Each sits in a group of polygons only, so appending reorders them.
- const order = sorted.filter(it => it.e.isConnected).sort((m, n) => n.dep - m.dep), key = order.map(it => it.id).join();
+ const order = sorted.filter(it => it.e.isConnected && it.on !== false).sort((m, n) => n.dep - m.dep), key = order.map(it => it.id).join();
if (key !== sortKey) { sortKey = key; order.forEach(it => it.e.parentNode.appendChild(it.e)); }
}
const dirty = () => { if (!queued) { queued = true; queueMicrotask(redraw); } };
/* ---------- the frame: floor grid, cube, axes ---------- */
- const orbit = mk('rect', { x: cx - size / 2 - 60, y: cy - 420, width: size + 120, height: 840, fill: 'transparent' }, g);
+ const orbit = mk('rect', { x: cx - size / 2 - 60, y: cy - 420, width: size + 120, height: 840, fill: 'transparent', rx: 18 }, g);
+ orbit.setAttribute('aria-label', '3D view: drag, or press the arrow keys, to turn it');
const frame = G(g), content = G(g), polys = G(content);
const floor = path(frame, '', { stroke: COL.chalk, 'stroke-opacity': .09, 'stroke-width': 1.5 });
const cube = path(frame, '', { stroke: COL.chalk, 'stroke-opacity': .16, 'stroke-width': 1.5 });
@@ -116,44 +142,74 @@ function space3(p, { cx = 1150, cy = 450, size = 640, range: R = 4, yaw = -30, p
for (const s of C) for (const t of C) d += D([proj([-R, s, t]), proj([R, s, t])]) + D([proj([s, -R, t]), proj([s, R, t])]) + D([proj([s, t, -R]), proj([s, t, R])]);
att(cube, 'd', d);
});
- ['x', 'y', 'z'].forEach((name, i) => {
- const at = s => { const q = [0, 0, 0]; q[i] = s; return proj(q); };
- const line = path(frame, '', { stroke: COL.chalk, fill: COL.chalk, 'stroke-width': 3 });
- const ticks = path(frame, '', { stroke: COL.dim, 'stroke-width': 2 });
+ // Each axis in its own group (V.axes[i]), so a beat can bring them in one at a time.
+ const axes = ['x', 'y', 'z'].map((name, i) => {
+ const ag = G(frame, {}), at = s => { const q = [0, 0, 0]; q[i] = s; return proj(q); };
+ const line = path(ag, '', { stroke: COL.chalk, fill: COL.chalk, 'stroke-width': 3 });
+ const ticks = path(ag, '', { stroke: COL.dim, 'stroke-width': 2 });
const ints = [];
for (let j = -R; j <= R; j++) if (j) ints.push(j);
- const shown = ints.filter(j => R < 4 || j % 2 === 0), nums = shown.map(j => T(frame, num(j), { size: 17, fill: COL.dim, font: MATH, anchor: 'middle' }));
- const label = T(frame, name, { size: 32, fill: COL.chalk, font: MATH, anchor: 'middle' });
+ const shown = ints.filter(j => R < 4 || j % 2 === 0), nums = shown.map(j => T(ag, num(j), { size: 17, fill: COL.dim, font: MATH, anchor: 'middle' }));
+ const label = T(ag, name, { size: 32, fill: COL.chalk, font: MATH, anchor: 'middle' });
label.setAttribute('font-style', 'italic');
- items.push(() => {
- const A = at(-R), B = at(R + .7), L = Math.hypot(B[0] - A[0], B[1] - A[1]) || 1;
- let nx = (A[1] - B[1]) / L, ny = (B[0] - A[0]) / L; // the side of the axis below it, or left of an upright one
+ return { g: ag, at, line, ticks, ints, shown, nums, label };
+ });
+ items.push(() => {
+ // labels first, so that tick numbers can keep clear of every label (an axis label, a tip label)
+ const lab = axes.map(A => {
+ const q = A.at(R + 1.1), L = Math.hypot(...[0, 1].map(j => A.at(R)[j] - A.at(-R)[j])) / (2 * R);
+ return { x: q[0], y: q[1], o: L < 9 ? 0 : 1 }; // an axis pointing straight at the reader has no room for its name
+ });
+ const keep = [...lab.filter(l => l.o).map(l => [l.x, l.y - 11]), ...avoids.flatMap(f => f(proj) || [])];
+ axes.forEach((A, i) => {
+ const P = A.at(-R), B = A.at(R + .7), L = Math.hypot(B[0] - P[0], B[1] - P[1]) || 1;
+ let nx = (P[1] - B[1]) / L, ny = (B[0] - P[0]) / L; // the side of the axis below it, or left of an upright one
if (ny - nx < 0) { nx = -nx; ny = -ny; }
- att(line, 'd', arrowD(A, B));
- att(ticks, 'd', ints.map(j => { const q = at(j); return D([[q[0] - nx * 6, q[1] - ny * 6], [q[0] + nx * 6, q[1] + ny * 6]]); }).join(''));
- const o = L / (2 * R + .7) < 28 ? 0 : 1; // numbers on an axis that points at the reader would pile up
- shown.forEach((j, n) => { const q = at(j); put(nums[n], { x: n1(q[0] + nx * 20), y: n1(q[1] + ny * 20 + 6), o }); });
- const q = at(R + 1.1);
- put(label, { x: n1(q[0]), y: n1(q[1] + 11) });
+ att(A.line, 'd', arrowD(P, B));
+ att(A.ticks, 'd', A.ints.map(j => { const q = A.at(j); return D([[q[0] - nx * 6, q[1] - ny * 6], [q[0] + nx * 6, q[1] + ny * 6]]); }).join(''));
+ const crowded = L / (2 * R + .7) < 28; // numbers on an axis that points at the reader would pile up
+ A.shown.forEach((j, n) => {
+ const q = A.at(j), x = q[0] + nx * 20, y = q[1] + ny * 20;
+ const near = keep.some(([kx, ky]) => Math.abs(kx - x) < 34 && Math.abs(ky - y) < 24);
+ put(A.nums[n], { x: n1(x), y: n1(y + 6), o: crowded || near ? 0 : 1 });
+ });
+ put(A.label, { x: n1(lab[i].x), y: n1(lab[i].y + 11), o: lab[i].o });
});
});
/* ---------- things in space: they re-project with the camera; set() moves them ---------- */
- function point(pos, { color = COL.chalk, r = 10, label = '', size: ls = 28, into = content } = {}) {
+ // A dot with a label; stem: true adds its shadow on the floor and a dashed line down to it, so its height reads.
+ function point(pos, { color = COL.chalk, r = 10, label = '', size: ls = 28, into = content, stem = false, dx, dy } = {}) {
const e = G(into, {});
+ const st_ = stem ? path(into, '', { stroke: color, 'stroke-width': 2, 'stroke-dasharray': '5 6', 'stroke-opacity': .7, fill: 'none' }) : null;
+ const sh = stem ? mk('ellipse', { rx: 7, ry: 3.5, fill: color, 'fill-opacity': .45 }, into) : null;
+ if (st_) into.insertBefore(st_, e), into.insertBefore(sh, e);
mk('circle', { r, fill: color, stroke: COL.board, 'stroke-width': 3 }, e);
- const t = T(e, label, { x: r + 8, y: -r - 6, size: ls, fill: color, font: MATH, weight: 600 });
- const it = { e, pos, t, set(q) { it.pos = q; dirty(); }, label(s) { if (t.textContent !== s) t.textContent = s; } };
- items.push(() => { const q = it.pos && proj(it.pos); put(e, q ? { x: n1(q[0]), y: n1(q[1]), o: 1 } : { o: 0 }); });
+ const t = T(e, label, { x: dx ?? r + 8, y: dy ?? -r - 6, size: ls, fill: color, font: MATH, weight: 600 });
+ const it = { e, pos, t, stemEl: st_, set(q) { it.pos = q; dirty(); }, label(s) { if (t.textContent !== s) t.textContent = s; } };
+ items.push(() => {
+ // hidden while pos is null; otherwise its opacity is the beat's to tween
+ const q = it.pos && proj(it.pos);
+ if (!q) { if (!it.hid) { it.hid = 1; put(e, { o: 0 }); } } else { put(e, { x: n1(q[0]), y: n1(q[1]), ...(it.hid ? { o: 1 } : {}) }); it.hid = 0; }
+ if (st_) {
+ const f = it.pos && Math.abs(it.pos[2]) > .05 ? proj([it.pos[0], it.pos[1], 0]) : null;
+ att(st_, 'd', f ? D([q, f]) : '');
+ if (f) { sh.setAttribute('cx', n1(f[0])); sh.setAttribute('cy', n1(f[1])); }
+ sh.style.opacity = f ? 1 : 0;
+ }
+ });
dirty();
return it;
}
- function line(a, b, { color = COL.chalk, w = 3, dash, head = false, into = content } = {}) {
+ function line(a, b, { color = COL.chalk, w = 3, dash, head = false, into = content, clip = false } = {}) {
const e = path(into, '', { stroke: color, 'stroke-width': w, ...(head ? { fill: color } : {}), ...(dash ? { 'stroke-dasharray': dash, 'fill-opacity': .5 } : {}) });
const it = { e, a, b, set(a2, b2) { it.a = a2; it.b = b2; dirty(); } };
items.push(() => {
- const A = it.a && proj(it.a), B = it.b && proj(it.b);
- att(e, 'd', !A || !B ? '' : head ? arrowD(A, B, w + 5) : D([A, B]));
+ // clip: true keeps the part inside the cube (one unit of margin), so a long path never leaves the stage
+ const s = it.a && it.b ? (clip ? S3_clipSeg(it.a, it.b, R + 1) : [it.a, it.b]) : null;
+ const cut = s && clip && Math.hypot(...s[1].map((x, j) => x - it.b[j])) > 1e-6;
+ const A = s && proj(s[0]), B = s && proj(s[1]);
+ att(e, 'd', !s ? '' : head && !cut ? arrowD(A, B, w + 5) : D([A, B]));
});
dirty();
return it;
@@ -172,17 +228,80 @@ function space3(p, { cx = 1150, cy = 450, size = 640, range: R = 4, yaw = -30, p
dirty();
return it;
}
- // The plane a·x + b·y + c·z = d, as far as it lies inside the cube; hidden when a, b and c are all 0.
- function plane(a, b, c, d, opts) {
- const it = poly(null, opts);
- it.set = (...q) => { it.coef = q; it.pts = S3_cut(...q, R); dirty(); };
+ // The plane a·x + b·y + c·z = d, as far as it lies inside the cube; hidden when a, b and c are all 0. It is drawn
+ // as pieces, cut where other planes (visible ones) cross it, each piece in painter's order; e is its whole outline
+ // (not painted), for hit boxes. fade(k, at, dur) dims it (1 full, 0.2 a ghost); width(w) thickens its edges.
+ function plane(a, b, c, d, { color = COL.chalk, fo = .2, w = 3, into = polys } = {}) {
+ const e = path(into, '', { stroke: 'none', fill: 'none' });
+ e.style.pointerEvents = 'none';
+ let kPlan = 1;
+ const it = {
+ e, color, fo, w, into, k: 1, visible: true, coef: null, pts: null, frags: [],
+ set(...q) { it.coef = q; it.pts = S3_cut(...q, R); dirty(); },
+ fade(to, at, dur = .6) { const from = kPlan; kPlan = to; prog(q => { it.k = from + (to - from) * q; dirty(); }, at, dur); },
+ width(px) { it.w = px; dirty(); },
+ };
+ planeItems.push(it);
it.set(a, b, c, d);
return it;
}
+ function cutPlane(it) {
+ let pieces = it.pts && it.visible ? [it.pts] : [];
+ const n = it.coef && it.coef.slice(0, 3);
+ for (const o of planeItems) {
+ if (o === it || !o.pts || !o.visible || o.k < .02 || !pieces.length) continue; // a faded-out plane cuts nothing
+ const m = o.coef.slice(0, 3), L = Math.hypot(...m);
+ if (Math.hypot(...S3_cross(n, m)) < 1e-9 * L * Math.hypot(...n) + 1e-12) continue; // parallel: no cut
+ const mn = m.map(x => x / L), dn = o.coef[3] / L;
+ pieces = pieces.flatMap(pc => [S3_half(pc, mn, dn, 1), S3_half(pc, mn, dn, -1)].filter(Boolean));
+ }
+ att(it.e, 'd', it.pts && it.visible ? D(it.pts.map(proj)) + 'Z' : '');
+ pieces.forEach((pc, i) => {
+ if (!it.frags[i]) {
+ const fe = path(it.into, '', { stroke: it.color, fill: it.color, 'stroke-linejoin': 'round' });
+ fe.style.pointerEvents = 'none';
+ it.frags[i] = { e: fe, dep: 0, id: polyN++ };
+ sorted.push(it.frags[i]);
+ }
+ const f = it.frags[i], S = pc.map(proj);
+ f.on = true;
+ att(f.e, 'd', D(S) + 'Z');
+ att(f.e, 'fill-opacity', n1(it.fo * it.k * 100) / 100);
+ att(f.e, 'stroke-opacity', n1(it.k * 100) / 100);
+ att(f.e, 'stroke-width', it.w);
+ f.dep = S.reduce((s, q) => s + q[2], 0) / S.length;
+ });
+ it.frags.slice(pieces.length).forEach(f => { f.on = false; att(f.e, 'd', ''); });
+ }
+ // A walk from the origin to pos: along x, then along y, then up (or down) z, each leg drawn on in turn from t0 (dur
+ // in all), or each from its own time (at: [tx, ty, tz], legs of dur / 3), ending in a dot. The legs stay; returns
+ // { legs, dot, end } (end: when the dot lands). A leg of length 0 is skipped.
+ function walk(pos, t0, { dur = 2.4, at, colors = [COL.whole, COL.nat, COL.int], color = COL.task, label = '', into = content, w = 5, dot: withDot = true } = {}) {
+ const corners = [[0, 0, 0], [pos[0], 0, 0], [pos[0], pos[1], 0], pos];
+ const lens = [0, 1, 2].map(j => Math.abs(pos[j])), total = lens.reduce((s, x) => s + x, 0) || 1;
+ let t = t0;
+ const legs = [0, 1, 2].map(j => {
+ const l = line(null, null, { color: colors[j], w, into });
+ l.e.setAttribute('stroke-linecap', 'round');
+ const d = !lens[j] ? 0 : at ? dur / 3 : .25 + dur * .8 * lens[j] / total, from = corners[j], to = corners[j + 1];
+ if (at) t = at[j];
+ if (d) prog(q => l.set(from, from.map((x, i) => x + (to[i] - x) * q)), t, d, at ? io : lin);
+ t += d + (d && !at ? .12 : 0);
+ return l;
+ });
+ const dt = withDot ? point(null, { color, label, into }) : null;
+ if (dt) { prog(() => dt.set(pos), t, 0, lin); pulse(dt.e, t); }
+ return { legs, dot: dt, end: t };
+ }
/* ---------- the camera ---------- */
- // The reader turns the view by dragging empty space, only while it is live.
+ // The reader turns the view by dragging empty space, or with the arrow keys once the view has focus; only while live.
let drag = null;
+ const turnBy = (dy, dp) => {
+ user.yaw += dy;
+ user.pitch = Math.max(PITCH[0] - cam.pitch, Math.min(PITCH[1] - cam.pitch, user.pitch + dp));
+ dirty();
+ };
orbit.addEventListener('pointerdown', e => {
if (!live) return;
e.preventDefault();
@@ -191,23 +310,34 @@ function space3(p, { cx = 1150, cy = 450, size = 640, range: R = 4, yaw = -30, p
});
orbit.addEventListener('pointermove', e => {
if (!drag) return;
- user.yaw = drag.yaw + (e.clientX - drag.x) / drag.k * .4;
- user.pitch = Math.max(PITCH[0] - cam.pitch, Math.min(PITCH[1] - cam.pitch, drag.pitch + (e.clientY - drag.y) / drag.k * .4));
- dirty();
+ user.yaw = drag.yaw; user.pitch = drag.pitch;
+ turnBy((e.clientX - drag.x) / drag.k * .4, (e.clientY - drag.y) / drag.k * .4);
});
const end = () => { drag = null; };
orbit.addEventListener('pointerup', end);
orbit.addEventListener('lostpointercapture', end);
+ orbit.addEventListener('keydown', e => {
+ if (!live) return;
+ const d = { ArrowLeft: [-10, 0], ArrowRight: [10, 0], ArrowUp: [0, 8], ArrowDown: [0, -8] }[e.key];
+ if (!d) return;
+ e.preventDefault(); e.stopPropagation(); // the player's ←/→ must not leave the beat
+ turnBy(...d);
+ });
+ orbit.addEventListener('focus', () => { if (live) { orbit.setAttribute('stroke', COL.faint); orbit.setAttribute('stroke-dasharray', '6 8'); } });
+ orbit.addEventListener('blur', () => orbit.removeAttribute('stroke'));
dirty();
show(g, t0, .5);
return {
- g, content, polys, k, R, proj, unproj, point, line, poly, plane,
+ g, content, polys, frame, k, R, proj, unproj, point, line, poly, plane, walk,
+ floor, cube, axes: axes.map(A => A.g),
arrow: (a, b, opts) => line(a, b, { w: 5, ...opts, head: true }),
seg: line,
redraw: dirty,
// f(proj) runs after every redraw: for chapter drawing that follows the camera (a label, a hit box).
on(f) { hooks.push(f); dirty(); },
+ // f(proj) returns screen points of labels drawn over the view; axis numbers near them step aside (hide).
+ avoid(f) { avoids.push(f); dirty(); },
// A pointer event in the view's own coordinates (the stage's, unless the panel moved).
local(e) { const q = svg.createSVGPoint(); q.x = e.clientX; q.y = e.clientY; const w = q.matrixTransform(g.getScreenCTM().inverse()); return [w.x, w.y]; },
// Turn the camera to { yaw, pitch } (degrees) over dur seconds on the beat clock, from where earlier turns left it.
@@ -223,19 +353,35 @@ function space3(p, { cx = 1150, cy = 450, size = 640, range: R = 4, yaw = -30, p
if (dur === undefined) clockRun(t => { drifts[i] = degPerSec * Math.max(0, t - at); dirty(); }, 0, { tail: true });
else prog(q => { drifts[i] = degPerSec * dur * q; dirty(); }, at, dur, lin);
},
- live(on) { live = on; orbit.style.cursor = on ? 'grab' : ''; },
+ // A gentle sway about z (amp degrees, period seconds) from `at` to the end of the beat: the view never stands still,
+ // so depth keeps reading, yet the picture stays near the angle a beat chose.
+ sway(amp = 6, period = 14, at = 0) {
+ const i = drifts.push(0) - 1;
+ clockRun(t => { drifts[i] = amp * Math.sin(2 * Math.PI * Math.max(0, t - at) / period); dirty(); }, 0, { tail: true });
+ },
+ live(on) {
+ live = on;
+ orbit.style.cursor = on ? 'grab' : '';
+ if (on) orbit.setAttribute('tabindex', 0); else { orbit.removeAttribute('tabindex'); orbit.removeAttribute('stroke'); }
+ },
};
}
/* ---------- lin3: a 3 × 3 system, equations, matrix form and space from one state ---------- */
// Every number on screen is the same value: scrub one (drag sideways, or focus it and press ↑/↓) and the planes, the
-// columns and the other copy follow; drag a plane by its edge (it slides along its normal: d changes) or an arrow tip
-// (it moves in the plane facing you, to the nearest lattice point) and the numbers follow.
-function lin3(p, { A = [[2, -1, 0], [-1, 2, -1], [0, -3, 4]], b = [0, -1, 4], eq = [90, 180], mat = [100, 490], size = 46, space: so = {}, view = 'row', sol: readout = true, t0 = .1 } = {}) {
- const I = [0, 1, 2], v = {}, RANGE = {};
+// columns and the other copies follow; drag a plane by its edge (it slides along its normal: d changes) or an arrow tip
+// and the numbers follow. A tip moves along one axis per drag (the axis nearest the pointer's first motion, shown as a
+// guide), from lattice point to lattice point; focused, ←/→ move it along x, ↑/↓ along z, Shift+↑/↓ (or PgUp/PgDn)
+// along y.
+// rows: 1 shows only the first equation and its plane. mix: [x, y] adds the column form
+// x·[col 1] + y·[col 2] + z·[col 3] = [b] there, with x, y, z (keys x0, x1, x2) scrubbable: changing them (or A) moves
+// b to A times the mix; changing b solves for the mix again.
+function lin3(p, { A = [[2, -1, 0], [-1, 2, -1], [0, -3, 4]], b = [0, -1, 4], eq = [90, 180], mat = [100, 490], size = 46, space: so = {}, view = 'row', sol: readout = true, rows = 3, mix = null, t0 = .1 } = {}) {
+ const I = [0, 1, 2], RI = I.slice(0, rows), v = {}, RANGE = {};
I.forEach(i => { I.forEach(j => { v[`a${i}${j}`] = A[i][j]; RANGE[`a${i}${j}`] = 9; }); v[`b${i}`] = b[i]; RANGE[`b${i}`] = 30; });
+ if (rows < 3) { mat = null; readout = false; }
const V = space3(p, { t0, ...so }), R = V.R, svg = $('stage'), listeners = [], slots = [];
- let live = false, plan = { ...v };
+ let live = false;
const fmt = (n, one = false) => {
const r = Math.round(n * 10) / 10, s = Number.isInteger(r) ? String(Math.abs(r)) : Math.abs(r).toFixed(1);
@@ -243,8 +389,25 @@ function lin3(p, { A = [[2, -1, 0], [-1, 2, -1], [0, -3, 4]], b = [0, -1, 4], eq
};
const setText = (e, s) => { if (e.textContent !== s) e.textContent = s; };
const clamp = (key, n) => Math.max(-RANGE[key], Math.min(RANGE[key], n));
+ const Am = (s = v) => I.map(i => I.map(j => s[`a${i}${j}`]));
const col = j => [v[`a0${j}`], v[`a1${j}`], v[`a2${j}`]], bv = () => [v.b0, v.b1, v.b2];
- const Am = () => I.map(i => I.map(j => v[`a${i}${j}`]));
+ const solveOf = s => {
+ const M = Am(s), bb = [s.b0, s.b1, s.b2], det = S3_det(M);
+ if (Math.abs(det) > 1e-9) {
+ const [x, y, z] = I.map(j => S3_det(M.map((r, i) => r.map((c, l) => l === j ? bb[i] : c))) / det);
+ return { x, y, z };
+ }
+ const rA = S3_rank(M), rAb = S3_rank(M.map((r, i) => [...r, bb[i]]));
+ return rA < rAb ? { none: true } : { many: true, rank: rA };
+ };
+ // In mix mode the mix and b are tied: a changed mix (or A) moves b; a changed b alone re-solves the mix.
+ const derive = (s, changed) => {
+ if (!mix) return;
+ if (changed.some(k => k[0] === 'x' || k[0] === 'a')) I.forEach(i => { s[`b${i}`] = I.reduce((t, j) => t + s[`a${i}${j}`] * s[`x${j}`], 0); });
+ else if (changed.some(k => k[0] === 'b')) { const r = solveOf(s); if (r.x !== undefined) [s.x0, s.x1, s.x2] = [r.x, r.y, r.z]; }
+ };
+ if (mix) { const r = solveOf(v); [v.x0, v.x1, v.x2] = r.x !== undefined ? [r.x, r.y, r.z] : [0, 0, 0]; I.forEach(j => { RANGE[`x${j}`] = 9; }); }
+ let plan = { ...v };
/* ---------- numbers you can scrub (as in linsys) ---------- */
function slot(g, key, x, y, { anchor = 'end', letter = '', one = false, fill = COL.chalk, w = 80, fs = size } = {}) {
@@ -258,7 +421,7 @@ function lin3(p, { A = [[2, -1, 0], [-1, 2, -1], [0, -3, 4]], b = [0, -1, 4], eq
box.setAttribute('aria-label', key);
let drag = null;
box.addEventListener('pointerdown', e => {
- if (!live) return;
+ if (!live || s.locked) return;
e.preventDefault();
drag = { x: e.clientX, from: Math.round(v[key]) };
box.setPointerCapture(e.pointerId);
@@ -272,7 +435,7 @@ function lin3(p, { A = [[2, -1, 0], [-1, 2, -1], [0, -3, 4]], b = [0, -1, 4], eq
box.addEventListener('pointerup', end);
box.addEventListener('lostpointercapture', end);
box.addEventListener('keydown', e => {
- if (!live) return;
+ if (!live || s.locked) return;
const d = { ArrowUp: 1, ArrowRight: 1, ArrowDown: -1, ArrowLeft: -1 }[e.key];
if (!d) return;
e.preventDefault(); e.stopPropagation(); // the player's ←/→ must not leave the beat
@@ -283,18 +446,18 @@ function lin3(p, { A = [[2, -1, 0], [-1, 2, -1], [0, -3, 4]], b = [0, -1, 4], eq
}
/* ---------- the equations: a x + b y + c z = d ---------- */
- const E = G(p, { o: 0 });
- I.forEach(i => {
- const y = eq[1] + i * 70, x = eq[0];
- mk('rect', { x: x - 34, y: y - size * .7, width: 8, height: size * .8, rx: 4, fill: S3_ROW[i] }, E);
- const terms = ['x', 'y', 'z'].map((n, j) => ({ s: slot(E, `a${i}${j}`, x + 92 + 135 * j, y, { letter: n, one: true }), sign: j ? T(E, '+', { x: x + 30 + 135 * j, y, size, fill: COL.chalk, font: MATH, anchor: 'middle' }) : null }));
- T(E, '=', { x: x + 442, y, size, fill: COL.chalk, font: MATH, anchor: 'middle' });
- slot(E, `b${i}`, x + 475, y, { anchor: 'start' });
+ const E = G(p, { o: 0 }), rowG = [];
+ RI.forEach(i => {
+ const y = eq[1] + i * 70, x = eq[0], R_ = rowG[i] = G(E, {});
+ mk('rect', { x: x - 34, y: y - size * .7, width: 8, height: size * .8, rx: 4, fill: S3_ROW[i] }, R_);
+ const terms = ['x', 'y', 'z'].map((n, j) => ({ s: slot(R_, `a${i}${j}`, x + 92 + 135 * j, y, { letter: n, one: true }), sign: j ? T(R_, '+', { x: x + 30 + 135 * j, y, size, fill: COL.chalk, font: MATH, anchor: 'middle' }) : null }));
+ T(R_, '=', { x: x + 442, y, size, fill: COL.chalk, font: MATH, anchor: 'middle' });
+ slot(R_, `b${i}`, x + 475, y, { anchor: 'start' });
// Later terms show their size and the sign before them carries their sign; a term that is 0 stays, faint.
terms.forEach(({ s, sign }, j) => {
const key = `a${i}${j}`;
s.set = () => {
- const n = v[key], zero = Math.round(n * 10) === 0, o = zero ? '.35' : '';
+ const n = Math.round(v[key]), zero = n === 0, o = zero ? '.35' : ''; // whole numbers only: a passing 2.5 would run into the sign
if (sign) { setText(sign, n < 0 ? '−' : '+'); sign.style.opacity = o; }
setText(s.t, zero ? '0' : fmt(sign ? Math.abs(n) : n, true));
s.t.style.opacity = o; s.l.style.opacity = o;
@@ -325,26 +488,48 @@ function lin3(p, { A = [[2, -1, 0], [-1, 2, -1], [0, -3, 4]], b = [0, -1, 4], eq
});
}
+ /* ---------- the column form: x·[col 1] + y·[col 2] + z·[col 3] = [b] ---------- */
+ const CF = G(p, { o: 0 }), mixG = [], colG = [];
+ if (mix) {
+ const [fx_, fy] = mix, ms = Math.round(size * .85), rh = 50, top = fy - ms * .95, bot = fy + 2 * rh + ms * .35, cw = 66;
+ const bracket = (g, x, w) => path(g, `M${x + 12} ${top}H${x}V${bot}H${x + 12}M${x + w - 12} ${top}H${x + w}V${bot}H${x + w - 12}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' });
+ let x = fx_;
+ I.forEach(j => {
+ if (j) { T(CF, '+', { x: x + 16, y: fy + rh + 12, size: ms, fill: COL.chalk, font: MATH, anchor: 'middle' }); x += 38; }
+ mixG[j] = G(CF, {});
+ slot(mixG[j], `x${j}`, x + 56, fy + rh + 12, { anchor: 'end', fill: COL.chalk, w: 62, fs: ms });
+ colG[j] = G(CF, {});
+ bracket(colG[j], x + 64, cw);
+ I.forEach(i => slot(colG[j], `a${i}${j}`, x + 64 + cw / 2, fy + rh * i, { anchor: 'middle', fill: S3_COLS[j], w: 56, fs: ms }));
+ x += 64 + cw + 6;
+ });
+ T(CF, '=', { x: x + 18, y: fy + rh + 12, size: ms, fill: COL.chalk, font: MATH, anchor: 'middle' });
+ bracket(CF, x + 42, 84);
+ I.forEach(i => slot(CF, `b${i}`, x + 84, fy + rh * i, { anchor: 'middle', fill: S3_B, w: 72, fs: ms }));
+ }
+
/* ---------- the space: rows as planes, columns as arrows ---------- */
const ROWV = G(V.content, { o: view === 'col' ? 0 : 1 }), COLV = G(V.content, { o: view === 'row' ? 0 : 1 });
const usable = (g, on) => { g.style.pointerEvents = on ? '' : 'none'; };
usable(ROWV, view !== 'col'); usable(COLV, view !== 'row');
const planeG = G(ROWV, {});
const planes = I.map(i => V.plane(0, 0, 0, 0, { color: S3_ROW[i], into: planeG }));
+ planes.forEach((pl, i) => { pl.visible = i < rows; });
const lines = I.map(() => V.seg(null, null, { color: COL.chalk, w: 2.5, dash: '7 7', into: ROWV }));
lines.forEach(l => l.e.setAttribute('stroke-opacity', .75));
const meet = V.point(null, { color: COL.chalk, r: 11, into: ROWV });
// A plane is dragged by its edge: a wide, invisible copy of its outline.
- const hits = planes.map((pl, i) => {
+ const hits = planes.map(pl => {
const h = path(ROWV, '', { stroke: 'transparent', 'stroke-width': 26, fill: 'none' });
- h.addEventListener('pointerenter', () => { if (live) pl.e.setAttribute('stroke-width', 6); });
- h.addEventListener('pointerleave', () => pl.e.setAttribute('stroke-width', 3));
+ h.addEventListener('pointerenter', () => { if (live) pl.width(6); });
+ h.addEventListener('pointerleave', () => pl.width(3));
return h;
});
- const combo = I.map(j => V.arrow(null, null, { color: S3_COLS[j], w: 4, dash: '10 8', into: COLV })); // x·col1, y·col2, z·col3 tip to tail
+ const combo = I.map(j => V.arrow(null, null, { color: S3_COLS[j], w: 4, dash: '10 8', into: COLV, clip: true })); // x·col1, y·col2, z·col3 tip to tail
// b goes under the columns and wider: when b is a column (z = 1 and the rest 0) both still show
const bArrow = V.arrow(null, null, { color: S3_B, w: 9, into: COLV }), cols = I.map(j => V.arrow(null, null, { color: S3_COLS[j], into: COLV }));
+ const guide = V.seg(null, null, { color: COL.chalk, w: 2, dash: '3 7', into: COLV });
const tipKeys = [0, 1, 2, 'b'], tipColor = [...S3_COLS, S3_B];
const tipOf = k => k === 'b' ? bv() : col(k);
const tips = tipKeys.map((k, n) => {
@@ -352,33 +537,43 @@ function lin3(p, { A = [[2, -1, 0], [-1, 2, -1], [0, -3, 4]], b = [0, -1, 4], eq
mk('circle', { r: 22, fill: 'transparent' }, g);
const ring = mk('circle', { r: 13, fill: 'none', stroke: tipColor[n], 'stroke-width': 3, 'stroke-dasharray': '4 4' }, g);
ring.style.opacity = 0;
+ g.setAttribute('aria-label', k === 'b' ? 'tip of b' : `tip of column ${k + 1}`);
return { g, ring, k };
});
const tipLabels = tipKeys.map((k, n) => T(COLV, '', { size: 28, fill: tipColor[n], font: MATH, weight: 600 }));
+ // beside the tip, a column's on the arrow's right-hand side and b's on its left (b often lies along a column);
+ // past the tip is where a dashed mix often runs on
+ const labelAt = (n, proj) => {
+ const O = proj([0, 0, 0]), q = proj(tipOf(tipKeys[n])), L = Math.hypot(q[0] - O[0], q[1] - O[1]) || 1, ux = (q[0] - O[0]) / L, uy = (q[1] - O[1]) / L;
+ const side = tipKeys[n] === 'b' ? -1 : 1, nx = -uy * side, ny = ux * side;
+ return { q, x: Math.round(q[0] + ux * 14 + nx * 20), y: Math.round(q[1] + uy * 14 + ny * 24 + 9), anchor: nx > .35 ? 'start' : nx < -.35 ? 'end' : 'middle' };
+ };
+ V.avoid(proj => st(COLV).o > .05 ? tipLabels.flatMap((t, n) => t.textContent ? [[labelAt(n, proj).x, labelAt(n, proj).y - 9]] : []) : []);
V.on(proj => {
planes.forEach((pl, i) => { const d = pl.e.getAttribute('d'); if (hits[i].getAttribute('d') !== d) hits[i].setAttribute('d', d); });
- const O = proj([0, 0, 0]);
- tips.forEach(({ g, k }, n) => {
- const q = proj(tipOf(k)), L = Math.hypot(q[0] - O[0], q[1] - O[1]) || 1, ux = (q[0] - O[0]) / L, uy = (q[1] - O[1]) / L;
- put(g, { x: Math.round(q[0] * 10) / 10, y: Math.round(q[1] * 10) / 10 });
- // beside the tip, a column's on the arrow's right-hand side and b's on its left (b often lies along a column);
- // past the tip is where a dashed mix often runs on
- const side = k === 'b' ? -1 : 1, nx = -uy * side, ny = ux * side, t = tipLabels[n], anchor = nx > .35 ? 'start' : nx < -.35 ? 'end' : 'middle';
- if (t.getAttribute('text-anchor') !== anchor) t.setAttribute('text-anchor', anchor);
- put(t, { x: Math.round(q[0] + ux * 14 + nx * 20), y: Math.round(q[1] + uy * 14 + ny * 24 + 9) });
+ // a meeting line is as bright as the dimmer of its two planes
+ [[0, 1], [0, 2], [1, 2]].forEach(([i, j], n) => { const o = String(Math.round(.75 * Math.min(planes[i].k, planes[j].k) * 100) / 100); if (lines[n].e.getAttribute('stroke-opacity') !== o) lines[n].e.setAttribute('stroke-opacity', o); });
+ tips.forEach(({ g }, n) => {
+ const L = labelAt(n, proj), t = tipLabels[n];
+ put(g, { x: Math.round(L.q[0] * 10) / 10, y: Math.round(L.q[1] * 10) / 10 });
+ if (t.getAttribute('text-anchor') !== L.anchor) t.setAttribute('text-anchor', L.anchor);
+ put(t, { x: L.x, y: L.y });
});
});
- const dragIn = (el, onDown, onMove) => {
+ const dragIn = (el, onDown, onMove, onUp) => {
let on = null;
- el.addEventListener('pointerdown', e => { if (!live) return; e.preventDefault(); e.stopPropagation(); on = onDown(V.local(e)); el.setPointerCapture(e.pointerId); });
+ const up = () => { if (on) onUp?.(on); on = null; };
+ el.addEventListener('pointerdown', e => { if (!live) return; e.preventDefault(); e.stopPropagation(); on = onDown(V.local(e)); if (on) el.setPointerCapture(e.pointerId); });
el.addEventListener('pointermove', e => { if (on) onMove(on, V.local(e)); });
- el.addEventListener('pointerup', () => { on = null; });
- el.addEventListener('lostpointercapture', () => { on = null; });
+ el.addEventListener('pointerup', up);
+ el.addEventListener('lostpointercapture', up);
};
// A plane slides along its normal n = (a, b, c): moving it by t·n raises d by t·|n|²; t comes from the pointer's
// motion along the normal as drawn on screen.
+ const free = keys => keys.every(key => slots.every(s => s.key !== key || !s.locked));
hits.forEach((h, i) => dragIn(h, at => {
+ if (!free([`b${i}`])) return null;
const n = I.map(j => v[`a${i}${j}`]), c = planes[i].pts ? I.map(j => planes[i].pts.reduce((s, q) => s + q[j], 0) / planes[i].pts.length) : [0, 0, 0];
const P0 = V.proj(c), P1 = V.proj(c.map((x, j) => x + n[j]));
return { at, d0: v[`b${i}`], n2: S3_dot(n, n), ns: [P1[0] - P0[0], P1[1] - P0[1]] };
@@ -387,21 +582,46 @@ function lin3(p, { A = [[2, -1, 0], [-1, 2, -1], [0, -3, 4]], b = [0, -1, 4], eq
edit({ [`b${i}`]: clamp(`b${i}`, Math.round(s.d0 + t * s.n2)) });
}));
const lattice = n => Math.max(-R, Math.min(R, Math.round(n))) || 0; // never −0
- tips.forEach(({ g, k }) => dragIn(g, () => ({ dep: V.proj(tipOf(k))[2] }), (s, [x, y]) => {
- const q = V.unproj(x, y, s.dep).map(lattice);
- edit(k === 'b' ? { b0: q[0], b1: q[1], b2: q[2] } : { [`a0${k}`]: q[0], [`a1${k}`]: q[1], [`a2${k}`]: q[2] });
+ const putTip = (k, q) => edit(k === 'b' ? { b0: q[0], b1: q[1], b2: q[2] } : { [`a0${k}`]: q[0], [`a1${k}`]: q[1], [`a2${k}`]: q[2] });
+ // One axis per drag: after the pointer has moved 10 px, the axis whose drawn direction is nearest its motion is
+ // chosen and shown as a guide line through the tip; the tip then steps along it from lattice point to lattice point.
+ const tipKeysOf = k => k === 'b' ? ['b0', 'b1', 'b2'] : I.map(i => `a${i}${k}`);
+ tips.forEach(({ g, k }) => dragIn(g, at => free(tipKeysOf(k)) ? { at, start: tipOf(k).map(lattice), axis: null } : null, (s, [x, y]) => {
+ const dx = x - s.at[0], dy = y - s.at[1];
+ if (s.axis === null) {
+ const L = Math.hypot(dx, dy);
+ if (L < 10) return;
+ const O = V.proj(s.start);
+ let best = -1;
+ I.forEach(j => {
+ const e = [...s.start]; e[j] += 1;
+ const P = V.proj(e), ux = P[0] - O[0], uy = P[1] - O[1], Lu = Math.hypot(ux, uy);
+ if (Lu < 6) return;
+ const c = Math.abs(dx * ux + dy * uy) / Lu / L;
+ if (c > best) { best = c; s.axis = j; s.u = [ux / Lu, uy / Lu]; s.L = Lu; }
+ });
+ if (s.axis === null) return;
+ const a = [...s.start], b = [...s.start]; a[s.axis] = -R; b[s.axis] = R;
+ guide.e.setAttribute('stroke', S3_ROW[s.axis]);
+ guide.set(a, b);
+ }
+ const q = [...s.start];
+ q[s.axis] = lattice(s.start[s.axis] + (dx * s.u[0] + dy * s.u[1]) / s.L);
+ putTip(k, q);
+ }, () => guide.set(null, null)));
+ tips.forEach(({ g, k }) => g.addEventListener('keydown', e => {
+ if (!live || !free(tipKeysOf(k))) return;
+ const up = e.key === 'ArrowUp' || e.key === 'PageUp' ? 1 : e.key === 'ArrowDown' || e.key === 'PageDown' ? -1 : 0;
+ const j = e.key === 'ArrowLeft' || e.key === 'ArrowRight' ? 0 : up && (e.shiftKey || e.key.startsWith('Page')) ? 1 : up ? 2 : -1;
+ if (j < 0) return;
+ e.preventDefault(); e.stopPropagation();
+ const q = tipOf(k).map(lattice);
+ q[j] = lattice(q[j] + (j === 0 ? (e.key === 'ArrowRight' ? 1 : -1) : up));
+ putTip(k, q);
}));
/* ---------- one state, drawn everywhere ---------- */
- const solve = () => {
- const M = Am(), bb = bv(), det = S3_det(M);
- if (Math.abs(det) > 1e-9) {
- const [x, y, z] = I.map(j => S3_det(M.map((r, i) => r.map((c, l) => l === j ? bb[i] : c))) / det);
- return { x, y, z };
- }
- const rA = S3_rank(M), rAb = S3_rank(M.map((r, i) => [...r, bb[i]]));
- return rA < rAb ? { none: true } : { many: true, rank: rA };
- };
+ const solve = () => solveOf(v);
const exact = n => { // a fraction in lowest terms when the numbers are whole, else one decimal
const det = Math.round(S3_det(Am())), num = Math.round(n * det);
if (!Object.values(v).every(Number.isInteger) || !det) return [fmt(n)];
@@ -412,20 +632,20 @@ function lin3(p, { A = [[2, -1, 0], [-1, 2, -1], [0, -3, 4]], b = [0, -1, 4], eq
let solKey = '';
function draw() {
slots.forEach(s => s.set());
- const rows = I.map(i => [v[`a${i}0`], v[`a${i}1`], v[`a${i}2`], v[`b${i}`]]);
- planes.forEach((pl, i) => pl.set(...rows[i]));
- [[0, 1], [0, 2], [1, 2]].forEach(([i, j], n) => lines[n].set(...(S3_meet(rows[i], rows[j], R) || [null, null])));
- const s = solve(), one = s.x !== undefined, X = one ? [s.x, s.y, s.z] : null;
- const inCube = one && X.every(c => Math.abs(c) <= R + 1e-9);
- meet.set(inCube ? X : null);
- if (inCube) meet.label(`(${X.map(c => fmt(c)).join(', ')})`);
+ const rws = I.map(i => i < rows ? [v[`a${i}0`], v[`a${i}1`], v[`a${i}2`], v[`b${i}`]] : [0, 0, 0, 0]);
+ planes.forEach((pl, i) => pl.set(...rws[i]));
+ [[0, 1], [0, 2], [1, 2]].forEach(([i, j], n) => lines[n].set(...(rows === 3 && S3_meet(rws[i], rws[j], R) || [null, null])));
+ const s = solve(), one = s.x !== undefined, X = mix ? [v.x0, v.x1, v.x2] : one ? [s.x, s.y, s.z] : null;
+ const inCube = rows === 3 && one && [s.x, s.y, s.z].every(c => Math.abs(c) <= R + 1e-9);
+ meet.set(inCube ? [s.x, s.y, s.z] : null);
+ if (inCube) meet.label(`(${[s.x, s.y, s.z].map(c => fmt(c)).join(', ')})`);
const O = [0, 0, 0], bb = bv();
I.forEach(j => cols[j].set(O, col(j)));
bArrow.set(O, bb);
- const reach = one && X.every(c => Math.abs(c) <= 12);
+ const reach = X && X.every(c => Math.abs(c) <= 12);
let at = O;
- I.forEach(j => { const nxt = j === 2 ? bb : at.map((c, l) => c + X?.[j] * col(j)[l]); combo[j].set(reach ? at : null, reach ? nxt : null); at = reach ? nxt : O; });
- const key = one ? X.map(c => exact(c).join()).join('|') : s.none ? 'none' : 'many' + s.rank;
+ I.forEach(j => { const nxt = j === 2 && !mix ? bb : at.map((c, l) => c + X?.[j] * col(j)[l]); combo[j].set(reach ? at : null, reach ? nxt : null); at = reach ? nxt : O; });
+ const key = one ? [s.x, s.y, s.z].map(c => exact(c).join()).join('|') : s.none ? 'none' : 'many' + s.rank;
if (readout && key !== solKey) {
solKey = key;
sol.replaceChildren();
@@ -436,44 +656,77 @@ function lin3(p, { A = [[2, -1, 0], [-1, 2, -1], [0, -3, 4]], b = [0, -1, 4], eq
listeners.forEach(f => f(v, s));
}
function edit(to) {
- let changed = false;
- for (const key in to) if (v[key] !== to[key]) { v[key] = to[key]; changed = true; }
- if (changed) draw();
+ const changed = Object.keys(to).filter(key => v[key] !== to[key]);
+ if (!changed.length) return;
+ changed.forEach(key => { v[key] = to[key]; });
+ derive(v, changed);
+ draw();
}
draw();
- show(E, t0 + .2); show(Mx, t0 + .4);
+ show(E, t0 + .2); show(Mx, t0 + .4); show(CF, t0 + .4);
return {
- v, space: V, E, M: Mx, planes, lines, meet, cols, bArrow, combo, ROWV, COLV, solve,
+ v, space: V, E, M: Mx, CF, rows: rowG, mixG, colG, sol, planes, hits, tips, lines, meet, cols, bArrow, combo, ROWV, COLV, solve,
// Move the numbers to new values over dur seconds, on the beat clock (deterministic, so seeking replays it).
to(next, at, dur = 1.2, ease = io) {
const from = { ...plan };
plan = { ...plan, ...next };
- const goal = { ...plan };
- prog(q => edit(Object.fromEntries(Object.keys(goal).map(key => [key, from[key] + (goal[key] - from[key]) * q]))), at, dur, ease);
+ derive(plan, Object.keys(next));
+ const goal = { ...plan }, keys = Object.keys(next);
+ prog(q => edit(Object.fromEntries(keys.map(key => [key, from[key] + (goal[key] - from[key]) * q]))), at, dur, ease);
},
// Show the row picture, the column picture, or both; only what shows can be dragged.
view(which, at, dur = .6) {
tw(ROWV, { o: which === 'col' ? 0 : 1 }, at, dur);
tw(COLV, { o: which === 'row' ? 0 : 1 }, at, dur);
- prog(() => { usable(ROWV, which !== 'col'); usable(COLV, which !== 'row'); }, at, 0, lin);
+ prog(() => { usable(ROWV, which !== 'col'); usable(COLV, which !== 'row'); V.redraw(); }, at, 0, lin);
+ },
+ // Light some planes (an index, a list, or null for all) and dim the rest, with their equations.
+ focus(which, at, dur = .6) {
+ const on = which === null || which === undefined ? I : [].concat(which);
+ I.forEach(i => {
+ planes[i].fade(on.includes(i) ? 1 : .18, at, dur);
+ if (rowG[i]) tw(rowG[i], { o: on.includes(i) ? 1 : .35 }, at, dur);
+ });
},
// Hands on: scrub numbers, drag planes and tips, orbit the space. Turned off by sys.live(false) or by leaving the beat.
live(on) {
live = on;
V.live(on);
for (const s of slots) {
- s.box.style.cursor = on ? 'ew-resize' : '';
- s.box.setAttribute('stroke', on ? COL.faint : 'none');
+ const o = on && !s.locked;
+ s.box.style.cursor = o ? 'ew-resize' : '';
+ s.box.setAttribute('stroke', o ? COL.faint : 'none');
s.box.setAttribute('stroke-dasharray', '4 6');
- if (on) s.box.setAttribute('tabindex', 0); else s.box.removeAttribute('tabindex');
+ if (o) s.box.setAttribute('tabindex', 0); else s.box.removeAttribute('tabindex');
}
- hits.forEach(h => { h.style.cursor = on ? 'move' : ''; });
- tips.forEach(({ g, ring }) => { g.style.cursor = on ? 'grab' : ''; ring.style.opacity = on ? 1 : 0; });
+ hits.forEach((h, i) => { h.style.cursor = on && free([`b${i}`]) ? 'move' : ''; });
+ tips.forEach(({ g, ring, k }) => {
+ const o = on && free(tipKeysOf(k));
+ g.style.cursor = o ? 'grab' : ''; ring.style.opacity = o ? 1 : 0;
+ if (o) g.setAttribute('tabindex', 0); else g.removeAttribute('tabindex');
+ });
},
+ // Only these keys can be scrubbed by the reader (the rest stay put, without a dashed box); null: all of them.
+ // Call it before live(true).
+ lock(keys) { slots.forEach(s => { s.locked = !!keys && !keys.includes(s.key); }); },
set: edit, // at once, for a reader's action or an answer shown
- onChange(f) { listeners.push(f); },
+ onChange(f) { listeners.push(f); f(v, solve()); },
+ // The text elements showing one number (every copy of it), e.g. to flash it.
+ num: key => slots.filter(s => s.key === key).map(s => s.t),
// Names beside the arrow tips: col 1, col 2, col 3, b.
- labels(names) { names.forEach((n, i) => { tipLabels[i].textContent = n; tipLabels[i].setAttribute('font-style', /^[a-z]$/.test(n) ? 'italic' : 'normal'); }); },
+ labels(names) { names.forEach((n, i) => { tipLabels[i].textContent = n; tipLabels[i].setAttribute('font-style', /^[a-z]$/.test(n) ? 'italic' : 'normal'); }); V.redraw(); },
};
}
+
+// lsTask for lin3, with the 3D view's own keys in the hint; keys (optional) are the only numbers the reader may change.
+const lin3Task = (sys, test, why, hint, reveal, keys = null) => (body, api) => {
+ sys.lock(keys);
+ sys.live(true);
+ return {
+ check: () => { const ok = test(sys.v, sys.solve()); api.grade(ok, ok ? why : hint); },
+ reveal: () => { reveal?.(); return why; },
+ lock: () => sys.live(false),
+ hint: [kbd('Tab'), 'pick a number', kbd('↑'), kbd('↓'), 'change it; drag the picture to turn it'],
+ };
+};
diff --git a/site/linear-algebra/lib/vecs.js b/site/linear-algebra/lib/vecs.js
new file mode 100644
index 0000000..ecab351
--- /dev/null
+++ b/site/linear-algebra/lib/vecs.js
@@ -0,0 +1,405 @@
+// Named 2D vectors drawn two ways from one state: columns of numbers in brackets, and arrows in the plane.
+// Every number on screen is the same value: scrub one (drag sideways, or focus it and press ↑/↓) and its arrow moves;
+// drag an arrow's tip and its numbers follow. Two scalars c and d make the combination c·v + d·w, drawn tip to tail:
+// 'cv' from the origin, 'dw' from the tip of 'cv', and 'sum' from the origin to where they end. With solve mode on,
+// dragging the tip of 'sum' (or scrubbing its numbers) finds c and d.
+// The beat moves it with vs.to(); a question turns the reader's hands on with vs.live(true).
+// Loads after engine.js and math.js (it uses plane() and mathW()); linsys.js is not needed.
+const VS_COL = [COL.irr, COL.real, COL.rat]; // first, second, third vector: green, violet, pink (the columns of A later)
+
+function vecs(p, { vecs: list = { v: [3, 2] }, c = 1, d = 1, plane: po = {}, snap = 1, steps = {}, range = {}, show: shown, size = 46, t0 = .1, hidePlane = false } = {}) {
+ const names = Object.keys(list), [n1, n2 = n1] = names;
+ const v = { c, d };
+ names.forEach(n => { v[n + '0'] = list[n][0]; v[n + '1'] = list[n][1]; });
+ const holder = G(p, { o: hidePlane ? 0 : 1 });
+ const P2 = plane(holder, { cx: 1160, cy: 450, u: 52, x0: -6, x1: 6, y0: -6, y1: 6, t0, ...po });
+ const { PX, PY } = P2, svg = $('stage');
+ const listeners = [], slots = [];
+ let live = false, solving = false, plan = { ...v }, dragSet = null, moveVec = false;
+ const colorOf = Object.fromEntries(names.map((n, i) => [n, VS_COL[i % 3]]));
+ Object.assign(colorOf, { cv: colorOf[n1], dw: colorOf[n2], dw0: colorOf[n2], cv1: colorOf[n1], sum: COL.task });
+
+ /* ---------- 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.
+ 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)];
+ };
+ const fmt = n => parts(n).map(x => typeof x === 'string' ? x : x.f.join('/')).join('');
+ const vec = n => [v[n + '0'], v[n + '1']];
+ const calc = () => {
+ const a = vec(n1), b = vec(n2), cv = [v.c * a[0], v.c * a[1]], dw = [v.d * b[0], v.d * b[1]];
+ return { cv, dw, sum: [cv[0] + dw[0], cv[1] + dw[1]] };
+ };
+ const get = key => {
+ if (key in v) return v[key];
+ const m = /^(cv|dw|sum)([01])$/.exec(key);
+ return m ? calc()[m[1]][+m[2]] : NaN;
+ };
+ const scalar = k => k === 'c' || k === 'd';
+ const step = k => steps[k] ?? (scalar(k) ? 1 : snap);
+ const lim = k => range[k] ?? (scalar(k) ? [-5, 5] : /1$/.test(k) ? [P2.y0, P2.y1] : [P2.x0, P2.x1]);
+ const clamp = (k, n) => Math.max(lim(k)[0], Math.min(lim(k)[1], n));
+ const snapTo = (n, s) => Math.round(n / s) * s;
+
+ // c and d that make c·v + d·w land on (X, Y); along v alone when v and w are parallel.
+ const solveFor = (X, Y) => {
+ const [a0, a1] = vec(n1), [b0, b1] = vec(n2), det = a0 * b1 - b0 * a1;
+ if (Math.abs(det) > 1e-9) return { c: (X * b1 - b0 * Y) / det, d: (a0 * Y - X * a1) / det };
+ const L = a0 * a0 + a1 * a1 || 1;
+ return { c: (X * a0 + Y * a1) / L, d: 0 };
+ };
+ const setKey = (key, n) => {
+ if (key in v) return edit({ [key]: clamp(key, n) });
+ if (!solving) return;
+ const s = calc().sum, i = +key.slice(-1);
+ s[i] = Math.max(i ? P2.y0 : P2.x0, Math.min(i ? P2.y1 : P2.x1, n));
+ edit(solveFor(s[0], s[1]));
+ };
+ const canScrub = key => key in v || (solving && /^sum/.test(key));
+
+ /* ---------- numbers you can scrub ---------- */
+ // A slot shows one value; its ink is redrawn when the value's text changes and keeps its colour in `color`,
+ // so a flash (c_color) survives the redraw. The box under it takes the drag; the text never does.
+ function slot(g, key, x, y, { w = size * 1.7, sz = size, fill = COL.chalk, anchor = 'middle', scrub = true, pf } = {}) {
+ const bx = anchor === 'middle' ? x - w / 2 : anchor === 'end' ? x - w : x;
+ const box = scrub ? mk('rect', { x: bx, y: y - sz * .95, width: w, height: sz * 1.3, rx: 10, fill: 'transparent' }, g) : null;
+ const ink = G(g, {}); ink.setAttribute('color', fill); ink.style.pointerEvents = 'none';
+ let shownKey = '';
+ const s = {
+ key, box, ink, fill,
+ set() {
+ const pp = pf ? pf(v) : parts(get(key)), k = JSON.stringify(pp);
+ if (k === shownKey) return;
+ shownKey = k; ink.replaceChildren();
+ const long = pp.some(q => typeof q === 'string' && q.includes(DECIMAL_SIGN)); // a value passing between whole numbers
+ M(ink, pp, { x, y: long ? y - sz * .06 : y, size: long ? sz * .78 : sz, fill: 'currentColor', anchor });
+ },
+ };
+ if (box) {
+ box.setAttribute('aria-label', key);
+ let drag = null;
+ box.addEventListener('pointerdown', e => {
+ if (!live || !canScrub(key)) return;
+ e.preventDefault();
+ drag = { x: e.clientX, from: snapTo(get(key), step(key)) };
+ box.setPointerCapture(e.pointerId);
+ });
+ box.addEventListener('pointermove', e => {
+ if (!drag) return;
+ const k = svg.getScreenCTM().a; // screen px per stage px
+ setKey(key, drag.from + Math.round((e.clientX - drag.x) / k / 22) * step(key));
+ });
+ const end = () => { drag = null; };
+ box.addEventListener('pointerup', end);
+ box.addEventListener('lostpointercapture', end);
+ box.addEventListener('keydown', e => {
+ if (!live || !canScrub(key)) return;
+ if (e.key === 'Enter') { e.preventDefault(); e.stopPropagation(); box.blur(); P.keys?.(e); return; } // Enter checks, as in an answer box
+ const dd = { ArrowUp: 1, ArrowRight: 1, ArrowDown: -1, ArrowLeft: -1 }[e.key];
+ if (!dd) return;
+ e.preventDefault(); e.stopPropagation(); // the player's ←/→ must not leave the beat
+ setKey(key, snapTo(get(key), step(key)) + dd * step(key));
+ });
+ }
+ slots.push(s);
+ s.set();
+ return s;
+ }
+
+ /* ---------- rows of algebra ---------- */
+ // items, laid out left to right on one baseline:
+ // 'string' math text in chalk ('=', '+', '−', 'v', 'c', '·')
+ // { t, fill } math text in a colour (a vector's letter)
+ // { col: id } a column in brackets: a vector's name, 'cv', 'dw' or 'sum'; its numbers scrub when they are state
+ // { col: id, fixed: true } the same column, numbers not scrubbable
+ // { fn: v => [top, bottom], w, fill } a column of computed math parts, e.g. ['3 + 1'] (see vs.paren)
+ // { key: 'c' } one scrubbable number (a scalar), chalk
+ // { key: 'd', signed: true } the same, with its sign drawn as the + or − before it (for a second term: c v − 2w)
+ // Each item is its own group in .parts, so a beat can reveal them one by one; o: 0 starts them all hidden.
+ function row(items, { x = 90, y = 250, size: sz = size, o = 1, gap = sz * .28 } = {}) {
+ const g = G(p, {}), out = [], mid = y - sz * .32, rh = sz * 1.3;
+ let cx = x;
+ for (const it of items) {
+ const part = G(g, { o });
+ if (typeof it === 'string' || it.t !== undefined) {
+ const str = typeof it === 'string' ? it : it.t, fill = it.fill ?? COL.chalk;
+ const w = mathW([str], sz);
+ M(part, [str], { x: cx, y, size: sz, fill, anchor: 'start' });
+ cx += w + gap;
+ } else if (it.col) {
+ const id = it.col, w = sz * 1.9, fill = colorOf[id] ?? COL.chalk;
+ const top = mid - sz * 1.32, bot = mid + sz * 1.32;
+ path(part, `M${cx + 14} ${top}H${cx}V${bot}H${cx + 14}M${cx + w - 14} ${top}H${cx + w}V${bot}H${cx + w - 14}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' });
+ [0, 1].forEach(i => slot(part, id + i, cx + w / 2, mid - sz * .31 + i * rh, { sz, fill, w: w - 16, scrub: !it.fixed }));
+ cx += w + gap;
+ } else if (it.fn) {
+ const w = it.w ?? sz * 4, fill = it.fill ?? COL.chalk;
+ const top = mid - sz * 1.32, bot = mid + sz * 1.32;
+ path(part, `M${cx + 14} ${top}H${cx}V${bot}H${cx + 14}M${cx + w - 14} ${top}H${cx + w}V${bot}H${cx + w - 14}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' });
+ [0, 1].forEach(i => slot(part, 'fn', cx + w / 2, mid - sz * .31 + i * rh, { sz, fill, scrub: false, pf: vv => [].concat(it.fn(vv)[i]) }));
+ cx += w + gap;
+ } 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;
+ }
+ 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;
+ }
+ out.push(part);
+ }
+ return { g, parts: out, w: cx - x };
+ }
+
+ /* ---------- arrows in the plane ---------- */
+ const layer = G(P2.g, {}), latG = G(layer, { o: 0 }), legG = G(layer, {}), arrG = G(layer, {}), labG = G(layer, {}), hanG = G(layer, {});
+ const arrowD = (xa, ya, xb, yb) => {
+ const a = [PX(xa), PY(ya)], b = [PX(xb), PY(yb)], L = Math.hypot(b[0] - a[0], b[1] - a[1]);
+ if (L < 1) return '';
+ const ux = (b[0] - a[0]) / L, uy = (b[1] - a[1]) / L, hl = Math.min(20, L * .45);
+ return `M${a[0]} ${a[1]}L${b[0] - ux * hl * .6} ${b[1] - uy * hl * .6}M${b[0] - hl * ux - 10 * uy} ${b[1] - hl * uy + 10 * ux}L${b[0]} ${b[1]}L${b[0] - hl * ux + 10 * uy} ${b[1] - hl * uy - 10 * ux}Z`;
+ };
+ // id → [tail, tip] in plane units
+ const ends = id => {
+ const k = calc();
+ if (id in colorOf && names.includes(id)) return [[0, 0], vec(id)];
+ return { cv: [[0, 0], k.cv], dw: [k.cv, k.sum], dw0: [[0, 0], k.dw], cv1: [k.dw, k.sum], sum: [[0, 0], k.sum] }[id];
+ };
+ const defaultLabel = {
+ cv: () => v.c === 1 ? [n1] : v.c === -1 ? ['−' + n1] : [...parts(v.c), n1],
+ dw: () => v.d === 1 ? [n2] : v.d === -1 ? ['−' + n2] : [...parts(v.d), n2],
+ sum: () => [],
+ };
+ defaultLabel.cv1 = defaultLabel.cv; defaultLabel.dw0 = defaultLabel.dw;
+ const ids = [...names, 'cv', 'dw', 'dw0', 'cv1', 'sum'];
+ const show0 = shown ?? names;
+ const A = {};
+ // Placed arrows ('dw', 'cv1') go under the ones from the origin; the sum on top.
+ const order = ['dw0', 'cv1', 'dw', 'cv', ...names, 'sum'];
+ for (const id of order) {
+ const g = G(arrG, { o: show0.includes(id) ? 1 : 0 }), color = colorOf[id];
+ const pa = path(g, '', { stroke: color, fill: color, 'stroke-width': id === 'sum' ? 6 : 5, 'stroke-linejoin': 'round', 'stroke-linecap': 'round' });
+ const zero = mk('circle', { r: 7, fill: color, cx: PX(0), cy: PY(0) }, g);
+ const lab = G(labG, { o: show0.includes(id) ? 1 : 0 }), labInk = G(lab, {});
+ const leg = G(legG, { o: 0 });
+ const legP = path(leg, '', { stroke: color, 'stroke-width': 3, 'stroke-dasharray': '7 7', fill: 'none' });
+ const legX = G(leg, {}), legY = G(leg, {});
+ const h = G(hanG, {});
+ mk('circle', { r: 24, fill: 'transparent' }, h);
+ const ring = mk('circle', { r: 14, fill: 'none', stroke: color, 'stroke-width': 3, 'stroke-dasharray': '4 4' }, h);
+ ring.style.opacity = 0; h.style.pointerEvents = 'none';
+ A[id] = { g, path: pa, zero, lab, labInk, labKey: '', label: defaultLabel[id] || (() => [id]), at: /^(dw|cv1)$/.test(id) ? 'mid' : 'tip', leg, legP, legX, legY, legKey: '', h, ring };
+ }
+ const tipCtl = { lab: 30 };
+
+ /* ---------- the lattice: every c·v + d·w with whole c and d ---------- */
+ const latLines = [0, 1].map(i => path(latG, '', { stroke: colorOf[i ? n2 : n1], 'stroke-width': 1.5, 'stroke-opacity': .45, fill: 'none' }));
+ const latDots = path(latG, '', { stroke: COL.chalk, 'stroke-width': 7, 'stroke-linecap': 'round', 'stroke-opacity': .55, fill: 'none' });
+ const span = path(latG, '', { stroke: COL.task, 'stroke-width': 5, 'stroke-opacity': .5, fill: 'none', 'stroke-linecap': 'round' });
+ let latOn = false;
+ // The part of the line through point q with direction e inside the grid, as a path piece.
+ const clipDir = (q, e) => {
+ const ts = [];
+ const tryT = (t, val, lo, hi) => { if (val >= lo - 1e-9 && val <= hi + 1e-9) ts.push(t); };
+ if (Math.abs(e[0]) > 1e-9) for (const X of [P2.x0, P2.x1]) { const t = (X - q[0]) / e[0]; tryT(t, q[1] + t * e[1], P2.y0, P2.y1); }
+ if (Math.abs(e[1]) > 1e-9) for (const Y of [P2.y0, P2.y1]) { const t = (Y - q[1]) / e[1]; tryT(t, q[0] + t * e[0], P2.x0, P2.x1); }
+ if (ts.length < 2) return '';
+ const a = Math.min(...ts), b = Math.max(...ts);
+ if (b - a < 1e-9) return '';
+ return `M${PX(q[0] + a * e[0])} ${PY(q[1] + a * e[1])}L${PX(q[0] + b * e[0])} ${PY(q[1] + b * e[1])}`;
+ };
+ function drawLattice() {
+ const a = vec(n1), b = vec(n2), det = a[0] * b[1] - b[0] * a[1];
+ let d1 = '', d2 = '', dots = '', sp = '';
+ if (Math.abs(det) > 1e-9) {
+ const cs = [], ds = [];
+ for (const X of [P2.x0, P2.x1]) for (const Y of [P2.y0, P2.y1]) { const s = solveFor(X, Y); cs.push(s.c); ds.push(s.d); }
+ const cr = [Math.ceil(Math.min(...cs)), Math.floor(Math.max(...cs))], dr = [Math.ceil(Math.min(...ds)), Math.floor(Math.max(...ds))];
+ // ponytail: nearly parallel vectors need ever more lines; past 300 the grid is left out (it is a smear by then)
+ if (cr[1] - cr[0] < 300 && dr[1] - dr[0] < 300) {
+ for (let k = dr[0]; k <= dr[1]; k++) d1 += clipDir([k * b[0], k * b[1]], a); // lines along v
+ for (let k = cr[0]; k <= cr[1]; k++) d2 += clipDir([k * a[0], k * a[1]], b); // lines along w
+ }
+ if ((cr[1] - cr[0] + 1) * (dr[1] - dr[0] + 1) < 6000) {
+ for (let i = cr[0]; i <= cr[1]; i++) for (let j = dr[0]; j <= dr[1]; j++) {
+ const X = i * a[0] + j * b[0], Y = i * a[1] + j * b[1];
+ if (X >= P2.x0 - 1e-9 && X <= P2.x1 + 1e-9 && Y >= P2.y0 - 1e-9 && Y <= P2.y1 + 1e-9) dots += `M${PX(X)} ${PY(Y)}h0`;
+ }
+ }
+ } else {
+ const e = Math.hypot(...a) > 1e-9 ? a : b;
+ if (Math.hypot(...e) > 1e-9) sp = clipDir([0, 0], e);
+ }
+ latLines[0].setAttribute('d', d1); latLines[1].setAttribute('d', d2); latDots.setAttribute('d', dots); span.setAttribute('d', sp);
+ }
+
+ /* ---------- one state, drawn everywhere ---------- */
+ function draw() {
+ slots.forEach(s => s.set());
+ for (const id of ids) {
+ const a = A[id], [[xa, ya], [xb, yb]] = ends(id), L = Math.hypot(xb - xa, yb - ya);
+ const dd = arrowD(xa, ya, xb, yb);
+ if (a.path.getAttribute('d') !== dd) a.path.setAttribute('d', dd);
+ a.zero.style.opacity = L < .3 ? 1 : 0; // the zero vector: a dot where the arrow would be
+ put(a.zero, { x: PX(xa) - PX(0), y: PY(ya) - PY(0) });
+ put(a.h, { x: PX(xb), y: PY(yb) });
+ // label: beside the tip (pushed out along the arrow) or beside the middle (on the side away from the origin)
+ const pp = a.label(v), key = JSON.stringify(pp);
+ if (key !== a.labKey) { a.labKey = key; a.labInk.replaceChildren(); if (pp.length) M(a.labInk, pp, { size: 32, fill: colorOf[id], anchor: 'middle' }); }
+ const ux = L > 1e-9 ? (xb - xa) / L : .7, uy = L > 1e-9 ? (yb - ya) / L : .7;
+ let lx, ly;
+ if (a.at === 'tip') {
+ lx = PX(xb) + ux * tipCtl.lab + (Math.abs(ux) > .5 ? Math.sign(ux) * 8 : 0); ly = PY(yb) - uy * tipCtl.lab + 11;
+ if (Math.abs(uy) < .3) ly += yb < -1e-9 ? 22 : -24; // off the x-axis line, away from it
+ if (Math.abs(ux) < .3) lx += 22; // off the y-axis line
+ }
+ else {
+ const mx = (xa + xb) / 2, my = (ya + yb) / 2;
+ let nx = -uy, ny = ux;
+ if (nx * mx + ny * my < 0) { nx = -nx; ny = -ny; }
+ lx = PX(mx) + nx * 30; ly = PY(my) - ny * 30 + 11;
+ }
+ put(a.lab, { x: lx + (a.nudge?.[0] ?? 0), y: ly + (a.nudge?.[1] ?? 0) });
+ // legs: across, then up, from the tail to the tip, each with its length
+ const legD = L < 1e-9 ? '' : `M${PX(xa)} ${PY(ya)}H${PX(xb)}V${PY(yb)}`;
+ if (a.legP.getAttribute('d') !== legD) a.legP.setAttribute('d', legD);
+ 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.
+ const rise = yb - ya, inside = Math.abs(rise) >= 1.5;
+ const hy = rise >= 0 ? (inside ? -12 : 50) : (inside ? 34 : -14);
+ 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' });
+ }
+ }
+ if (latOn) drawLattice();
+ listeners.forEach(f => f(v, calc()));
+ }
+ function edit(to) {
+ let changed = false;
+ for (const k in to) if (v[k] !== to[k]) { v[k] = to[k]; changed = true; }
+ if (changed) draw();
+ }
+
+ /* ---------- dragging in the plane ---------- */
+ const pt = e => { const q = svg.createSVGPoint(); q.x = e.clientX; q.y = e.clientY; const w = q.matrixTransform(P2.g.getScreenCTM().inverse()); return [(w.x - P2.cx) / P2.u, (P2.cy - w.y) / P2.u]; };
+ const inBox = ([X, Y]) => [Math.max(P2.x0, Math.min(P2.x1, snapTo(X, snap))), Math.max(P2.y0, Math.min(P2.y1, snapTo(Y, snap)))];
+ const proj = (q, e) => { const L = e[0] * e[0] + e[1] * e[1]; return L > 1e-9 ? (q[0] * e[0] + q[1] * e[1]) / L : 0; };
+ // With move on, the tip of 'cv' or 'dw' carries its vector (v = tip / c, w = (tip − c·v) / d); else it sets c or d.
+ const onDrag = {
+ cv: q => {
+ if (moveVec && Math.abs(v.c) > 1e-9) { const [X, Y] = inBox(q); return edit({ [n1 + '0']: X / v.c, [n1 + '1']: Y / v.c }); }
+ edit({ c: clamp('c', snapTo(proj(q, vec(n1)), step('c'))) });
+ },
+ dw: q => {
+ const k = calc();
+ if (moveVec && Math.abs(v.d) > 1e-9) { const [X, Y] = inBox(q); return edit({ [n2 + '0']: (X - k.cv[0]) / v.d, [n2 + '1']: (Y - k.cv[1]) / v.d }); }
+ edit({ d: clamp('d', snapTo(proj([q[0] - k.cv[0], q[1] - k.cv[1]], vec(n2)), step('d'))) });
+ },
+ sum: q => { if (solving) { const [X, Y] = inBox(q); edit(solveFor(X, Y)); } },
+ };
+ names.forEach(n => { onDrag[n] = q => { const [X, Y] = inBox(q); edit({ [n + '0']: X, [n + '1']: Y }); }; });
+ for (const id of ['sum', ...names, 'cv', 'dw']) {
+ const h = A[id].h;
+ let on = false;
+ h.addEventListener('pointerdown', e => { if (!live) return; e.preventDefault(); hanG.append(h); on = true; h.setPointerCapture(e.pointerId); onDrag[id](pt(e)); });
+ h.addEventListener('pointermove', e => { if (on) onDrag[id](pt(e)); });
+ h.addEventListener('pointerup', () => { on = false; });
+ h.addEventListener('lostpointercapture', () => { on = false; });
+ }
+
+ draw();
+
+ const vs = {
+ v, P: P2, stage: holder, A, names, calc, solveFor, parts, fmt, row, lattice: latG,
+ paren: n => n < 0 ? `(${fmt(n)})` : fmt(n), // a number inside a sum: 1 + (−4)
+ // Move the numbers to new values over dur seconds, on the beat clock (deterministic, so seeking replays it).
+ to(next, at, dur = 1.2, ease = io) {
+ const from = { ...plan };
+ plan = { ...plan, ...next };
+ const goal = { ...plan };
+ prog(q => edit(Object.fromEntries(Object.keys(goal).map(k => [k, from[k] + (goal[k] - from[k]) * q]))), at, dur, ease);
+ },
+ // Show or hide arrows (with their labels) on the beat clock: vs.show(['cv', 'dw'], t0).
+ show(list, at, dur = .5) { [].concat(list).forEach(id => { show(A[id].g, at, dur); show(A[id].lab, at, dur); }); },
+ hide(list, at, dur = .5) { [].concat(list).forEach(id => { hide(A[id].g, at, dur); hide(A[id].lab, at, dur); }); },
+ dim(list, at, o = .3, dur = .5) { [].concat(list).forEach(id => { tw(A[id].g, { o }, at, dur); tw(A[id].lab, { o }, at, dur); }); },
+ // The dashed walk across then up, with its numbers.
+ legs(list, at, on = true, dur = .5) { [].concat(list).forEach(id => tw(A[id].leg, { o: on ? 1 : 0 }, at, dur)); },
+ // A label is a function of the state returning math parts; where = 'tip' or 'mid'; nudge = [dx, dy] in stage px.
+ label(id, f, where, nudge) { A[id].label = typeof f === 'function' ? f : () => [].concat(f); if (where) A[id].at = where; if (nudge) A[id].nudge = nudge; A[id].labKey = ''; draw(); },
+ lattice(at, on = true, dur = .8) { latOn = true; drawLattice(); tw(latG, { o: on ? 1 : 0 }, at, dur); },
+ // Solve mode: the tip of 'sum' and its numbers can be moved, and c and d follow.
+ solve(on = true) { solving = on; },
+ // Hands on: scrub numbers and drag tips. drag lists the arrows whose tips move (default: every arrow showing);
+ // move: true makes the tips of 'cv' and 'dw' carry v and w instead of changing c and d.
+ live(on, { drag, move = false } = {}) {
+ live = on; dragSet = drag ?? null; moveVec = move;
+ for (const s of slots) {
+ 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.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');
+ }
+ for (const id of ids) {
+ 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.ring.style.opacity = can ? 1 : 0;
+ }
+ },
+ set: edit, // at once, for a reader's action or an answer shown
+ num: key => slots.filter(s => s.key === key).map(s => s.ink), // every copy of this value on screen
+ // Light a value up in amber and back, wherever it shows.
+ flash(key, at) { slots.filter(s => s.key === key).forEach(s => { tw(s.ink, { c_color: COL.task }, at, .25); tw(s.ink, { c_color: s.fill }, at + 1.2, .6); }); },
+ onChange(f) { listeners.push(f); },
+ redraw: draw,
+ };
+ return vs;
+}
+
+// A question that is a task on the vectors: the reader changes them until test(v, calc) holds, then checks.
+const vsTask = (vs, test, why, hint, reveal, opts) => (body, api) => {
+ vs.live(true, opts);
+ return {
+ 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'],
+ };
+};
+
+// A column vector in HTML text (prompts, feedback, grid rows): hcol(3, −2, COL.irr). Numbers are written as given.
+const hcol = (top, bot, color) => {
+ const e = h('span', 'vcol', [h('span', '', [String(top).replace('-', '−')]), h('span', '', [String(bot).replace('-', '−')])]);
+ if (color) e.style.color = color;
+ return e;
+};
+document.head.append(Object.assign(document.createElement('style'), { textContent:
+ '.vcol{display:inline-flex;flex-direction:column;align-items:center;vertical-align:middle;line-height:1.08;padding:.08em .42em;margin:0 .12em;position:relative;font-family:var(--math-font,serif);min-width:1.1em}' +
+ '.vcol::before,.vcol::after{content:"";position:absolute;top:0;bottom:0;width:.28em;border:.09em solid currentColor}' +
+ '.vcol::before{left:0;border-right:none}.vcol::after{right:0;border-left:none}' }));
+
+// Questions whose answer is a column: each row shows q (rich text, columns by hcol) = [box over box].
+// rows: { q, ans: [top, bottom], why, hint, fx }. Graded by blanks (any equal value, fractions too).
+const vcolBlanks = rowsIn => (body, api) => {
+ const ctl = blanks(rowsIn.map(r => ({ ...r, parts: [{ box: String(r.ans[0]) }, { box: String(r.ans[1]) }] })))(body, api);
+ body.querySelectorAll('.bline').forEach((line, i) => {
+ const bs = line.querySelectorAll('input.box');
+ line.prepend(...(rowsIn[i].q ? [rich(rowsIn[i].q, 30), h('span', 'veq', ' = ')] : []), h('span', 'vcol vin', [bs[0], bs[1]]));
+ });
+ if (rowsIn.length > 3) body.classList.add('vgrid'); // many rows: two columns, so a full-screen set fits
+ return ctl;
+};
+document.head.append(Object.assign(document.createElement('style'), { textContent:
+ '.blanks.vgrid{display:grid;grid-template-columns:1fr 1fr;column-gap:2.5em}' +
+ '.vcol.vin{padding:.15em .5em;gap:.18em;font-size:30px}.vcol.vin input{margin:0}.bline .veq{font-family:var(--math-font,serif);font-size:30px;margin:0 .3em}' }));
diff --git a/site/linear-algebra/sandbox3/index.html b/site/linear-algebra/sandbox3/index.html
index e3beb08..5376ff4 100644
--- a/site/linear-algebra/sandbox3/index.html
+++ b/site/linear-algebra/sandbox3/index.html
@@ -17,9 +17,9 @@
'use strict';
// SANDBOX: silent beats to try space3.js and lin3 (the 3 × 3 system) before a chapter uses them.
const CHAPTER = { number: 99, title: 'Sandbox: Space in 3D', minutes: 2, language: 'en' };
-const CARD = { x: 40, y: 668, w: 720, cls: 'side' };
+const CARD = { x: 40, y: 430, w: 720, cls: 'side' }; // under the equations and their readout; the try beats drop the matrix
const title = (p, str, t0) => { const e = T(p, str, { x: 60, y: 110, size: 40, weight: 600, o: 0 }); show(e, t0); return e; };
-const sys3 = (p, view) => lin3(p, { view });
+const sys3 = (p, view, mat) => lin3(p, { view, ...(mat === false ? { mat: null } : {}) });
const TARGET = (v, s) => s.x === 1 && s.y === 1 && s.z === 1;
const BEATS = [
@@ -60,7 +60,7 @@ const BEATS = [
['try1', 'Your turn: planes', () => {
const p = panel(0);
title(p, 'Your turn', .1);
- S.sys = sys3(p, 'row');
+ S.sys = sys3(p, 'row', false);
}, { dur: 1.5, ask: done => quiz(CARD, [{
id: 'p-meet', prompt: ['Make the three planes meet at ', $m('(1, 1, 1)'), ': drag a plane by its edge, or scrub a number.'],
build: lsTask(S.sys, TARGET, 'All three planes pass through (1, 1, 1): the right sides are 1, 0 and 1.',
@@ -69,7 +69,7 @@ const BEATS = [
['try2', 'Your turn: columns', () => {
const p = panel(0);
title(p, 'Your turn', .1);
- S.sys = sys3(p, 'col');
+ S.sys = sys3(p, 'col', false);
S.sys.labels(['col 1', 'col 2', 'col 3', 'b']);
}, { dur: 1.5, ask: done => quiz(CARD, [{
id: 'c-mix', prompt: ['Drag the tip of ', $m('b'), ' until the mix is ', $m('1·col 1 + 1·col 2 + 1·col 3'), '.'],