Skip to content

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

feat(linear-algebra): chapters 26-28 and inv.js finish Unit 3

yzr9ee154e4a06b
diff --git a/site/linear-algebra/ch26/audio/en/collapse.mp3 b/site/linear-algebra/ch26/audio/en/collapse.mp3
new file mode 100644
index 0000000..909953c
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/collapse.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/fex1.mp3 b/site/linear-algebra/ch26/audio/en/fex1.mp3
new file mode 100644
index 0000000..9d33334
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/fex1.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/fex2.mp3 b/site/linear-algebra/ch26/audio/en/fex2.mp3
new file mode 100644
index 0000000..109a072
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/fex2.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/final1.mp3 b/site/linear-algebra/ch26/audio/en/final1.mp3
new file mode 100644
index 0000000..a6c84ef
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/final1.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/final2.mp3 b/site/linear-algebra/ch26/audio/en/final2.mp3
new file mode 100644
index 0000000..9bce6a1
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/final2.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/final3.mp3 b/site/linear-algebra/ch26/audio/en/final3.mp3
new file mode 100644
index 0000000..3b8721f
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/final3.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/final4.mp3 b/site/linear-algebra/ch26/audio/en/final4.mp3
new file mode 100644
index 0000000..4e151ea
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/final4.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/finish.mp3 b/site/linear-algebra/ch26/audio/en/finish.mp3
new file mode 100644
index 0000000..f18ab38
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/finish.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/formula.mp3 b/site/linear-algebra/ch26/audio/en/formula.mp3
new file mode 100644
index 0000000..8eac22c
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/formula.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/idef.mp3 b/site/linear-algebra/ch26/audio/en/idef.mp3
new file mode 100644
index 0000000..9949fcb
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/idef.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/intro.mp3 b/site/linear-algebra/ch26/audio/en/intro.mp3
new file mode 100644
index 0000000..28a1144
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/intro.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/live.mp3 b/site/linear-algebra/ch26/audio/en/live.mp3
new file mode 100644
index 0000000..0756a7d
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/live.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/play.mp3 b/site/linear-algebra/ch26/audio/en/play.mp3
new file mode 100644
index 0000000..cf95208
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/play.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/q1.mp3 b/site/linear-algebra/ch26/audio/en/q1.mp3
new file mode 100644
index 0000000..e79a9f9
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/q1.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/q2.mp3 b/site/linear-algebra/ch26/audio/en/q2.mp3
new file mode 100644
index 0000000..472239b
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/q2.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/q3.mp3 b/site/linear-algebra/ch26/audio/en/q3.mp3
new file mode 100644
index 0000000..3f874c1
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/q3.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/shear.mp3 b/site/linear-algebra/ch26/audio/en/shear.mp3
new file mode 100644
index 0000000..8e67792
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/shear.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/solve.mp3 b/site/linear-algebra/ch26/audio/en/solve.mp3
new file mode 100644
index 0000000..4783504
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/solve.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/timings.js b/site/linear-algebra/ch26/audio/en/timings.js
new file mode 100644
index 0000000..84897d8
--- /dev/null
+++ b/site/linear-algebra/ch26/audio/en/timings.js
@@ -0,0 +1,926 @@
+window.TIMINGS = {
+ "intro": {
+ "dur": 15.264,
+ "marks": {
+ "sub": 4.596,
+ "move": 9.883
+ },
+ "cues": [
+ [
+ 0.104,
+ "Chapter twenty-six."
+ ],
+ [
+ 1.862,
+ "The inverse: undoing a matrix."
+ ],
+ [
+ 4.596,
+ "A matrix moves the plane."
+ ],
+ [
+ 6.576,
+ "In this chapter we look for the matrix that moves it back."
+ ],
+ [
+ 9.883,
+ "Watch: one matrix leans the plane over, and another one stands it up again."
+ ]
+ ]
+ },
+ "undo": {
+ "dur": 52.464,
+ "marks": {
+ "A": 4.05,
+ "go": 9.596,
+ "ask": 14.648,
+ "half": 18.411,
+ "back": 26.966,
+ "name": 34.206,
+ "num": 42.031
+ },
+ "cues": [
+ [
+ 0.117,
+ "Here's the plain plane, with its grid and the little flag."
+ ],
+ [
+ 4.05,
+ "Take A equals two, zero in the first row, and zero, one in the second."
+ ],
+ [
+ 9.596,
+ "A stretches the plane sideways: everything becomes twice as wide."
+ ],
+ [
+ 14.648,
+ "Now the question of this chapter: which matrix moves it back?"
+ ],
+ [
+ 18.411,
+ "To undo twice as wide, we need half as wide: one half, zero in the first row, and zero, one in the second."
+ ],
+ [
+ 26.966,
+ "Watch it act on the stretched plane."
+ ],
+ [
+ 28.971,
+ "Every grid line slides back to where it started, and the flag is home again."
+ ],
+ [
+ 34.206,
+ "This matrix is called the inverse of A."
+ ],
+ [
+ 37.096,
+ "We write A with a small minus one up high, and we say: A inverse."
+ ],
+ [
+ 42.031,
+ "It works like numbers."
+ ],
+ [
+ 43.685,
+ "Three times one third is one: one third undoes three."
+ ],
+ [
+ 48.815,
+ "In the same way, A inverse undoes A."
+ ]
+ ]
+ },
+ "idef": {
+ "dur": 49.488,
+ "marks": {
+ "pt": 5.273,
+ "a1": 7.695,
+ "a2": 9.505,
+ "mult": 13.398,
+ "rc": 21.94,
+ "rc2": 27.201,
+ "rc3": 31.732,
+ "rc4": 32.839,
+ "I": 33.789,
+ "other": 41.615
+ },
+ "cues": [
+ [
+ 0.104,
+ "Do A, then A inverse, and every point ends where it started."
+ ],
+ [
+ 5.273,
+ "Follow one point: three, one."
+ ],
+ [
+ 7.695,
+ "A sends it to six, one."
+ ],
+ [
+ 9.505,
+ "Then A inverse sends six, one back to three, one."
+ ],
+ [
+ 13.398,
+ "Doing A and then A inverse is the product A inverse times A."
+ ],
+ [
+ 18.503,
+ "A acts first, so it stands on the right, next to x."
+ ],
+ [
+ 21.94,
+ "Row times column: one half times two, plus zero times zero, is one."
+ ],
+ [
+ 27.201,
+ "One half times zero, plus zero times one, is zero."
+ ],
+ [
+ 31.732,
+ "Then zero, and one."
+ ],
+ [
+ 33.789,
+ "A inverse times A is the identity matrix I: the matrix that leaves every point where it is."
+ ],
+ [
+ 41.615,
+ "The other order works too."
+ ],
+ [
+ 43.255,
+ "Squeeze first, then stretch, and you're also home."
+ ],
+ [
+ 47.031,
+ "A times A inverse is I as well."
+ ]
+ ]
+ },
+ "turn": {
+ "dur": 55.368,
+ "marks": {
+ "A": 2.487,
+ "go": 11.523,
+ "ask": 12.865,
+ "inv": 16.953,
+ "back": 25.299,
+ "check": 27.5,
+ "c2": 38.763,
+ "c3": 43.529,
+ "c4": 48.529,
+ "I": 50.521
+ },
+ "cues": [
+ [
+ 0.104,
+ "Second example: a turn."
+ ],
+ [
+ 2.487,
+ "A is zero, minus one in the first row, and one, zero in the second: a quarter turn, counterclockwise."
+ ],
+ [
+ 11.523,
+ "The flag turns up."
+ ],
+ [
+ 12.865,
+ "How do we undo a turn?"
+ ],
+ [
+ 14.245,
+ "Turn back by the same amount, clockwise."
+ ],
+ [
+ 16.953,
+ "From chapter ten, the clockwise quarter turn is zero, one in the first row, and minus one, zero in the second."
+ ],
+ [
+ 25.299,
+ "Turn back, and the plane is home."
+ ],
+ [
+ 27.5,
+ "Check by multiplying: A inverse times A."
+ ],
+ [
+ 31.237,
+ "Row one, which is zero, one, times column one, which is zero, one: zero plus one is one."
+ ],
+ [
+ 38.763,
+ "Row one times column two, minus one, zero: zero."
+ ],
+ [
+ 43.529,
+ "Row two, minus one, zero, times column one: zero."
+ ],
+ [
+ 48.529,
+ "And times column two: one."
+ ],
+ [
+ 50.521,
+ "The identity."
+ ],
+ [
+ 51.641,
+ "The clockwise turn undoes the counterclockwise turn."
+ ]
+ ]
+ },
+ "shear": {
+ "dur": 37.848,
+ "marks": {
+ "A": 1.706,
+ "go": 5.495,
+ "inv": 10.378,
+ "back": 20.065,
+ "minus": 20.951,
+ "flip": 26.888,
+ "flip2": 33.789
+ },
+ "cues": [
+ [
+ 0.13,
+ "Third: a shear."
+ ],
+ [
+ 1.706,
+ "One, one in the first row, and zero, one in the second."
+ ],
+ [
+ 5.495,
+ "Every line slides to the right: the higher it is, the further it slides."
+ ],
+ [
+ 10.378,
+ "To undo it, slide every line back to the left by the same amount: one, minus one in the first row, and zero, one in the second."
+ ],
+ [
+ 20.065,
+ "Home again."
+ ],
+ [
+ 20.951,
+ "Notice: the inverse has minus one where A had one."
+ ],
+ [
+ 24.766,
+ "Slide right, then slide left."
+ ],
+ [
+ 26.888,
+ "And one more: a flip, minus one, zero, and zero, one."
+ ],
+ [
+ 32.292,
+ "The flag points left."
+ ],
+ [
+ 33.789,
+ "Flip it again, and it's back."
+ ],
+ [
+ 35.69,
+ "A flip is its own inverse."
+ ]
+ ]
+ },
+ "q1": {
+ "dur": 6.744,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn."
+ ],
+ [
+ 1.042,
+ "The plane has been sheared upward."
+ ],
+ [
+ 2.969,
+ "Drag the two tips to build the matrix that brings it home."
+ ]
+ ]
+ },
+ "formula": {
+ "dur": 28.776,
+ "marks": {
+ "gen": 7.24,
+ "swap": 12.604,
+ "sign": 15.521,
+ "div": 19.714,
+ "all": 24.44
+ },
+ "cues": [
+ [
+ 0.104,
+ "Stretches, turns and shears are easy to undo by eye."
+ ],
+ [
+ 4.258,
+ "For any two by two matrix there's a formula."
+ ],
+ [
+ 7.24,
+ "Call the numbers a, b in the first row, and c, d in the second."
+ ],
+ [
+ 12.604,
+ "Step one: swap a and d."
+ ],
+ [
+ 15.521,
+ "Step two: put a minus sign in front of b and c."
+ ],
+ [
+ 19.714,
+ "Step three: divide everything by a d minus b c."
+ ],
+ [
+ 24.44,
+ "Swap, change two signs, divide."
+ ],
+ [
+ 27.37,
+ "That's the whole recipe."
+ ]
+ ]
+ },
+ "fex1": {
+ "dur": 52.728,
+ "marks": {
+ "A": 1.12,
+ "det": 6.042,
+ "sw": 12.109,
+ "sg": 14.675,
+ "res": 19.102,
+ "check": 28.555,
+ "c2": 35.117,
+ "c3": 39.336,
+ "c4": 43.633,
+ "I": 47.422,
+ "grid": 48.568
+ },
+ "cues": [
+ [
+ 0.104,
+ "Let's use it."
+ ],
+ [
+ 1.12,
+ "A is two, one in the first row, and one, one in the second."
+ ],
+ [
+ 6.042,
+ "a d minus b c is two times one, minus one times one: one."
+ ],
+ [
+ 12.109,
+ "Swap the two and the one on the diagonal."
+ ],
+ [
+ 14.675,
+ "Put minus signs on the other two: minus one, and minus one."
+ ],
+ [
+ 19.102,
+ "Divide by one, which changes nothing."
+ ],
+ [
+ 21.849,
+ "A inverse is one, minus one in the first row, and minus one, two in the second."
+ ],
+ [
+ 28.555,
+ "Check: A inverse times A."
+ ],
+ [
+ 30.794,
+ "One times two, plus minus one times one: one."
+ ],
+ [
+ 35.117,
+ "One times one, plus minus one times one: zero."
+ ],
+ [
+ 39.336,
+ "Minus one times two, plus two times one: zero."
+ ],
+ [
+ 43.633,
+ "Minus one times one, plus two times one: one."
+ ],
+ [
+ 47.422,
+ "The identity."
+ ],
+ [
+ 48.568,
+ "And on the plane: A moves it, and A inverse brings it home."
+ ]
+ ]
+ },
+ "fex2": {
+ "dur": 62.28,
+ "marks": {
+ "A": 2.63,
+ "det": 8.073,
+ "sw": 16.81,
+ "sg": 18.893,
+ "div": 21.406,
+ "res": 24.115,
+ "check": 30.039,
+ "c2": 41.003,
+ "c3": 48.789,
+ "c4": 53.62,
+ "I": 57.982,
+ "home": 59.401
+ },
+ "cues": [
+ [
+ 0.104,
+ "A second example, with a fraction."
+ ],
+ [
+ 2.63,
+ "A is three, one in the first row, and four, two in the second."
+ ],
+ [
+ 8.073,
+ "a d minus b c: three times two is six, minus one times four, which is four."
+ ],
+ [
+ 15.039,
+ "Six minus four is two."
+ ],
+ [
+ 16.81,
+ "Swap the three and the two."
+ ],
+ [
+ 18.893,
+ "Minus signs on the one and the four."
+ ],
+ [
+ 21.406,
+ "Now divide every number by two: one, minus one half in the first row, and minus two, three halves in the second."
+ ],
+ [
+ 30.039,
+ "Check, this time in the other order: A times A inverse."
+ ],
+ [
+ 34.154,
+ "Row three, one, times column one, minus two: three minus two is one."
+ ],
+ [
+ 41.003,
+ "Three times minus one half, plus one times three halves: minus three halves plus three halves is zero."
+ ],
+ [
+ 48.789,
+ "Row four, two, times column one: four minus four, zero."
+ ],
+ [
+ 53.62,
+ "And times column two: minus two plus three, one."
+ ],
+ [
+ 57.982,
+ "The identity again."
+ ],
+ [
+ 59.401,
+ "And on the plane, A inverse brings it home."
+ ]
+ ]
+ },
+ "why": {
+ "dur": 43.896,
+ "marks": {
+ "mul": 1.732,
+ "e1": 7.63,
+ "e2": 14.388,
+ "e3": 19.557,
+ "e4": 25.469,
+ "out": 32.604,
+ "div": 37.891
+ },
+ "cues": [
+ [
+ 0.104,
+ "Why does the formula work?"
+ ],
+ [
+ 1.732,
+ "Multiply the swapped matrix, d, minus b, minus c, a, by A."
+ ],
+ [
+ 7.63,
+ "Top left: d times a, plus minus b times c."
+ ],
+ [
+ 11.797,
+ "That's a d minus b c."
+ ],
+ [
+ 14.388,
+ "Top right: d times b, minus b times d."
+ ],
+ [
+ 18.398,
+ "That's zero."
+ ],
+ [
+ 19.557,
+ "Bottom left: minus c times a, plus a times c."
+ ],
+ [
+ 24.284,
+ "Zero again."
+ ],
+ [
+ 25.469,
+ "Bottom right: minus c times b, plus a times d."
+ ],
+ [
+ 30.065,
+ "a d minus b c once more."
+ ],
+ [
+ 32.604,
+ "So the product is a d minus b c, times the identity."
+ ],
+ [
+ 37.891,
+ "Divide by a d minus b c, and you get exactly I."
+ ],
+ [
+ 42.565,
+ "That's why we divide."
+ ]
+ ]
+ },
+ "live": {
+ "dur": 41.472,
+ "marks": {
+ "set": 3.268,
+ "b": 17.07,
+ "grow": 20.586,
+ "s4": 22.917,
+ "s3": 23.529,
+ "s2": 24.44,
+ "s1": 24.688,
+ "big": 25.443,
+ "zero": 32.109
+ },
+ "cues": [
+ [
+ 0.104,
+ "Now let's change A, and watch its inverse follow."
+ ],
+ [
+ 3.268,
+ "Here is A, two, one, one, three, with its inverse beside it, built by the formula."
+ ],
+ [
+ 10.859,
+ "a d minus b c is six minus one, five, so the inverse has fifths in it."
+ ],
+ [
+ 17.07,
+ "Now push the top right number up, one step at a time."
+ ],
+ [
+ 20.586,
+ "a d minus b c shrinks: four, three, two, one."
+ ],
+ [
+ 25.443,
+ "And the numbers in the inverse grow."
+ ],
+ [
+ 27.604,
+ "The plane is getting thinner, so undoing it takes a bigger stretch."
+ ],
+ [
+ 32.109,
+ "At six, a d minus b c is zero."
+ ],
+ [
+ 35.964,
+ "The two columns lie on one line, the plane is flat, and there is no inverse."
+ ]
+ ]
+ },
+ "q2": {
+ "dur": 3.912,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.133,
+ "Use the formula on the matrix from the lecture."
+ ]
+ ]
+ },
+ "collapse": {
+ "dur": 54.888,
+ "marks": {
+ "A": 4.974,
+ "det": 8.893,
+ "go": 13.385,
+ "pts": 16.276,
+ "land": 21.302,
+ "undo": 30.13,
+ "line": 40.208,
+ "never": 45.651
+ },
+ "cues": [
+ [
+ 0.104,
+ "What exactly goes wrong when a d minus b c is zero?"
+ ],
+ [
+ 4.974,
+ "Take one, two in the first row, and two, four in the second."
+ ],
+ [
+ 8.893,
+ "a d minus b c is four minus four: zero."
+ ],
+ [
+ 13.385,
+ "A squashes the whole plane onto one line."
+ ],
+ [
+ 16.276,
+ "Look at two points: zero, zero, and two, minus one."
+ ],
+ [
+ 21.302,
+ "Two, minus one goes to two minus two, and four minus four: zero, zero."
+ ],
+ [
+ 27.917,
+ "Both points land on the same spot."
+ ],
+ [
+ 30.13,
+ "An inverse would have to send zero, zero back where it came from."
+ ],
+ [
+ 34.115,
+ "But which one?"
+ ],
+ [
+ 35.156,
+ "Zero, zero, or two, minus one?"
+ ],
+ [
+ 38.919,
+ "It can't do both."
+ ],
+ [
+ 40.208,
+ "In fact the whole red line lands on zero, zero."
+ ],
+ [
+ 43.984,
+ "That's the lost direction."
+ ],
+ [
+ 45.651,
+ "Once the plane is flat, nothing can stand it up again."
+ ],
+ [
+ 49.036,
+ "No matrix undoes A."
+ ],
+ [
+ 51.706,
+ "Chapter twenty-eight looks at these matrices closely."
+ ]
+ ]
+ },
+ "q3": {
+ "dur": 3.792,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.146,
+ "Which of these matrices have an inverse?"
+ ]
+ ]
+ },
+ "solve": {
+ "dur": 52.248,
+ "marks": {
+ "eq": 2.109,
+ "x": 7.344,
+ "ex": 16.25,
+ "mul": 22.109,
+ "x2": 32.721,
+ "chk": 34.284,
+ "pic": 41.393,
+ "any": 47.956
+ },
+ "cues": [
+ [
+ 0.104,
+ "One more use of the inverse."
+ ],
+ [
+ 2.109,
+ "To solve A x equals b, multiply both sides by A inverse."
+ ],
+ [
+ 7.344,
+ "On the left, A inverse times A is I, and I times x is just x."
+ ],
+ [
+ 13.333,
+ "So x equals A inverse times b."
+ ],
+ [
+ 16.25,
+ "Take A equals two, one, one, one, and b equals five, three."
+ ],
+ [
+ 22.109,
+ "A inverse is one, minus one, minus one, two."
+ ],
+ [
+ 25.846,
+ "Times five, three: five minus three is two, and minus five plus six is one."
+ ],
+ [
+ 32.721,
+ "So x is two, one."
+ ],
+ [
+ 34.284,
+ "Check: A times two, one is four plus one, five, and two plus one, three."
+ ],
+ [
+ 40.404,
+ "That's b."
+ ],
+ [
+ 41.393,
+ "In the picture: A sends x to b, and A inverse sends b straight back to x."
+ ],
+ [
+ 47.956,
+ "And it works for every b: one matrix answers them all."
+ ]
+ ]
+ },
+ "wrap": {
+ "dur": 28.512,
+ "marks": {
+ "w1": 1.003,
+ "w2": 5.938,
+ "w3": 10.221,
+ "w4": 19.492,
+ "end": 26.354
+ },
+ "cues": [
+ [
+ 0.104,
+ "To sum up."
+ ],
+ [
+ 1.003,
+ "The inverse, A inverse, undoes A: it moves the plane back."
+ ],
+ [
+ 5.938,
+ "A inverse times A is I, and A times A inverse is I."
+ ],
+ [
+ 10.221,
+ "For a two by two matrix: swap a and d, change the signs of b and c, and divide by a d minus b c."
+ ],
+ [
+ 19.492,
+ "When a d minus b c is zero, the plane collapses onto a line, and there is no inverse."
+ ],
+ [
+ 26.354,
+ "Now try the chapter practice."
+ ]
+ ]
+ },
+ "final1": {
+ "dur": 3.072,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Chapter practice."
+ ],
+ [
+ 1.523,
+ "Undo each move."
+ ]
+ ]
+ },
+ "final2": {
+ "dur": 2.304,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Next, use the formula."
+ ]
+ ]
+ },
+ "final3": {
+ "dur": 4.584,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Now: which matrices can be undone?"
+ ],
+ [
+ 2.904,
+ "And solve with the inverse."
+ ]
+ ]
+ },
+ "final4": {
+ "dur": 3.672,
+ "marks": {},
+ "cues": [
+ [
+ 0.091,
+ "Last set."
+ ],
+ [
+ 1.237,
+ "Bring the plane home with your hands."
+ ]
+ ]
+ },
+ "play": {
+ "dur": 14.568,
+ "marks": {
+ "go": 4.128
+ },
+ "cues": [
+ [
+ 0.117,
+ "Playground."
+ ],
+ [
+ 1.094,
+ "Nothing here is marked right or wrong."
+ ],
+ [
+ 4.128,
+ "Change A by dragging the columns or the numbers, and watch its inverse follow."
+ ],
+ [
+ 9.57,
+ "Try to make a d minus b c zero."
+ ],
+ [
+ 12.865,
+ "Press continue when you're done."
+ ]
+ ]
+ },
+ "finish": {
+ "dur": 11.28,
+ "marks": {},
+ "cues": [
+ [
+ 0.091,
+ "Well done."
+ ],
+ [
+ 1.094,
+ "That's the end of chapter twenty-six, the inverse: undoing a matrix."
+ ],
+ [
+ 6.562,
+ "Next: finding the inverse by elimination, the Gauss\u2013Jordan way."
+ ]
+ ]
+ }
+};
diff --git a/site/linear-algebra/ch26/audio/en/turn.mp3 b/site/linear-algebra/ch26/audio/en/turn.mp3
new file mode 100644
index 0000000..9ff9c12
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/turn.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/undo.mp3 b/site/linear-algebra/ch26/audio/en/undo.mp3
new file mode 100644
index 0000000..0dff544
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/undo.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/why.mp3 b/site/linear-algebra/ch26/audio/en/why.mp3
new file mode 100644
index 0000000..fe366eb
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/why.mp3 differ
diff --git a/site/linear-algebra/ch26/audio/en/wrap.mp3 b/site/linear-algebra/ch26/audio/en/wrap.mp3
new file mode 100644
index 0000000..7cdb75d
Binary files /dev/null and b/site/linear-algebra/ch26/audio/en/wrap.mp3 differ
diff --git a/site/linear-algebra/ch26/index.html b/site/linear-algebra/ch26/index.html
new file mode 100644
index 0000000..2527c4b
--- /dev/null
+++ b/site/linear-algebra/ch26/index.html
@@ -0,0 +1,509 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>The Inverse: Undoing a Matrix</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/grid2.js"></script>
+<script src="../lib/inv.js"></script>
+<script src="../lib/play.js"></script>
+<script src="audio/en/timings.js"></script>
+<script>
+'use strict';
+const CHAPTER = { number: 26, title: 'The Inverse: Undoing a Matrix', minutes: 11, language: 'en', next: '../ch27/' };
+
+/* ---------- layout and colours ---------- */
+const COLC = [COL.irr, COL.real]; // column 1 green, column 2 violet
+const LEFT = { x: 40, y: 430, w: 720, cls: 'side' }; // question card under the matrices; the plane stays on the right
+const TOPL = { x: 40, y: 200, w: 720, cls: 'side' };
+const I2 = [[1, 0], [0, 1]];
+const ZOOM = { u: 64, x0: -5, x1: 5, y0: -5, y1: 5 }; // a closer plane for the named moves: the flag reads
+const INV = ['A', E('−1')]; // "A⁻¹" as math parts
+
+/* ---------- chapter drawing helpers (chapter 10's) ---------- */
+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 title = (p, str) => text(p, str, 60, 110, .2, { size: 40, weight: 600 });
+const keysOf = (A, k = 'a') => ({ [k + '00']: A[0][0], [k + '01']: A[0][1], [k + '10']: A[1][0], [k + '11']: A[1][1] });
+const colFill = (i, j) => COLC[j];
+const mat = (p, A, x, y, t0, { size = 50, name = 'A', fill = colFill } = {}) => { const m = ivMat(p, A, { x, y, size, name, fill, o: 0 }); show(m.g, t0, .4); return m; };
+const fl = (cell, t0) => { const e = cell.g.parentNode; tw(e, { s: 1.25 }, t0, .25); tw(e, { s: 1 }, t0 + .5, .4); };
+const ringAt = (P2, [x, y], color, into, t0, label, { dx = 20, dy = -18, anchor = 'start' } = {}) => {
+ const g = G(into, { x: P2.PX(x), y: P2.PY(y), o: 0 });
+ mk('circle', { r: 17, fill: 'none', stroke: color, 'stroke-width': 3, 'stroke-dasharray': '5 5' }, g);
+ if (label) T(g, label, { x: dx, y: dy, size: 22, fill: color, font: MATH, anchor });
+ if (t0 !== undefined) show(g, t0, .4); else put(g, { o: 1 });
+ return g;
+};
+const dotAt = (P2, [x, y], into, t0, { r = 9, color = COL.chalk } = {}) => { const d = G(into, { x: P2.PX(x), y: P2.PY(y), o: 0 }); mk('circle', { r, fill: color, stroke: COL.board, 'stroke-width': 2 }, d); show(d, t0, .3); return d; };
+// A pointer that drags a handle from a to b (stage px) over [tm, tm + dur]; shown t0 … t1. A function of time alone.
+function pointer(p, steps, t0, t1) {
+ const g = G(p, { o: 0 });
+ path(g, 'M0 0L0 30L8 22L14 36L20 33L14 20L25 20Z', { fill: COL.chalk, stroke: COL.board, 'stroke-width': 2 });
+ prog(q => { const t = t0 + q * (t1 - t0); let [x, y] = steps[0][1]; for (const [tm, to, dur = .35] of steps) { const k = io(Math.max(0, Math.min(1, (t - tm) / dur))); x += (to[0] - x) * k; y += (to[1] - y) * k; } put(g, { x: x + 4, y: y + 4 }); }, t0, t1 - t0, lin);
+ show(g, t0, .3); hide(g, t1, .3);
+ return g;
+}
+// Rings round entries of a grid2's matrix while a·d − b·c is read: a and d first, then b and c.
+const adbc = (p, g, t1, t2, t3) => [[[0, 0], [1, 1], t1, t2, COL.chalk], [[0, 1], [1, 0], t2, t3, COL.chalk]].forEach(([e1, e2, a, b, c]) => [e1, e2].forEach(([i, j]) => {
+ const r = mk('circle', { cx: g.lay.A[0][j], cy: g.lay.A[1][i] - 18, r: 36, fill: 'none', stroke: c, 'stroke-width': 3, 'stroke-dasharray': i === j ? '' : '6 5' }, p);
+ put(r, { o: 0 }); show(r, a, .3); hide(r, b, .3);
+}));
+// Inline matrix for a card.
+function matEl(rows, { size = 28 } = {}) {
+ 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: COLC[j], font: MATH, anchor: 'middle' })));
+ return svg;
+}
+const isI = T2 => Math.abs(T2[0][0] - 1) < 1e-9 && Math.abs(T2[0][1]) < 1e-9 && Math.abs(T2[1][0]) < 1e-9 && Math.abs(T2[1][1] - 1) < 1e-9;
+const mtxt = A => `[${A[0].map(num).join(' ')}; ${A[1].map(num).join(' ')}]`;
+const fracTxt = x => { const f = g2frac(x); return !f || f[1] === 1 ? num(x) : `${f[0] < 0 ? '−' : ''}${Math.abs(f[0])}/${f[1]}`; };
+const ansTxt = x => fracTxt(x).replace('−', '-'); // a box's expected answer
+const inv2 = A => { const d = A[0][0] * A[1][1] - A[0][1] * A[1][0]; return [[A[1][1] / d, -A[0][1] / d], [-A[1][0] / d, A[0][0] / d]]; };
+
+/* ---------- practice data ---------- */
+const UNDOQ = [ // named moves and their inverses
+ { A: [[3, 0], [0, 1]], why: '3 times as wide is undone by a third as wide.' },
+ { A: [[2, 0], [0, 4]], why: 'Twice as wide and 4 times as tall: undo with half as wide and a quarter as tall.' },
+ { A: [[1, -2], [0, 1]], why: 'A shear 2 to the left is undone by a shear 2 to the right.' },
+ { A: [[0, 1], [1, 0]], why: 'Swapping x and y twice puts them back: this matrix is its own inverse.' },
+ { A: [[-1, 0], [0, -1]], why: 'A half turn, done twice, is a whole turn: its own inverse.' },
+ { A: [[1, 0], [3, 1]], why: 'A shear that lifts by 3x is undone by one that lowers by 3x.' },
+];
+const FORMQ = [[[3, 2], [1, 1]], [[4, 3], [1, 1]], [[2, 1], [4, 3]], [[5, 2], [2, 1]], [[1, 2], [3, 4]]];
+const YESNO = [['y', 'Has an inverse', COL.good, 'Y'], ['n', 'No inverse', COL.bad, 'N']];
+const INVQ = [
+ { A: [[1, 2], [3, 6]], ans: ['n'], why: 'ad − bc = 6 − 6 = 0: column 2 is twice column 1.' },
+ { A: [[1, 2], [3, 5]], ans: ['y'], why: 'ad − bc = 5 − 6 = −1, not zero.' },
+ { A: [[4, 2], [2, 1]], ans: ['n'], why: 'ad − bc = 4 − 4 = 0.' },
+ { A: [[0, 0], [0, 1]], ans: ['n'], why: 'ad − bc = 0 − 0 = 0: (1, 0) is sent to (0, 0).' },
+ { A: [[0, 3], [2, 0]], ans: ['y'], why: 'ad − bc = 0 − 6 = −6, not zero.' },
+ { A: [[-1, 2], [2, -4]], ans: ['n'], why: 'ad − bc = 4 − 4 = 0: column 2 is −2 times column 1.' },
+];
+const SOLVEQ = [{ A: [[3, 1], [2, 1]], b: [4, 3] }, { A: [[2, 1], [1, 1]], b: [1, 0] }];
+const HANDQ = [
+ { pre: [[0, -1], [1, 0]], what: 'a quarter turn counterclockwise', hint: 'Turn back: a quarter turn clockwise. (1, 0) must end up at (0, −1).' },
+ { pre: [[1, 0], [0, -1]], what: 'a flip upside down', hint: 'Flip it again: (0, 1) goes down to (0, −1).' },
+ { pre: [[2, 1], [1, 1]], what: 'A = [2 1; 1 1]', hint: 'Use the formula: ad − bc = 1, so A⁻¹ = [1 −1; −1 2].' },
+ { pre: [[1, -1], [0, 1]], what: 'a shear to the left', hint: 'Shear back to the right: (0, 1) goes to (1, 1).' },
+];
+
+/* ---------- beats: [id, title, run(m, D), { ask }?] ---------- */
+const BEATS = [
+ ['intro', 'The inverse: undoing a matrix', (m, D) => {
+ const g = G(scene, { o: 0, y: 24 });
+ T(g, 'Unit 3, Chapter 26', { x: 800, y: 250, size: 28, fill: COL.dim, anchor: 'middle' });
+ T(g, 'The Inverse: Undoing a Matrix', { x: 800, y: 360, size: 80, weight: 600, anchor: 'middle' });
+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);
+ const r = text(scene, 'the matrix that moves the plane back', 800, 450, m('sub'), { size: 36, fill: COL.dim, anchor: 'middle' });
+ const sm = G(scene, { o: 0 });
+ const k = grid2(sm, { A: I2, pre: I2, mat: null, shape: true, units: false, plane: { cx: 800, cy: 690, u: 30, x0: -5, x1: 5, y0: -3, y1: 3, labels: false } });
+ put(k.parts.cols, { o: 0 });
+ show(sm, m('sub') + .5, .6);
+ k.to({ p01: 1 }, m('move') + .3, 1.4); k.to({ a01: -1 }, m('move') + 2.6, 1.4);
+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(sm, D - .9, .8);
+ }],
+
+ ['undo', 'Undo a stretch', (m) => {
+ const p = panel(0);
+ title(p, 'Which matrix moves it back?');
+ const g = S.g = grid2(p, { A: I2, pre: I2, mat: null, shape: true, plane: ZOOM });
+ put(g.parts.cols, { o: 0 });
+ const Am = mat(p, [[2, 0], [0, 1]], 90, 290, m('A'));
+ g.to({ p00: 2 }, m('go') + .2, 2.2);
+ text(p, 'A: twice as wide', 90, 520, m('go') + .8, { size: 30, weight: 600 });
+ text(p, 'which matrix moves it back?', 90, 580, m('ask') + .3, { size: 30, fill: COL.dim });
+ const Bm = mat(p, [[.5, 0], [0, 1]], 430, 290, m('half') + 2.4, { name: INV });
+ g.to({ a00: .5 }, m('back') + .6, 2.6);
+ text(p, 'half as wide: every line back home', 90, 640, m('back') + 3, { size: 30, weight: 600 });
+ say(p, [...INV, ' “A inverse”'], 90, 720, m('name') + 1.5, { size: 40 });
+ say(p, ['3 · ', F(1, 3), ' = 1: ', F(1, 3), ' undoes 3'], 90, 815, m('num') + .4, { size: 34, fill: COL.dim });
+ fl(Am.cells[0][0], m('half') + 1); fl(Bm.cells[0][0], m('half') + 3);
+ pulse(Bm.g, m('name') + 3.5, 1.2);
+ // "A inverse undoes A": once more, from home (pre and A reset together, so the plane does not jump)
+ g.to({ p00: 1, a00: 1 }, m('num') + .3, .05);
+ g.to({ p00: 2 }, m('num') + 4.6, 1.2); g.to({ a00: .5 }, m('num') + 6.8, 1.2);
+ fl(Am.cells[0][0], m('num') + 4.6); fl(Bm.cells[0][0], m('num') + 6.8);
+ }],
+
+ ['idef', 'A⁻¹ A = I', (m) => {
+ const p = panel(0);
+ title(p, 'A, then A⁻¹: every point comes home');
+ const g = S.g = grid2(p, { A: I2, pre: I2, mat: null, shape: true, units: false, pts: [{ p: [3, 1] }] });
+ put(g.parts.cols, { o: 0 }); put(g.parts.pts, { o: 0 }); show(g.parts.pts, m('pt'), .3);
+ const { PX, PY } = g.P;
+ const lab = (s, x, y, t0, t1) => { const e = T(p, s, { x: PX(x), y: PY(y) - 22, size: 24, fill: COL.chalk, font: MATH, anchor: 'middle', o: 0 }); show(e, t0, .3); if (t1) hide(e, t1, .3); return e; };
+ lab('(3, 1)', 3, 1, m('pt') + .3, m('a1') + .2);
+ g.to({ p00: 2 }, m('a1') + .3, 1.6);
+ lab('(6, 1)', 5.6, 1, m('a1') + 1.9, m('a2') + .2);
+ g.to({ a00: .5 }, m('a2') + .3, 1.6);
+ lab('(3, 1) again', 3, 1, m('a2') + 1.9);
+ say(p, ['first A, then ', ...INV, ': ', ...INV, 'A'], 90, 210, m('mult') + .2, { size: 34 });
+ text(p, 'A acts first, so it stands on the right, next to x', 90, 260, m('mult') + 3, { size: 24, fill: COL.dim });
+ const pr = ivProd(p, [[.5, 0], [0, 1]], [[2, 0], [0, 1]], { at: [90, 380], size: 42, names: [INV, 'A', 'I'], work: [90, 560], o: 0 });
+ show(pr.g, m('mult') + .3, .5);
+ pr.entry(0, 0, m('rc'), m('rc2') - m('rc') - .2); pr.entry(0, 1, m('rc2'), m('rc3') - m('rc2') - .2);
+ pr.entry(1, 0, m('rc3'), m('rc4') - m('rc3') - .1); pr.entry(1, 1, m('rc4'), 1.4);
+ text(p, 'I, the identity: every point stays where it is', 90, 640, m('I') + .3, { size: 28, weight: 600 });
+ pulse(pr.C.g, m('I') + 1.5, 1.2);
+ const still = G(p, {}); [[-3, 2], [1, -2], [-2, -3], [4, -1], [-4, -1]].forEach((q, k) => ringAt(g.P, q, COL.chalk, still, m('I') + 2.5 + k * .6)); hide(still, m('other') - .2, .3);
+ say(p, ['other order: A', ...INV, ' = I too'], 90, 720, m('other') + 3.4, { size: 34 });
+ // the other order on the plane: squeeze first, then stretch (pre and A swap roles; the plane does not jump)
+ g.to({ a00: 1, p00: 1 }, m('other') + .2, .05);
+ g.to({ p00: .5 }, m('other') + .6, 1.4); g.to({ a00: 2 }, m('other') + 2.3, 1.4);
+ const sq = text(p, 'squeeze …', 1160, 820, m('other') + .6, { size: 26, fill: COL.dim, anchor: 'middle' }); hide(sq, m('other') + 2.2, .2);
+ text(p, '… then stretch: home', 1160, 820, m('other') + 2.3, { size: 26, fill: COL.dim, anchor: 'middle' });
+ }],
+
+ ['turn', 'Undo a turn', (m) => {
+ const p = panel(0);
+ title(p, 'Undo a turn: turn back');
+ const g = S.g = grid2(p, { A: I2, pre: I2, mat: null, shape: true, plane: ZOOM });
+ put(g.parts.cols, { o: 0 });
+ mat(p, [[0, -1], [1, 0]], 90, 260, m('A'));
+ g.turn(0, 90, m('go'), 1.6, io, 'p');
+ text(p, 'a quarter turn, counterclockwise', 90, 450, m('A') + 3, { size: 28, fill: COL.dim });
+ text(p, 'undo: turn back, clockwise', 90, 500, m('ask') + 1, { size: 28, weight: 600 });
+ const Bt = mat(p, [[0, 1], [-1, 0]], 420, 260, m('inv') + .3, { name: INV });
+ [[0, 0], [0, 1], [1, 0], [1, 1]].forEach(([i, j], k) => fl(Bt.cells[i][j], m('inv') + 3.2 + k * 1.1));
+ g.turn(0, -90, m('back') + .2, 1.8);
+ const pr = ivProd(p, [[0, 1], [-1, 0]], [[0, -1], [1, 0]], { at: [90, 620], size: 40, names: [INV, 'A', 'I'], work: [90, 820], o: 0 });
+ show(pr.g, m('check'), .5);
+ pr.entry(0, 0, m('check') + 1.6, m('c2') - m('check') - 1.8); pr.entry(0, 1, m('c2'), m('c3') - m('c2') - .2);
+ pr.entry(1, 0, m('c3'), m('c4') - m('c3') - .2); pr.entry(1, 1, m('c4'), 1.6);
+ }],
+
+ ['shear', 'Undo a shear, undo a flip', (m) => {
+ const p = panel(0);
+ title(p, 'Undo a shear: slide back');
+ const g = S.g = grid2(p, { A: I2, pre: I2, mat: null, shape: true, plane: ZOOM });
+ put(g.parts.cols, { o: 0 });
+ const a = mat(p, [[1, 1], [0, 1]], 90, 260, m('A'));
+ g.to({ p01: 1 }, m('go'), 2);
+ const b = mat(p, [[1, -1], [0, 1]], 420, 260, m('inv') + .3, { name: INV });
+ const sl = G(p, {});
+ [1, 2, 3].forEach((k, i) => { g.P.arrow(k + .6, k, .6, k, COL.chalk, m('inv') + 1.5 + i * .6, { into: sl }); }); // each line slides back by its height
+ text(sl, 'back by 1, 2, 3', 1160, 830, m('inv') + 3.4, { size: 24, fill: COL.dim, anchor: 'middle' });
+ hide(sl, m('back') + .6, .4);
+ g.to({ a01: -1 }, m('back') + .1, 2);
+ const t1 = text(p, 'slide right, then slide left', 90, 480, m('minus') + 1.2, { size: 28, weight: 600 });
+ const r1 = mk('circle', { cx: a.cx(1), cy: a.ry(0) - 16, r: 34, fill: 'none', stroke: COL.chalk, 'stroke-width': 3 }, p); put(r1, { o: 0 }); show(r1, m('minus') + .4, .3);
+ const r2 = mk('circle', { cx: b.cx(1), cy: b.ry(0) - 16, r: 38, fill: 'none', stroke: COL.chalk, 'stroke-width': 3 }, p); put(r2, { o: 0 }); show(r2, m('minus') + .8, .3);
+ [a.g, b.g, t1, r1, r2].forEach(e => hide(e, m('flip') - .1, .4));
+ // reset to home without a jump (pre and A cancel throughout), then the flip
+ g.to({ p01: 0, a01: 0 }, m('flip') - .2, .05);
+ mat(p, [[-1, 0], [0, 1]], 90, 600, m('flip') + .2);
+ text(p, 'a flip', 90, 520, m('flip') + .2, { size: 30, weight: 600 });
+ g.to({ p00: -1 }, m('flip') + .6, 1.8);
+ mat(p, [[-1, 0], [0, 1]], 420, 600, m('flip2') + .2, { name: INV });
+ g.to({ a00: -1 }, m('flip2') + .6, 1.8);
+ say(p, [...INV, ' = A: its own inverse'], 90, 830, m('flip2') + 2.6, { size: 32 });
+ }],
+
+ ['q1', 'Quick check', () => {
+ const p = panel(0);
+ title(p, 'Quick check');
+ mat(p, [[1, 0], [2, 1]], 90, 250, .3, { size: 44 });
+ text(p, 'A sheared the plane up', 90, 370, .4, { size: 26, fill: COL.dim });
+ const g = S.g = grid2(p, { A: I2, pre: [[1, 0], [2, 1]], mat: [420, 250], size: 44, shape: true, name: 'B' });
+ g.labels(['col 1', 'col 2']);
+ }, { ask: done => quiz(LEFT, [{
+ id: 'c-home', prompt: ['Drag the tips of ', $m('B'), ' until the whole grid is back home, on the faint one.'],
+ build: g2Task(S.g, () => isI(S.g.total()), 'B = [1 0; −2 1]: it lowers every point by 2 times its x, which undoes the upward shear. B = A⁻¹.',
+ 'A lifted every point by 2 times its x: (1, 0) went up to (1, 2). To bring it back, B must send (1, 0) down to (1, −2), and keep (0, 1) where it is.',
+ () => S.g.set(keysOf([[1, 0], [-2, 1]])), ['A', 'cols']),
+ }], done) }],
+
+ ['formula', 'A formula for 2 × 2', (m) => {
+ const p = panel(0);
+ title(p, 'The inverse of any 2 × 2 matrix');
+ const s = 56, gg = G(p, {});
+ say(gg, ['A ='], 90, 290, m('gen') - .4, { size: s });
+ const br = (x0, y0, w, t0) => { const e = path(gg, `M${x0 + 14} ${y0 - s}H${x0}V${y0 + 80 + s * .45}H${x0 + 14}M${x0 + w - 14} ${y0 - s}H${x0 + w}V${y0 + 80 + s * .45}H${x0 + w - 14}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' }, { o: 0 }); show(e, t0); return e; };
+ br(200, 260, 230, m('gen') - .4);
+ const L = { a: [260, 260, COLC[0]], b: [370, 260, COLC[1]], c: [260, 340, COLC[0]], d: [370, 340, COLC[1]] };
+ const letter = (k, t0) => { const g = G(gg, { x: L[k][0], y: L[k][1], o: 0 }); M(g, [k], { size: s, fill: L[k][2], anchor: 'middle' }); show(g, t0, .3); return g; };
+ ['a', 'b', 'c', 'd'].forEach((k, i) => letter(k, m('gen') + .3 + i * .5));
+ // the inverse: a and d swap (copies fly), b and c move across with a minus sign, then the fraction
+ say(gg, [...INV, ' ='], 90, 560, m('swap') - .2, { size: s });
+ br(470, 530, 300, m('swap') - .2);
+ const N = { a: [710, 610], d: [550, 530], b: [710, 530], c: [550, 610] };
+ const fly = (k, t0) => { const g = letter(k, t0); tw(g, { x: N[k][0], y: N[k][1] }, t0 + .2, 1.4); return g; };
+ fly('d', m('swap') + .3); fly('a', m('swap') + .7);
+ fly('b', m('sign') + .3); fly('c', m('sign') + .6);
+ say(gg, ['−'], 662, 530, m('sign') + 1.6, { size: s, fill: COLC[1] }); say(gg, ['−'], 502, 610, m('sign') + 1.9, { size: s, fill: COLC[0] });
+ const fr = say(gg, [F('1', 'ad − bc')], 330, 590, m('div') + .4, { size: s * .8 });
+ // the recipe on the right, one step at a time
+ const step = (n, words, t0) => { const g = G(p, { o: 0, x: 20 }); mk('circle', { cx: 900, cy: -12, r: 24, fill: COL.chalk }, g); T(g, String(n), { x: 900, y: -2, size: 28, fill: COL.board, weight: 700, anchor: 'middle' }); M(g, words, { x: 945, size: 34, anchor: 'start' }); tw(g, { o: 1, x: 0 }, t0, .5); put(g, { y: 280 + n * 100 }); return g; };
+ const s1 = step(1, ['swap a and d'], m('swap') + .2), s2 = step(2, ['minus signs on b and c'], m('sign') + .2), s3 = step(3, ['divide by ad − bc'], m('div') + .2);
+ const hl = mk('rect', { x: 860, y: 340, width: 600, height: 64, rx: 14, fill: COL.chalk }, p); put(hl, { o: 0 }); // the recipe read once more, step by step
+ tw(hl, { o: .12 }, m('all'), .3); [1, 2].forEach(k => tw(hl, { a_y: 340 + k * 100 }, m('all') + k * 1.1, .4)); tw(hl, { o: 0 }, m('all') + 3.6, .4);
+ [s1, s2, s3].forEach((e, i) => pulse(e, m('all') + .2 + i * 1, 1));
+ pulse(fr, m('all') + 2.2, 1);
+ }],
+
+ ['fex1', 'Example: the formula', (m) => {
+ const p = panel(0);
+ title(p, 'Use it: A = [2 1; 1 1]');
+ text(p, 'swap a and d · minus signs on b and c · divide by ad − bc', 60, 165, .3, { size: 24, fill: COL.dim });
+ const g = S.g = grid2(p, { A: [[2, 1], [1, 1]], mat: [90, 290], size: 50, shape: true, t0: m('A') - .5 });
+ g.labels(['col 1', 'col 2']);
+ const iv = g.inverse({ at: [90, 475], size: 40 });
+ ['det', 'lhs', 'scale', 'adj', 'eq', 'res'].forEach(k => put(iv[k], { o: 0 }));
+ show(iv.det, m('det') + .3, .4); adbc(p, g, m('det') + .8, m('det') + 3.4, m('sw') - .3);
+ show(iv.lhs, m('sw'), .3); show(iv.adj, m('sw'), .3);
+ [1, 2].forEach(k => { put(iv.adjCells[k].g, { o: 0 }); show(iv.adjCells[k].g, m('sg') + .3 + (k - 1) * .5, .3); });
+ [0, 3].forEach(k => pulse(iv.adjCells[k].g, m('sw') + .5, 1.2));
+ show(iv.scale, m('res'), .3);
+ [0, 1, 2, 3].forEach(k => pulse(iv.resCells[k].g, m('res') + 3.6 + k * 1.1, 1)); show(iv.eq, m('res') + 1, .3); show(iv.res, m('res') + 1.4, .4);
+ hide(iv.root, m('check') - .2, .4);
+ const pr = ivProd(p, [[1, -1], [-1, 2]], [[2, 1], [1, 1]], { at: [90, 490], size: 40, names: [INV, 'A', 'I'], work: [90, 660], o: 0 });
+ show(pr.g, m('check'), .5);
+ pr.entry(0, 0, m('check') + 1.2, m('c2') - m('check') - 1.4); pr.entry(0, 1, m('c2'), m('c3') - m('c2') - .2);
+ pr.entry(1, 0, m('c3'), m('c4') - m('c3') - .2); pr.entry(1, 1, m('c4'), 2);
+ hide(g.M, m('grid') + .1, .3);
+ g.to(keysOf(I2), m('grid') + 2.2, 2.4);
+ text(p, 'A⁻¹ brings the plane home', 90, 770, m('grid') + 2.2, { size: 30, weight: 600 });
+ }],
+
+ ['fex2', 'Example with fractions', (m) => {
+ const p = panel(0);
+ title(p, 'A second one: A = [3 1; 4 2]');
+ text(p, 'swap a and d · minus signs on b and c · divide by ad − bc', 60, 165, .3, { size: 24, fill: COL.dim });
+ const g = S.g = grid2(p, { A: [[3, 1], [4, 2]], mat: [90, 290], size: 50, shape: true, t0: m('A') - .5 });
+ g.labels(['col 1', 'col 2']);
+ const iv = g.inverse({ at: [90, 475], size: 40 });
+ ['det', 'lhs', 'scale', 'adj', 'eq', 'res'].forEach(k => put(iv[k], { o: 0 }));
+ show(iv.det, m('det') + .3, .4); adbc(p, g, m('det') + .8, m('det') + 3.6, m('sw') - .3);
+ show(iv.lhs, m('sw'), .3); show(iv.adj, m('sw'), .3);
+ [1, 2].forEach(k => { put(iv.adjCells[k].g, { o: 0 }); show(iv.adjCells[k].g, m('sg') + .3 + (k - 1) * .5, .3); });
+ [0, 3].forEach(k => pulse(iv.adjCells[k].g, m('sw') + .5, 1.2));
+ show(iv.scale, m('div') + .3, .3); show(iv.eq, m('res'), .3); show(iv.res, m('res') + .3, .4);
+ hide(iv.root, m('check') - .2, .4);
+ const pr = ivProd(p, [[3, 1], [4, 2]], [[1, -.5], [-2, 1.5]], { at: [90, 490], size: 40, names: ['A', INV, 'I'], work: [90, 680], o: 0 });
+ show(pr.g, m('check'), .5);
+ pr.entry(0, 0, m('check') + 2.4, m('c2') - m('check') - 2.6); pr.entry(0, 1, m('c2'), m('c3') - m('c2') - .2);
+ pr.entry(1, 0, m('c3'), m('c4') - m('c3') - .2); pr.entry(1, 1, m('c4'), m('I') - m('c4') + 1);
+ hide(g.M, m('home') - .1, .3);
+ g.to(keysOf(I2), m('home') + .3, 2.4);
+ text(p, 'A⁻¹ brings the plane home', 90, 800, m('home') + .3, { size: 30, weight: 600 });
+ }],
+
+ ['why', 'Why the formula works', (m) => {
+ const p = panel(0);
+ title(p, 'Why divide by ad − bc?');
+ const L = [['d', ['−', 'b']], [['−', 'c'], 'a']], R = [['a', 'b'], ['c', 'd']];
+ const fill = (i, j) => COLC[j];
+ const C = [['ad − bc', '0'], ['0', 'ad − bc']];
+ const works = [
+ [['d·a + (−b)·c = ad − bc'], ['d·b + (−b)·d = 0']],
+ [['(−c)·a + a·c = 0'], ['(−c)·b + a·d = ad − bc']],
+ ];
+ const pr = ivProd(p, L, R, { at: [150, 320], size: 48, names: ['swapped', 'A', ''], C, works: (i, j) => works[i][j], work: [150, 560], workSize: 38, cwC: 48 * 3.4, o: 0 });
+ show(pr.g, m('mul'), .5);
+ pr.entry(0, 0, m('e1'), m('e2') - m('e1') - .2); pr.entry(0, 1, m('e2'), m('e3') - m('e2') - .2);
+ pr.entry(1, 0, m('e3'), m('e4') - m('e3') - .2); pr.entry(1, 1, m('e4'), m('out') - m('e4') - .2);
+ say(p, ['= (ad − bc) · I'], 150, 680, m('out') + .3, { size: 44 });
+ say(p, ['divide by ad − bc: ', F('1', 'ad − bc'), ' · swapped · A = I'], 150, 800, m('div') + .4, { size: 40 });
+ }],
+
+ ['live', 'Change A, watch A⁻¹', (m) => {
+ const p = panel(0);
+ title(p, 'Change A, and A⁻¹ follows');
+ const g = S.g = grid2(p, { A: I2, mat: [90, 270], size: 50, shape: true });
+ g.labels(['col 1', 'col 2']);
+ const iv = g.inverse({ at: [90, 440], size: 40 });
+ put(iv.root, { o: 0 }); show(iv.root, m('set') + .5, .5);
+ g.to({ a00: 2, a01: 1, a10: 1, a11: 3 }, m('set') + .6, 2.6); // A forms, and its inverse follows on the way
+ adbc(p, g, m('set') + 5.6, m('set') + 7.6, m('set') + 9.4);
+ const fifth = mk('rect', { x: iv.xs.xR - 6, y: iv.mid - 75, width: 230, height: 140, rx: 14, fill: COL.chalk }, p); put(fifth, { o: 0 }); tw(fifth, { o: .1 }, m('set') + 10, .4); tw(fifth, { o: 0 }, m('b'), .4);
+ [0, 1].forEach(j => { tw(g.cols[j], { 'a_stroke-width': 10 }, m('zero') + 3 + j * .6, .3); tw(g.cols[j], { 'a_stroke-width': 5 }, m('zero') + 4.4, .5); });
+ pulse(iv.none, m('zero') + 6, 1.2);
+ const sx = g.lay.A[0][1], sy = 250;
+ const steps = [[0, [sx + 60, sy + 70]], [m('b') + 1.4, [sx, sy]]];
+ [['s4', 2], ['s3', 3], ['s2', 4], ['s1', 5], ['zero', 6]].forEach(([k, b]) => { g.to({ a01: b }, m(k), .35); steps.push([m(k), [sx + (b - 1) * 22, sy]]); });
+ pointer(p, steps, m('b') + .8, m('zero') + 1.4);
+ text(p, 'thinner plane, bigger undo', 90, 760, m('big') + .5, { size: 28, weight: 600 });
+ text(p, 'flat: no inverse', 90, 820, m('zero') + 1, { size: 30, weight: 600, fill: COL.bad });
+ }],
+
+ ['q2', 'Quick check', () => {
+ const p = panel(0);
+ title(p, 'Quick check');
+ const g = S.g = grid2(p, { A: [[1, 3], [2, 7]], mat: [90, 260], size: 50, shape: true, plane: { u: 40, x0: -8, x1: 8, y0: -8, y1: 8 } });
+ g.labels(['col 1', 'col 2']);
+ }, { ask: done => quiz(LEFT, [{
+ id: 'c-lecture', prompt: ['Find the inverse of ', $m('A'), ' with the formula.'],
+ build: blanks([
+ { parts: ['ad − bc = ', { box: '1' }], why: '1 · 7 − 3 · 2 = 7 − 6 = 1.', hint: 'a·d − b·c: 1 times 7, minus 3 times 2.' },
+ { parts: ['first row of A⁻¹: (', { box: '7' }, ', ', { box: '-3' }, ')'], why: 'Swap 1 and 7; −3 for b.', hint: 'Swap a and d: 7 goes top left. Then b = 3 gets a minus sign. Divide by 1.' },
+ { parts: ['second row of A⁻¹: (', { box: '-2' }, ', ', { box: '1' }, ')'], why: 'A⁻¹ = [7 −3; −2 1]. Check: 1·7 + 3·(−2) = 1.', hint: 'c = 2 gets a minus sign; a = 1 goes bottom right.' },
+ ]),
+ }], done) }],
+
+ ['collapse', 'When ad − bc = 0', (m) => {
+ const p = panel(0);
+ title(p, 'ad − bc = 0: the plane goes flat');
+ const g = S.g = grid2(p, { A: I2, mat: null, shape: true, lost: true });
+ g.labels(['col 1', 'col 2']);
+ put(g.parts.lost, { o: 0 });
+ mat(p, [[1, 2], [2, 4]], 90, 260, m('A'));
+ say(p, ['ad − bc = 1·4 − 2·2 = 0'], 90, 470, m('det') + .3, { size: 36 });
+ g.to(keysOf([[1, 2], [2, 4]]), m('go') + .2, 2.4);
+ const { PX, PY } = g.P;
+ const d0 = dotAt(g.P, [0, 0], p, m('pts') + .3), d1 = dotAt(g.P, [2, -1], p, m('pts') + 1.2);
+ const l1 = T(p, '(2, −1)', { x: PX(2) + 14, y: PY(-1) + 30, size: 22, fill: COL.chalk, font: MATH, o: 0 }); show(l1, m('pts') + 1.2, .3); hide(l1, m('land') + 2.4, .3);
+ tw(d1, { x: PX(0), y: PY(0) }, m('land') + 2.6, 1.4); pulse(d0, m('land') + 6, 1.2);
+ const same = text(p, 'one spot, two points', PX(0) + 24, PY(0) + 44, m('land') + 4.4, { size: 24, fill: COL.chalk }); hide(same, m('undo') + 2, .3);
+ say(p, ['(2, −1) → (2 − 2, 4 − 4) = (0, 0)'], 90, 540, m('land') + .4, { size: 30 });
+ // the undo cannot choose: two dashed arrows back from (0, 0)
+ const q = G(p, {});
+ draw(path(q, `M${PX(0)} ${PY(0)}Q${PX(-1.2)} ${PY(1.2)} ${PX(-.2)} ${PY(.3)}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' }, { d: 0 }), m('undo') + 5, .8);
+ draw(path(q, `M${PX(0)} ${PY(0)}Q${PX(1.6)} ${PY(1.4)} ${PX(2)} ${PY(-.7)}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' }, { d: 0 }), m('undo') + 6.4, .8);
+ const qm = T(q, '?', { x: PX(-1.3), y: PY(1.6), size: 44, fill: COL.chalk, weight: 700, o: 0 }); show(qm, m('undo') + 2.5, .3);
+ const ghost = dotAt(g.P, [2, -1], q, m('undo') + 6.4, { r: 8, color: COL.dim });
+ hide(q, m('line') + .2, .4);
+ text(p, 'back to (0, 0) or to (2, −1)?', 90, 610, m('undo') + 2.5, { size: 28, weight: 600 });
+ show(g.parts.lost, m('line') + .2, .5);
+ const dots = G(p, { o: 0 });
+ [-4, -2, 2, 4].forEach(a => { const d = G(dots, { x: PX(a), y: PY(-a / 2) }); mk('circle', { r: 7, fill: COL.bad, stroke: COL.board, 'stroke-width': 2 }, d); tw(d, { x: PX(0), y: PY(0) }, m('line') + 1.6, 1.6); });
+ show(dots, m('line') + .6, .3); hide(dots, m('never'), .3);
+ text(p, 'the red line all lands on (0, 0)', 90, 670, m('line') + .8, { size: 28, fill: COL.bad, weight: 600 });
+ text(p, 'flat for good: no matrix undoes A', 90, 750, m('never') + .4, { size: 32, weight: 600 });
+ text(p, 'more in chapter 28', 90, 805, m('never') + 6, { size: 26, fill: COL.dim });
+ }],
+
+ ['q3', 'Quick check', () => {
+ const p = panel(0);
+ title(p, 'Quick check');
+ text(p, 'ad − bc = 0 → flat plane, no inverse', 60, 170, .3, { size: 28, fill: COL.dim });
+ }, { ask: done => quiz(TOPL, [{
+ id: 'c-which', prompt: ['Which of these have an inverse? Work out ad − bc.'],
+ build: grid([
+ { parts: [matEl([[2, 4], [1, 2]], { size: 24 })], ans: ['n'], why: '4 − 4 = 0: column 2 is twice column 1.' },
+ { parts: [matEl([[3, 1], [1, 2]], { size: 24 })], ans: ['y'], why: '6 − 1 = 5.' },
+ { parts: [matEl([[0, 1], [1, 0]], { size: 24 })], ans: ['y'], why: '0 − 1 = −1: a minus is fine, only 0 is not.' },
+ { parts: [matEl([[2, 6], [1, 3]], { size: 24 })], ans: ['n'], why: '6 − 6 = 0.' },
+ ], YESNO, { multi: false, text: true }),
+ }], done) }],
+
+ ['solve', 'Solving with the inverse', (m) => {
+ const p = panel(0);
+ title(p, 'Ax = b, so x = A⁻¹b');
+ const s = 38;
+ say(p, ['A x = b'], 90, 200, .4, { size: s });
+ say(p, [...INV, ' A x = ', ...INV, ' b'], 90, 260, m('eq') + .4, { size: s });
+ say(p, ['x = ', ...INV, ' b'], 90, 320, m('x') + 3, { size: s, fill: COL.chalk });
+ text(p, 'A⁻¹A = I, and I x = x', 400, 260, m('x') + .3, { size: 24, fill: COL.dim });
+ const g = S.g = grid2(p, { A: [[2, 1], [1, 1]], x: [0, 0], mat: [90, 460], size: 44, shape: false, units: false, brackets: true, t0: m('ex') - .4 });
+ g.labels(['col 1', 'col 2']);
+ g.combo.forEach(e => put(e, { o: 0 }));
+ put(g.parts.x, { o: 0 }); show(g.parts.x, m('x2') - .2, .4); // x and Ax join the plane when x is found
+ const { PX, PY } = g.P;
+ const bl = ringAt(g.P, [5, 3], COL.task, p, m('ex') + 1.5, 'b = (5, 3)', { dx: -20, dy: 34, anchor: 'end' });
+ hide(bl.lastChild, m('x2') + .2, .3);
+ const ml = say(p, [...INV, 'b = [1 −1; −1 2]·(5, 3)'], 90, 660, m('mul') + .4, { size: 30 });
+ say(p, ['= (5 − 3, −5 + 6) = (2, 1)'], 90 + ml._w + 12, 660, m('mul') + 5.4, { size: 30 });
+ g.to({ x0: 2, x1: 1 }, m('x2') + .2, 1.6);
+ text(p, 'check: A·(2, 1) = (4 + 1, 2 + 1) = (5, 3) = b', 90, 720, m('chk') + .3, { size: 28, fill: COL.good, weight: 600 });
+ pulse(g.axDot, m('chk') + 5.5, 1.2); pulse(g.xRing, m('chk') + 2, 1.2);
+ show(g.combo[0], m('chk') + 1.2, .4); show(g.combo[1], m('chk') + 3.4, .4); hide(g.combo[0], m('pic'), .3); hide(g.combo[1], m('pic'), .3);
+ const back = G(p, { o: 0 });
+ path(back, `M${PX(5) - 10} ${PY(3) + 6}Q${PX(3.2)} ${PY(3.8)} ${PX(2.2)} ${PY(1.25)}`, { stroke: COL.chalk, 'stroke-width': 3, 'stroke-dasharray': '8 7', fill: 'none' });
+ M(back, INV, { x: PX(3.1), y: PY(3.75), size: 28, anchor: 'middle' });
+ show(back, m('pic') + 2, .5);
+ text(p, 'one matrix answers every b', 90, 790, m('any') + .3, { size: 28, weight: 600 });
+ }],
+
+ ['wrap', 'Summary', (m) => {
+ const p = panel(0);
+ [['A⁻¹ undoes A: it moves the plane back.', 'w1'], ['A⁻¹A = I and AA⁻¹ = I.', 'w2'],
+ ['2 × 2: swap a and d, minus signs on b and c, divide by ad − bc.', 'w3'], ['ad − bc = 0: the plane goes flat, no inverse.', 'w4']].forEach(([str, mark], i) => {
+ const g = G(p, { x: -16, y: 150 + i * 95, o: 0 });
+ mk('circle', { cx: 150, cy: -12, r: 26, fill: COL.chalk }, 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);
+ });
+ const sm = G(p, { o: 0 });
+ const k = grid2(sm, { A: I2, pre: I2, mat: null, shape: true, units: false, plane: { cx: 1180, cy: 680, u: 30, x0: -5, x1: 5, y0: -5, y1: 5, labels: false } });
+ put(k.parts.cols, { o: 0 });
+ show(sm, .3, .6);
+ k.to({ p01: 1 }, m('w1') + .4, 1.2); k.to({ a01: -1 }, m('w1') + 2, 1.2);
+ const home = { p00: 1, p01: 0, p10: 0, p11: 1, a00: 1, a01: 0, a10: 0, a11: 1 }; // pre and A back to I together: the plane does not jump
+ k.to(home, m('w2') - .3, .05);
+ k.turn(0, 90, m('w2'), 1, io, 'p'); k.turn(0, -90, m('w2') + 1.4, 1);
+ k.to(home, m('w3') - .3, .05);
+ k.to({ p00: 2, p01: 1, p10: 1 }, m('w3') + 1, 1.4); k.to({ a01: -1, a10: -1, a11: 2 }, m('w3') + 4, 1.6);
+ k.to(home, m('w4') - .3, .05);
+ k.to({ p01: 2, p10: 2, p11: 4 }, m('w4') + .3, 1.6);
+ }],
+
+ ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, UNDOQ.map((q, k) => {
+ const B = inv2(q.A);
+ return {
+ id: `p-undo${k + 1}`, prompt: ['Find the matrix that undoes ', $m('A'), ' = ', matEl(q.A), '.'],
+ build: blanks([
+ { parts: [$m('A', E('−1')), ' first row: (', { box: ansTxt(B[0][0]) }, ', ', { box: ansTxt(B[0][1]) }, ')'], why: q.why, hint: 'Ask what A does to (1, 0) and (0, 1), and do the opposite. Or use the formula.' },
+ { parts: [$m('A', E('−1')), ' second row: (', { box: ansTxt(B[1][0]) }, ', ', { box: ansTxt(B[1][1]) }, ')'], why: `A⁻¹ = [${B[0].map(fracTxt).join(' ')}; ${B[1].map(fracTxt).join(' ')}].`, hint: 'Check by multiplying: A⁻¹ times A must give I.' },
+ ]),
+ };
+ }), done, 'Chapter practice · set 1 of 4') }],
+ ['final2', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, FORMQ.map((A, k) => {
+ const d = A[0][0] * A[1][1] - A[0][1] * A[1][0], B = inv2(A);
+ return {
+ id: `p-form${k + 1}`, prompt: ['Use the formula on ', $m('A'), ' = ', matEl(A), '.'],
+ build: blanks([
+ { parts: ['ad − bc = ', { box: String(d) }], why: `${A[0][0]}·${A[1][1]} − ${A[0][1]}·${A[1][0]} = ${num(d)}.`, hint: 'a times d, minus b times c.' },
+ { parts: [$m('A', E('−1')), ' first row: (', { box: ansTxt(B[0][0]) }, ', ', { box: ansTxt(B[0][1]) }, ')'], why: `d and −b, divided by ${num(d)}.`, hint: `Top row of the swapped matrix: (${num(A[1][1])}, ${num(-A[0][1])}). Divide each by ${num(d)}.` },
+ { parts: [$m('A', E('−1')), ' second row: (', { box: ansTxt(B[1][0]) }, ', ', { box: ansTxt(B[1][1]) }, ')'], why: `A⁻¹ = [${B[0].map(fracTxt).join(' ')}; ${B[1].map(fracTxt).join(' ')}].`, hint: `Bottom row of the swapped matrix: (${num(-A[1][0])}, ${num(A[0][0])}). Divide each by ${num(d)}.` },
+ ]),
+ };
+ }), done, 'Chapter practice · set 2 of 4') }],
+ ['final3', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
+ id: 'p-which', prompt: ['Which matrices have an inverse?'],
+ build: grid(INVQ.map(q => ({ parts: [matEl(q.A, { size: 24 })], ans: q.ans, why: q.why })), YESNO, { multi: false, text: true }),
+ }, ...SOLVEQ.map((q, k) => {
+ const B = inv2(q.A), x = [B[0][0] * q.b[0] + B[0][1] * q.b[1], B[1][0] * q.b[0] + B[1][1] * q.b[1]];
+ return {
+ id: `p-solve${k + 1}`, prompt: ['Solve ', $m('A x = b'), ' with ', $m('A'), ' = ', matEl(q.A), ' and ', $m('b'), ` = (${q.b.map(num).join(', ')}): first find `, $m('A', E('−1')), ', then ', $m('x = A', E('−1'), 'b'), '.'],
+ build: blanks([
+ { parts: [$m('A', E('−1')), ' = [ (', { box: String(B[0][0]) }, ', ', { box: String(B[0][1]) }, '); (', { box: String(B[1][0]) }, ', ', { box: String(B[1][1]) }, ') ]'], why: `ad − bc = 1, so A⁻¹ is the swapped matrix: [${B[0].map(num).join(' ')}; ${B[1].map(num).join(' ')}].`, hint: 'ad − bc is 1 here, so A⁻¹ is just the swapped matrix: swap a and d, minus signs on b and c.' },
+ { parts: ['x = (', { box: String(x[0]) }, ', ', { box: String(x[1]) }, ')'], why: `Check: A·(${x.map(num).join(', ')}) = (${q.b.map(num).join(', ')}).`, hint: `Row times column: (${B[0].map(num).join(', ')})·(${q.b.map(num).join(', ')}) for the first number.` },
+ ]),
+ };
+ })], done, 'Chapter practice · set 3 of 4') }],
+ ['final4', 'Chapter practice', () => {
+ const p = panel(0);
+ title(p, 'Bring the plane home');
+ S.g = grid2(p, { A: I2, pre: HANDQ[0].pre, mat: [90, 260], size: 46, shape: true, name: 'B' });
+ S.g.labels(['col 1', 'col 2']);
+ }, { ask: done => quiz(LEFT, HANDQ.map((q, k) => ({
+ id: `p-home${k + 1}`, prompt: ['The plane was moved by ', q.what.startsWith('A =') ? matEl(q.pre) : q.what, '. Drag the tips of ', $m('B'), ' until the grid is home.'],
+ build: (body, api) => { S.g.set({ ...keysOf(I2), ...keysOf(q.pre, 'p') }); return g2Task(S.g, () => isI(S.g.total()), `B = ${mtxt(inv2(q.pre))} = A⁻¹: the grid is back on the faint one.`, q.hint, () => S.g.set(keysOf(inv2(q.pre))), ['A', 'cols'])(body, api); },
+ })), done, 'Chapter practice · set 4 of 4') }],
+ ['play', 'Playground', (m, D) => {
+ const p = panel(0);
+ title(p, 'Playground');
+ S.sys = grid2(p, { A: [[2, 1], [1, 1]], mat: [90, 225], size: 42, shape: true, lost: true });
+ S.sys.labels(['col 1', 'col 2']);
+ S.sys.inverse({ at: [90, 365], size: 34 });
+ const hint = text(p, 'try: make ad − bc zero · a turn · a matrix that is its own inverse', 1160, 870, m('go'), { size: 24, fill: COL.dim, anchor: 'middle' });
+ hide(hint, Math.min(m('go') + 9, D - .7), .6);
+ }, { ask: playAsk(() => S.sys, { pos: { x: 40, y: 560, w: 720, cls: 'side' }, tip: 'A, its inverse and the plane, live. Drag a column tip or change a number, or draw on the board. Nothing is marked.' }) }],
+ ['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/ch27/audio/en/check.mp3 b/site/linear-algebra/ch27/audio/en/check.mp3
new file mode 100644
index 0000000..2c1cd7c
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/check.mp3 differ
diff --git a/site/linear-algebra/ch27/audio/en/check3.mp3 b/site/linear-algebra/ch27/audio/en/check3.mp3
new file mode 100644
index 0000000..82f4555
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/check3.mp3 differ
diff --git a/site/linear-algebra/ch27/audio/en/cols.mp3 b/site/linear-algebra/ch27/audio/en/cols.mp3
new file mode 100644
index 0000000..c1708ec
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/cols.mp3 differ
diff --git a/site/linear-algebra/ch27/audio/en/down.mp3 b/site/linear-algebra/ch27/audio/en/down.mp3
new file mode 100644
index 0000000..cf4d6ad
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/down.mp3 differ
diff --git a/site/linear-algebra/ch27/audio/en/ex2.mp3 b/site/linear-algebra/ch27/audio/en/ex2.mp3
new file mode 100644
index 0000000..27150f9
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/ex2.mp3 differ
diff --git a/site/linear-algebra/ch27/audio/en/final1.mp3 b/site/linear-algebra/ch27/audio/en/final1.mp3
new file mode 100644
index 0000000..bd0a4ed
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/final1.mp3 differ
diff --git a/site/linear-algebra/ch27/audio/en/final2.mp3 b/site/linear-algebra/ch27/audio/en/final2.mp3
new file mode 100644
index 0000000..d34be21
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/final2.mp3 differ
diff --git a/site/linear-algebra/ch27/audio/en/final3.mp3 b/site/linear-algebra/ch27/audio/en/final3.mp3
new file mode 100644
index 0000000..71a2c85
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/final3.mp3 differ
diff --git a/site/linear-algebra/ch27/audio/en/final4.mp3 b/site/linear-algebra/ch27/audio/en/final4.mp3
new file mode 100644
index 0000000..e672c4b
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/final4.mp3 differ
diff --git a/site/linear-algebra/ch27/audio/en/finish.mp3 b/site/linear-algebra/ch27/audio/en/finish.mp3
new file mode 100644
index 0000000..9376200
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/finish.mp3 differ
diff --git a/site/linear-algebra/ch27/audio/en/intro.mp3 b/site/linear-algebra/ch27/audio/en/intro.mp3
new file mode 100644
index 0000000..249af86
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/intro.mp3 differ
diff --git a/site/linear-algebra/ch27/audio/en/play.mp3 b/site/linear-algebra/ch27/audio/en/play.mp3
new file mode 100644
index 0000000..08f5ff5
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/play.mp3 differ
diff --git a/site/linear-algebra/ch27/audio/en/q1.mp3 b/site/linear-algebra/ch27/audio/en/q1.mp3
new file mode 100644
index 0000000..68da4ed
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/q1.mp3 differ
diff --git a/site/linear-algebra/ch27/audio/en/q2.mp3 b/site/linear-algebra/ch27/audio/en/q2.mp3
new file mode 100644
index 0000000..a9c37ad
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/q2.mp3 differ
diff --git a/site/linear-algebra/ch27/audio/en/q3.mp3 b/site/linear-algebra/ch27/audio/en/q3.mp3
new file mode 100644
index 0000000..1c30cb3
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/q3.mp3 differ
diff --git a/site/linear-algebra/ch27/audio/en/recipe.mp3 b/site/linear-algebra/ch27/audio/en/recipe.mp3
new file mode 100644
index 0000000..cb40fd9
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/recipe.mp3 differ
diff --git a/site/linear-algebra/ch27/audio/en/table.mp3 b/site/linear-algebra/ch27/audio/en/table.mp3
new file mode 100644
index 0000000..28bea47
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/table.mp3 differ
diff --git a/site/linear-algebra/ch27/audio/en/three.mp3 b/site/linear-algebra/ch27/audio/en/three.mp3
new file mode 100644
index 0000000..4c8d5ee
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/three.mp3 differ
diff --git a/site/linear-algebra/ch27/audio/en/timings.js b/site/linear-algebra/ch27/audio/en/timings.js
new file mode 100644
index 0000000..afb8df0
--- /dev/null
+++ b/site/linear-algebra/ch27/audio/en/timings.js
@@ -0,0 +1,743 @@
+window.TIMINGS = {
+ "intro": {
+ "dur": 16.896,
+ "marks": {
+ "sub": 4.453,
+ "move": 9.792
+ },
+ "cues": [
+ [
+ 0.104,
+ "Chapter twenty-seven."
+ ],
+ [
+ 1.875,
+ "Finding the inverse: Gauss\u2013Jordan."
+ ],
+ [
+ 4.453,
+ "The formula from chapter twenty-six only works for two by two matrices."
+ ],
+ [
+ 9.792,
+ "Here's a method that works for any size: the elimination you already know, run on two sides at once."
+ ]
+ ]
+ },
+ "cols": {
+ "dur": 49.008,
+ "marks": {
+ "A": 2.266,
+ "want": 7.604,
+ "split": 11.12,
+ "s2": 18.333,
+ "two": 22.096,
+ "pic": 30.859,
+ "x1": 35.273,
+ "x2": 37.161,
+ "read": 42.096
+ },
+ "cues": [
+ [
+ 0.104,
+ "Take the matrix from the lecture."
+ ],
+ [
+ 2.266,
+ "A is one, three in the first row, and two, seven in the second."
+ ],
+ [
+ 7.604,
+ "We want A inverse, so that A times A inverse is I."
+ ],
+ [
+ 11.12,
+ "Look at it one column at a time."
+ ],
+ [
+ 13.008,
+ "A times the first column of A inverse must give the first column of I: one, zero."
+ ],
+ [
+ 18.333,
+ "And A times the second column must give zero, one."
+ ],
+ [
+ 22.096,
+ "So these are two systems, A x equals b: one with b equal to one, zero, and one with b equal to zero, one."
+ ],
+ [
+ 30.859,
+ "In the picture: which point does A send to one, zero?"
+ ],
+ [
+ 35.273,
+ "It's seven, minus two."
+ ],
+ [
+ 37.161,
+ "And the point that A sends to zero, one is minus three, one."
+ ],
+ [
+ 42.096,
+ "Those two points are the columns of A inverse."
+ ],
+ [
+ 45.195,
+ "Now let's find them by elimination, instead of by searching."
+ ]
+ ]
+ },
+ "table": {
+ "dur": 29.088,
+ "marks": {
+ "A": 2.734,
+ "bar": 3.516,
+ "I": 4.557,
+ "aug": 12.917,
+ "goal": 17.318,
+ "grid": 22.344
+ },
+ "cues": [
+ [
+ 0.104,
+ "Elimination works on the numbers only."
+ ],
+ [
+ 2.734,
+ "Write A, draw a line, and write both right sides next to it: one, zero, and zero, one."
+ ],
+ [
+ 9.544,
+ "Side by side, they make the identity matrix."
+ ],
+ [
+ 12.917,
+ "This is A next to I: two right-hand sides at once instead of one."
+ ],
+ [
+ 17.318,
+ "The goal: turn the left half into I."
+ ],
+ [
+ 20.052,
+ "Then the right half will be A inverse."
+ ],
+ [
+ 22.344,
+ "Watch the plane on the right, too."
+ ],
+ [
+ 24.128,
+ "It is moved by the left half."
+ ],
+ [
+ 26.029,
+ "When the left half is I, the plane is home."
+ ]
+ ]
+ },
+ "down": {
+ "dur": 34.344,
+ "marks": {
+ "piv": 2.93,
+ "mult": 4.622,
+ "op": 9.323,
+ "go": 12.214,
+ "right": 20.703,
+ "plane": 27.096
+ },
+ "cues": [
+ [
+ 0.091,
+ "Step one is the elimination you know."
+ ],
+ [
+ 2.93,
+ "The first pivot is one."
+ ],
+ [
+ 4.622,
+ "Below it is a two, so the multiplier is two over one: two."
+ ],
+ [
+ 9.323,
+ "Row two minus two times row one."
+ ],
+ [
+ 12.214,
+ "Every number in row two changes, on both sides of the line."
+ ],
+ [
+ 16.146,
+ "Two minus two is zero."
+ ],
+ [
+ 18.398,
+ "Seven minus six is one."
+ ],
+ [
+ 20.703,
+ "On the right: zero minus two is minus two, and one minus zero is one."
+ ],
+ [
+ 27.096,
+ "And the plane took one step towards home."
+ ],
+ [
+ 29.727,
+ "The left half is now one, three, zero, one: a shear."
+ ]
+ ]
+ },
+ "up": {
+ "dur": 44.664,
+ "marks": {
+ "above": 8.385,
+ "op": 10.99,
+ "go": 13.893,
+ "right": 18.021,
+ "left": 26.224,
+ "home": 27.76,
+ "read": 28.984,
+ "same": 37.279
+ },
+ "cues": [
+ [
+ 0.104,
+ "Now something new."
+ ],
+ [
+ 1.315,
+ "In chapter nineteen we would stop here and substitute back."
+ ],
+ [
+ 5.13,
+ "Gauss\u2013Jordan keeps eliminating, upward."
+ ],
+ [
+ 8.385,
+ "Above the second pivot there's a three."
+ ],
+ [
+ 10.99,
+ "Row one minus three times row two."
+ ],
+ [
+ 13.893,
+ "Three minus three is zero, and the one stays one."
+ ],
+ [
+ 18.021,
+ "On the right: one minus three times minus two is seven, and zero minus three times one is minus three."
+ ],
+ [
+ 26.224,
+ "The left half is I."
+ ],
+ [
+ 27.76,
+ "The plane is home."
+ ],
+ [
+ 28.984,
+ "So the right half is A inverse: seven, minus three in the first row, and minus two, one in the second."
+ ],
+ [
+ 37.279,
+ "Its columns are seven, minus two and minus three, one: the same two points we found in the picture."
+ ]
+ ]
+ },
+ "check": {
+ "dur": 33.096,
+ "marks": {
+ "e1": 3.724,
+ "e2": 10.312,
+ "e3": 17.76,
+ "e4": 24.622,
+ "I": 30.456
+ },
+ "cues": [
+ [
+ 0.091,
+ "Always check by multiplying: A times A inverse."
+ ],
+ [
+ 3.724,
+ "Row one, three, times column seven, minus two: seven minus six, one."
+ ],
+ [
+ 10.312,
+ "Row one, three, times column minus three, one: minus three plus three, zero."
+ ],
+ [
+ 17.76,
+ "Row two, seven, times seven, minus two: fourteen minus fourteen, zero."
+ ],
+ [
+ 24.622,
+ "Row two, seven, times minus three, one: minus six plus seven, one."
+ ],
+ [
+ 30.456,
+ "The identity."
+ ],
+ [
+ 31.562,
+ "Gauss\u2013Jordan worked."
+ ]
+ ]
+ },
+ "why": {
+ "dur": 32.112,
+ "marks": {
+ "E": 2.852,
+ "all": 10.612,
+ "left": 14.531,
+ "right": 22.083,
+ "rec": 28.477
+ },
+ "cues": [
+ [
+ 0.104,
+ "Why does the right half end up as A inverse?"
+ ],
+ [
+ 2.852,
+ "Each row operation is a multiplication by an elimination matrix, from chapter twenty-one."
+ ],
+ [
+ 8.555,
+ "It acts on both halves at once."
+ ],
+ [
+ 10.612,
+ "Put all the steps together into one matrix, and call it E."
+ ],
+ [
+ 14.531,
+ "On the left, E times A became I."
+ ],
+ [
+ 16.927,
+ "So E is the matrix that undoes A: E is A inverse."
+ ],
+ [
+ 22.083,
+ "On the right, E times I is just E."
+ ],
+ [
+ 24.635,
+ "So the right half is A inverse, written out for us."
+ ],
+ [
+ 28.477,
+ "The right half is a record of everything we did to A."
+ ]
+ ]
+ },
+ "q1": {
+ "dur": 5.712,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn."
+ ],
+ [
+ 0.99,
+ "Choose the multiplier that clears the number under the pivot, and watch the plane."
+ ]
+ ]
+ },
+ "ex2": {
+ "dur": 67.2,
+ "marks": {
+ "A": 3.164,
+ "down": 7.721,
+ "d2": 14.427,
+ "up": 19.414,
+ "u2": 24.622,
+ "div": 29.349,
+ "d3": 34.284,
+ "read": 42.331,
+ "check": 49.284,
+ "plane": 61.797
+ },
+ "cues": [
+ [
+ 0.104,
+ "A second example, where the pivots are not one."
+ ],
+ [
+ 3.164,
+ "A is two, one in the first row, and six, four in the second."
+ ],
+ [
+ 7.721,
+ "Down: the multiplier is six over two, three."
+ ],
+ [
+ 11.602,
+ "Row two minus three times row one."
+ ],
+ [
+ 14.427,
+ "Row two becomes zero, one, and on the right, minus three, one."
+ ],
+ [
+ 19.414,
+ "Up: above the second pivot there's a one."
+ ],
+ [
+ 22.266,
+ "Row one minus one times row two."
+ ],
+ [
+ 24.622,
+ "Row one becomes two, zero, and on the right, four, minus one."
+ ],
+ [
+ 29.349,
+ "The left half isn't I yet: the first pivot is two."
+ ],
+ [
+ 32.552,
+ "Divide row one by two."
+ ],
+ [
+ 34.284,
+ "Two over two is one."
+ ],
+ [
+ 36.276,
+ "On the right: four over two is two, and minus one over two is minus one half."
+ ],
+ [
+ 42.331,
+ "So A inverse is two, minus one half in the first row, and minus three, one in the second."
+ ],
+ [
+ 49.284,
+ "Check with the formula from chapter twenty-six: a d minus b c is eight minus six, two."
+ ],
+ [
+ 56.302,
+ "One half of four, minus one, minus six, two gives the same matrix."
+ ],
+ [
+ 61.797,
+ "On the plane, that last step was a squeeze to half the width, and it brought the plane home."
+ ]
+ ]
+ },
+ "q2": {
+ "dur": 4.128,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.146,
+ "Do Gauss\u2013Jordan on this matrix."
+ ]
+ ]
+ },
+ "three": {
+ "dur": 50.28,
+ "marks": {
+ "A": 4.023,
+ "aug": 10.56,
+ "c1": 14.648,
+ "c1b": 18.594,
+ "c2": 21.68,
+ "tri": 25.807,
+ "up": 31.419,
+ "up2": 34.466,
+ "up3": 36.406,
+ "I": 39.727,
+ "read": 41.211
+ },
+ "cues": [
+ [
+ 0.104,
+ "The same method works for three by three, with more steps."
+ ],
+ [
+ 4.023,
+ "A is one, two, one; two, five, three; and one, three, three."
+ ],
+ [
+ 10.56,
+ "Write A, and the three by three identity beside it."
+ ],
+ [
+ 14.648,
+ "Column one: row two minus two times row one, and row three minus one times row one."
+ ],
+ [
+ 21.68,
+ "Column two: row three minus one times row two."
+ ],
+ [
+ 25.807,
+ "Now the left half is a triangle, with ones on the diagonal."
+ ],
+ [
+ 29.974,
+ "That's the end of the way down."
+ ],
+ [
+ 31.419,
+ "Now go up."
+ ],
+ [
+ 32.474,
+ "Row two minus row three, row one minus row three, and finally row one minus two times row two."
+ ],
+ [
+ 39.727,
+ "The left half is I."
+ ],
+ [
+ 41.211,
+ "So A inverse is six, minus three, one; minus three, two, minus one; and one, minus one, one."
+ ]
+ ]
+ },
+ "check3": {
+ "dur": 33.048,
+ "marks": {
+ "e1": 2.891,
+ "e2": 11.094,
+ "e3": 18.685,
+ "rest": 28.737
+ },
+ "cues": [
+ [
+ 0.104,
+ "Check a few numbers of A times A inverse."
+ ],
+ [
+ 2.891,
+ "Row one of A, one, two, one, times column one of A inverse, six, minus three, one: six minus six plus one, one."
+ ],
+ [
+ 11.094,
+ "Row two, two, five, three, times the same column: twelve minus fifteen plus three, zero."
+ ],
+ [
+ 18.685,
+ "Row three, one, three, three, times column three, one, minus one, one: one minus three plus three, one."
+ ],
+ [
+ 28.737,
+ "The other six work out the same way."
+ ],
+ [
+ 31.211,
+ "A times A inverse is I."
+ ]
+ ]
+ },
+ "q3": {
+ "dur": 3.12,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.107,
+ "One step on a three by three."
+ ]
+ ]
+ },
+ "recipe": {
+ "dur": 30.864,
+ "marks": {
+ "r1": 1.927,
+ "r2": 4.076,
+ "r3": 7.982,
+ "r4": 11.823,
+ "r5": 14.154,
+ "r6": 20.234
+ },
+ "cues": [
+ [
+ 0.104,
+ "So here is the recipe."
+ ],
+ [
+ 1.927,
+ "Write A and I side by side."
+ ],
+ [
+ 4.076,
+ "Eliminate down: zeros below each pivot."
+ ],
+ [
+ 7.982,
+ "Eliminate up: zeros above each pivot."
+ ],
+ [
+ 11.823,
+ "Divide each row by its pivot."
+ ],
+ [
+ 14.154,
+ "Now the left half is I, and the right half is A inverse."
+ ],
+ [
+ 18.633,
+ "Check by multiplying."
+ ],
+ [
+ 20.234,
+ "And if a pivot is zero, and no row below can swap in, the left half can never become I."
+ ],
+ [
+ 26.966,
+ "Then A has no inverse."
+ ],
+ [
+ 29.219,
+ "That's chapter twenty-eight."
+ ]
+ ]
+ },
+ "wrap": {
+ "dur": 25.104,
+ "marks": {
+ "w1": 0.99,
+ "w2": 6.823,
+ "w3": 14.414,
+ "w4": 21.172,
+ "end": 22.826
+ },
+ "cues": [
+ [
+ 0.104,
+ "To sum up."
+ ],
+ [
+ 0.99,
+ "A times A inverse equals I is several systems at once, one for each column of I."
+ ],
+ [
+ 6.823,
+ "Gauss\u2013Jordan writes A and I side by side, eliminates down, then up, then divides by the pivots."
+ ],
+ [
+ 14.414,
+ "When the left half becomes I, the right half is A inverse: it recorded every step."
+ ],
+ [
+ 21.172,
+ "Check by multiplying."
+ ],
+ [
+ 22.826,
+ "Now try the chapter practice."
+ ]
+ ]
+ },
+ "final1": {
+ "dur": 2.76,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Chapter practice."
+ ],
+ [
+ 1.523,
+ "One step at a time."
+ ]
+ ]
+ },
+ "final2": {
+ "dur": 3.912,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Next, whole inverses of two by two matrices."
+ ]
+ ]
+ },
+ "final3": {
+ "dur": 1.92,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Now three by three."
+ ]
+ ]
+ },
+ "final4": {
+ "dur": 3.792,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Last set."
+ ],
+ [
+ 1.211,
+ "Choose the multipliers with your hands."
+ ]
+ ]
+ },
+ "play": {
+ "dur": 12.6,
+ "marks": {
+ "go": 3.906
+ },
+ "cues": [
+ [
+ 0.117,
+ "Playground."
+ ],
+ [
+ 1.055,
+ "Nothing here is marked right or wrong."
+ ],
+ [
+ 3.906,
+ "Choose a row operation, set its multiplier, and watch the table and the plane."
+ ],
+ [
+ 9.414,
+ "Try to bring the plane home."
+ ],
+ [
+ 10.938,
+ "Press continue when you're done."
+ ]
+ ]
+ },
+ "finish": {
+ "dur": 11.376,
+ "marks": {},
+ "cues": [
+ [
+ 0.091,
+ "Well done."
+ ],
+ [
+ 1.094,
+ "That's the end of chapter twenty-seven, finding the inverse: Gauss\u2013Jordan."
+ ],
+ [
+ 6.51,
+ "Next: matrices with no inverse, and the inverse of a product."
+ ]
+ ]
+ }
+};
diff --git a/site/linear-algebra/ch27/audio/en/up.mp3 b/site/linear-algebra/ch27/audio/en/up.mp3
new file mode 100644
index 0000000..c681b67
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/up.mp3 differ
diff --git a/site/linear-algebra/ch27/audio/en/why.mp3 b/site/linear-algebra/ch27/audio/en/why.mp3
new file mode 100644
index 0000000..8366e14
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/why.mp3 differ
diff --git a/site/linear-algebra/ch27/audio/en/wrap.mp3 b/site/linear-algebra/ch27/audio/en/wrap.mp3
new file mode 100644
index 0000000..284634a
Binary files /dev/null and b/site/linear-algebra/ch27/audio/en/wrap.mp3 differ
diff --git a/site/linear-algebra/ch27/index.html b/site/linear-algebra/ch27/index.html
new file mode 100644
index 0000000..b600d5f
--- /dev/null
+++ b/site/linear-algebra/ch27/index.html
@@ -0,0 +1,435 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>Finding the Inverse: Gauss–Jordan</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/grid2.js"></script>
+<script src="../lib/inv.js"></script>
+<script src="../lib/play.js"></script>
+<script src="audio/en/timings.js"></script>
+<script>
+'use strict';
+const CHAPTER = { number: 27, title: 'Finding the Inverse: Gauss–Jordan', minutes: 9, language: 'en', next: '../ch28/' };
+
+/* ---------- layout and colours ---------- */
+const COLC = [COL.irr, COL.real, COL.rat];
+const LEFT = { x: 40, y: 430, w: 720, cls: 'side' };
+const TOPL = { x: 40, y: 180, w: 760, cls: 'side' };
+const I2 = [[1, 0], [0, 1]];
+const LEC = [[1, 3], [2, 7]], LECI = [[7, -3], [-2, 1]];
+const EX2 = [[2, 1], [6, 4]];
+const A3 = [[1, 2, 1], [2, 5, 3], [1, 3, 3]], A3I = [[6, -3, 1], [-3, 2, -1], [1, -1, 1]];
+const PL = { cx: 1210, u: 40, x0: -8, x1: 8, y0: -8, y1: 8 }; // the plane on the right, wide enough for (7, −2) and (3, 7)
+const TAB = [120, 270]; // where a 2 × 2 table [A | I] stands
+const INV = ['A', E('−1')];
+
+/* ---------- 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 title = (p, str) => text(p, str, 60, 110, .2, { size: 40, weight: 600 });
+const ringAt = (P2, [x, y], color, into, t0, label, { dx = 20, dy = -18, anchor = 'start' } = {}) => {
+ const g = G(into, { x: P2.PX(x), y: P2.PY(y), o: 0 });
+ mk('circle', { r: 17, fill: 'none', stroke: color, 'stroke-width': 3, 'stroke-dasharray': '5 5' }, g);
+ if (label) T(g, label, { x: dx, y: dy, size: 22, fill: color, font: MATH, anchor });
+ if (t0 !== undefined) show(g, t0, .4); else put(g, { o: 1 });
+ return g;
+};
+// A 2 × 2 table [A | I] with the plane beside it, moved by the table's left half.
+function table2(p, A, { rows = null, t0 = .1, at = TAB, size = 42 } = {}) {
+ const g = grid2(p, { A, mat: null, shape: true, plane: PL, t0 });
+ g.labels(['col 1', 'col 2']);
+ const t = gj(p, A, { at, size, link: g, t0 });
+ if (rows) t.load(rows);
+ return { g, t };
+}
+const rowBand = (p, t, i, t0, t1) => { const r = mk('rect', { x: t.cx(t.n) - 44, y: t.ry(i) - 46, width: t.cx(2 * t.n - 1) - t.cx(t.n) + 88, height: 62, rx: 12, fill: COL.task }, p); p.insertBefore(r, p.firstChild); put(r, { o: 0 }); tw(r, { o: .15 }, t0, .3); tw(r, { o: 0 }, t1, .3); };
+const rowsOf = (A, R = A.map((r, i) => r.map((_, j) => +(i === j)))) => A.map((r, i) => [...r, ...R[i]]);
+// An [A | I] table for a card (right block amber, as b is).
+function augEl(rows, n, { size = 24 } = {}) {
+ const m = rows[0].length, cw = size * 1.9, rh = size * 1.3, gap = 14, w = cw * m + 16 + (m > n ? gap : 0), 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 });
+ if (m > n) path(svg, `M${8 + cw * n + gap / 2} 4V${hh - 4}`, { stroke: 'currentColor', 'stroke-width': 1.5, 'stroke-dasharray': '4 4', opacity: .6 });
+ rows.forEach((r, i) => r.forEach((v, j) => T(svg, fracTxt(v), { x: 8 + cw * (j + .5) + (j >= n ? gap : 0), y: rh * (i + .5) + size * .5, size: size * (String(fracTxt(v)).length > 3 ? .8 : 1), fill: j >= n ? COL.task : 'currentColor', font: MATH, anchor: 'middle' })));
+ return svg;
+}
+const fracTxt = x => { const f = g2frac(x); return !f || f[1] === 1 ? num(x) : `${f[0] < 0 ? '−' : ''}${Math.abs(f[0])}/${f[1]}`; };
+const ansTxt = x => fracTxt(x).replace('−', '-');
+const invOf = A => { const n = A.length, R = rowsOf(A).map(r => r.slice()); for (let c = 0; c < n; c++) { const pr = R[c][c]; R[c] = R[c].map(x => x / pr); for (let i = 0; i < n; i++) if (i !== c) { const l = R[i][c]; R[i] = R[i].map((x, k) => x - l * R[c][k]); } } return R.map(r => r.slice(n)); };
+const rowBoxes = (label, vals, why, hint) => ({ parts: [label, ' (', ...vals.flatMap((v, k) => [...(k ? [', '] : []), { box: ansTxt(v) }]), ')'], why, hint });
+
+/* ---------- practice data ---------- */
+const STEPQ = [
+ { rows: rowsOf([[1, 4], [2, 9]]), i: 1, j: 0, l: 2, why: '2 ÷ 1 = 2. Row 2 − 2 × row 1: (2 − 2, 9 − 8 | 0 − 2, 1 − 0) = (0, 1 | −2, 1).' },
+ { rows: [[1, 4, 1, 0], [0, 1, -2, 1]], i: 0, j: 1, l: 4, why: 'Clear the 4 above the pivot: row 1 − 4 × row 2 = (1, 0 | 1 + 8, 0 − 4) = (1, 0 | 9, −4). So A⁻¹ = [9 −4; −2 1].' },
+ { rows: rowsOf([[2, 6], [1, 4]]), i: 1, j: 0, l: .5, why: '1 ÷ 2 = 1/2. Row 2 − ½ × row 1: (1 − 1, 4 − 3 | 0 − ½, 1 − 0) = (0, 1 | −1/2, 1).' },
+];
+const WHOLEQ = [[[1, 1], [2, 3]], [[2, 3], [1, 2]], [[1, -2], [1, -1]], [[2, 2], [1, 2]], [[3, 0], [1, 1]]];
+const THREEQ = [
+ { A: [[2, 0, 0], [0, 4, 0], [0, 0, 1]], why: 'Only divisions: row 1 ÷ 2, row 2 ÷ 4. A diagonal matrix is undone number by number.' },
+ { A: [[1, 0, 0], [-3, 1, 0], [0, 0, 1]], why: 'This E subtracts 3 × row 1 from row 2; its inverse adds it back: a +3 in the same place.' },
+ { A: [[1, 2, 0], [0, 1, 1], [1, 2, 1]], why: 'Row 3 − row 1, then row 2 − row 3, then row 1 − 2 × row 2. Check: row 1 of A times column 1, (1, 2, 0)·(−1, 1, −1) = 1.' },
+];
+const HANDQ = [
+ { rows: rowsOf([[2, 1], [4, 3]]), i: 1, j: 0, l: 2, what: 'the 4 under the pivot 2' },
+ { rows: [[1, 3, 1, 0], [0, 1, -2, 1]], i: 0, j: 1, l: 3, what: 'the 3 above the second pivot' },
+ { rows: rowsOf([[2, 1], [-4, 1]]), i: 1, j: 0, l: -2, what: 'the −4 under the pivot 2' },
+ { rows: rowsOf([[1, 0], [5, 1]]), i: 1, j: 0, l: 5, what: 'the 5 under the pivot 1' },
+];
+
+/* ---------- beats: [id, title, run(m, D), { ask }?] ---------- */
+const BEATS = [
+ ['intro', 'Finding the inverse: Gauss–Jordan', (m, D) => {
+ const g = G(scene, { o: 0, y: 24 });
+ T(g, 'Unit 3, Chapter 27', { x: 800, y: 250, size: 28, fill: COL.dim, anchor: 'middle' });
+ T(g, 'Finding the Inverse: Gauss–Jordan', { x: 800, y: 360, size: 76, weight: 600, anchor: 'middle' });
+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);
+ const r = text(scene, 'elimination on two sides at once', 800, 450, m('sub'), { size: 36, fill: COL.dim, anchor: 'middle' });
+ const sm = G(scene, { o: 0 });
+ const t = gj(sm, LEC, { at: [610, 640], size: 36 });
+ show(sm, m('move') - .4, .6);
+ t.sub(1, 0, 2, m('move') + 1, 1.2, { lead: .5 }); t.sub(0, 1, 3, m('move') + 3, 1.2, { lead: .5 }); t.done(m('move') + 4.6);
+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(sm, D - .9, .8);
+ }],
+
+ ['cols', 'One column at a time', (m) => {
+ const p = panel(0);
+ title(p, 'A A⁻¹ = I, one column at a time');
+ const g = S.g = grid2(p, { A: I2, x: [0, 0], mat: [90, 270], size: 46, plane: PL, brackets: true, shape: false, units: false, t0: m('A') - .4 });
+ g.to({ a00: 1, a01: 3, a10: 2, a11: 7 }, m('A') + .6, 2.6);
+ say(p, ['want ', ...INV, ': A ', ...INV, ' = I'], 90, 455, m('want') + .4, { size: 34 });
+ g.labels(['col 1', 'col 2']);
+ g.combo.forEach(e => put(e, { o: 0 }));
+ [g.xLab, g.axLab].forEach(e => put(e, { o: 0 })); // x and Ax are read in the brackets
+ put(g.parts.x, { o: 0 }); show(g.parts.x, m('pic') - .2, .4);
+ say(p, ['A · (column 1 of ', ...INV, ') = (1, 0)'], 90, 515, m('split') + .5, { size: 32 });
+ say(p, ['A · (column 2 of ', ...INV, ') = (0, 1)'], 90, 565, m('s2') + .3, { size: 32 });
+ text(p, 'two systems Ax = b: b = (1, 0) and b = (0, 1)', 90, 625, m('two') + .5, { size: 26, fill: COL.task, weight: 600 });
+ ringAt(g.P, [1, 0], COL.task, p, m('two') + 1.5, '(1, 0)', { dx: 6, dy: 40 });
+ ringAt(g.P, [0, 1], COL.task, p, m('two') + 5.2, '(0, 1)', { dx: -18, dy: -16, anchor: 'end' });
+ g.to({ x0: 3, x1: -1 }, m('pic') + .6, 1.4); g.to({ x0: 7, x1: -2 }, m('x1') - .2, 1.4);
+ g.to({ x0: -3, x1: 1 }, m('x2') + 1.4, 1.8);
+ const xs = G(p, {});
+ ringAt(g.P, [7, -2], COL.irr, xs, m('x1') + 1.4, '(7, −2)', { dx: -14, dy: 36, anchor: 'end' });
+ ringAt(g.P, [-3, 1], COL.real, xs, m('read') - .2, '(−3, 1)', { dx: -14, dy: -18, anchor: 'end' });
+ const Bm = ivMat(p, LECI, { x: 90, y: 720, size: 40, name: INV, fill: (i, j) => COLC[j], o: 0 });
+ show(Bm.g, m('read') + .6, .5);
+ text(p, 'its columns: the two points', 330, 755, m('read') + 1.5, { size: 26, fill: COL.dim });
+ }],
+
+ ['table', 'A next to I', (m) => {
+ const p = panel(0);
+ title(p, 'Write A and I side by side');
+ const { g, t } = S.tb = table2(p, LEC, { t0: m('A') - .5 });
+ put(t.divider, { o: 0 }); show(t.divider, m('bar'), .3);
+ const right = t.cells.flatMap(r => r.slice(2).map(c => c.g.parentNode));
+ right.forEach((e, k) => { put(e, { o: 0 }); show(e, m('I') + .2 + k * .35, .3); });
+ put(t.nameG[1], { o: 0 }); show(t.nameG[1], m('I') + 1.6, .3);
+ say(p, ['[ A | I ]: two right sides at once'], 90, 470, m('aug') + .3, { size: 32 });
+ say(p, ['goal: [ A | I ] → [ I | ', ...INV, ' ]'], 90, 540, m('goal') + .3, { size: 34 });
+ text(p, 'the plane is moved by the left half', 90, 620, m('grid') + .5, { size: 28, weight: 600 });
+ text(p, 'left half = I → the plane is home', 90, 670, m('grid') + 3, { size: 28, fill: COL.dim });
+ t.block(0, m('grid') + .5, m('grid') + 4);
+ t.block(1, m('I') + 4.5, m('aug'));
+ }],
+
+ ['down', 'Eliminate down', (m) => {
+ const p = panel(0);
+ title(p, 'Step 1: eliminate down');
+ const { g, t } = table2(p, LEC);
+ t.ring(0, 0, m('piv'), m('op'));
+ t.ring(1, 0, m('mult'), m('op'), { dash: true });
+ say(p, ['multiplier = 2 ÷ 1 = 2'], 90, 470, m('mult') + .6, { size: 32 });
+ t.sub(1, 0, 2, m('go') + .2, 2.6, { lead: m('go') + .2 - m('op') });
+ say(p, ['2 − 2·1 = 0,'], 90, 540, m('go') + 1.2, { size: 30 }); say(p, ['7 − 2·3 = 1'], 290, 540, m('go') + 4.6, { size: 30 });
+ t.block(1, m('right'), m('plane'));
+ say(p, ['0 − 2·1 = −2,'], 90, 600, m('right') + .5, { size: 30, fill: COL.task }); say(p, ['1 − 2·0 = 1'], 300, 600, m('right') + 3.6, { size: 30, fill: COL.task });
+ text(p, 'left half [1 3; 0 1]: one step closer to home', 90, 680, m('plane') + .5, { size: 28, weight: 600 });
+ t.block(0, m('plane') + .3, m('plane') + 5.5);
+ }],
+
+ ['up', 'Eliminate up', (m) => {
+ const p = panel(0);
+ title(p, 'Step 2: eliminate up');
+ const { g, t } = table2(p, LEC, { rows: [[1, 3, 1, 0], [0, 1, -2, 1]] });
+ text(p, 'back substitution would stop here; Gauss–Jordan goes on', 90, 470, 1, { size: 24, fill: COL.dim });
+ const upA = G(p, {}); draw(path(upA, `M${t.cx(3) + 70} ${t.ry(1) - 10}V${t.ry(0) - 30}M${t.cx(3) + 58} ${t.ry(0) - 16}L${t.cx(3) + 70} ${t.ry(0) - 32}L${t.cx(3) + 82} ${t.ry(0) - 16}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' }, { d: 0 }), 3, 1.2); hide(upA, m('op') - .3, .3);
+ t.ring(1, 1, m('above') - .3, m('op'));
+ t.ring(0, 1, m('above') + .4, m('op'), { dash: true });
+ t.sub(0, 1, 3, m('go') + .2, 2.6, { lead: m('go') + .2 - m('op') });
+ say(p, ['3 − 3·1 = 0, 1 − 3·0 = 1'], 90, 540, m('go') + 1, { size: 30 });
+ t.block(1, m('right'), m('left'));
+ say(p, ['1 − 3·(−2) = 7,'], 90, 600, m('right') + .5, { size: 30, fill: COL.task }); say(p, ['0 − 3·1 = −3'], 320, 600, m('right') + 4.2, { size: 30, fill: COL.task });
+ [0, 1].forEach(i => rowBand(p, t, i, m('read') + 1.5 + i * 2.6, m('read') + 3.9 + i * 2.6));
+ t.block(0, m('left'), m('read'));
+ text(p, 'left half I: the plane is home', 90, 670, m('home') + .2, { size: 28, weight: 600 });
+ t.names(['I', INV], m('read') + .2); t.done(m('read'));
+ const Bm = ivMat(p, LECI, { x: 90, y: 760, size: 38, fill: (i, j) => COLC[j], o: 0 });
+ say(p, [...INV, ' ='], 90, 787, m('read') + 1, { size: 36 }); put(Bm.g, { x: 110 }); show(Bm.g, m('read') + 1, .4);
+ ringAt(g.P, [7, -2], COL.irr, p, m('same') + .6, '(7, −2)', { dx: -14, dy: 36, anchor: 'end' });
+ ringAt(g.P, [-3, 1], COL.real, p, m('same') + 1.6, '(−3, 1)', { dx: -14, dy: -18, anchor: 'end' });
+ }],
+
+ ['check', 'Check by multiplying', (m) => {
+ const p = panel(0);
+ title(p, 'Check: A times A⁻¹');
+ const pr = ivProd(p, LEC, LECI, { at: [150, 330], size: 52, names: ['A', INV, 'I'], work: [150, 560], workSize: 40, o: 0 });
+ show(pr.g, .4, .5);
+ pr.entry(0, 0, m('e1'), m('e2') - m('e1') - .2); pr.entry(0, 1, m('e2'), m('e3') - m('e2') - .2);
+ pr.entry(1, 0, m('e3'), m('e4') - m('e3') - .2); pr.entry(1, 1, m('e4'), m('I') - m('e4'));
+ text(p, 'A A⁻¹ = I: Gauss–Jordan worked', 150, 680, m('I') + .3, { size: 32, weight: 600, fill: COL.good });
+ }],
+
+ ['why', 'Why the right half is A⁻¹', (m) => {
+ const p = panel(0);
+ title(p, 'Why the right half becomes A⁻¹');
+ const e1 = ivMat(p, [[1, 0], [-2, 1]], { x: 90, y: 250, size: 38, name: 'E₁', o: 0 });
+ const e2 = ivMat(p, [[1, -3], [0, 1]], { x: 420, y: 250, size: 38, name: 'E₂', o: 0 });
+ show(e1.g, m('E') + 1, .4); show(e2.g, m('E') + 3.5, .4);
+ text(p, 'row 2 − 2 × row 1', 90, 395, m('E') + 1.2, { size: 24, fill: COL.dim });
+ text(p, 'row 1 − 3 × row 2', 420, 395, m('E') + 3.7, { size: 24, fill: COL.dim });
+ say(p, ['E = E₂E₁ (both steps, E₁ first)'], 90, 480, m('all') + .4, { size: 34 });
+ say(p, ['E [ A | I ] = [ EA | EI ]'], 90, 570, m('all') + 2.2, { size: 40 });
+ say(p, ['EA = I, so E = ', ...INV], 90, 650, m('left') + .5, { size: 40 });
+ say(p, ['EI = E = ', ...INV, ': the right half'], 90, 730, m('right') + .8, { size: 40, fill: COL.task });
+ text(p, 'the right half recorded every step', 90, 820, m('rec') + .3, { size: 30, weight: 600 });
+ // the same two steps, run again on a small table on the right
+ const sm = G(p, { o: 0 });
+ const t = gj(sm, LEC, { at: [900, 300], size: 36 });
+ put(t.g, { o: 1 });
+ show(sm, m('E') + .5, .4);
+ t.sub(1, 0, 2, m('E') + 2, 1.2, { lead: .6 }); t.sub(0, 1, 3, m('E') + 4.5, 1.2, { lead: .6 }); t.done(m('all'));
+ t.block(1, m('right') + .5, m('rec') + 3); t.block(0, m('left') + 1, m('right'));
+ }],
+
+ ['q1', 'Quick check', () => {
+ const p = panel(0);
+ title(p, 'Quick check');
+ S.tb = table2(p, [[1, 2], [3, 7]]);
+ }, { ask: done => quiz(LEFT, [{
+ id: 'c-mult', prompt: ['Choose the multiplier ℓ that puts a 0 under the pivot.'],
+ build: (body, api) => { S.tb.t.open(1, 0); return gjTask(S.tb.t, v => v.c10 === 0, 'ℓ = 3 ÷ 1 = 3. Row 2 becomes (0, 1 | −3, 1), and the plane takes one step home.',
+ v => v.l < 3 ? `Row 2 still starts with ${num(3 - v.l)}. The number to clear is 3, the pivot is 1: ℓ = 3 ÷ 1.` : 'Too far: row 2 now starts below zero. ℓ = 3 ÷ 1 = 3.', () => S.tb.t.set({ l: 3 }))(body, api); },
+ }], done) }],
+
+ ['ex2', 'Pivots that are not 1', (m) => {
+ const p = panel(0);
+ title(p, 'A second one: A = [2 1; 6 4]');
+ const { g, t } = table2(p, EX2, { t0: m('A') - .5 });
+ t.ring(0, 0, m('down'), m('down') + 3.4);
+ t.sub(1, 0, 3, m('d2') - .4, 2, { lead: m('d2') - .4 - (m('down') + 3.4) });
+ say(p, ['ℓ = 6 ÷ 2 = 3'], 90, 470, m('down') + 1, { size: 30 });
+ t.ring(1, 1, m('up') + .3, m('up') + 3);
+ t.sub(0, 1, 1, m('u2') - .4, 2, { lead: m('u2') - .4 - (m('up') + 3) });
+ say(p, ['ℓ = 1 ÷ 1 = 1'], 90, 530, m('up') + 1, { size: 30 });
+ t.ring(0, 0, m('div') + .4, m('div') + 3.5, { color: COL.bad });
+ t.div(0, 2, m('d3') - .3, 1.8, { lead: m('d3') - .3 - (m('div') + 3.2) });
+ say(p, ['pivot 2: divide row 1 by 2'], 90, 590, m('div') + 3.2, { size: 30 });
+ t.names(['I', INV], m('read')); t.done(m('read'));
+ say(p, ['4 ÷ 2 = 2, −1 ÷ 2 = −', F(1, 2)], 90, 650, m('d3') + 2.6, { size: 28, fill: COL.task });
+ [0, 1].forEach(i => rowBand(p, t, i, m('read') + .8 + i * 2.6, m('read') + 3.2 + i * 2.6));
+ const ck = say(p, ['check: ad − bc = 8 − 6 = 2,'], 90, 720, m('check') + .5, { size: 28 });
+ const ck2 = say(p, [F(1, 2), '·[4 −1; −6 2]'], 90 + ck._w + 14, 720, m('check') + 5.2, { size: 28 });
+ say(p, ['= [2 −', F(1, 2), '; −3 1]'], 90 + ck._w + ck2._w + 26, 720, m('check') + 9, { size: 28 });
+ text(p, 'the last step, ÷ 2, squeezed the plane home', 90, 790, m('plane') + .3, { size: 28, weight: 600 });
+ }],
+
+ ['q2', 'Quick check', () => {
+ const p = panel(0);
+ title(p, 'Quick check');
+ S.tb = table2(p, [[1, 2], [3, 7]]);
+ }, { ask: done => quiz(LEFT, [{
+ id: 'c-gj1', prompt: ['Gauss–Jordan on ', $m('A'), ' = [1 2; 3 7]. First, down.'],
+ build: blanks([
+ { parts: ['down: ℓ = ', { box: '3' }], why: '3 ÷ 1 = 3: row 2 − 3 × row 1.', hint: 'Under the pivot 1 sits a 3.' },
+ { parts: ['new row 2, right half: (', { box: '-3' }, ', ', { box: '1' }, ')'], why: '(0, 1) − 3 × (1, 0) = (−3, 1). Row 2 is now (0, 1 | −3, 1).', hint: 'On the right: (0, 1) − 3 × (1, 0).' },
+ ]),
+ }, {
+ id: 'c-gj2', prompt: ['Now row 2 is (0, 1 | −3, 1). Go up.'],
+ build: blanks([
+ { parts: ['up: ℓ = ', { box: '2' }], why: 'Row 1 − 2 × row 2 clears the 2 above the second pivot.', hint: 'Above the second pivot (a 1) there is a 2.' },
+ { parts: ['new row 1, right half: (', { box: '7' }, ', ', { box: '-2' }, ')'], why: 'A⁻¹ = [7 −2; −3 1]. Check: 1·7 + 2·(−3) = 1.', hint: 'On the right: (1, 0) − 2 × (−3, 1).' },
+ ]),
+ }], done) }],
+
+ ['three', 'Three by three', (m) => {
+ const p = panel(0);
+ title(p, 'The same recipe, 3 × 3');
+ const t = gj(p, A3, { at: [200, 300], size: 44, t0: m('A') - .5 });
+ const right = t.cells.flatMap(r => r.slice(3).map(c => c.g.parentNode));
+ right.forEach(e => { put(e, { o: 0 }); show(e, m('aug') + .4, .4); });
+ put(t.divider, { o: 0 }); show(t.divider, m('aug'), .3); put(t.nameG[1], { o: 0 }); show(t.nameG[1], m('aug') + .5, .3);
+ t.sub(1, 0, 2, m('c1') + 2.2, 1.4, { lead: 1.2 });
+ t.sub(2, 0, 1, m('c1b') + 1.3, 1.4, { lead: 1 });
+ t.sub(2, 1, 1, m('c2') + 1.6, 1.4, { lead: 1.2 });
+ const tri = path(p, `M${t.cx(0) - 40} ${t.ry(0) - 44}L${t.cx(2) + 40} ${t.ry(0) - 44}L${t.cx(2) + 40} ${t.ry(2) + 20}Z`, { fill: COL.chalk, 'fill-opacity': .1, stroke: COL.chalk, 'stroke-width': 2 }, { o: 0 });
+ show(tri, m('tri') + .3, .5); hide(tri, m('up'), .4);
+ text(p, 'down: zeros below the pivots ✓', 160, 560, m('tri') + 1, { size: 28, weight: 600 });
+ t.sub(1, 2, 1, m('up') + 1.8, 1.2, { lead: .9 });
+ t.sub(0, 2, 1, m('up2') + .6, 1.2, { lead: .6 });
+ t.sub(0, 1, 2, m('up3') + 1.6, 1.4, { lead: 1.2 });
+ text(p, 'up: zeros above the pivots ✓', 160, 620, m('I') - .2, { size: 28, weight: 600 });
+ t.done(m('I')); t.block(0, m('I'), m('read'));
+ t.names(['I', INV], m('read') + .2);
+ [0, 1, 2].forEach(i => rowBand(p, t, i, m('read') + 1 + i * 2.6, m('read') + 3.4 + i * 2.6));
+ t.block(0, m('A') + 1.5, m('aug'));
+ }],
+
+ ['check3', 'Check a few numbers', (m) => {
+ const p = panel(0);
+ title(p, 'Check: A times A⁻¹');
+ const pr = ivProd(p, A3, A3I, { at: [110, 320], size: 40, cw: 70, names: ['A', INV, 'I'], work: [110, 560], workSize: 36, o: 0 });
+ show(pr.g, .4, .5);
+ pr.entry(0, 0, m('e1'), m('e2') - m('e1') - .2); pr.entry(1, 0, m('e2'), m('e3') - m('e2') - .2); pr.entry(2, 2, m('e3'), m('rest') - m('e3') - .2);
+ pr.fill(m('rest') + .3);
+ text(p, 'A A⁻¹ = I', 110, 660, m('rest') + 2, { size: 32, weight: 600, fill: COL.good });
+ }],
+
+ ['q3', 'Quick check', () => {
+ const p = panel(0);
+ title(p, 'Quick check');
+ gj(p, [[1, 2, 0], [0, 1, 1], [1, 2, 1]], { at: [960, 330], size: 40 });
+ }, { ask: done => quiz(TOPL, [{
+ id: 'c-three', prompt: ['First step: clear the 1 in row 3, column 1.'],
+ build: blanks([
+ { parts: ['row 3 − ', { box: '1' }, ' × row 1'], why: '1 ÷ 1 = 1.', hint: 'The number to clear is 1 and the pivot is 1.' },
+ rowBoxes('new row 3, left half:', [0, 0, 1], '(1, 2, 1) − (1, 2, 0) = (0, 0, 1).', 'Take row 1, (1, 2, 0), away from row 3, (1, 2, 1).'),
+ rowBoxes('new row 3, right half:', [-1, 0, 1], '(0, 0, 1) − (1, 0, 0) = (−1, 0, 1).', 'The right halves too: (0, 0, 1) − (1, 0, 0).'),
+ ]),
+ }], done) }],
+
+ ['recipe', 'The recipe', (m) => {
+ const p = panel(0);
+ title(p, 'Gauss–Jordan, step by step');
+ [['write [ A | I ]', 'r1'], ['down: zeros below each pivot', 'r2'], ['up: zeros above each pivot', 'r3'], ['divide each row by its pivot', 'r4'], ['read A⁻¹ on the right; check by multiplying', 'r5']].forEach(([str, mark], i) => {
+ const g = G(p, { x: -16, y: 210 + i * 80, o: 0 });
+ mk('circle', { cx: 80, cy: -10, r: 22, fill: COL.chalk }, g);
+ T(g, String(i + 1), { x: 80, y: -1, size: 26, fill: COL.board, weight: 700, anchor: 'middle' });
+ T(g, str, { x: 125, size: 30, weight: 600 });
+ tw(g, { o: 1, x: 0 }, m(mark), .5);
+ });
+ const sm = G(p, {});
+ const t = gj(sm, EX2, { at: [900, 260], size: 36, t0: m('r1') });
+ t.sub(1, 0, 3, m('r2') + 1, 1, { lead: .5 }); t.sub(0, 1, 1, m('r3') + 1, 1, { lead: .5 }); t.div(0, 2, m('r4') + .8, 1, { lead: .5 }); t.done(m('r5'));
+ t.names(['I', INV], m('r5') + .3);
+ hide(sm, m('r6') - .2, .4);
+ // when it fails: a zero row, no pivot
+ const bad = G(p, { o: 0 });
+ const t2 = gj(bad, [[1, 2], [2, 4]], { at: [900, 620], size: 36 });
+ put(t2.g, { o: 1 });
+ show(bad, m('r6'), .4);
+ t2.sub(1, 0, 2, m('r6') + 2, 1.2, { lead: .6 });
+ t2.ring(1, 1, m('r6') + 4, undefined, { color: COL.bad });
+ text(p, 'a zero row, no pivot: no inverse', 1100, 800, m('r6') + 4.5, { size: 28, fill: COL.bad, weight: 600, anchor: 'middle' });
+ }],
+
+ ['wrap', 'Summary', (m) => {
+ const p = panel(0);
+ [['A A⁻¹ = I is one system for each column of I.', 'w1'], ['Gauss–Jordan: [ A | I ], down, up, divide by the pivots.', 'w2'],
+ ['The left half becomes I, the right half A⁻¹.', 'w3'], ['Check by multiplying.', 'w4']].forEach(([str, mark], i) => {
+ const g = G(p, { x: -16, y: 150 + i * 95, o: 0 });
+ mk('circle', { cx: 150, cy: -12, r: 26, fill: COL.chalk }, 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);
+ });
+ const sm = G(p, { o: 0 });
+ const k = grid2(sm, { A: LEC, mat: null, shape: true, units: false, plane: { cx: 1250, cy: 690, u: 18, x0: -8, x1: 8, y0: -8, y1: 8, labels: false } });
+ put(k.parts.cols, { o: 0 });
+ const t = gj(sm, LEC, { at: [520, 650], size: 34, link: k });
+ show(sm, .3, .6);
+ t.sub(1, 0, 2, m('w2') + 2, 1.4, { lead: .5 }); t.sub(0, 1, 3, m('w2') + 4.4, 1.4, { lead: .5 }); t.done(m('w3'));
+ t.names(['I', INV], m('w3') + .5); t.block(1, m('w3') + 2, m('w4'));
+ }],
+
+ ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [...STEPQ.map((q, k) => {
+ const after = q.rows[q.i].map((x, c) => x - q.l * q.rows[q.j][c]);
+ return {
+ id: `p-step${k + 1}`, prompt: ['In ', augEl(q.rows, 2), ', clear the number in row ', String(q.i + 1), ', column ', String(q.j + 1), '.'],
+ build: blanks([
+ { parts: [`row ${q.i + 1} − `, { box: ansTxt(q.l) }, ` × row ${q.j + 1}`], why: `ℓ = ${fracTxt(q.rows[q.i][q.j])} ÷ ${fracTxt(q.rows[q.j][q.j])} = ${fracTxt(q.l)}.`, hint: 'The multiplier is (the number to clear) ÷ (the pivot in its column).' },
+ rowBoxes(`new row ${q.i + 1}:`, after, q.why, 'Take ℓ times the pivot row away from every number of the row, on both sides of the line.'),
+ ]),
+ };
+ }), {
+ id: 'p-step4', prompt: ['In ', augEl(rowsOf([[3, 0], [0, 2]]), 2), ', divide by the pivots and read ', $m('A', E('−1')), '.'],
+ build: blanks([
+ { parts: ['row 1 ÷ ', { box: '3' }, ', row 2 ÷ ', { box: '2' }], why: 'Each row by its own pivot.', hint: 'The pivots are the numbers on the diagonal of the left half.' },
+ rowBoxes('first row of A⁻¹:', [1 / 3, 0], '(1, 0) ÷ 3 = (1/3, 0).', 'Divide the right half of row 1 by 3.'),
+ rowBoxes('second row of A⁻¹:', [0, 1 / 2], '(0, 1) ÷ 2 = (0, 1/2). A⁻¹ = [1/3 0; 0 1/2].', 'Divide the right half of row 2 by 2.'),
+ ]),
+ }], done, 'Chapter practice · set 1 of 4') }],
+ ['final2', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, WHOLEQ.map((A, k) => {
+ const B = invOf(A);
+ return {
+ id: `p-whole${k + 1}`, prompt: ['Find ', $m('A', E('−1')), ' for ', $m('A'), ' = ', augEl(A, 2), ' by Gauss–Jordan (or the formula), and check.'],
+ build: blanks([
+ rowBoxes('first row of A⁻¹:', B[0], 'Down, up, divide: the right half of row 1.', `Start from ${'[A | I]'}: clear the number under the first pivot, then the one above the second, then divide.`),
+ rowBoxes('second row of A⁻¹:', B[1], `A⁻¹ = [${B[0].map(fracTxt).join(' ')}; ${B[1].map(fracTxt).join(' ')}].`, 'Check: A times your A⁻¹ must give I.'),
+ ]),
+ };
+ }), done, 'Chapter practice · set 2 of 4') }],
+ ['final3', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, THREEQ.map((q, k) => {
+ const B = invOf(q.A);
+ return {
+ id: `p-three${k + 1}`, prompt: ['Find ', $m('A', E('−1')), ' for ', $m('A'), ' = ', augEl(q.A, 3), '.'],
+ build: blanks(B.map((r, i) => rowBoxes(`row ${i + 1} of A⁻¹:`, r, i === 2 ? q.why : 'Right.', 'Write [A | I]; zeros below the pivots, zeros above, then divide each row by its pivot.'))),
+ };
+ }), done, 'Chapter practice · set 3 of 4') }],
+ ['final4', 'Chapter practice', () => {
+ const p = panel(0);
+ title(p, 'Choose the multiplier');
+ S.tb = table2(p, I2, { rows: HANDQ[0].rows });
+ }, { ask: done => quiz(LEFT, HANDQ.map((q, k) => ({
+ id: `p-hand${k + 1}`, prompt: ['Set ℓ to clear ', q.what, ', and watch the plane.'],
+ build: (body, api) => {
+ const t = S.tb.t; t.load(q.rows); t.open(q.i, q.j);
+ return gjTask(t, v => Math.abs(v[`c${q.i}${q.j}`]) < 1e-9, `ℓ = ${fracTxt(q.rows[q.i][q.j])} ÷ ${fracTxt(q.rows[q.j][q.j])} = ${fracTxt(q.l)}.`,
+ v => `Row ${q.i + 1}, column ${q.j + 1} reads ${fracTxt(v[`c${q.i}${q.j}`])}, not 0. ℓ = (number to clear) ÷ (pivot).`, () => t.set({ l: q.l }))(body, api);
+ },
+ })), done, 'Chapter practice · set 4 of 4') }],
+ ['play', 'Playground', (m, D) => {
+ const p = panel(0);
+ title(p, 'Playground');
+ const { g, t } = S.tb = table2(p, EX2);
+ t.open(1, 0);
+ // three row operations to choose from (click, or keys 1–3); the open one's ℓ is live
+ const ops = [{ k: '1', words: 'row 2 − ℓ × row 1', act: () => t.open(1, 0) }, { k: '2', words: 'row 1 − ℓ × row 2', act: () => t.open(0, 1) }, { k: '3', words: 'divide each row by its pivot', act: () => {
+ const R = t.rows().map(r => { const pv = r.slice(0, 2).find(x => Math.abs(x) > 1e-9); return pv ? r.map(x => x / pv) : r; });
+ t.load(R); t.open(1, 0);
+ } }];
+ S.playOps = ops.map(({ k, words, act }, i) => {
+ const c = G(p, { x: 90, y: 412 + i * 56 });
+ const r = mk('rect', { x: 0, y: -36, width: 520, height: 50, rx: 12, fill: COL.chalk, 'fill-opacity': .08, stroke: COL.faint, 'stroke-width': 2 }, c);
+ T(c, k, { x: 22, y: -2, size: 26, fill: COL.dim, weight: 700, anchor: 'middle' });
+ T(c, words, { x: 50, y: -2, size: 26, fill: COL.chalk });
+ c.style.cursor = 'pointer';
+ c.addEventListener('click', () => { if (P.waiting && BEATS[P.i].id === 'play') { act(); t.live(true); } });
+ return { k, act };
+ });
+ S.sys = { get v() { return t.v; }, live: on => t.live(on), set: vals => t.set(vals) };
+ const hint = text(p, 'try: bring the plane home · make the right half A⁻¹', 1210, 870, m('go'), { size: 24, fill: COL.dim, anchor: 'middle' });
+ hide(hint, Math.min(m('go') + 9, D - .7), .6);
+ }, { ask: playAsk(() => S.sys, { pos: { x: 40, y: 578, w: 720, cls: 'side' }, tip: 'Pick a row operation (1, 2, 3), drag or arrow its ℓ, and watch the table and the plane. Nothing is marked.' }) }],
+ ['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],
+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
+
+// the playground's operation keys
+document.addEventListener('keydown', e => {
+ if (!P.waiting || BEATS[P.i]?.id !== 'play' || e.target.matches?.('input') || e.altKey || e.metaKey || e.ctrlKey) return;
+ const op = S.playOps?.find(o => o.k === e.key);
+ if (op) { e.preventDefault(); op.act(); S.tb.t.live(true); }
+});
+
+boot();
+</script>
+</body>
+</html>
diff --git a/site/linear-algebra/ch28/audio/en/alg.mp3 b/site/linear-algebra/ch28/audio/en/alg.mp3
new file mode 100644
index 0000000..0d97618
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/alg.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/elim.mp3 b/site/linear-algebra/ch28/audio/en/elim.mp3
new file mode 100644
index 0000000..bc76814
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/elim.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/final1.mp3 b/site/linear-algebra/ch28/audio/en/final1.mp3
new file mode 100644
index 0000000..95ef885
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/final1.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/final2.mp3 b/site/linear-algebra/ch28/audio/en/final2.mp3
new file mode 100644
index 0000000..dd712f8
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/final2.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/final3.mp3 b/site/linear-algebra/ch28/audio/en/final3.mp3
new file mode 100644
index 0000000..d55d864
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/final3.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/final4.mp3 b/site/linear-algebra/ch28/audio/en/final4.mp3
new file mode 100644
index 0000000..8630067
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/final4.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/find.mp3 b/site/linear-algebra/ch28/audio/en/find.mp3
new file mode 100644
index 0000000..0d0e231
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/find.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/finish.mp3 b/site/linear-algebra/ch28/audio/en/finish.mp3
new file mode 100644
index 0000000..5812cf6
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/finish.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/intro.mp3 b/site/linear-algebra/ch28/audio/en/intro.mp3
new file mode 100644
index 0000000..3d2d0ad
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/intro.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/lost2.mp3 b/site/linear-algebra/ch28/audio/en/lost2.mp3
new file mode 100644
index 0000000..7a805c3
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/lost2.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/many.mp3 b/site/linear-algebra/ch28/audio/en/many.mp3
new file mode 100644
index 0000000..cc18e76
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/many.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/missed.mp3 b/site/linear-algebra/ch28/audio/en/missed.mp3
new file mode 100644
index 0000000..aff7cf7
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/missed.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/play.mp3 b/site/linear-algebra/ch28/audio/en/play.mp3
new file mode 100644
index 0000000..788fbb4
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/play.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/prod.mp3 b/site/linear-algebra/ch28/audio/en/prod.mp3
new file mode 100644
index 0000000..b5094eb
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/prod.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/q1.mp3 b/site/linear-algebra/ch28/audio/en/q1.mp3
new file mode 100644
index 0000000..223dbb7
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/q1.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/q2.mp3 b/site/linear-algebra/ch28/audio/en/q2.mp3
new file mode 100644
index 0000000..bf8f257
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/q2.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/q3.mp3 b/site/linear-algebra/ch28/audio/en/q3.mp3
new file mode 100644
index 0000000..acb8f1f
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/q3.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/q4.mp3 b/site/linear-algebra/ch28/audio/en/q4.mp3
new file mode 100644
index 0000000..db2daac
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/q4.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/test.mp3 b/site/linear-algebra/ch28/audio/en/test.mp3
new file mode 100644
index 0000000..cbc49ff
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/test.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/three.mp3 b/site/linear-algebra/ch28/audio/en/three.mp3
new file mode 100644
index 0000000..afaa5b5
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/three.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/timings.js b/site/linear-algebra/ch28/audio/en/timings.js
new file mode 100644
index 0000000..3addad6
--- /dev/null
+++ b/site/linear-algebra/ch28/audio/en/timings.js
@@ -0,0 +1,828 @@
+window.TIMINGS = {
+ "intro": {
+ "dur": 13.8,
+ "marks": {
+ "sub": 3.646,
+ "move": 6.172
+ },
+ "cues": [
+ [
+ 0.104,
+ "Chapter twenty-eight."
+ ],
+ [
+ 1.615,
+ "Matrices with no inverse."
+ ],
+ [
+ 3.646,
+ "Not every matrix can be undone."
+ ],
+ [
+ 6.172,
+ "This chapter gives the test that tells them apart, and then undoes two matrices, one after the other."
+ ]
+ ]
+ },
+ "test": {
+ "dur": 37.368,
+ "marks": {
+ "cols": 6.016,
+ "go": 14.961,
+ "x": 17.839,
+ "ax": 21.081,
+ "test": 29.505
+ },
+ "cues": [
+ [
+ 0.091,
+ "Take A equals one, three in the first row, and two, six in the second."
+ ],
+ [
+ 6.016,
+ "Look at its columns: one, two, and three, six."
+ ],
+ [
+ 10.69,
+ "The second is three times the first."
+ ],
+ [
+ 13.516,
+ "Both lie on one line."
+ ],
+ [
+ 14.961,
+ "So A squashes the whole plane onto that line."
+ ],
+ [
+ 17.839,
+ "Now take x equals three, minus one."
+ ],
+ [
+ 21.081,
+ "A x is three times column one, minus column two: three minus three, and six minus six."
+ ],
+ [
+ 28.229,
+ "Zero, zero."
+ ],
+ [
+ 29.505,
+ "Here is the test."
+ ],
+ [
+ 30.911,
+ "If some x that is not zero has A x equal to zero, then A has no inverse."
+ ]
+ ]
+ },
+ "why": {
+ "dur": 38.304,
+ "marks": {
+ "sup": 2.109,
+ "mul": 4.206,
+ "left": 9.609,
+ "right": 13.659,
+ "so": 20.495,
+ "but": 22.383,
+ "pic": 29.258
+ },
+ "cues": [
+ [
+ 0.104,
+ "Why does that rule out an inverse?"
+ ],
+ [
+ 2.109,
+ "Suppose A inverse did exist."
+ ],
+ [
+ 4.206,
+ "Start from A x equals zero, and multiply both sides by A inverse."
+ ],
+ [
+ 9.609,
+ "On the left, A inverse times A x is just x."
+ ],
+ [
+ 13.659,
+ "On the right, A inverse times zero is zero: any matrix times zero is zero."
+ ],
+ [
+ 20.495,
+ "So x would have to be zero."
+ ],
+ [
+ 22.383,
+ "But x is three, minus one, not zero."
+ ],
+ [
+ 26.016,
+ "That's impossible, so there is no A inverse."
+ ],
+ [
+ 29.258,
+ "In the picture: x and the origin both land on zero, zero."
+ ],
+ [
+ 34.18,
+ "An inverse would have to send zero back to both of them at once."
+ ]
+ ]
+ },
+ "lost2": {
+ "dur": 34.2,
+ "marks": {
+ "A": 1.484,
+ "cols": 7.044,
+ "x": 12.969,
+ "ax": 15.417,
+ "line": 22.044,
+ "no": 31.901
+ },
+ "cues": [
+ [
+ 0.091,
+ "A second example."
+ ],
+ [
+ 1.484,
+ "A is two, minus two in the first row, and minus one, one in the second."
+ ],
+ [
+ 7.044,
+ "Column two is minus one times column one: again, both columns lie on one line."
+ ],
+ [
+ 12.969,
+ "Try x equals one, one."
+ ],
+ [
+ 15.417,
+ "Two minus two is zero, and minus one plus one is zero."
+ ],
+ [
+ 20.456,
+ "A x is zero."
+ ],
+ [
+ 22.044,
+ "And not only one, one."
+ ],
+ [
+ 23.659,
+ "Two, two, and minus one, minus one: every point on this red line lands on zero."
+ ],
+ [
+ 30.247,
+ "The whole line is lost."
+ ],
+ [
+ 31.901,
+ "So this A has no inverse either."
+ ]
+ ]
+ },
+ "many": {
+ "dur": 23.232,
+ "marks": {
+ "pt": 2.148,
+ "slide": 6.797,
+ "same": 11.745,
+ "fold": 15.104
+ },
+ "cues": [
+ [
+ 0.104,
+ "Something stronger is true."
+ ],
+ [
+ 2.148,
+ "Take any point, say one, zero."
+ ],
+ [
+ 4.492,
+ "A sends it to two, minus one."
+ ],
+ [
+ 6.797,
+ "Now slide it along the lost direction: to two, one, then three, two."
+ ],
+ [
+ 11.745,
+ "They all land on the same point, two, minus one."
+ ],
+ [
+ 15.104,
+ "A folds each of these lines onto a single point."
+ ],
+ [
+ 18.711,
+ "Many points, one landing spot."
+ ],
+ [
+ 20.924,
+ "No matrix can unfold that."
+ ]
+ ]
+ },
+ "missed": {
+ "dur": 25.824,
+ "marks": {
+ "off": 1.693,
+ "never": 4.792,
+ "ch14": 12.227,
+ "both": 19.036
+ },
+ "cues": [
+ [
+ 0.104,
+ "And there's a second problem."
+ ],
+ [
+ 1.693,
+ "Take b equals one, one, off the line."
+ ],
+ [
+ 4.792,
+ "No x lands there, because everything lands on the line."
+ ],
+ [
+ 8.372,
+ "So A x equals one, one has no solution at all."
+ ],
+ [
+ 12.227,
+ "That's the question from chapter fourteen: when the columns lie on one line, not every b can be reached."
+ ],
+ [
+ 19.036,
+ "So a matrix with no inverse fails twice: some points collide, and some points are never reached."
+ ]
+ ]
+ },
+ "find": {
+ "dur": 55.032,
+ "marks": {
+ "look": 1.745,
+ "mix": 11.211,
+ "x": 15.781,
+ "chk": 18.685,
+ "ex2": 26.979,
+ "x2": 37.344,
+ "chk2": 43.216,
+ "any": 50.052
+ },
+ "cues": [
+ [
+ 0.104,
+ "How do you find such an x?"
+ ],
+ [
+ 1.745,
+ "Compare the columns."
+ ],
+ [
+ 3.216,
+ "In A equals two, four in the first row, and one, two in the second, column two is two times column one."
+ ],
+ [
+ 11.211,
+ "So two of column one, minus one of column two, is zero."
+ ],
+ [
+ 15.781,
+ "That's x equals two, minus one."
+ ],
+ [
+ 18.685,
+ "Check by rows: two times two, minus four, is zero."
+ ],
+ [
+ 23.32,
+ "And one times two, minus two, is zero."
+ ],
+ [
+ 26.979,
+ "Another one: three, minus six in the first row, and one, minus two in the second."
+ ],
+ [
+ 33.724,
+ "Column two is minus two times column one."
+ ],
+ [
+ 37.344,
+ "So x is minus two, minus one."
+ ],
+ [
+ 40.143,
+ "Or, turning both signs around, two, one."
+ ],
+ [
+ 43.216,
+ "Check: three times two, minus six, is zero, and two minus two is zero."
+ ],
+ [
+ 50.052,
+ "And any multiple of x works too: the whole line through it is lost."
+ ]
+ ]
+ },
+ "q1": {
+ "dur": 4.032,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn."
+ ],
+ [
+ 1.042,
+ "Drag a column tip so the whole plane goes flat."
+ ]
+ ]
+ },
+ "q2": {
+ "dur": 5.28,
+ "marks": {},
+ "cues": [
+ [
+ 0.091,
+ "Quick check."
+ ],
+ [
+ 1.133,
+ "Find a point, not zero, that A sends to zero."
+ ]
+ ]
+ },
+ "elim": {
+ "dur": 36.144,
+ "marks": {
+ "A": 2.76,
+ "step": 6.55,
+ "zero": 9.401,
+ "pivot": 12.695,
+ "stuck": 16.432,
+ "three": 22.565,
+ "t2": 28.906,
+ "t3": 33.177
+ },
+ "cues": [
+ [
+ 0.104,
+ "Elimination finds the same thing."
+ ],
+ [
+ 2.76,
+ "Take one, three, two, six again, and write it next to I."
+ ],
+ [
+ 6.55,
+ "Row two minus two times row one."
+ ],
+ [
+ 9.401,
+ "The left half of row two becomes zero, zero."
+ ],
+ [
+ 12.695,
+ "There is no second pivot, and no row below to swap in."
+ ],
+ [
+ 16.432,
+ "The left half can never become I, so Gauss\u2013Jordan stops: no inverse."
+ ],
+ [
+ 22.565,
+ "Three tests, one answer."
+ ],
+ [
+ 24.544,
+ "a d minus b c is six minus six, zero."
+ ],
+ [
+ 28.906,
+ "A x is zero for x equals three, minus one."
+ ],
+ [
+ 33.177,
+ "And elimination finds a zero row."
+ ]
+ ]
+ },
+ "three": {
+ "dur": 50.04,
+ "marks": {
+ "A": 2.539,
+ "cols": 9.128,
+ "x": 13.854,
+ "ax": 19.427,
+ "elim": 31.419,
+ "elim2": 37.305,
+ "no": 42.161
+ },
+ "cues": [
+ [
+ 0.104,
+ "The same happens in three by three."
+ ],
+ [
+ 2.539,
+ "A is one, zero, one; two, one, three; and zero, one, one."
+ ],
+ [
+ 9.128,
+ "Look closely: column three is column one plus column two."
+ ],
+ [
+ 13.854,
+ "So x equals one, one, minus one gives A x equals zero."
+ ],
+ [
+ 19.427,
+ "Row one: one plus zero minus one, zero."
+ ],
+ [
+ 23.385,
+ "Row two: two plus one minus three, zero."
+ ],
+ [
+ 27.344,
+ "Row three: zero plus one minus one, zero."
+ ],
+ [
+ 31.419,
+ "Elimination agrees."
+ ],
+ [
+ 33.021,
+ "Row two minus two times row one gives zero, one, one."
+ ],
+ [
+ 37.305,
+ "Then row three minus row two gives zero, zero, zero."
+ ],
+ [
+ 42.161,
+ "A zero row, only two pivots: no inverse."
+ ],
+ [
+ 45.977,
+ "In space, this A squashes everything onto one plane."
+ ]
+ ]
+ },
+ "q3": {
+ "dur": 3.12,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.133,
+ "Which of these have an inverse?"
+ ]
+ ]
+ },
+ "prod": {
+ "dur": 45.264,
+ "marks": {
+ "socks": 5.234,
+ "off": 10.404,
+ "B": 16.432,
+ "A": 20.586,
+ "undoA": 26.445,
+ "undoB": 32.786,
+ "rule": 36.589
+ },
+ "cues": [
+ [
+ 0.104,
+ "Now the other side: when A and B both have inverses, so does A times B."
+ ],
+ [
+ 5.234,
+ "Think of socks and shoes."
+ ],
+ [
+ 7.279,
+ "In the morning you put on your socks, then your shoes."
+ ],
+ [
+ 10.404,
+ "In the evening you take off the shoes first, then the socks."
+ ],
+ [
+ 14.05,
+ "The last thing on is the first thing off."
+ ],
+ [
+ 16.432,
+ "Matrices work the same way."
+ ],
+ [
+ 18.555,
+ "First, B shears the plane."
+ ],
+ [
+ 20.586,
+ "Then A turns it."
+ ],
+ [
+ 21.693,
+ "Together that's A B: B acts first, so it stands on the right."
+ ],
+ [
+ 26.445,
+ "To undo, first undo the turn, with A inverse."
+ ],
+ [
+ 30.56,
+ "The plane is back to just the shear."
+ ],
+ [
+ 32.786,
+ "Then undo the shear, with B inverse."
+ ],
+ [
+ 35.807,
+ "Home."
+ ],
+ [
+ 36.589,
+ "So the inverse of A B is B inverse times A inverse."
+ ],
+ [
+ 40.768,
+ "A inverse acts first, so it stands on the right."
+ ],
+ [
+ 44.18,
+ "Reverse order."
+ ]
+ ]
+ },
+ "wrong": {
+ "dur": 21.408,
+ "marks": {
+ "start": 2.383,
+ "ub": 4.271,
+ "ua": 7.474,
+ "look": 10.508
+ },
+ "cues": [
+ [
+ 0.104,
+ "What if we undo them in the wrong order?"
+ ],
+ [
+ 2.383,
+ "Start again from A B."
+ ],
+ [
+ 4.271,
+ "Undo the shear first, with B inverse."
+ ],
+ [
+ 7.474,
+ "Then undo the turn, with A inverse."
+ ],
+ [
+ 10.508,
+ "The plane is not home."
+ ],
+ [
+ 11.927,
+ "The flag is somewhere else."
+ ],
+ [
+ 13.62,
+ "A inverse times B inverse is not the inverse of A B."
+ ],
+ [
+ 17.539,
+ "Order matters, just as A B and B A are different."
+ ]
+ ]
+ },
+ "alg": {
+ "dur": 40.248,
+ "marks": {
+ "mul": 1.497,
+ "inner": 5.521,
+ "gone": 8.177,
+ "last": 9.57,
+ "nums": 11.654,
+ "e1": 21.875,
+ "e2": 27.174,
+ "e3": 30.052,
+ "e4": 34.935,
+ "I": 37.63
+ },
+ "cues": [
+ [
+ 0.104,
+ "Check it with algebra."
+ ],
+ [
+ 1.497,
+ "Multiply A B by B inverse A inverse."
+ ],
+ [
+ 5.521,
+ "In the middle, B times B inverse is I."
+ ],
+ [
+ 8.177,
+ "A times I is A, and A times A inverse is I."
+ ],
+ [
+ 11.654,
+ "And with numbers."
+ ],
+ [
+ 12.982,
+ "A B is zero, minus one, one, one."
+ ],
+ [
+ 16.68,
+ "B inverse A inverse is one, one, minus one, zero."
+ ],
+ [
+ 21.875,
+ "Row zero, minus one, times column one, minus one: one."
+ ],
+ [
+ 27.174,
+ "Times column one, zero: zero."
+ ],
+ [
+ 30.052,
+ "Row one, one, times column one, minus one: zero."
+ ],
+ [
+ 34.935,
+ "And times one, zero: one."
+ ],
+ [
+ 37.63,
+ "The identity."
+ ],
+ [
+ 38.711,
+ "Reverse order works."
+ ]
+ ]
+ },
+ "q4": {
+ "dur": 3.024,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.198,
+ "Find the inverse of a product."
+ ]
+ ]
+ },
+ "wrap": {
+ "dur": 31.752,
+ "marks": {
+ "w1": 1.016,
+ "w2": 6.693,
+ "w3": 13.294,
+ "w4": 20.898,
+ "end": 29.557
+ },
+ "cues": [
+ [
+ 0.104,
+ "To sum up."
+ ],
+ [
+ 1.016,
+ "A has no inverse when some x, not zero, has A x equal to zero."
+ ],
+ [
+ 6.693,
+ "Then the columns lie on one line, or in one plane: the grid goes flat, and points collide."
+ ],
+ [
+ 13.294,
+ "Elimination shows it as a zero row."
+ ],
+ [
+ 16.654,
+ "For two by two, a d minus b c is zero."
+ ],
+ [
+ 20.898,
+ "When A and B have inverses, the inverse of A B is B inverse times A inverse: reverse order, like socks and shoes."
+ ],
+ [
+ 29.557,
+ "Now try the chapter practice."
+ ]
+ ]
+ },
+ "final1": {
+ "dur": 3.528,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Chapter practice."
+ ],
+ [
+ 1.55,
+ "Which matrices have an inverse?"
+ ]
+ ]
+ },
+ "final2": {
+ "dur": 2.424,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Next, find the lost direction."
+ ]
+ ]
+ },
+ "final3": {
+ "dur": 1.968,
+ "marks": {},
+ "cues": [
+ [
+ 0.091,
+ "Now, inverses of products."
+ ]
+ ]
+ },
+ "final4": {
+ "dur": 2.472,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Last set."
+ ],
+ [
+ 1.224,
+ "Use your hands."
+ ]
+ ]
+ },
+ "play": {
+ "dur": 13.32,
+ "marks": {
+ "go": 4.18
+ },
+ "cues": [
+ [
+ 0.104,
+ "Playground."
+ ],
+ [
+ 1.094,
+ "Nothing here is marked right or wrong."
+ ],
+ [
+ 4.18,
+ "Change A, and watch its inverse."
+ ],
+ [
+ 6.641,
+ "Make the plane flat, then drag x onto the red line, and watch A x."
+ ],
+ [
+ 11.667,
+ "Press continue when you're done."
+ ]
+ ]
+ },
+ "finish": {
+ "dur": 10.512,
+ "marks": {},
+ "cues": [
+ [
+ 0.091,
+ "Well done."
+ ],
+ [
+ 1.094,
+ "That's the end of chapter twenty-eight, matrices with no inverse, and the end of Unit three."
+ ],
+ [
+ 7.422,
+ "Next: factoring A into L times U."
+ ]
+ ]
+ }
+};
diff --git a/site/linear-algebra/ch28/audio/en/why.mp3 b/site/linear-algebra/ch28/audio/en/why.mp3
new file mode 100644
index 0000000..3d1e0e7
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/why.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/wrap.mp3 b/site/linear-algebra/ch28/audio/en/wrap.mp3
new file mode 100644
index 0000000..06fe32a
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/wrap.mp3 differ
diff --git a/site/linear-algebra/ch28/audio/en/wrong.mp3 b/site/linear-algebra/ch28/audio/en/wrong.mp3
new file mode 100644
index 0000000..2b15d5e
Binary files /dev/null and b/site/linear-algebra/ch28/audio/en/wrong.mp3 differ
diff --git a/site/linear-algebra/ch28/index.html b/site/linear-algebra/ch28/index.html
new file mode 100644
index 0000000..4293ee8
--- /dev/null
+++ b/site/linear-algebra/ch28/index.html
@@ -0,0 +1,451 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>Matrices with No Inverse</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/grid2.js"></script>
+<script src="../lib/inv.js"></script>
+<script src="../lib/play.js"></script>
+<script src="audio/en/timings.js"></script>
+<script>
+'use strict';
+const CHAPTER = { number: 28, title: 'Matrices with No Inverse', minutes: 9, language: 'en' };
+
+/* ---------- layout and colours ---------- */
+const COLC = [COL.irr, COL.real, COL.rat];
+const LEFT = { x: 40, y: 430, w: 720, cls: 'side' };
+const TOPL = { x: 40, y: 190, w: 760, cls: 'side' };
+const I2 = [[1, 0], [0, 1]];
+const A1 = [[1, 3], [2, 6]], A2 = [[2, -2], [-1, 1]];
+const SHEAR = [[1, 1], [0, 1]], TURN = [[0, -1], [1, 0]], AB = [[0, -1], [1, 1]], ABI = [[1, 1], [-1, 0]];
+const ZOOM = { u: 60, x0: -5, x1: 5, y0: -5, y1: 5 };
+const INV = ['A', E('−1')], BINV = ['B', E('−1')];
+
+/* ---------- 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 title = (p, str) => text(p, str, 60, 110, .2, { size: 40, weight: 600 });
+const keysOf = (A, k = 'a') => ({ [k + '00']: A[0][0], [k + '01']: A[0][1], [k + '10']: A[1][0], [k + '11']: A[1][1] });
+const mat = (p, A, x, y, t0, { size = 44, name = 'A' } = {}) => { const m = ivMat(p, A, { x, y, size, name, fill: (i, j) => COLC[j], o: 0 }); show(m.g, t0, .4); return m; };
+const dotAt = (P2, [x, y], into, t0, { r = 9, color = COL.chalk, label = null, dx = 14, dy = -14 } = {}) => {
+ const d = G(into, { x: P2.PX(x), y: P2.PY(y), o: 0 });
+ mk('circle', { r, fill: color, stroke: COL.board, 'stroke-width': 2 }, d);
+ if (label) T(d, label, { x: dx, y: dy, size: 22, fill: color, font: MATH });
+ show(d, t0, .3); return d;
+};
+// a dot that starts at p and slides to where A sends it
+const land = (P2, A, p, into, t0, t1, opts = {}) => { const d = dotAt(P2, p, into, t0, opts); const [X, Y] = ivMul(A, [[p[0]], [p[1]]]).map(r => r[0]); tw(d, { x: P2.PX(X), y: P2.PY(Y) }, t1, 1.4); if (opts.label) hide(d.lastChild, t1 + 1.8, .3); return d; }; // its label goes once it has landed
+const ringAt = (P2, [x, y], color, into, t0, label, { dx = 20, dy = -18, anchor = 'start' } = {}) => {
+ const g = G(into, { x: P2.PX(x), y: P2.PY(y), o: 0 });
+ mk('circle', { r: 17, fill: 'none', stroke: color, 'stroke-width': 3, 'stroke-dasharray': '5 5' }, g);
+ if (label) T(g, label, { x: dx, y: dy, size: 22, fill: color, font: MATH, anchor });
+ show(g, t0, .4);
+ return g;
+};
+function matEl(rows, { size = 24 } = {}) {
+ 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: COLC[j], font: MATH, anchor: 'middle' })));
+ return svg;
+}
+const rot = d => { const a = d * Math.PI / 180, k = n => Math.round(n * 1e9) / 1e9; return [[k(Math.cos(a)), k(-Math.sin(a))], [k(Math.sin(a)), k(Math.cos(a))]]; };
+const isI = T2 => Math.abs(T2[0][0] - 1) < 1e-9 && Math.abs(T2[0][1]) < 1e-9 && Math.abs(T2[1][0]) < 1e-9 && Math.abs(T2[1][1] - 1) < 1e-9;
+const flat = v => Math.abs(v.a00 * v.a11 - v.a01 * v.a10) < 1e-9 && (v.a00 || v.a01 || v.a10 || v.a11);
+
+/* ---------- practice data ---------- */
+const YESNO = [['y', 'Has an inverse', COL.good, 'Y'], ['n', 'No inverse', COL.bad, 'N']];
+const WHICHQ = [
+ { A: [[2, 4], [3, 6]], ans: ['n'], why: 'Column 2 = 2 × column 1; x = (2, −1) gives Ax = 0.' },
+ { A: [[1, 2], [2, 1]], ans: ['y'], why: 'ad − bc = 1 − 4 = −3, not zero.' },
+ { A: [[0, 0], [3, 1]], ans: ['n'], why: 'A row of zeros: x = (1, −3) gives Ax = 0.' },
+ { A: [[1, 1, 0], [0, 1, 1], [1, 2, 1]], ans: ['n'], why: 'Row 3 = row 1 + row 2: elimination gives a zero row. (x = (1, −1, 1) gives Ax = 0.)' },
+ { A: [[2, 0, 0], [0, 3, 0], [0, 0, 1]], ans: ['y'], why: 'Three pivots 2, 3, 1: divide by each.' },
+ { A: [[3, 1], [6, 2]], ans: ['n'], why: 'Row 2 = 2 × row 1: ad − bc = 6 − 6 = 0.' },
+];
+const LOSTQ = [
+ { A: [[1, 2], [3, 6]], x: [2, -1] }, { A: [[2, 6], [1, 3]], x: [3, -1] }, { A: [[4, -2], [2, -1]], x: [1, 2] },
+ { A: [[0, 1], [0, 3]], x: [1, 0] }, { A: [[1, 0, 1], [0, 1, 1], [1, 1, 2]], x: [1, 1, -1] },
+];
+const PRODQ = [
+ { Ai: [[1, 1], [0, 1]], Bi: [[2, 0], [0, 1]] },
+ { Ai: [[0, 1], [1, 0]], Bi: [[1, 0], [2, 1]] },
+];
+
+/* ---------- beats: [id, title, run(m, D), { ask }?] ---------- */
+const BEATS = [
+ ['intro', 'Matrices with no inverse', (m, D) => {
+ const g = G(scene, { o: 0, y: 24 });
+ T(g, 'Unit 3, Chapter 28', { x: 800, y: 250, size: 28, fill: COL.dim, anchor: 'middle' });
+ T(g, 'Matrices with No Inverse', { x: 800, y: 360, size: 80, weight: 600, anchor: 'middle' });
+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);
+ const r = text(scene, 'when the plane goes flat, nothing brings it back', 800, 450, m('sub'), { size: 36, fill: COL.dim, anchor: 'middle' });
+ const sm = G(scene, { o: 0 });
+ const k = grid2(sm, { A: I2, mat: null, shape: true, units: false, plane: { cx: 800, cy: 690, u: 30, x0: -5, x1: 5, y0: -3, y1: 3, labels: false } });
+ put(k.parts.cols, { o: 0 });
+ show(sm, m('sub') + .5, .6);
+ k.to(keysOf([[1, .5], [.5, .25]]), m('sub') + 1.2, 2.2);
+ k.to(keysOf(I2), m('move') + .2, .8); k.to(keysOf([[1, 1], [0, 1]]), m('move') + 1.4, 1.2); k.to(keysOf(I2), m('move') + 3, 1.2);
+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(sm, D - .9, .8);
+ }],
+
+ ['test', 'The test: Ax = 0', (m) => {
+ const p = panel(0);
+ title(p, 'The test: some x ≠ 0 with Ax = 0');
+ const g = S.g = grid2(p, { A: I2, mat: null, shape: true });
+ g.labels(['col 1', 'col 2']);
+ put(g.parts.cols, { o: 0 }); show(g.parts.cols, m('go') + 1.6, .4);
+ const ma = mat(p, A1, 90, 250, .4);
+ ma.cells.forEach((r, i) => r.forEach(c => { put(c.g.parentNode, { o: 0 }); show(c.g.parentNode, 1.4 + i * 2, .4); }));
+ const ca = G(p, {});
+ g.P.arrow(0, 0, 1, 2, COLC[0], m('cols') + .8, { into: ca }); g.P.arrow(0, 0, 3, 6, COLC[1], m('cols') + 2.6, { into: ca });
+ draw(path(ca, `M${g.P.PX(-3)} ${g.P.PY(-6)}L${g.P.PX(3.2)} ${g.P.PY(6.4)}`, { stroke: COL.chalk, 'stroke-width': 2.5, 'stroke-dasharray': '8 8' }, { d: 0 }), m('cols') + 4.6, 1.4);
+ hide(ca, m('go') + 1.6, .3);
+ text(p, 'column 2 = 3 × column 1: one line', 90, 450, m('cols') + 2.4, { size: 28, weight: 600 });
+ g.to(keysOf(A1), m('go') + .2, 2.4);
+ const x = dotAt(g.P, [3, -1], p, m('x'), { label: 'x = (3, −1)', dx: 14, dy: 30 });
+ const ar = G(p, {});
+ g.P.arrow(0, 0, 3, 6, COLC[0], m('ax') + .6, { into: ar }); g.P.arrow(3, 6, 0, 0, COLC[1], m('ax') + 2.6, { into: ar });
+ hide(ar, m('test') - .3, .3);
+ const ax1 = say(p, ['A x = 3·(1, 2) − 1·(3, 6)'], 90, 520, m('ax') + .4, { size: 30 });
+ say(p, ['= (3 − 3, 6 − 6) = (0, 0)'], 90 + ax1._w + 12, 520, m('ax') + 5.4, { size: 30 });
+ const c = dotAt(g.P, [3, -1], p, m('ax') + 4.5, { r: 7 }); tw(c, { x: g.P.PX(0), y: g.P.PY(0) }, m('ax') + 5, 1.2);
+ const rule = G(p, { o: 0 });
+ mk('rect', { x: 70, y: 590, width: 690, height: 120, rx: 16, fill: 'none', stroke: COL.chalk, 'stroke-width': 3 }, rule);
+ M(rule, ['some x ≠ 0 with A x = 0'], { x: 100, y: 640, size: 34, anchor: 'start' });
+ M(rule, ['→ A has no inverse'], { x: 100, y: 690, size: 34, fill: COL.bad, anchor: 'start' });
+ show(rule, m('test') + .6, .5);
+ }],
+
+ ['why', 'Why there is no inverse', (m) => {
+ const p = panel(0);
+ title(p, 'Why: suppose A⁻¹ existed');
+ const g = S.g = grid2(p, { A: A1, mat: null, shape: false, lost: true });
+ put(g.parts.lost, { o: 0 }); show(g.parts.lost, m('pic'), .4);
+ text(p, 'suppose A⁻¹ exists …', 90, 220, m('sup') + .3, { size: 30, fill: COL.dim });
+ say(p, ['A x = 0'], 90, 300, m('mul') + .2, { size: 40 });
+ say(p, [...INV, ' A x = ', ...INV, ' 0'], 90, 375, m('mul') + 2.4, { size: 40 });
+ const hb = (x, w, t0, t1) => { const r = mk('rect', { x, y: 336, width: w, height: 54, rx: 10, fill: COL.chalk }, p); put(r, { o: 0 }); tw(r, { o: .14 }, t0, .3); tw(r, { o: 0 }, t1, .3); };
+ hb(80, 175, m('left') + .1, m('right')); hb(262, 120, m('right') + .1, m('so'));
+ say(p, ['x'], 90, 450, m('left') + .8, { size: 40 });
+ say(p, [' = 0'], 112, 450, m('right') + 1.4, { size: 40 });
+ const so = G(p, { o: 0 }); mk('rect', { x: 76, y: 408, width: 150, height: 60, rx: 12, fill: 'none', stroke: COL.chalk, 'stroke-width': 3 }, so); show(so, m('so') + .2, .3);
+ text(p, 'but x = (3, −1) is not 0: impossible', 90, 540, m('but') + .4, { size: 30, fill: COL.bad, weight: 600 });
+ text(p, 'so A has no inverse', 90, 600, m('but') + 4, { size: 30, weight: 600 });
+ const { PX, PY } = g.P;
+ dotAt(g.P, [0, 0], p, m('pic') + .3);
+ land(g.P, A1, [3, -1], p, m('pic') + .8, m('pic') + 1.6, { label: '(3, −1)', dx: 12, dy: 28 });
+ const q = G(p, {});
+ draw(path(q, `M${PX(0)} ${PY(0)}Q${PX(1)} ${PY(-2.6)} ${PX(2.8)} ${PY(-1.2)}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' }, { d: 0 }), m('pic') + 4, .8);
+ draw(path(q, `M${PX(0)} ${PY(0)}Q${PX(-1.4)} ${PY(-1.2)} ${PX(-.25)} ${PY(-.3)}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' }, { d: 0 }), m('pic') + 5, .8);
+ const qm = T(q, '?', { x: PX(1.2), y: PY(-2.3), size: 44, fill: COL.chalk, weight: 700, o: 0 }); show(qm, m('pic') + 5.4, .3);
+ }],
+
+ ['lost2', 'A second example', (m) => {
+ const p = panel(0);
+ title(p, 'Another one: A = [2 −2; −1 1]');
+ const g = S.g = grid2(p, { A: I2, mat: null, shape: true, lost: true });
+ g.labels(['col 1', 'col 2']);
+ put(g.parts.lost, { o: 0 });
+ mat(p, A2, 90, 250, m('A'));
+ g.to(keysOf(A2), m('A') + 1.5, 2.4);
+ text(p, 'column 2 = −1 × column 1', 90, 450, m('cols') + 1, { size: 28, weight: 600 });
+ land(g.P, A2, [1, 1], p, m('x'), m('ax') + 3.2, { label: 'x = (1, 1)', dx: 14, dy: -14 });
+ say(p, ['A x = (2 − 2, −1 + 1) = (0, 0)'], 90, 520, m('ax') + .4, { size: 30 });
+ show(g.parts.lost, m('line') + .2, .5);
+ const dots = G(p, {});
+ [[2, 2], [-1, -1], [3, 3], [-2, -2]].forEach((q, k) => land(g.P, A2, q, dots, m('line') + .8 + k * .5, m('line') + 4.4, { color: COL.bad, r: 7 }));
+ text(p, 'the red line all lands on (0, 0)', 90, 590, m('line') + 1, { size: 28, fill: COL.bad, weight: 600 });
+ text(p, 'no inverse', 90, 660, m('no') + .3, { size: 32, weight: 600 });
+ }],
+
+ ['many', 'Many points, one landing spot', (m) => {
+ const p = panel(0);
+ title(p, 'A folds whole lines onto points');
+ const g = S.g = grid2(p, { A: A2, mat: null, shape: false, lost: true });
+ g.labels(['col 1', 'col 2']);
+ mat(p, A2, 90, 250, .3);
+ const { PX, PY } = g.P;
+ const ln = path(p, `M${PX(-4)} ${PY(-5)}L${PX(6)} ${PY(5)}`, { stroke: COL.chalk, 'stroke-width': 2.5, 'stroke-dasharray': '8 8' }, { d: 0 });
+ draw(ln, m('slide'), 1.2);
+ const pts = [[1, 0], [2, 1], [3, 2]];
+ const ds = pts.map((q, k) => dotAt(g.P, q, p, k ? m('slide') + 1 + k * 1.2 : m('pt') + .3, { label: `(${q.map(num).join(', ')})`, dx: 12, dy: -14 }));
+ ringAt(g.P, [2, -1], COL.chalk, p, m('pt') + 1.6, '(2, −1)', { dx: 14, dy: 30 });
+ say(p, ['A·(1, 0) = (2, −1)'], 90, 450, m('pt') + 1.6, { size: 30 });
+ say(p, ['A·(2, 1) = (4 − 2, −2 + 1) = (2, −1)'], 90, 510, m('same') + .3, { size: 30 });
+ ds.forEach((d, k) => { hide(d.lastChild, m('same') + 1.3, .2); tw(d, { x: PX(2), y: PY(-1) }, m('same') + 1.5 + k * .4, 1.4); });
+ text(p, 'a whole line → one point', 90, 590, m('fold') + .3, { size: 30, weight: 600 });
+ text(p, 'no matrix can unfold it', 90, 640, m('fold') + 3.6, { size: 28, fill: COL.dim });
+ }],
+
+ ['missed', 'Some b are never reached', (m) => {
+ const p = panel(0);
+ title(p, 'And some points are never reached');
+ const g = S.g = grid2(p, { A: A2, mat: null, shape: false });
+ g.labels(['col 1', 'col 2']);
+ mat(p, A2, 90, 250, .3);
+ const { PX, PY } = g.P;
+ ringAt(g.P, [1, 1], COL.task, p, m('off') + .3, 'b = (1, 1)', { dx: 16, dy: -18 });
+ const im = path(p, `M${PX(-6)} ${PY(3)}L${PX(6)} ${PY(-3)}`, { stroke: COL.chalk, 'stroke-width': 6, 'stroke-opacity': .5 }, { d: 0 });
+ draw(im, m('never') + .3, 1.2);
+ text(p, 'every A x lands on this line', 90, 450, m('never') + 1, { size: 28, weight: 600 });
+ say(p, ['A x = (1, 1): no solution'], 90, 510, m('never') + 4, { size: 30, fill: COL.bad });
+ text(p, 'can we solve for every b? (chapter 14) — no', 90, 580, m('ch14') + .3, { size: 26, fill: COL.dim });
+ [[-1, 2], [3, 2], [-2, -3], [2, 4]].forEach((q, k) => ringAt(g.P, q, COL.task, p, m('ch14') + 2 + k * 1.1));
+ const run = dotAt(g.P, [-5, 2.5], p, m('ch14') + 1, { r: 9 }); tw(run, { x: g.P.PX(5), y: g.P.PY(-2.5) }, m('ch14') + 1.2, 5.6, lin); // A x can only run along the line
+ text(p, '1. some points collide (Ax = 0 for x ≠ 0)', 90, 660, m('both') + 2.6, { size: 28, weight: 600 });
+ text(p, '2. some points are never reached', 90, 710, m('both') + 4.4, { size: 28, weight: 600 });
+ }],
+
+ ['find', 'Finding the lost x', (m) => {
+ const p = panel(0);
+ title(p, 'How to find x: compare the columns');
+ const g = S.g = grid2(p, { A: I2, mat: null, shape: false, lost: true });
+ g.labels(['col 1', 'col 2']);
+ put(g.parts.lost, { o: 0 });
+ const F1 = [[2, 4], [1, 2]], F2 = [[3, -6], [1, -2]];
+ const m1 = mat(p, F1, 90, 250, m('look') + .3);
+ g.to(keysOf(F1), m('look') + .8, 2);
+ say(p, ['column 2 = 2 × column 1'], 90, 440, m('look') + 3, { size: 30 });
+ say(p, ['2·(2, 1) − 1·(4, 2) = (0, 0)'], 90, 500, m('mix') + .3, { size: 30 });
+ land(g.P, F1, [2, -1], p, m('x') + .2, m('chk') + .4, { label: 'x = (2, −1)', dx: 14, dy: 28 });
+ say(p, ['rows: 2·2 − 4 = 0, 1·2 − 2 = 0'], 90, 560, m('chk') + .6, { size: 28, fill: COL.good });
+ hide(m1.g, m('ex2') - .2, .3);
+ mat(p, F2, 90, 250, m('ex2') + .2);
+ g.to(keysOf(F2), m('ex2') + .8, 2);
+ say(p, ['column 2 = −2 × column 1'], 90, 640, m('ex2') + 4, { size: 30 });
+ say(p, ['x = (−2, −1) or (2, 1)'], 90, 700, m('x2') + .4, { size: 30 });
+ land(g.P, F2, [2, 1], p, m('x2') + 3.4, m('chk2') + .3, { label: '(2, 1)', dx: 14, dy: -14 });
+ say(p, ['rows: 3·2 − 6 = 0, 2 − 2 = 0'], 90, 760, m('chk2') + .5, { size: 28, fill: COL.good });
+ show(g.parts.lost, m('any') + .3, .5);
+ text(p, 'any multiple: the whole red line is lost', 90, 830, m('any') + .8, { size: 28, fill: COL.bad, weight: 600 });
+ }],
+
+ ['q1', 'Quick check', () => {
+ const p = panel(0);
+ title(p, 'Quick check');
+ const g = S.g = grid2(p, { A: [[1, 1], [2, -1]], mat: [90, 250], size: 46, shape: true, lost: true });
+ g.labels(['col 1', 'col 2']);
+ }, { ask: done => quiz(LEFT, [{
+ id: 'c-flat', prompt: ['Drag a column tip so that the whole plane goes flat (ad − bc = 0).'],
+ build: g2Task(S.g, flat, 'Both columns on one line: the plane falls onto it, and the red line of points lands on (0, 0).',
+ 'Put column 2 on the line through (0, 0) and column 1, (1, 2): at (2, 4), (−1, −2) or (0, 0) …', () => S.g.set({ a01: -1, a11: -2 }), ['A', 'cols']),
+ }], done) }],
+
+ ['q2', 'Quick check', () => {
+ const p = panel(0);
+ title(p, 'Quick check');
+ const g = S.g = grid2(p, { A: [[1, 2], [2, 4]], mat: [90, 250], size: 46, shape: false });
+ g.labels(['col 1', 'col 2']);
+ }, { ask: done => quiz(LEFT, [{
+ id: 'c-lost', prompt: ['Click a point ', $m('x'), ', not ', $m('(0, 0)'), ', that ', $m('A'), ' sends to ', $m('(0, 0)'), '.'],
+ build: pickPoint(S.g.P, [2, -1], (x, y) => `A·(${num(x)}, ${num(y)}) = (${num(x + 2 * y)}, ${num(2 * x + 4 * y)}). Every multiple of (2, −1) works.`,
+ (x, y) => !x && !y ? 'Not (0, 0) itself: we want x ≠ 0.' : `A·(${num(x)}, ${num(y)}) = (${num(x + 2 * y)}, ${num(2 * x + 4 * y)}), not (0, 0). Try x + 2y = 0, like (2, −1).`,
+ null, (x, y) => (x || y) && x + 2 * y === 0),
+ }], done) }],
+
+ ['elim', 'Elimination finds it too', (m) => {
+ const p = panel(0);
+ title(p, 'Gauss–Jordan gets stuck');
+ const g = grid2(p, { A: A1, mat: null, shape: true });
+ g.labels(['col 1', 'col 2']);
+ const t = gj(p, A1, { at: [120, 270], size: 42, link: g, t0: m('A') - .3 });
+ t.sub(1, 0, 2, m('step') + 1.6, 2, { lead: 1.4 });
+ t.ring(1, 0, m('zero') + .3, undefined, { color: COL.bad }); t.ring(1, 1, m('zero') + .6, undefined, { color: COL.bad });
+ text(p, 'no second pivot, no row to swap in', 90, 460, m('pivot') + .3, { size: 28, weight: 600 });
+ text(p, 'the left half can never become I', 90, 510, m('stuck') + .3, { size: 28, fill: COL.bad, weight: 600 });
+ t.block(0, m('stuck') + 1, m('three'), COL.bad);
+ say(p, ['1. ad − bc = 6 − 6 = 0'], 90, 600, m('three') + 1.5, { size: 30 });
+ say(p, ['2. A·(3, −1) = (0, 0)'], 90, 655, m('t2') + .2, { size: 30 });
+ say(p, ['3. a zero row'], 90, 710, m('t3') + .2, { size: 30 });
+ }],
+
+ ['three', 'Three by three', (m) => {
+ const p = panel(0);
+ title(p, 'The same in 3 × 3');
+ const A = [[1, 0, 1], [2, 1, 3], [0, 1, 1]];
+ const t = gj(p, A, { at: [200, 290], size: 46, right: false, t0: m('A') - .3 });
+ t.cells.forEach((r, i) => r.forEach(c => { put(c.g.parentNode, { o: 0 }); show(c.g.parentNode, m('A') + .8 + i * 1.6, .4); }));
+ [0, 1, 2].forEach(j => { const r = mk('rect', { x: t.cx(j) - 40, y: t.top - 4, width: 80, height: t.bot - t.top + 8, rx: 12, fill: COLC[j] }, p); p.insertBefore(r, p.firstChild); put(r, { o: 0 }); tw(r, { o: .2 }, m('cols') + .4 + j * .8, .3); tw(r, { o: 0 }, m('x'), .3); });
+ say(p, ['column 3 = column 1 + column 2'], 640, 300, m('cols') + 2.6, { size: 30 });
+ say(p, ['x = (1, 1, −1): A x = 0'], 640, 370, m('x') + .3, { size: 30 });
+ const span = (m('elim') - m('ax')) / 3;
+ ['row 1: 1 + 0 − 1 = 0', 'row 2: 2 + 1 − 3 = 0', 'row 3: 0 + 1 − 1 = 0'].forEach((s, k) => say(p, [s], 640, 440 + k * 50, m('ax') + .3 + k * span, { size: 28 }));
+ t.sub(1, 0, 2, m('elim') + 2.2, 1.4, { lead: 1.4 });
+ t.sub(2, 1, 1, m('elim2') + 1.4, 1.4, { lead: 1.1 });
+ t.done(m('no'));
+ const bad = mk('rect', { x: t.cx(0) - 44, y: t.ry(2) - 48, width: t.cx(2) - t.cx(0) + 88, height: 64, rx: 12, fill: 'none', stroke: COL.bad, 'stroke-width': 3 }, p); put(bad, { o: 0 }); show(bad, m('no') + .2, .3);
+ text(p, 'only two pivots: no inverse', 200, 600, m('no') + .5, { size: 30, fill: COL.bad, weight: 600 });
+ text(p, 'in space: everything lands on one plane', 200, 650, m('no') + 3.5, { size: 26, fill: COL.dim });
+ }],
+
+ ['q3', 'Quick check', () => {
+ const p = panel(0);
+ title(p, 'Quick check');
+ text(p, 'tests: some x ≠ 0 with Ax = 0 · a zero row · ad − bc = 0', 60, 160, .3, { size: 26, fill: COL.dim });
+ }, { ask: done => quiz(TOPL, [{
+ id: 'c-which', prompt: ['Which have an inverse?'],
+ build: grid([
+ { parts: [matEl([[1, 2], [3, 6]])], ans: ['n'], why: 'Column 2 = 2 × column 1.' },
+ { parts: [matEl([[2, 1], [1, 1]])], ans: ['y'], why: 'ad − bc = 2 − 1 = 1.' },
+ { parts: [matEl([[1, 0, 1], [0, 1, 1], [1, 1, 2]])], ans: ['n'], why: 'Column 3 = column 1 + column 2: x = (1, 1, −1) gives Ax = 0.' },
+ { parts: [matEl([[1, 0, 0], [0, 2, 0], [0, 0, 3]])], ans: ['y'], why: 'Three pivots, 1, 2 and 3.' },
+ ], YESNO, { multi: false, text: true }),
+ }], done) }],
+
+ ['prod', 'Socks and shoes', (m) => {
+ const p = panel(0);
+ title(p, 'Undoing two moves: socks and shoes');
+ const g = S.g = grid2(p, { A: I2, pre: I2, mat: null, shape: true, plane: ZOOM });
+ put(g.parts.cols, { o: 0 });
+ text(p, 'on: socks, then shoes', 90, 200, m('socks') + .5, { size: 30, weight: 600 });
+ text(p, 'off: shoes first, then socks', 90, 250, m('off') + .5, { size: 30, weight: 600 });
+ mat(p, SHEAR, 90, 370, m('B') + .2, { size: 40, name: 'B: shear (socks)' });
+ g.to({ p01: 1 }, m('B') + .8, 1.6);
+ mat(p, TURN, 380, 370, m('A') + .2, { size: 40, name: 'A: turn (shoes)' });
+ g.turn(0, 90, m('A') + .8, 1.6);
+ say(p, ['together: A B (B first, on the right)'], 90, 540, m('A') + 3, { size: 28 });
+ mat(p, [[0, 1], [-1, 0]], 90, 640, m('undoA') + .2, { size: 40, name: [...INV, ': turn back'] });
+ g.turn(90, 0, m('undoA') + .9, 1.6);
+ mat(p, [[1, -1], [0, 1]], 380, 640, m('undoB') + .2, { size: 40, name: [...BINV, ': shear back'] });
+ g.to({ p01: 0 }, m('undoB') + .9, 1.6);
+ say(p, ['(A B)', E('−1'), ' = ', ...BINV, ' ', ...INV], 90, 840, m('rule') + .6, { size: 44, fill: COL.chalk });
+ text(p, 'reverse order', 520, 840, m('rule') + 6, { size: 28, fill: COL.dim });
+ }],
+
+ ['wrong', 'The wrong order', (m) => {
+ const p = panel(0);
+ title(p, 'The wrong order does not undo');
+ const g = S.g = grid2(p, { A: TURN, pre: SHEAR, mat: null, shape: true, plane: ZOOM });
+ put(g.parts.cols, { o: 0 });
+ say(p, ['start: A B'], 90, 230, m('start') + .3, { size: 34 });
+ g.to({ ...keysOf(AB, 'p'), ...keysOf(I2) }, m('ub') - .1, .05); // the same plane, held as pre = AB (no jump)
+ mat(p, [[1, -1], [0, 1]], 90, 380, m('ub') + .2, { size: 40, name: [...BINV, ' first'] });
+ g.to(keysOf([[1, -1], [0, 1]]), m('ub') + .8, 1.6);
+ mat(p, [[0, 1], [-1, 0]], 380, 380, m('ua') + .2, { size: 40, name: [...INV, ' second'] });
+ const Bi = [[1, -1], [0, 1]];
+ prog(q => g.set(keysOf(ivMul(rot(-90 * q), Bi))), m('ua') + .8, 1.6); // A⁻¹ turns the plane back on top of B⁻¹
+ text(p, 'not home: the flag is somewhere else', 90, 560, m('look') + .3, { size: 30, fill: COL.bad, weight: 600 });
+ say(p, [...INV, ' ', ...BINV, ' (A B) = [1 1; 1 2] ≠ I'], 90, 630, m('look') + 3.4, { size: 30 });
+ text(p, 'order matters, as AB ≠ BA', 90, 700, m('look') + 7, { size: 26, fill: COL.dim });
+ }],
+
+ ['alg', 'Check with algebra', (m) => {
+ const p = panel(0);
+ title(p, 'Check: (AB)(B⁻¹A⁻¹) = I');
+ const s = 40;
+ say(p, ['(A B)(', ...BINV, ' ', ...INV, ')'], 90, 230, m('mul') + .3, { size: s });
+ say(p, ['= A (B ', ...BINV, ') ', ...INV], 90, 310, m('inner') + .3, { size: s });
+ say(p, ['= A I ', ...INV], 90, 390, m('inner') + 2.6, { size: s });
+ say(p, ['= A ', ...INV], 90, 470, m('gone') + .3, { size: s });
+ say(p, ['= I'], 90, 550, m('last') + .3, { size: s, fill: COL.good });
+ const pr = ivProd(p, AB, ABI, { at: [820, 330], size: 42, names: ['A B', [...BINV, ' ', ...INV], 'I'], work: [820, 540], o: 0 });
+ show(pr.g, m('nums') + .3, .5);
+ [[pr.A, m('nums') + .6, m('nums') + 4.4], [pr.B, m('nums') + 4.6, m('e1')]].forEach(([q, t0, t1]) => { const r = mk('rect', { x: q.x - 10, y: q.top - 8, width: q.w + 20, height: q.bot - q.top + 16, rx: 12, fill: COL.chalk }, pr.g); pr.g.insertBefore(r, pr.g.firstChild); put(r, { o: 0 }); tw(r, { o: .13 }, t0, .3); tw(r, { o: 0 }, t1, .3); });
+ pr.entry(0, 0, m('e1'), m('e2') - m('e1') - .2); pr.entry(0, 1, m('e2'), m('e3') - m('e2') - .2);
+ pr.entry(1, 0, m('e3'), m('e4') - m('e3') - .2); pr.entry(1, 1, m('e4'), m('I') - m('e4') + 1);
+ text(p, 'reverse order works', 820, 640, m('I') + .6, { size: 30, fill: COL.good, weight: 600 });
+ }],
+
+ ['q4', 'Quick check', () => {
+ const p = panel(0);
+ title(p, 'Quick check');
+ mat(p, [[1, 2], [0, 1]], 90, 250, .3, { size: 40, name: INV });
+ mat(p, [[1, 0], [3, 1]], 380, 250, .4, { size: 40, name: BINV });
+ }, { ask: done => quiz(LEFT, [{
+ id: 'c-prod', prompt: ['Find ', $m('(AB)', E('−1')), '.'],
+ build: blanks([
+ { parts: ['first row: (', { box: '1' }, ', ', { box: '2' }, ')'], why: '(AB)⁻¹ = B⁻¹A⁻¹: row 1 of B⁻¹, (1, 0), times the columns of A⁻¹.', hint: 'Reverse order: B⁻¹ on the left, A⁻¹ on the right. (A⁻¹B⁻¹ is the wrong order.)' },
+ { parts: ['second row: (', { box: '3' }, ', ', { box: '7' }, ')'], why: '(3, 1)·(1, 0) = 3 and (3, 1)·(2, 1) = 7. (AB)⁻¹ = [1 2; 3 7].', hint: 'Row 2 of B⁻¹ is (3, 1). Times column 1 of A⁻¹, (1, 0); times column 2, (2, 1).' },
+ ]),
+ }], done) }],
+
+ ['wrap', 'Summary', (m) => {
+ const p = panel(0);
+ [['No inverse when some x ≠ 0 has Ax = 0.', 'w1'], ['Then the columns lie on one line (or one plane): the grid goes flat.', 'w2'],
+ ['Elimination: a zero row. 2 × 2: ad − bc = 0.', 'w3'], ['(AB)⁻¹ = B⁻¹A⁻¹: socks and shoes.', 'w4']].forEach(([str, mark], i) => {
+ const g = G(p, { x: -16, y: 150 + i * 95, o: 0 });
+ mk('circle', { cx: 150, cy: -12, r: 26, fill: COL.chalk }, 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);
+ });
+ const sm = G(p, { o: 0 });
+ const k = grid2(sm, { A: I2, pre: I2, mat: null, shape: true, units: false, plane: { cx: 1180, cy: 680, u: 30, x0: -5, x1: 5, y0: -5, y1: 5, labels: false } });
+ put(k.parts.cols, { o: 0 });
+ show(sm, .3, .6);
+ k.to(keysOf(A1), m('w2') + .3, 1.6); k.to(keysOf(I2), m('w4') - .5, .4);
+ k.to({ p01: 1 }, m('w4') + .4, 1); k.turn(0, 90, m('w4') + 1.6, 1);
+ k.turn(90, 0, m('w4') + 3, 1); k.to({ p01: 0 }, m('w4') + 4.2, 1);
+ }],
+
+ ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
+ id: 'p-which', prompt: ['Which matrices have an inverse? Use any test.'],
+ build: grid(WHICHQ.map(q => ({ parts: [matEl(q.A)], ans: q.ans, why: q.why })), YESNO, { multi: false, text: true }),
+ }], done, 'Chapter practice · set 1 of 4') }],
+ ['final2', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, LOSTQ.map((q, k) => ({
+ id: `p-lost${k + 1}`, prompt: ['Find an ', $m('x ≠ 0'), ' with ', $m('A x = 0'), ' for ', $m('A'), ' = ', matEl(q.A), '. (Any multiple is fine.)'],
+ build: blanks([{
+ parts: ['x = (', ...q.x.flatMap((v, i) => [...(i ? [', '] : []), { box: String(v) }]), ')'],
+ test: v => v.some(Boolean) && q.A.every(r => Math.abs(r.reduce((s, a, j) => s + a * v[j], 0)) < 1e-9),
+ why: `For example x = (${q.x.map(num).join(', ')}): each row of A times x gives 0.`,
+ hint: q.x.length === 3 ? 'Look for one column that is a mix of the others: column 3 = column 1 + column 2.' : 'Find how column 2 compares with column 1, and take that mix with a minus sign.',
+ }]),
+ })), done, 'Chapter practice · set 2 of 4') }],
+ ['final3', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [...PRODQ.map((q, k) => {
+ const C = ivMul(q.Bi, q.Ai);
+ return {
+ id: `p-prod${k + 1}`, prompt: [$m('A', E('−1')), ' = ', matEl(q.Ai), ' and ', $m('B', E('−1')), ' = ', matEl(q.Bi), '. Find ', $m('(AB)', E('−1')), '.'],
+ build: blanks([
+ { parts: ['first row: (', { box: String(C[0][0]) }, ', ', { box: String(C[0][1]) }, ')'], why: 'B⁻¹ on the left, A⁻¹ on the right.', hint: 'Reverse order: (AB)⁻¹ = B⁻¹A⁻¹. Row 1 of B⁻¹ times each column of A⁻¹.' },
+ { parts: ['second row: (', { box: String(C[1][0]) }, ', ', { box: String(C[1][1]) }, ')'], why: `(AB)⁻¹ = [${C[0].map(num).join(' ')}; ${C[1].map(num).join(' ')}].`, hint: 'Row 2 of B⁻¹ times each column of A⁻¹.' },
+ ]),
+ };
+ }), {
+ id: 'p-abc', prompt: ['Three moves: first ', $m('C'), ', then ', $m('B'), ', then ', $m('A'), ' (that is ', $m('ABC'), '). What undoes them?'],
+ build: choice(['C⁻¹ B⁻¹ A⁻¹', 'A⁻¹ B⁻¹ C⁻¹', 'B⁻¹ A⁻¹ C⁻¹'], 0, 'Undo the last move first: A⁻¹ acts first, so it stands on the right: C⁻¹B⁻¹A⁻¹.',
+ [null, 'That undoes C first, but C was put on first: it must come off last.', 'A⁻¹ first is right, but then B⁻¹, and C⁻¹ last.']),
+ }, {
+ id: 'p-flat', prompt: [$m('A'), ' has no inverse (it squashes the plane flat). Can ', $m('AB'), ' have one?'],
+ build: choice(['No: after B, A still squashes the plane flat', 'Yes, if B has an inverse'], 0, 'AB means B, then A; A flattens whatever B gives it, and nothing undoes a flat plane.',
+ [null, 'B acts first; A acts last and flattens the plane. No inverse can follow that.']),
+ }], done, 'Chapter practice · set 3 of 4') }],
+ ['final4', 'Chapter practice', () => {
+ const p = panel(0);
+ title(p, 'With your hands');
+ S.g = grid2(p, { A: [[2, 0], [1, 1]], pre: I2, x: [1, 0], mat: [90, 250], size: 44, shape: true, lost: true, name: 'M', brackets: true });
+ S.g.labels(['col 1', 'col 2']);
+ }, { ask: done => quiz(LEFT, [{
+ id: 'p-squash', prompt: ['Drag column 2 of ', $m('M'), ' so the plane goes flat, keeping column 1 at ', $m('(2, 1)'), '.'],
+ build: (body, api) => { S.g.set({ ...keysOf([[2, 0], [1, 1]]), ...keysOf(I2, 'p') }); put(S.g.parts.x, { o: 0 }); return g2Task(S.g, v => flat(v) && v.a00 === 2 && v.a10 === 1, 'Column 2 on the line through (2, 1): the plane is flat.', 'Column 2 must lie on the line through (0, 0) and (2, 1): at (4, 2), (−2, −1), (0, 0) …', () => S.g.set({ a01: 4, a11: 2 }), ['cols'])(body, api); },
+ }, {
+ id: 'p-lostx', prompt: ['Now ', $m('M'), ' = [1 −1; 2 −2]. Drag ', $m('x'), ' to a point, not ', $m('(0, 0)'), ', that ', $m('M'), ' sends to ', $m('(0, 0)'), '.'],
+ build: (body, api) => { S.g.set({ ...keysOf([[1, -1], [2, -2]]), ...keysOf(I2, 'p'), x0: 1, x1: 0 }); put(S.g.parts.x, { o: 1 }); return g2Task(S.g, v => (v.x0 || v.x1) && v.x0 === v.x1, 'x on the red line: Mx = (0, 0).', 'Mx = (x − y, 2x − 2y). Both are 0 when x = y: try (1, 1).', () => S.g.set({ x0: 1, x1: 1 }), ['x'])(body, api); },
+ }, {
+ id: 'p-undoab', prompt: ['The plane was moved by ', $m('B'), ' = shear, then ', $m('A'), ' = turn (', $m('AB'), ' = [0 −1; 1 1]). Drag the tips of ', $m('M'), ' until the grid is home.'],
+ build: (body, api) => { S.g.set({ ...keysOf(I2), ...keysOf(AB, 'p') }); put(S.g.parts.x, { o: 0 }); return g2Task(S.g, () => isI(S.g.total()), 'M = (AB)⁻¹ = B⁻¹A⁻¹ = [1 1; −1 0]: turn back, then shear back.', '(AB)⁻¹ = B⁻¹A⁻¹ = [1 −1; 0 1][0 1; −1 0]. Column 1 is (1, −1), column 2 is (1, 0).', () => S.g.set(keysOf(ABI)), ['cols'])(body, api); },
+ }], done, 'Chapter practice · set 4 of 4') }],
+ ['play', 'Playground', (m, D) => {
+ const p = panel(0);
+ title(p, 'Playground');
+ S.sys = grid2(p, { A: [[2, 1], [1, 1]], x: [1, 1], mat: [90, 225], size: 40, shape: true, lost: true, brackets: true });
+ S.sys.labels(['col 1', 'col 2']);
+ S.sys.inverse({ at: [90, 370], size: 32 });
+ const hint = text(p, 'try: make it flat · then put x on the red line · watch Ax', 1160, 870, m('go'), { size: 24, fill: COL.dim, anchor: 'middle' });
+ hide(hint, Math.min(m('go') + 9, D - .7), .6);
+ }, { ask: playAsk(() => S.sys, { pos: { x: 40, y: 560, w: 720, cls: 'side' }, tip: 'A, x, A x and A⁻¹, live. Drag a column tip, x, or a number, or draw on the board. Nothing is marked.' }) }],
+ ['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
index 7e21fa7..095b195 100644
--- a/site/linear-algebra/lib/grid2.js
+++ b/site/linear-algebra/lib/grid2.js
@@ -4,26 +4,61 @@
// 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()).
+//
+// Inverses (chapters 26–28), all optional, so chapter 10's uses are unchanged:
+// pre: M the plane was moved by M first: the grid, square, flag and points show A·M (keys p00 p01 p10 p11 in g.v,
+// tweenable like A's), while the arrows and tips stay A's columns. With pre = A0 and A going from I to
+// A0⁻¹ the moved plane comes home: that is "A⁻¹ undoes A0". The moved axes are chalk in this mode.
+// fracs: true A's numbers show exact fractions (1/2) at rest instead of 0.5.
+// name: 'B' the letter under the matrix (and in the inverse panel).
+// lost: true when ad − bc = 0 (and A is not all zeros), the line of points A sends to (0, 0) is drawn dashed red on
+// the plane: the lost direction (g.parts.lost; fade it in on a word, live it simply shows).
+// g.inverse({ at: [x, y], size }) builds a live panel: ad − bc = 2·1 − 1·1 = 1 over A⁻¹ = 1/1 · [d −b; −c a] = [ … ];
+// its parts (each a group to show on a word) are in g.inv: det, lhs, scale, adj, eq, res, none,
+// plus adjCells and resCells (the four entries of each matrix, row by row, as g2val), xs and mid (layout);
+// ("no inverse: ad − bc = 0", shown in place of scale … res when ad − bc = 0). The adjusted matrix keeps
+// each number's column colour, so the swap of a and d and the sign change of b and c are visible.
+// g.det(), g.inverseOf() (null when ad − bc = 0), g.total() (the plane's matrix A·pre), g.turn(d0, d1, at, dur, ease, 'p')
+// turns pre instead of A.
+// Exact fractions: g2frac(v) → [n, d] or null; g2parts(v) → math parts (whole, F(n, d), or one decimal while moving).
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.
// It stands beside the unit square (x 1.4 … 2.3), not on it, so the square and the flag never hide each other.
const G2_FLAG = [[1.4, .25], [1.55, .25], [1.55, 1.05], [2.3, 1.3], [1.55, 1.55], [1.55, 1.75], [1.4, 1.75]];
+const g2frac = v => { if (!isFinite(v)) return null; for (let d = 1; d <= 200; d++) { const n = Math.round(v * d); if (Math.abs(v * d - n) < 1e-7) return [n, d]; } return null; };
+const g2fmt = n => { const r = Math.round(n * 10) / 10; return (r < 0 ? '−' : '') + (Number.isInteger(r) ? String(Math.abs(r)) : Math.abs(r).toFixed(1)); };
+const g2parts = v => {
+ const f = g2frac(v);
+ if (!f) return [Math.abs(v) >= 1000 ? (v < 0 ? '−' : '') + '999+' : g2fmt(v)];
+ const [n, d] = f;
+ return d === 1 ? [num(n)] : n < 0 ? ['−', F(-n, d)] : [F(n, d)];
+};
+const g2key = ps => ps.map(q => typeof q === 'string' ? q : q.f.join('/')).join('');
+// A number drawn as math parts, rebuilt only when what it shows changes.
+function g2val(parent, { x = 0, y = 0, size = 40, fill = COL.chalk, anchor = 'middle' } = {}) {
+ const g = G(parent, {});
+ let key = null;
+ return { g, set(v, color = fill, parts = g2parts(v)) { const k = g2key(parts) + color; if (k === key) return; key = k; g.replaceChildren(); M(g, parts, { x, y, size, fill: color, anchor }); } };
+}
+
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, showMat = true, brackets = false } = {}) {
- 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 };
+ units = true, pts = [], t0 = .1, hidePlane = false, result = true, showMat = true, brackets = false, pre = null, fracs = false, name = 'A', lost = false } = {}) {
+ const Pm = pre || [[1, 0], [0, 1]];
+ 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, p00: Pm[0][0], p01: Pm[0][1], p10: Pm[1][0], p11: Pm[1][1] };
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 fmt = g2fmt;
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 tmap = ([a, b]) => map([v.p00 * a + v.p01 * b, v.p10 * a + v.p11 * b]); // the plane: pre first, then A
const XY = ([a, b]) => `${PX(a).toFixed(1)} ${PY(b).toFixed(1)}`;
/* ---------- numbers you can scrub ---------- */
@@ -32,7 +67,13 @@ function grid2(p, { A = [[1, 0], [0, 1]], x = null, mat = [90, 300], size = 54,
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: () => { const str = fmt(v[key]); setText(t, str); const fs = String(str.length > 2 ? Math.round(size * .74) : size); if (t.getAttribute('font-size') !== fs) t.setAttribute('font-size', fs); } };
+ const fv = fracs ? g2val(g, { x, y, size: size * .8, fill }) : null;
+ if (fv) fv.g.style.pointerEvents = 'none';
+ const s = { key, t, box: bx, set: () => {
+ const fr = fv && g2frac(v[key]);
+ if (fr && fr[1] > 1) { t.style.display = 'none'; fv.g.style.display = ''; fv.set(v[key], t.getAttribute('fill')); return; }
+ if (fv) { fv.g.style.display = 'none'; t.style.display = ''; }
+ const str = fmt(v[key]); setText(t, str); const fs = String(str.length > 2 ? Math.round(size * .74) : size); if (t.getAttribute('font-size') !== fs) t.setAttribute('font-size', fs); } };
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)) }); });
@@ -61,7 +102,7 @@ function grid2(p, { A = [[1, 0], [0, 1]], x = null, mat = [90, 300], size = 54,
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 });
+ T(Mx, name, { 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);
@@ -83,9 +124,10 @@ function grid2(p, { A = [[1, 0], [0, 1]], x = null, mat = [90, 300], size = 54,
/* ---------- 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 lostG = layer(lost ? 1 : 0), 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 axs = G2_COLS.map(c => path(gridG, '', { stroke: pre ? COL.chalk : c, 'stroke-opacity': pre ? .55 : .75, 'stroke-width': 3, fill: 'none' }));
+ const lostL = path(lostG, '', { stroke: COL.bad, 'stroke-width': 4, 'stroke-dasharray': '12 9', 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.chalk, 'fill-opacity': .45, stroke: COL.chalk, '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' });
@@ -176,7 +218,7 @@ function grid2(p, { A = [[1, 0], [0, 1]], x = null, mat = [90, 300], size = 54,
seg([P2.x0, 0], [P2.x1, 0], .5); seg([0, P2.y0], [0, P2.y1], .5);
seg([0, 0], c0); seg([0, 0], c1);
if (x) { const m1 = [v.x0 * c0[0], v.x0 * c0[1]]; seg([0, 0], m1); seg(m1, ax); seg([0, 0], ax); }
- if (shape) { const F = G2_FLAG.map(map); F.forEach((q, i) => seg(q, F[(i + 1) % F.length], 1.5)); seg(F[1], F[3], 1.5); seg(F[0], F[5], 1.5); } // the flag, outline and body
+ if (shape) { const F = G2_FLAG.map(tmap); F.forEach((q, i) => seg(q, F[(i + 1) % F.length], 1.5)); seg(F[1], F[3], 1.5); seg(F[0], F[5], 1.5); } // the flag, outline and body
// the dots and handles themselves weigh most
for (const q of x ? [c0, c1, ax, [v.x0, v.x1]] : [c0, c1]) for (const [ox, oy] of [[0, 0], [-12, 0], [12, 0], [0, -12], [0, 12]]) pts.push([PX(q[0]) + ox, PY(q[1]) + oy, 4]);
const placed = [...unitBoxes.map(b => [...b, 120]), ...tickBoxes.map(b => [...b, 120])];
@@ -203,25 +245,66 @@ function grid2(p, { A = [[1, 0], [0, 1]], x = null, mat = [90, 300], size = 54,
place(xLab, [v.x0, v.x1], [v.x0, v.x1], widthOf(xLab, xLab.textContent.length, 24), 28, 21);
}
}
+ /* ---------- the inverse, live: ad − bc and A⁻¹ = 1/(ad − bc) · [d −b; −c a] ---------- */
+ let inv = null;
+ function inverse({ at: [ix, iy] = [90, 520], size: s = 40 } = {}) {
+ const root = G(p, {}), part = () => G(root, {});
+ const det = part(), lhs = part(), scale = part(), adj = part(), eq = part(), res = part(), none = part();
+ const rh = s * 1.6, mid = iy + s * 2.4 + rh / 2; // matrices: rows at mid ± rh/2
+ const xL = ix, xS = xL + s * 3.1, xA = xS + s * 1.9, cwA = s * 2, xE = xA + cwA * 2 + 36, xR = xE + s * 1.3, cwR = s * 2.1;
+ const brk = (g, x0, w) => { const top = mid - rh / 2 - s * .95, bot = mid + rh / 2 + s * .45; path(g, `M${x0 + 12} ${top}H${x0}V${bot}H${x0 + 12}M${x0 + w - 12} ${top}H${x0 + w}V${bot}H${x0 + w - 12}`, { stroke: COL.chalk, 'stroke-width': 2.5, fill: 'none' }); };
+ M(lhs, [name, E('−1'), ' ='], { x: xL, y: mid + s * .3, size: s, anchor: 'start' });
+ brk(adj, xA, cwA * 2 + 20); brk(res, xR, cwR * 2 + 20);
+ M(eq, ['='], { x: xE + s * .45, y: mid + s * .3, size: s, anchor: 'middle' });
+ const ax = j => xA + 10 + cwA * (j + .5), rx = j => xR + 10 + cwR * (j + .5), ry = i => mid - rh / 2 + i * rh + s * .3;
+ const A_ = [[0, 0], [0, 1], [1, 0], [1, 1]].map(([i, j]) => g2val(adj, { x: ax(j), y: ry(i), size: s * .9 }));
+ const R_ = [[0, 0], [0, 1], [1, 0], [1, 1]].map(([i, j]) => g2val(res, { x: rx(j), y: ry(i), size: s * .9 }));
+ const S_ = g2val(scale, { x: xS + s * .6, y: mid + s * .3, size: s * .9 });
+ const D_ = g2val(det, { x: ix, y: iy, size: s * .9, anchor: 'start' });
+ const N_ = T(none, 'no inverse: ad − bc = 0', { x: xS, y: mid + s * .3, size: s * .8, fill: COL.bad, weight: 600 });
+ const inner = [scale, adj, eq, res].map(g => { const k = G(g, {}); while (g.firstChild !== k) k.append(g.firstChild); return k; });
+ const draw = () => {
+ const a = v.a00, b = v.a01, c = v.a10, d = v.a11, dt = a * d - b * c, zero = Math.abs(dt) < 1e-9;
+ const pp = x => { const q = g2parts(x); return x < 0 ? ['(', ...q, ')'] : q; };
+ const dk = [...g2parts(a), '·', ...pp(d), ' − ', ...pp(b), '·', ...pp(c), ' = ', ...g2parts(dt)];
+ D_.set(0, COL.chalk, ['ad − bc = ', ...dk]);
+ inner.forEach(k => { k.style.display = zero ? 'none' : ''; });
+ N_.style.display = zero ? '' : 'none';
+ if (zero) { [...A_, ...R_, S_].forEach(c => c.set(0, COL.chalk, [''])); return; } // hidden, and blank: what shows never depends on the path taken
+ const fd = g2frac(dt);
+ S_.set(0, COL.chalk, fd && fd[1] === 1 ? [...(dt < 0 ? ['−'] : []), F(1, Math.abs(fd[0]))] : g2parts(1 / dt));
+ [[d, G2_COLS[1]], [-b, G2_COLS[1]], [-c, G2_COLS[0]], [a, G2_COLS[0]]].forEach(([x, col], k) => A_[k].set(x, col));
+ [d / dt, -b / dt, -c / dt, a / dt].forEach((x, k) => R_[k].set(x));
+ };
+ inv = { root, det, lhs, scale, adj, eq, res, none, draw, mid, adjCells: A_, resCells: R_, xs: { xL, xS, xA, xE, xR } };
+ draw();
+ return inv;
+ }
function draw() {
slots.forEach(s => s.set());
const c0 = [v.a00, v.a10], c1 = [v.a01, v.a11], ax = map([v.x0, v.x1]);
+ const t0c = tmap([1, 0]), t1c = tmap([0, 1]); // the plane's own columns (A's, unless pre is set)
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
+ d += seg([k * t0c[0], k * t0c[1]], t1c, -K, K); // the image of the line x = k
+ d += seg([k * t1c[0], k * t1c[1]], t0c, -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
+ setD(axs[0], seg([0, 0], t0c, -K, K)); // the x-axis lands along column 1
+ setD(axs[1], seg([0, 0], t1c, -K, K)); // the y-axis along column 2
+ }
+ if (square) setD(sq, poly([[0, 0], t0c, [t0c[0] + t1c[0], t0c[1] + t1c[1]], t1c]));
+ if (shape) setD(sh, poly(G2_FLAG.map(tmap)));
+ if (lost) { // the points A sends to (0, 0): a line when ad − bc = 0 and A is not all zeros
+ const dt = v.a00 * v.a11 - v.a01 * v.a10, r = Math.hypot(v.a00, v.a01) > 1e-9 ? [v.a00, v.a01] : [v.a10, v.a11];
+ setD(lostL, Math.abs(dt) < 1e-9 && Math.hypot(...r) > 1e-9 ? seg([0, 0], [-r[1], r[0]], -40, 40) : '');
}
- if (square) setD(sq, poly([[0, 0], c0, [c0[0] + c1[0], c0[1] + c1[1]], c1]));
- if (shape) setD(sh, poly(G2_FLAG.map(map)));
+ if (inv) inv.draw();
ptDots.forEach(({ g, lab }, i) => {
- const [a, b] = map(ptDots[i].q.p);
+ const [a, b] = tmap(ptDots[i].q.p);
put(g, { x: PX(a), y: PY(b) });
});
[c0, c1].forEach((c, j) => {
@@ -252,7 +335,12 @@ function grid2(p, { A = [[1, 0], [0, 1]], x = null, mat = [90, 300], size = 54,
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 },
+ parts: { grid: gridG, square: sqG, shape: shG, units: unG, pts: ptG, cols: colG, x: xG, lost: lostG },
+ get inv() { return inv; },
+ inverse,
+ det: () => v.a00 * v.a11 - v.a01 * v.a10,
+ inverseOf() { const dt = v.a00 * v.a11 - v.a01 * v.a10; return Math.abs(dt) < 1e-9 ? null : [[v.a11 / dt, -v.a01 / dt], [-v.a10 / dt, v.a00 / dt]]; },
+ total: () => { const c0 = tmap([1, 0]), c1 = tmap([0, 1]); return [[c0[0], c1[0]], [c0[1], c1[1]]]; },
// 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 };
@@ -262,8 +350,8 @@ function grid2(p, { A = [[1, 0], [0, 1]], x = null, mat = [90, 300], size = 54,
},
// Turn the plane from deg0 to deg1 degrees (counterclockwise) on the beat clock: a true turn, where a straight blend
// of the numbers would shrink the plane halfway. Later g.to() calls start from where the turn ends.
- turn(deg0, deg1, at, dur = 1.6, ease = io) {
- const rot = d => { const a = d * Math.PI / 180, k = n => Math.round(n * 1e6) / 1e6; return { a00: k(Math.cos(a)), a01: k(-Math.sin(a)), a10: k(Math.sin(a)), a11: k(Math.cos(a)) }; };
+ turn(deg0, deg1, at, dur = 1.6, ease = io, key = 'a') {
+ const rot = d => { const a = d * Math.PI / 180, k = n => Math.round(n * 1e6) / 1e6; return { [key + '00']: k(Math.cos(a)), [key + '01']: k(-Math.sin(a)), [key + '10']: k(Math.sin(a)), [key + '11']: k(Math.cos(a)) }; };
plan = { ...plan, ...rot(deg1) };
prog(q => edit(rot(deg0 + (deg1 - deg0) * q)), at, dur, ease);
},
diff --git a/site/linear-algebra/lib/inv.js b/site/linear-algebra/lib/inv.js
new file mode 100644
index 0000000..f1edbcb
--- /dev/null
+++ b/site/linear-algebra/lib/inv.js
@@ -0,0 +1,219 @@
+// Inverses (chapters 26–28): matrices with exact fractions, a product checked entry by entry, and the Gauss–Jordan
+// table [A | I], whose numbers change in place while each row operation runs (and, for 2 × 2, move a linked grid2).
+// Loads after engine.js, math.js and grid2.js (it uses g2val, g2parts).
+//
+// const m = ivMat(p, [[1, 3], [2, 7]], { x, y, size, name: 'A', fill: (i, j) => colour }) // .cells[i][j] (g2val), .set(rows), .w, .cx(j), .ry(i)
+// const pr = ivProd(p, L, R, { at: [x, y], names: ['A⁻¹', 'A', 'I'], work: [x, y] }) // L · R = C, C's entries hidden
+// pr.entry(i, j, at, dur) row i of L and column j of R light up, the working "1·7 + 3·(−2) = 1" shows, C's entry appears
+// pr.all(at, gap) every entry in turn; pr.fill(at) all of C at once
+//
+// const t = gj(p, A, { at: [x, y], link: g }) // [A | I]; link: a grid2 whose A follows the left block (2 × 2)
+// t.sub(i, j, l, at, dur) row i − l × row j, as a continuous change (rows count from 0); its label beside the row
+// t.div(i, k, at, dur) row i ÷ k
+// t.ring(i, j, at, t1), t.flash(i, j, at), t.block(0 | 1, at, t1) (a band behind the left or right block), t.names([…], at)
+// t.done(at) hides the open label
+// Hands on: t.open(i, j) opens "row i − ℓ × row j" at once with ℓ = 0; t.live(true) makes ℓ a number to drag sideways
+// (or Tab to it, ↑/↓); t.v (the table's numbers c<i><j> and l), t.set, t.load(rows) work for playAsk; gjTask is the
+// question type. Numbers are exact at rest (whole or fractions), one decimal while they move.
+const IV_ROW = [COL.whole, COL.nat, COL.int], IV_COL = [COL.irr, COL.real, COL.rat];
+
+const ivParts = v => typeof v === 'number' ? g2parts(v) : [].concat(v); // a number, or math parts (letters)
+function ivMat(p, rows, { x = 0, y = 0, size = 40, cw = size * 1.9, rh = size * 1.5, fill = () => COL.chalk, name = null, o = 1 } = {}) {
+ const n = rows.length, m = rows[0].length, g = G(p, { o });
+ const w = cw * m + 20, top = y - size * .95, bot = y + (n - 1) * rh + size * .45;
+ 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': 2.5, fill: 'none' });
+ const cx = j => x + 10 + cw * (j + .5), ry = i => y + i * rh;
+ const cells = rows.map((r, i) => r.map((v, j) => { const c = g2val(G(g, {}), { x: cx(j), y: ry(i), size, fill: fill(i, j) }); c.set(0, fill(i, j), ivParts(v)); return c; }));
+ let lab = null;
+ if (name) lab = M(g, [].concat(name), { x: x + w / 2, y: bot + size * .95, size: size * .75, fill: COL.dim, anchor: 'middle' });
+ return { g, cells, w, cw, cx, ry, top, bot, x, y, n, m, lab, set(r2) { r2.forEach((r, i) => r.forEach((v, j) => cells[i][j].set(0, fill(i, j), ivParts(v)))); } };
+}
+
+const ivMul = (L, R) => L.map(r => R[0].map((_, j) => r.reduce((s, x, k) => s + x * R[k][j], 0)));
+// a number inside a working line: negatives in brackets after a times sign
+const ivPP = x => { const q = g2parts(x); return x < 0 ? ['(', ...q, ')'] : q; };
+
+// C and works: a product of letters (C's entries as parts, works(i, j) the working line's parts); numbers by default.
+function ivProd(p, L, R, { at: [x, y] = [90, 260], size = 40, names = ['A', 'B', 'AB'], gap = 34, work = null, workSize = 34, o = 1, C: C0 = null, works = null, cw = size * 1.9, cwC = cw } = {}) {
+ const g = G(p, { o }), C = C0 || ivMul(L, R);
+ const A = ivMat(g, L, { x, y, size, cw, name: names[0] });
+ const B = ivMat(g, R, { x: x + A.w + gap, y, size, cw, name: names[1] });
+ const ex = B.x + B.w + gap * .9;
+ const midY = (A.top + A.bot) / 2 + size * .3;
+ M(g, ['='], { x: ex, y: midY, size, anchor: 'middle' });
+ const Cm = ivMat(g, C, { x: ex + gap * .9, y, size, cw: cwC, name: names[2] });
+ Cm.cells.flat().forEach(c => put(c.g.parentNode, { o: 0 }));
+ const [wx, wy] = work || [x, A.bot + size * 2.2];
+ const band = (bx, by, bw, bh, c) => { const r = mk('rect', { x: bx, y: by, width: bw, height: bh, rx: 12, fill: c }, g); g.insertBefore(r, g.firstChild); put(r, { o: 0 }); return r; };
+ const entry = (i, j, t, dur = 2.6) => {
+ const rb = band(A.x + 4, A.ry(i) - size * .85, A.w - 8, size * 1.15, IV_ROW[i % 3]);
+ const cb = band(B.cx(j) - B.cw / 2 + 4, B.top + 4, B.cw - 8, B.bot - B.top - 8, IV_COL[j % 3]);
+ tw(rb, { o: .22 }, t, .3); tw(cb, { o: .22 }, t + .2, .3); tw(rb, { o: 0 }, t + dur, .4); tw(cb, { o: 0 }, t + dur, .4);
+ // the working: the products first, "= result" a little later, when it is said (with C's entry)
+ const tr = t + Math.max(.9, Math.min(dur * .6, dur - 1));
+ if (works) {
+ const wl = M(g, works(i, j), { x: wx, y: wy, size: workSize, anchor: 'start', o: 0 });
+ show(wl, t + .3, .3); hide(wl, t + dur, .3);
+ } else {
+ const lhs = [];
+ L[i].forEach((a, k) => { if (k) lhs.push(' + '); lhs.push(...g2parts(a), '·', ...ivPP(R[k][j])); });
+ const wl = M(g, lhs, { x: wx, y: wy, size: workSize, anchor: 'start', o: 0 });
+ const wr = M(g, [' = ', ...g2parts(C[i][j])], { x: wx + wl._w, y: wy, size: workSize, anchor: 'start', o: 0 });
+ show(wl, t + .3, .3); hide(wl, t + dur, .3); show(wr, tr, .3); hide(wr, t + dur, .3);
+ }
+ const ce = Cm.cells[i][j].g.parentNode, at = works ? t + .9 : tr;
+ show(ce, at, .4); pulse(ce, at, 1);
+ };
+ return {
+ g, A, B, C: Cm, prod: C, entry,
+ all(t, step = 1.2, dur = 1.1) { let k = 0; C.forEach((r, i) => r.forEach((_, j) => entry(i, j, t + step * k++, dur))); },
+ fill(t) { Cm.cells.flat().forEach(c => show(c.g.parentNode, t, .4)); },
+ };
+}
+
+/* ---------- Gauss–Jordan: [A | I] → [I | A⁻¹] ---------- */
+function gj(p, A, { at: [x0, y0] = [110, 300], size = 42, cw = size * 2.05, rh = size * 1.55, right = true, link = null, t0 = .1, labelX = null, names: nm = ['A', 'I'], o = 0 } = {}) {
+ const n = A.length, mcols = right ? 2 * n : n, I = [...Array(n).keys()], J = [...Array(mcols).keys()], svg = $('stage');
+ const key = (i, j) => `c${i}${j}`;
+ const v = { l: 0 };
+ I.forEach(i => J.forEach(j => { v[key(i, j)] = j < n ? A[i][j] : +(j - n === i); }));
+ let plan = { ...v };
+ const g = G(p, { o });
+ show(g, t0 + .2);
+ const cx = j => x0 + cw * (j + .5) + (j >= n ? 28 : 0), ry = i => y0 + i * rh;
+ const W = cw * mcols + (right ? 28 : 0);
+ const top = y0 - size * .95, bot = y0 + (n - 1) * rh + size * .45;
+ path(g, `M${x0 - 6} ${top}H${x0 - 18}V${bot}H${x0 - 6}M${x0 + W + 6} ${top}H${x0 + W + 18}V${bot}H${x0 + W + 6}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' });
+ const divider = right ? path(g, `M${x0 + cw * n + 14} ${top + 6}V${bot - 6}`, { stroke: COL.dim, 'stroke-width': 2.5, 'stroke-dasharray': '6 6', fill: 'none' }) : null;
+ const bars = I.map(i => mk('rect', { x: x0 - 52, y: ry(i) - size * .7, width: 8, height: size * .8, rx: 4, fill: IV_ROW[i] }, g));
+ const fillOf = j => j < n ? COL.chalk : COL.task;
+ const cells = I.map(i => J.map(j => g2val(G(g, {}), { x: cx(j), y: ry(i), size, fill: fillOf(j) })));
+ const nameG = [G(g, {}), G(g, {})];
+ const setNames = (ns) => ns.forEach((s, k) => { if (k && !right) return; nameG[k].replaceChildren(); M(nameG[k], [].concat(s), { x: k ? (cx(n) + cx(mcols - 1)) / 2 : (cx(0) + cx(n - 1)) / 2, y: top - 18, size: size * .7, fill: k ? COL.task : COL.dim, anchor: 'middle' }); });
+ setNames(nm);
+ const listeners = [];
+ function draw() {
+ I.forEach(i => J.forEach(j => cells[i][j].set(v[key(i, j)], fillOf(j))));
+ if (link && n === 2) link.set({ a00: v.c00, a01: v.c01, a10: v.c10, a11: v.c11 });
+ listeners.forEach(f => f(v));
+ }
+ function edit(to) { let ch = false; for (const k in to) if (v[k] !== to[k]) { v[k] = to[k]; ch = true; } if (ch) draw(); }
+ draw();
+ const rowOf = (s, i) => J.map(j => s[key(i, j)]);
+ const withRow = (s, i, r) => ({ ...s, ...Object.fromEntries(J.map(j => [key(i, j), r[j]])) });
+ const lerp = (a, b) => q => edit(Object.fromEntries(Object.keys(b).filter(k => k !== 'l').map(k => [k, a[k] + (b[k] - a[k]) * q])));
+
+ /* labels beside the rows: "row 2 − 3 × row 1", "row 1 ÷ 2" */
+ const lx = labelX ?? x0 + W + 50;
+ let open = null;
+ function label(i, words, t) {
+ if (open && t !== null) hide(open, t - .05, .3);
+ const lg = G(g, { o: 0 }); let x = lx;
+ words.forEach(([s, c, box]) => {
+ const holder = G(lg, {}), e = M(holder, [].concat(s), { x, y: ry(i), size: size * .78, fill: c, anchor: 'start' });
+ const w = box ? Math.max(e._w, size * .9) : e._w;
+ if (box) { const r = mk('rect', { x: x - 8, y: ry(i) - size * .78, width: w + 16, height: size * 1.02, rx: 8, fill: 'none', stroke: c, 'stroke-width': 2 }, lg); lg._box = r; lg._num = holder; lg._numX = x; lg._row = i; }
+ x += w + size * .3 + (box ? 12 : 0);
+ });
+ if (t !== null) show(lg, t, .35);
+ open = lg;
+ return lg;
+ }
+ const rowW = (i, c = IV_ROW[i]) => [`row ${i + 1}`, c];
+ function sub(i, j, l, t, dur = 1.8, { lead = .8 } = {}) {
+ label(i, [rowW(i), ['−', COL.chalk], [g2parts(l), COL.chalk, true], ['×', COL.chalk], rowW(j)], t - lead);
+ const from = { ...plan }, to = withRow(plan, i, rowOf(plan, i).map((x, c) => x - l * plan[key(j, c)]));
+ plan = to;
+ prog(lerp(from, to), t, dur);
+ return to;
+ }
+ function div(i, k, t, dur = 1.6, { lead = .8 } = {}) {
+ label(i, [rowW(i), ['÷', COL.chalk], [g2parts(k), COL.chalk, true]], t - lead);
+ const from = { ...plan }, to = withRow(plan, i, rowOf(plan, i).map(x => x / k));
+ plan = to;
+ prog(lerp(from, to), t, dur);
+ return to;
+ }
+ function ring(i, j, t, t1, { color = COL.chalk, dash = false } = {}) {
+ const c = mk('circle', { cx: cx(j), cy: ry(i) - size * .32, r: size * .78, fill: 'none', stroke: color, 'stroke-width': 3, ...(dash ? { 'stroke-dasharray': '6 5' } : {}) }, g);
+ put(c, { o: 0 }); show(c, t, .3); if (t1 !== undefined) hide(c, t1, .3);
+ return c;
+ }
+ function flash(i, j, t) { const e = cells[i][j].g.parentNode; tw(e, { c_fill: COL.task }, t, .2); pulse(e, t, 1.2); }
+ function block(k, t, t1, color = k ? COL.task : COL.chalk) {
+ const bx = k ? cx(n) - cw / 2 : cx(0) - cw / 2, r = mk('rect', { x: bx - 4, y: top - 6, width: cw * n + 8, height: bot - top + 12, rx: 14, fill: color }, g);
+ g.insertBefore(r, g.firstChild); put(r, { o: 0 }); tw(r, { o: .13 }, t, .4); if (t1 !== undefined) tw(r, { o: 0 }, t1, .4);
+ return r;
+ }
+
+ /* hands on: one open operation whose multiplier the reader sets */
+ let cur = null, live = false;
+ const apply = () => { if (!cur) return; edit(withRow(v, cur.i, cur.base.map((x, c) => x - v.l * v[key(cur.j, c)]))); cur.lg._num.replaceChildren(); M(cur.lg._num, g2parts(v.l), { x: cur.lg._numX, y: ry(cur.lg._row), size: size * .78, fill: COL.chalk, anchor: 'start' }); };
+ const RANGE = 9;
+ function openNow(i, j) {
+ if (open) put(open, { o: 0 });
+ if (cur) cur.hit.remove(); // one live multiplier at a time
+ v.l = 0;
+ const lg = label(i, [rowW(i), ['−', COL.chalk], [['0'], COL.chalk, true], ['×', COL.chalk], rowW(j)], null);
+ put(lg, { o: 1 });
+ const hit = mk('rect', { x: lg._numX - 14, y: ry(i) - size * .95, width: 64, height: size * 1.35, rx: 8, fill: 'transparent' }, lg);
+ hit.setAttribute('aria-label', 'multiplier');
+ cur = { i, j, base: rowOf(v, i), lg, hit };
+ let drag = null;
+ hit.addEventListener('pointerdown', e => { if (!live) return; e.preventDefault(); drag = { x: e.clientX, from: v.l }; hit.setPointerCapture(e.pointerId); });
+ hit.addEventListener('pointermove', e => { if (!drag) return; const k = svg.getScreenCTM().a; setL(drag.from + Math.round((e.clientX - drag.x) / k / 26)); });
+ const end = () => { drag = null; };
+ hit.addEventListener('pointerup', end); hit.addEventListener('lostpointercapture', end);
+ hit.addEventListener('keydown', e => {
+ if (!live) return;
+ if (e.key === 'Enter') { e.preventDefault(); e.stopPropagation(); hit.blur(); P.keys?.(e); return; }
+ const d = { ArrowUp: 1, ArrowRight: 1, ArrowDown: -1, ArrowLeft: -1 }[e.key];
+ if (!d) return;
+ e.preventDefault(); e.stopPropagation(); setL(v.l + d);
+ });
+ liveNow();
+ return cur;
+ }
+ const setL = l => { v.l = Math.max(-RANGE, Math.min(RANGE, l)); apply(); };
+ function liveNow() {
+ if (!cur) return;
+ cur.hit.style.cursor = live ? 'ew-resize' : '';
+ if (live) cur.hit.setAttribute('tabindex', 0); else cur.hit.removeAttribute('tabindex');
+ cur.lg._box.setAttribute('stroke-dasharray', live ? '5 5' : '');
+ }
+ function commit() { if (cur) cur.hit.remove(); cur = null; v.l = 0; plan = { ...v }; }
+ function load(rows) { commit(); const s = {}; I.forEach(i => J.forEach(j => { s[key(i, j)] = rows[i][j]; })); edit(s); plan = { ...v }; }
+
+ return {
+ g, v, n, cells, cx, ry, top, bot, W, bars, divider, nameG,
+ get plan() { return plan; },
+ sub, div, ring, flash, block, label,
+ names(ns, t) { const old = nameG.map(e => e.cloneNode(true)); old.forEach((e, k) => { nameG[k].parentNode.append(e); hide(e, t, .3); }); nameG.forEach(e => put(e, { o: 0 })); setNames(ns); nameG.forEach(e => show(e, t + .2, .4)); },
+ done(t) { if (open) hide(open, t, .3); },
+ to(next, t, dur = 1.2) { const from = { ...plan }; plan = { ...plan, ...next }; prog(lerp(from, plan), t, dur); },
+ open: openNow, commit, load,
+ rows: () => I.map(i => rowOf(v, i)),
+ live(on) { live = on; liveNow(); },
+ // { l } alone moves the open operation's multiplier (and its row); with the table's numbers it restores a whole
+ // state (playAsk's reset): the numbers as given, the multiplier as given, the open row's base worked back from them
+ set(vals) {
+ const { l, ...rest } = vals;
+ if (!Object.keys(rest).length) { if (l !== undefined && cur) setL(l); return; }
+ if (l !== undefined) v.l = l;
+ edit(rest);
+ if (cur) { cur.base = rowOf(v, cur.i).map((x, c) => x + v.l * v[key(cur.j, c)]); apply(); }
+ },
+ onChange(f) { listeners.push(f); },
+ };
+}
+
+// A question on an open operation: the reader sets the multiplier until test(v) holds, then checks.
+const gjTask = (t, test, why, hint, reveal) => (body, api) => {
+ t.live(true);
+ return {
+ check: () => { const ok = test(t.v); api.grade(ok, ok ? why : (typeof hint === 'function' ? hint(t.v) : hint)); },
+ reveal: () => { reveal?.(); return why; },
+ lock: () => t.live(false),
+ hint: [kbd('Tab'), 'pick the multiplier', kbd('↑'), kbd('↓'), 'change it, or drag it sideways'],
+ };
+};