Skip to the content

Module 1: Numbers and what they count

Module 2: Arithmetic, properly

Module 3: Fractions, decimals, percentages and ratios

Module 4: Powers, roots and scientific notation

Module 5: Letters for numbers: variables and expressions

Module 6: Solving linear equations

Module 7: Inequalities and absolute value

Module 8: Functions: a rule from inputs to outputs

Module 9: Lines and slope

Module 10: Systems of equations

Module 11: Polynomials and factoring

Module 12: Quadratic equations and parabolas

Module 13: Rational and radical expressions

Module 14: Exponentials and logarithms

Module 15: Sequences, series and induction

Module 16: Angles, triangles and trigonometry

Module 17: Complex numbers

Module 18: Vectors and matrices

Module 19: Linear maps, determinants and eigenvectors

Module 20: Abstract algebra and thinking like a mathematician

Answer key

  1. 1. Numbers and what they count · Ten digits write every natural number · QuizIn the number 52 816, what is the digit 2 worth?C. 2000Count places from the right: 6 is ones, 1 is tens, 8 is hundreds, 2 is thousands, 5 is ten-thousands. So the 2 is worth 2×1000=2000. The usual slip is counting from the left; places are always counted from the ones, at the right.
  2. 1. Numbers and what they count · Ten digits write every natural number · ProblemIn the number 47 305, what is the 7 worth, and what is the 3 worth? Then write 5×10000+8×100+6×1 as one number.The 7 is worth 7000; The 3 is worth 300; The number 50806
    1. Counting from the right in 47 305: 5 is ones, 0 is tens, 3 is hundreds, 7 is thousands and 4 is ten-thousands.
    2. So the 7 is worth 7×1000=7000, and the 3 is worth 3×100=300.
    3. The sum has 5 ten-thousands, no thousands, 8 hundreds, no tens and 6 ones. Each empty place gets a 0:
    4. 5×10000+0×1000+8×100+0×10+6×1=50806
    5. The number is 50 806. Leaving out the zeros would give 586, a different number.
  3. 1. Numbers and what they count · Code in this course: your first C++ program · QuizWhat does this line print?A. 2 2.25 09 / 4 divides two ints, so the answer is the whole part, 2, with the quarter thrown away. 9.0 / 4 has a double in it, so the division keeps its fraction: 2.25. And 1 / 3 is 0, the most common surprise of all: a fraction of two whole numbers written as code must have a .0 somewhere, as in 1.0 / 3.
  4. 1. Numbers and what they count · Functions, decisions, loops and lists in C++ · Fill the blanksFinish the function that adds up the squares of a list, so that 12+22+32 gives 14.1: double, 2: 0, 3: for, 4: x * x, 5: returnThe function returns a double, the same type as the numbers it adds. The total starts at 0, the sum of nothing, and the range-for adds each square in turn. Squaring is x * x (or std::pow(x, 2) from <cmath>); x ^ 2 would compile and give nonsense. Without return, the caller would never get the total.
  5. 1. Numbers and what they count · Try it: split a number into its places · Code challengeWrite placeValues(n): for a natural number n, return what each digit is worth, biggest place first. placeValues(3407) is {3000, 400, 0, 7}, and placeValues(0) is {0}. parts.insert(parts.begin(), x) puts x at the front of a vector.One solution:
    Solution
    #include <vector>
    std::vector<int> placeValues(int n) {  if (n == 0) return {0};  std::vector<int> parts;  int place = 1;  while (n > 0) {    parts.insert(parts.begin(), (n % 10) * place);    n = n / 10;    place *= 10;  }  return parts;}
    The loop works from the right, because the remainder by 10 always gives the ones digit; inserting at parts.begin() puts each new part at the front, so the biggest place ends up first. n / 10 needs no rounding down: on ints it already drops the fraction. place grows by ten each time, matching each step left. Zero needs its own case: the loop never runs for it, and an empty list is not how you write 0. The last test is the point of place value: the parts always add back to the number.
  6. 1. Numbers and what they count · Negative numbers fill the gap below zero · QuizAt 6 in the morning it was −3 degrees. By noon it was 7 degrees warmer. What was the temperature at noon?B. 4 degreesStart at −3 on the number line and move 7 steps right: −2,−1,0,1,2,3,4. So −3+7=4. The tempting 10 adds the 3 and the 7 as if both were positive, ignoring that the start was below zero; −10 goes the wrong way.
  7. 1. Numbers and what they count · Further right is bigger · Put in orderPut these numbers in order, smallest first.1. −7 2. −2.5 3. −12 4. 0 5. 32 6. 3Picture them on the number line, left to right. Among negatives, the one with the bigger size is further left, so −7 comes before −2.5, which comes before −12. Then 0. 32 is 1.5, so it sits between 1 and 2, before 3.
  8. 1. Numbers and what they count · Absolute value is distance from zero · Code challengeWrite distance(a, b): how far apart a and b are on the number line. It must never be negative. std::abs(x), from <cmath>, gives the absolute value of x.One solution:
    Solution
    #include <cmath>
    double distance(double a, double b) {  return std::abs(a - b);}
    b - a is right only when b is the bigger one; swap them and it goes negative. The absolute value removes the direction, so std::abs(a - b) and std::abs(b - a) are the same distance. Notice the test across zero: −3 to 4 is 7, not 1. Subtracting a negative adds its size. (The tests use EXPECT_NEAR with a tiny tolerance, 1e-9, the habit for any double a program computes.)
  9. 1. Numbers and what they count · Absolute value is distance from zero · ProblemWork out |−14| and |6−15|. Then find the distance between −8 and 5 on the number line.|−14|= 14; |6−15|= 9; The distance 13
    1. −14 is 14 steps from zero, so |−14|=14.
    2. Inside the bars first: 6−15=−9, so |6−15|=|−9|=9.
    3. The distance between −8 and 5:
    4. |−8−5|=|−13|=13
    5. Check by counting: from −8 up to 0 is 8 steps, and from 0 up to 5 is 5 more, 8+5=13.
  10. 1. Numbers and what they count · Fractions fill the gaps between integers · QuizWhich number lies between 13 and 12?B. 512Their average is 12(13+12)=12⋅56=512. As decimals: 0.333⋯<0.4166⋯<0.5. No two different fractions are “next to each other”: you can always average again. 14 is smaller than both, and 23 bigger than both.
  11. 1. Numbers and what they count · Some lengths are not fractions · QuizWhich of these are irrational? Choose all that are.B. 3; D. π9=3, an integer. 0.3=13: repeating decimals are rational. 227 is a fraction by definition; it is close to π but not equal (227=3.1428…, π=3.1415…). 3 is irrational by the same argument as 2, and π is irrational too, though that proof is much harder (Lambert, 1761).
  12. 1. Numbers and what they count · The real numbers fill the whole line · QuizWhat is the smallest of the sets ℕ,ℤ,ℚ,ℝ that contains −124?B. ℤSimplify first: −124=−3, an integer. It is not natural, because it is negative. It is also in ℚ and ℝ, since the sets nest, but ℤ is the smallest. Judging by looks alone (“it has a fraction bar, so it is in ℚ”) is the common slip.
  13. 1. Numbers and what they count · Practice problems · ProblemAt 6 in the morning it was −9 degrees. By 2 in the afternoon it had risen 13 degrees, and by midnight it had fallen 7 degrees from there. What was the temperature at 2 in the afternoon, and at midnight? How many degrees apart were the coldest and the warmest of these three readings?At 2 in the afternoon 4 degrees; At midnight -3 degrees; Coldest to warmest 13 degrees
    1. Start at −9 and move 13 steps right: −9+13=4 degrees.
    2. From 4, move 7 steps left: 4−7=−3 degrees.
    3. The readings were −9, 4 and −3. The coldest is −9 and the warmest is 4:
    4. |−9−4|=|−13|=13 degrees
  14. 1. Numbers and what they count · Practice problems · ProblemFind the number exactly halfway between −3.5 and 6 on the number line. How far is it from each of them?Halfway 1.25; Distance to each 4.75
    1. The number halfway is the average:
    2. −3.5+62=2.52=1.25
    3. Its distance to each end:
    4. |1.25−6|=|−4.75|=4.75|−3.5−1.25|=|−4.75|=4.75
    5. Check: the whole gap is |−3.5−6|=9.5, and half of it is 4.75.
  15. 1. Numbers and what they count · Practice problems · ProblemHow many integers lie between −4.5 and 3.2 on the number line? How many of those are natural numbers?Integers 8; Natural numbers 4
    1. The first integer to the right of −4.5 is −4; the last one to the left of 3.2 is 3. Between them:
    2. −4, −3, −2, −1, 0, 1, 2, 3
    3. That is 8 integers.
    4. The natural numbers are the ones that are not negative, 0,1,2,3: 4 of them. (A book that starts ℕ at 1 would say 3.)
  16. 1. Numbers and what they count · Practice problems · ProblemA building’s floors are numbered from −3 (the lowest car park) up to 12. A lift starts on floor −3, goes up to floor 9, and then down to floor −1. How many floors does it travel on each trip, and in all?Going up 12 floors; Going down 10 floors; In all 22 floors
    1. Going up, from −3 to 9:
    2. |−3−9|=|−12|=12 floors
    3. Going down, from 9 to −1:
    4. |−1−9|=|−10|=10 floors
    5. In all, 12+10=22 floors. From −3 straight to −1 is only 2 floors: that is how far it ended up from where it began, not how far it went.
  17. 2. Arithmetic, properly · An agreed order makes a sum mean one thing · QuizWhat is 8−2×3+1?A. 3Multiply first: 2×3=6. Then add and subtract left to right: 8−6=2, then 2+1=3. 19 comes from doing 8−2 first. 1 comes from adding 6+1 before subtracting, which breaks the left-to-right rule.
  18. 2. Arithmetic, properly · An agreed order makes a sum mean one thing · ProblemWork out 20−4×3+18÷6×2 and (5−2)2×2−24÷(3+1).The first 14; The second 12
    1. The first has no brackets or powers. Multiply and divide, left to right: 4×3=12, and 18÷6×2=3×2=6. Then add and subtract, left to right:
    2. 20−12+6=8+6=14
    3. The second: brackets first, 5−2=3 and 3+1=4. Then the power, 32=9. Then multiply and divide, and subtract last:
    4. 9×2−24÷4=18−6=12
  19. 2. Arithmetic, properly · Programming languages use the same order · QuizWhat does this print?A. 8, then 1412 / 3 * 2 goes left to right: 4 * 2 is 8. 2 + 3 * 4 multiplies first: 2 + 12 is 14. The computer applies the same agreed order you do, which is the point of having one.
  20. 2. Arithmetic, properly · Programming languages use the same order · Put in orderPut the steps for working out (2+3)2×4−6÷2 in order.1. Brackets: 2+3=5 2. Power: 52=25 3. Multiply and divide, left to right: 25×4=100, 6÷2=3 4. Subtract: 100−3=97Brackets, then powers, then the multiply-and-divide level, then the add-and-subtract level. The answer is 97. Squaring before adding, 2+32, would give a different number entirely: the brackets say the sum is squared.
  21. 2. Arithmetic, properly · Order and grouping do not matter for adding and multiplying · QuizFor which of these is a∘b=b∘a true for all numbers, where ∘ is the operation?C. Taking the larger, max⁡(a,b)The larger of two numbers is the same whichever you name first, so max⁡ is commutative. One counterexample is enough to break a law: 5−3=2 but 3−5=−2; 6÷3=2 but 3÷6=12; 23=8 but 32=9.
  22. 2. Arithmetic, properly · Multiplying spreads over a sum · Fill the blanksFill the blanks so each comparison is true. Each uses the distributive law.1: 3, 2: 1, 3: 20103=100+3, so 6×103=600+18. 49=50−1, so 9×49=450−9. The last runs the law backwards, which is called factoring: both terms have a 4, so 4×12+4×8=4×(12+8)=4×20=80.
  23. 2. Arithmetic, properly · Zero and one change nothing · QuizWhich number has no reciprocal?A. 0A reciprocal of 0 would be a number r with 0×r=1, but 0 times anything is 0. So none exists, and this is exactly why you cannot divide by zero. 1 and −1 are their own reciprocals; the reciprocal of 12 is 2.
  24. 2. Arithmetic, properly · Primes are the numbers with no smaller factors · QuizWhich of these are prime? Choose all that are.B. 2; E. 971 has one factor, so it is not prime by definition. 2 is prime, the only even one. 51=3×17 (its digits add to 6, divisible by 3). 91=7×13, the classic trap: it passes the easy tests. 97 is prime: no prime up to 97≈9.8, that is 2, 3, 5 or 7, divides it.
  25. 2. Arithmetic, properly · Every number is a product of primes in one way · Code challengeWrite primeFactors(n) for a natural number n ≥ 1: its prime factors, smallest first, each repeated as often as it divides. primeFactors(360) is {2, 2, 2, 3, 3, 5}; primeFactors(1) is empty, {}.One solution:
    Solution
    #include <vector>
    std::vector<int> primeFactors(int n) {  std::vector<int> factors;  for (int p = 2; p * p <= n; p++) {    while (n % p == 0) {      factors.push_back(p);      n = n / p;    }  }  if (n > 1) factors.push_back(n);  return factors;}
    Dividing out each factor completely, with while, is what makes the list only primes: by the time p reaches 4, every 2 is gone, so 4 can never divide what is left. Stopping when p * p > n uses the square-root rule from the last slide; whatever is left above 1 then is a prime itself, which is why the line after the loop is needed (it is how 13 and the 97 in 8633=89×97 get in).
  26. 2. Arithmetic, properly · The gcd and the lcm · QuizOne bus leaves the station every 12 minutes and another every 20 minutes. They both leave at 9:00. When do they next leave together?C. 10:00They leave together at the common multiples of 12 and 20, and the next is the least: 12=22×3, 20=22×5, so lcm⁡=22×3×5=60 minutes, at 10:00. 4 is the gcd, which answers a different question (the biggest step that fits both). 12×20=240 minutes is a common multiple, but not the least.
  27. 2. Arithmetic, properly · The gcd and the lcm · ProblemFactorise 84 and 120 into primes. Then find gcd⁡(84,120) and lcm⁡(84,120).gcd⁡(84,120)= 12; lcm⁡(84,120)= 840
    1. 84=22×3×7120=23×3×5
    2. The primes they share are 2 and 3. At the lower powers: gcd⁡=22×3=12.
    3. Every prime, at the higher power: lcm⁡=23×3×5×7=840.
    4. Check: 12×840=10080=84×120.
  28. 2. Arithmetic, properly · Euclid’s algorithm finds the gcd fast · Code challengeWrite gcd(a, b) with Euclid’s algorithm, for natural numbers not both zero, and lcm(a, b) for positive ones, using gcd. a % b is the remainder of a divided by b.One solution:
    Solution
    int gcd(int a, int b) {  while (b != 0) {    int r = a % b;    a = b;    b = r;  }  return a;}
    int lcm(int a, int b) {  return (a / gcd(a, b)) * b;}
    Save the remainder before overwriting: a = b first would lose a. If a < b, the first pass just swaps them, since 105 % 252 is 105, which is why the order does not matter. For the lcm, a×b÷gcd⁡ is right, and the integer division is exact, because the gcd divides a. Dividing before multiplying keeps the numbers smaller, which matters when a * b would pass an int’s limit, about 2.1 billion. The usual mistake is lcm = a * b, which is a common multiple but only the least when the gcd is 1. (C++ has both ready-made, std::gcd and std::lcm in <numeric>; this is how they work.)
  29. 2. Arithmetic, properly · Estimate before you calculate · QuizWithout calculating exactly, which is closest to 398×51?B. 20000398≈400 and 51≈50, so the answer is about 400×50=20000 (exactly 20298). Counting zeros is where estimates go wrong: 4×5=20, then add the two zeros from 400 and the one from 50.
  30. 2. Arithmetic, properly · Practice problems · ProblemWrite 1176 as a product of primes, in the form 2a×3b×7c. What are a, b and c?a= 3; b= 1; c= 2
    1. Halve while you can: 1176=2×588=2×2×294=2×2×2×147.
    2. 147 is odd. Its digits add up to 12, so 3 divides it: 147=3×49, and 49=7×7.
    3. 1176=2×2×2×3×7×7=23×31×72
    4. So a=3, b=1 and c=2. Check: 8×3×49=24×49=1176.
  31. 2. Arithmetic, properly · Practice problems · ProblemUse Euclid’s algorithm to find gcd⁡(1071,462). Then use the gcd to find lcm⁡(1071,462).gcd⁡= 21; lcm⁡= 23562
    1. 1071=2×462+147462=3×147+21147=7×21+0
    2. The remainder is 0, so the last non-zero remainder, 21, is the gcd.
    3. Then, dividing before multiplying to keep the numbers small:
    4. lcm⁡=1071×46221=1071×22=23562
  32. 2. Arithmetic, properly · Practice problems · ProblemA floor 360 cm long and 264 cm wide is to be covered with square tiles, all the same size, with no gaps and no cutting. What is the largest tile side that works, and how many tiles of that size are needed?Side 24 cm; Tiles 165
    1. The side must divide 360 and 264, and be as big as possible: it is their gcd.
    2. 360=23×32×5264=23×3×11gcd⁡=23×3=24
    3. Tiles of 24 cm fit 360÷24=15 along the length and 264÷24=11 across the width.
    4. So 15×11=165 tiles are needed.
  33. 2. Arithmetic, properly · Practice problems · ProblemThree lighthouses flash every 12, 18 and 30 seconds. They all flash together at midnight. How many seconds later do they next all flash together? How many times do they all flash together after midnight, up to and including 1 o’clock?Next together after 180 s; Times up to 1 o’clock 20
    1. The next time they meet is the least common multiple of all three:
    2. 12=22×318=2×3230=2×3×5
    3. Every prime at its highest power: 22×32×5=180 seconds, 3 minutes.
    4. They flash together every 180 seconds: at 180, 360, …, 3600. That is 3600÷180=20 times.
  34. 3. Fractions, decimals, percentages and ratios · Many fractions name the same number · QuizWhat is 4256 in lowest terms?C. 3442=2×3×7 and 56=23×7, so the gcd is 2×7=14, and 42÷1456÷14=34. 2128 and 68 are equivalent but not in lowest terms: they still share a 7 and a 2. Dividing by the gcd in one step saves the guessing.
  35. 3. Fractions, decimals, percentages and ratios · Add fractions over a common denominator · QuizWhat is 23−14?C. 512The common denominator is 12: 23=812 and 14=312, so the difference is 512. Subtracting tops and bottoms separately, 2−13−4, is the classic mistake: it gives −1, a negative number from taking a quarter away from two thirds.
  36. 3. Fractions, decimals, percentages and ratios · Add fractions over a common denominator · ProblemWork out 56+38 and 710−215. Give each in lowest terms.56+38= 29/24 ≈ 1.20833; 710−215= 17/30 ≈ 0.566667
    1. lcm⁡(6,8)=24, so rewrite both as twenty-fourths:
    2. 56+38=2024+924=2924
    3. 29 is prime and does not divide 24, so this is in lowest terms. (It is 1524.)
    4. lcm⁡(10,15)=30:
    5. 710−215=2130−430=1730
  37. 3. Fractions, decimals, percentages and ratios · Multiplying is easier than adding · QuizA ribbon is 56 m long. How many pieces 112 m long can you cut from it?B. 10“How many fit” is division: 56÷112=56×12=606=10. 572 multiplies instead of dividing, which would be the length of one twelfth of the ribbon. Dividing by a number less than 1 makes the answer bigger, which is a good check.
  38. 3. Fractions, decimals, percentages and ratios · Try it: add two fractions exactly · Code challengeFinish addFractions(a, b, c, d): return ab+cd as a pair {top, bottom} in lowest terms, with a positive bottom. b and d are positive. A std::pair<int, int> holds two ints: {5, 12} makes one.One solution:
    Solution
    #include <cmath>#include <utility>
    int gcd(int a, int b) {  while (b != 0) {    int r = a % b;    a = b;    b = r;  }  return std::abs(a);}
    std::pair<int, int> addFractions(int a, int b, int c, int d) {  int top = a * d + c * b;  int bottom = b * d;  int g = gcd(top, bottom);  return {top / g, bottom / g};}
    Over the common denominator bd, the tops become ad and cb. Dividing by the gcd then gives lowest terms: 14+16=6+424=1024, and gcd⁡(10,24)=2 makes it 512. The gcd of 0 and the bottom is the bottom itself, which is how a sum of 0 comes out as 01. Integer division is exactly right here: the gcd divides both, so nothing is thrown away. Adding tops and bottoms, the starter’s way, gives 210 for a quarter plus a sixth, smaller than a quarter alone.
  39. 3. Fractions, decimals, percentages and ratios · Decimals are fractions over powers of ten · QuizWhich of these have a decimal that stops? Choose all that do.A. 720; C. 34020=22×5 and 40=23×5, so 720=0.35 and 340=0.075 stop. 6 and 15 both contain a 3: 16=0.16 and 215=0.13 repeat for ever. Check lowest terms first: 36 stops, since it is 12.
  40. 3. Fractions, decimals, percentages and ratios · Recurring decimals turn back into fractions · QuizWhat fraction is 0.4=0.444…?B. 49x=0.444…, so 10x=4.444…, and 10x−x=4, so 9x=4 and x=49. 410 and 25 are the same number, 0.4 exactly, which stops. 499 is 0.04, a two-digit block.
  41. 3. Fractions, decimals, percentages and ratios · A percentage is a fraction out of one hundred · ProblemA jacket costs 80 euros. Its price goes up by 15%, and then the new price is cut by 20% in a sale. What is the sale price? What is the overall percentage change from 80 euros (negative for a fall)?Sale price 73.6 euros; Overall change -8 %
    1. Each change multiplies:
    2. 80×1.15=9292×0.8=73.60
    3. The sale price is 73.60 euros. Overall:
    4. 73.60−8080×100%=−6.4080×100%=−8%
    5. Or straight from the multipliers: 1.15×0.8=0.92, which is 8% less than 1. Adding the percentages, 15−20=−5%, is the trap: the 20% is of a bigger price.
  42. 3. Fractions, decimals, percentages and ratios · Try it: percentage change · Code challengeWrite percentChange(before, after), the change as a percentage of before, and afterChanges(value, percents), which applies each percentage change in turn. afterChanges(100, {10, -10}) is about 99.One solution:
    Solution
    #include <vector>
    double percentChange(double before, double after) {  return (after - before) / before * 100;}
    double afterChanges(double value,                    const std::vector<double>& percents) {  for (double p : percents) value = value * (1 + p / 100);  return value;}
    Divide the change by the old value: from 80 to 60 is −2080=−25%, but from 60 back to 80 is 2060≈+33.3%, because the base differs. Each change multiplies, so chains are products, never sums: 1.1×0.9=0.99. The tests use EXPECT_NEAR because 1.1 and 0.9 are not exact in binary, and the product is 99.00000000000001, not exactly 99. The parameters are doubles for a reason: with ints, p / 100 would be 0 for every change under 100%.
  43. 3. Fractions, decimals, percentages and ratios · Try it: percentage change · QuizA coat is reduced by 25% to 60 euros. What was the price before?B. 80 eurosDown 25% multiplies by 0.75, so 0.75×old=60 and old=60÷0.75=80. Check: 25% of 80 is 20, and 80−20=60. Adding 25% of 60 back, to get 75, is the trap: the 25% was of the old price, not the new one.
  44. 3. Fractions, decimals, percentages and ratios · Ratios compare amounts; proportion keeps them fixed · QuizA recipe for 4 people uses 300 g of flour. How much flour do you need for 6?B. 450 gFlour is proportional to people: 3004=75 g per person, and 6×75=450 g. Or scale by the ratio 64=1.5. Adding 100 g, “two more people, so a bit more”, is not proportion: it gives the two extra people only 50 g each, while the first four get 75 g each.
  45. 3. Fractions, decimals, percentages and ratios · Rates and unit conversion are fractions too · Fill the blanksConvert 72 km/h to metres per second. Fill in the two conversion numbers.1: 1000, 2: 3600A kilometre is 1000 m and an hour is 60×60=3600 s. So 72×10003600=20 m/s. A quick rule: divide km/h by 3.6 to get m/s. Multiplying by 3600 instead of dividing is the usual slip; check the units cancel and the answer is sensible (20 m/s is a car on an open road, not a rocket). The variables are doubles so that 50 km/h comes out as 13.89 m/s; with ints it would be 13.
  46. 3. Fractions, decimals, percentages and ratios · Practice problems · ProblemWrite 0.36 and 0.185 as fractions in lowest terms.0.36= 4/11 ≈ 0.363636; 0.185= 5/27 ≈ 0.185185
    1. The block 36 has two digits, so multiply by 100:
    2. x=0.363636…100x=36.363636…99x=36,x=3699=411
    3. The block 185 has three digits, so multiply by 1000:
    4. y=0.185185…1000y=185.185185…999y=185,y=185999
    5. Simplify: 185=5×37 and 999=27×37, so y=527. Check: 5÷27=0.185185…
  47. 3. Fractions, decimals, percentages and ratios · Practice problems · ProblemWork out (23+14)÷56, in lowest terms.11/10 ≈ 1.1
    1. The bracket first, over twelfths:
    2. 23+14=812+312=1112
    3. Then divide by multiplying by the reciprocal:
    4. 1112÷56=1112×65=6660=1110
    5. The answer is 1110, or 1.1. It is a bit more than 1112, as it should be: dividing by a number less than 1 makes the answer bigger.
  48. 3. Fractions, decimals, percentages and ratios · Practice problems · ProblemAfter a rise of 12%, the rent of a flat is 896 euros a month. What was it before the rise?Before 800 euros
    1. Up 12% multiplies by 1.12, so:
    2. 1.12×old=896⟹old=8961.12=800
    3. Check: 12% of 800 is 96, and 800+96=896. Taking 12% off 896 instead gives about 788.48: the 12% was of the old rent, not the new one.
  49. 3. Fractions, decimals, percentages and ratios · More practice problems · ProblemThree friends share 168 euros in the ratio 2:5:7. How much does each get?The first 24 euros; The second 60 euros; The third 84 euros
    1. The ratio has 2+5+7=14 equal parts, so one part is 168÷14=12 euros.
    2. The shares are 2×12=24, 5×12=60 and 7×12=84 euros.
    3. Check: 24+60+84=168.
  50. 3. Fractions, decimals, percentages and ratios · More practice problems · ProblemA car uses 6.5 litres of fuel per 100 km. How much fuel does it use on a 340 km trip? At 1.80 euros a litre, what does that fuel cost?Fuel 22.1 L; Cost 39.78 euros
    1. 340 km×6.5 L100 km=2210100 L=22.1 L
    2. 22.1 L×1.80 euros1 L=39.78 euros
    3. The trip uses 22.1 litres, which cost 39.78 euros.
  51. 4. Powers, roots and scientific notation · A power is repeated multiplication · QuizWhat are (−2)4 and −24?B. 16 and −16(−2)4=(−2)(−2)(−2)(−2)=16: an even number of negatives makes a positive. In −24 the power comes before the minus (Module 2’s order), so it is −(24)=−16. The brackets decide whether the minus sign belongs to the base. And −8 would be −2×4, a different operation.
  52. 4. Powers, roots and scientific notation · The laws of exponents follow from counting factors · QuizSimplify (x3)4×x2x5.A. x9(x3)4=x12 (power of a power multiplies), then x12×x2=x14 (multiplying adds), then x14x5=x9 (dividing subtracts). x4 comes from adding 3+4 instead of multiplying, the most common slip with these laws.
  53. 4. Powers, roots and scientific notation · The laws of exponents follow from counting factors · ProblemSimplify (2a3)2×a48a5, for a≠0.a^5/2
    1. Square the bracket, the 2 and the a3 both: (2a3)2=22(a3)2=4a6.
    2. Multiply by a4 (add exponents): 4a6×a4=4a10.
    3. Divide by 8a5, the numbers and the powers apart:
    4. 4a108a5=48×a10−5=a52
    5. Forgetting to square the 2 gives 2a108a5=a54, the most common slip here.
  54. 4. Powers, roots and scientific notation · Zero and negative exponents keep the pattern going · QuizWhat is 5−2?C. 125A negative exponent means “one over”: 5−2=152=125. The minus is in the exponent, so it says nothing about the sign of the answer, which is positive. −10 multiplies the 5 by the exponent, mixing up powers with products.
  55. 4. Powers, roots and scientific notation · Try it: powers by repeated multiplication · Code challengeWrite power(base, n) for a whole number n, which may be zero or negative, by multiplying in a loop. Do not use std::pow.One solution:
    Solution
    #include <cmath>
    double power(double base, int n) {  double result = 1;  for (int i = 0; i < std::abs(n); i++) {    result = result * base;  }  if (n < 0) return 1 / result;  return result;}
    Starting result at 1, the identity for multiplication (Module 2), is what makes n = 0 give 1: the loop simply never runs. For a negative n, multiply |n| times and take the reciprocal, exactly as a−n=1an says; result is a double, so 1 / result keeps its fraction. Starting at 0 instead is the usual slip: every product would be 0.
  56. 4. Powers, roots and scientific notation · A root undoes a power · QuizWhich of these are real numbers? Choose all that are.B. −83; C. 0(−2)3=−8, so −83=−2: odd roots of negatives are fine. 0=0. But no real number squares to −9, since squares are never negative, and the same goes for a fourth root of −16. Even roots of negatives need the complex numbers of Module 17.
  57. 4. Powers, roots and scientific notation · A fractional exponent is a root · QuizWhat is 163/4?B. 8The bottom, 4, is a fourth root: 164=2, because 24=16. The top, 3, is a cube: 23=8. 12 is 16×34, treating the exponent as a multiplier, which it never is.
  58. 4. Powers, roots and scientific notation · A fractional exponent is a root · ProblemWork out 323/5, 27−2/3 and (49)−1/2, exactly.323/5= 8; 27−2/3= 1/9 ≈ 0.111111; (49)−1/2= 3/2 ≈ 1.5
    1. The fifth root of 32 is 2, since 25=32. Then cube it: 323/5=23=8.
    2. The cube root of 27 is 3. Square it, then take one over:
    3. 27−2/3=1272/3=132=19
    4. The square root of 49 is 23, since 23×23=49. One over it flips it:
    5. (49)−1/2=12/3=32
  59. 4. Powers, roots and scientific notation · Simplify a root by taking out squares · QuizWhat is 12+27?B. 53Simplify each: 12=4×3=23 and 27=9×3=33. Now they are like amounts of the same thing: 23+33=53. 39 assumes roots add, a+b=a+b, which is false: 9+16=7, but 25=5.
  60. 4. Powers, roots and scientific notation · Try it: a square root by halving the gap · Code challengeWrite squareRoot(a) for a ≥ 0 by bisection, without std::sqrt or std::pow. Start with low = 0 and high = std::max(1.0, a), and halve the gap 60 times. (std::max, from <algorithm>, wants two values of the same type: 1.0, not 1.)One solution:
    Solution
    #include <algorithm>
    double squareRoot(double a) {  double low = 0;  double high = std::max(1.0, a);  for (int i = 0; i < 60; i++) {    double mid = (low + high) / 2;    if (mid * mid < a) low = mid;    else high = mid;  }  return (low + high) / 2;}
    The root always stays between low and high: low only moves to numbers whose square is below a, and high to ones whose square is not. Why std::max(1.0, a) for the start? For a below 1 the root is bigger than a (0.25=0.5), so high = a would leave it outside the gap. Comparing mid * mid with a avoids needing a root to find a root.
  61. 4. Powers, roots and scientific notation · Scientific notation writes huge and tiny numbers · QuizWhat is 0.00045 in scientific notation?A. 4.5×10−4Move the point right until one non-zero digit is in front: 0.00045→4.5 is 4 places. Making the number bigger must be balanced by 10−4. 45×10−5 is the same value, but not in standard form, because 45 is not below 10. A positive power would make it huge.
  62. 4. Powers, roots and scientific notation · Orders of magnitude compare by powers of ten · QuizThe Earth’s diameter is about 1.3×107 m and the distance to the Sun about 1.5×1011 m. Roughly how many Earths would fit in a row from the Earth to the Sun?C. About 10 000Divide: 1.5×10111.3×107≈1.2×104, about 10 000 (about 11 500 with these figures). Subtracting the exponents, 11−7=4, is what dividing powers does; 4 is the exponent, not the answer, and 1018 adds them.
  63. 4. Powers, roots and scientific notation · Significant figures say how precise a number is · QuizWhat is 0.0045072 to 3 significant figures?B. 0.00451Start counting at the first non-zero digit: 4, 5, 0 are the first three, and the next digit is 7, so the 0 rounds up to 1: 0.00451. 0.005 is 3 decimal places, a different rule, and keeps only one significant figure. 0.00450 forgets to round up.
  64. 4. Powers, roots and scientific notation · Practice problems · ProblemSimplify 50+18−8, and rationalise the denominator of 63.50+18−8= 6*sqrt(2) ≈ 8.48528; 63= 2*sqrt(3) ≈ 3.4641
    1. Take the biggest square out of each:
    2. 50=252=5218=328=22
    3. Now they are like amounts of 2: 52+32−22=62.
    4. 63×33=633=23
  65. 4. Powers, roots and scientific notation · Practice problems · ProblemSunlight travels about 1.5×1011 m from the Sun to the Earth, at 3.0×108 m/s. How many seconds does the trip take? How many minutes is that?Time 500 s; In minutes 25/3 ≈ 8.33333 min
    1. 1.5×10113.0×108=1.53.0×1011−8=0.5×103=500 s
    2. In minutes: 500÷60=813≈8.33 minutes. The sunlight you see left the Sun over 8 minutes ago.
  66. 4. Powers, roots and scientific notation · Practice problems · ProblemWork out (6.4×105)×(2.5×10−8) and 4.8×1071.6×10−3. You can type an answer like 3×104 as 3e4 or 3*10^4.The product 0.016; The quotient 30000000000
    1. Product: 6.4×2.5=16, and 105×10−8=10−3. So it is 16×10−3, and in standard form:
    2. 16×10−3=1.6×101×10−3=1.6×10−2=0.016
    3. Quotient: 4.8÷1.6=3, and 107÷10−3=107−(−3)=1010:
    4. 4.8×1071.6×10−3=3×1010
  67. 4. Powers, roots and scientific notation · More practice problems · ProblemRound 0.0060819 to 3 significant figures, and 48750 to 2 significant figures.0.0060819 to 3 s.f. 0.00608; 48750 to 2 s.f. 49000
    1. In 0.0060819 the significant figures start at the 6: 6, 0, 8 are the first three, and the next digit is 1, so the 8 stays. The answer is 0.00608; the zero between 6 and 8 counts.
    2. In 48750 the first two are 4 and 8, and the next digit is 7, so the 8 rounds up to 9. The places after it become zeros to keep the size: 49000.
    3. Writing 49 would be a different number: rounding keeps the number about the same size.
  68. 4. Powers, roots and scientific notation · More practice problems · ProblemA colony of bacteria doubles every 20 minutes, starting from 1 cell. After 4 hours it has 2n cells: what is n, and how many cells is that? How many cells are there after 10 hours, in scientific notation to 3 significant figures?n= 12; After 4 hours 4096 cells; After 10 hours 2^30 ≈ 1073741824 cells
    1. 4 hours is 240 minutes, which is 240÷20=12 doublings, so n=12 and there are 212=4096 cells.
    2. 10 hours is 600 minutes, which is 30 doublings:
    3. 230=(210)3=10243=1073741824≈1.07×109
    4. About a billion cells from one, in 10 hours.
  69. 5. Letters for numbers: variables and expressions · An expression names a value; an equation makes a claim · QuizWhich of these is an equation?B. 4x−7=9Only 4x−7=9 has an equals sign, so only it says something that can be true or false. The others are expressions: values waiting for an x. Asking “what is the answer to 4x−7?” has no single reply; asking “when is 4x−7=9?” does.
  70. 5. Letters for numbers: variables and expressions · Substitute to find an expression’s value · QuizWhat is 2a−b2 when a=3 and b=−4?B. −102(3)−(−4)2=6−16=−10. The square of −4 is +16, and the minus in front of b2 then subtracts it. Writing −42 without brackets, or thinking “minus a negative is plus”, gives the wrong 22.
  71. 5. Letters for numbers: variables and expressions · Substitute to find an expression’s value · ProblemFind the value of a2−3ba+b when a=−4 and b=2, and of 2x2−5x+3 when x=−12.a2−3ba+b= -5; 2x2−5x+3= 6
    1. Top: (−4)2−3(2)=16−6=10. Bottom: (−4)+2=−2. So the value is 10−2=−5.
    2. Second, with x=−12:
    3. 2(−12)2−5(−12)+3=2×14+52+3=12+52+3=6
  72. 5. Letters for numbers: variables and expressions · Only like terms can be added · QuizSimplify 4a2+3a−a2+2−5a.A. 3a2−2a+2Group by kind: a2 terms 4a2−a2=3a2; a terms 3a−5a=−2a; the constant 2. A term’s sign goes with it, so −5a is subtracted. Adding all the coefficients together, 4+3−1+2−5=3, treats unlike terms as if they were alike.
  73. 5. Letters for numbers: variables and expressions · Only like terms can be added · Code challengeEach term is a Term, a coefficient and its letters, so 3x is {3, "x"}, 2x2 is {2, "x²"} and a constant 5 is {5, ""}. Write collect(terms): add the coefficients of like terms, and return a std::map from letters to coefficient. Leave out any that come to 0. In a map, m[key] is the value kept for key (0 the first time), and for (const auto& [key, value] : m) visits each entry.One solution:
    Solution
    #include <map>#include <string>#include <vector>
    struct Term {  int coefficient;  std::string letters;};
    std::map<std::string, int> collect(const std::vector<Term>& terms) {  std::map<std::string, int> sums;  for (const Term& term : terms) {    sums[term.letters] += term.coefficient;  }  std::map<std::string, int> result;  for (const auto& [letters, total] : sums) {    if (total != 0) result[letters] = total;  }  return result;}
    The letters are the key: two terms are alike exactly when their letters match, so they land in the same entry and their coefficients add. A map’s sums[letters] starts a new kind at zero, so += works the first time too. A struct (here Term) groups named values: term.letters reads one. Leaving out the zeros afterwards is what 4a−4a=0 means: the term is gone, not “0a”. This is how computer algebra systems store polynomials, a map from each kind of term to its coefficient.
  74. 5. Letters for numbers: variables and expressions · Expanding brackets multiplies every term · Find the bugThis simplification of −3(2x−4)+5x goes wrong on one line. Which?Line 2: = -6x + 12 + 5xThe −3 multiplies both terms: −3×2x=−6x, and −3×(−4)=+12, since two negatives make a positive. Line 3 collects the terms of line 2 correctly, but from a wrong start; the right answer is −x+12. Check by substituting: at x=0 the original is −3(−4)=12, not −12.
  75. 5. Letters for numbers: variables and expressions · Expanding brackets multiplies every term · ProblemExpand and simplify (2x−3)(x+4) and 5(2x−3)−3(x−4).(2x−3)(x+4)= 2*x^2 + 5*x - 12; 5(2x−3)−3(x−4)= 7*x - 3
    1. Four products, then collect the like terms:
    2. (2x−3)(x+4)=2x2+8x−3x−12=2x2+5x−12
    3. Expand each bracket, minding the signs: −3×(−4)=+12.
    4. 5(2x−3)−3(x−4)=10x−15−3x+12=7x−3
    5. Check the first at x=1: (2−3)(1+4)=−5, and 2+5−12=−5.
  76. 5. Letters for numbers: variables and expressions · Factoring puts the brackets back · Fill the blanksFactor 12x−18 completely. The two functions must agree for every x; the last line checks a few.1: 6, 2: 2, 3: 3gcd⁡(12,18)=6, and 12x−18=6(2x−3). 2(6x−9) or 3(4x−6) are also equal, but not completely factored: the inside still has a common factor. Taking out the highest common factor in one step leaves a bracket with none left.
  77. 5. Letters for numbers: variables and expressions · Factoring puts the brackets back · QuizFactor 8a3+12a2 completely.B. 4a2(2a+3)Numbers: gcd⁡(8,12)=4. Letters: each term has at least a2. So the common factor is 4a2, and 8a3÷4a2=2a, 12a2÷4a2=3. The other options are all equal to the expression but leave something common inside the bracket; 4a(2a2+3) is not even equal, since it expands to 8a3+12a.
  78. 5. Letters for numbers: variables and expressions · Turning words into expressions · QuizA garden is w metres wide and 3 metres longer than it is wide. What is its perimeter, the distance all the way round?B. 4w+6The length is w+3. A rectangle has two widths and two lengths, so the perimeter is 2w+2(w+3)=2w+2w+6=4w+6. w+(w+3) goes only half way round. w(w+3) is the area, a different question. 4w+3 forgets that the extra 3 is in both lengths.
  79. 5. Letters for numbers: variables and expressions · Turning words into expressions · Code challengeWrite two expressions as functions. ticketCost(adults, children): 12 euros per adult, 7 per child. gardenPerimeter(width): the perimeter of a garden 3 m longer than it is wide.One solution:
    Solution
    int ticketCost(int adults, int children) {  return 12 * adults + 7 * children;}
    double gardenPerimeter(double width) {  double length = width + 3;  return 2 * width + 2 * length;}
    Naming the length, width + 3, before using it keeps the code close to the words, and it is easy to check: the garden 5 m wide is 8 m long, so 2×5+2×8=26. The last test checks your function against the simplified expression 4w+6 for several widths: two expressions are the same when they agree for every value, which is the next slide’s idea.
  80. 5. Letters for numbers: variables and expressions · An identity is true for every value · QuizWhich of these are identities, true for every x? Choose all that are.A. 2(x+3)=2x+6; C. x+x=2x; E. x(x−2)=x2−2xExpanding the left side of the first and last gives the right side exactly, and x+x=2x is collecting like terms. (x+1)2=x2+2x+1, so that one is true only when 2x=0, at x=0. 3x−1=8 is an ordinary equation, true only at x=3.
  81. 5. Letters for numbers: variables and expressions · Practice problems · ProblemFactor 15x2y−10xy2 completely. What is the highest common factor you take out, and what is left in the bracket?Common factor 5*x*y; In the bracket 3*x - 2*y
    1. Numbers: gcd⁡(15,10)=5. Letters: both terms have at least one x and at least one y. So the highest common factor is 5xy.
    2. Divide each term by it: 15x2y÷5xy=3x and 10xy2÷5xy=2y.
    3. 15x2y−10xy2=5xy(3x−2y)
    4. Check by expanding: 5xy×3x=15x2y and 5xy×2y=10xy2.
  82. 5. Letters for numbers: variables and expressions · Practice problems · ProblemA rectangle is w cm wide, and its length is 2 cm more than three times its width. Write its perimeter in terms of w, simplified. Then find the perimeter when w=4.5.Perimeter 8*w + 4 cm; When w=4.5 40 cm
    1. The length is 3w+2. The perimeter is two widths and two lengths:
    2. 2w+2(3w+2)=2w+6w+4=8w+4
    3. At w=4.5: 8×4.5+4=36+4=40 cm. Check: the length is 15.5, and 2×4.5+2×15.5=9+31=40.
  83. 5. Letters for numbers: variables and expressions · Practice problems · ProblemA family goes to the cinema: a adults at 9 euros each, and children at 6 euros each, with 3 more children than adults. Write the total cost in terms of a, simplified. What does it come to for 2 adults?Total 15*a + 18 euros; For 2 adults 48 euros
    1. There are a+3 children. The cost is the adults’ plus the children’s:
    2. 9a+6(a+3)=9a+6a+18=15a+18
    3. For a=2: 15×2+18=48 euros. Check: 2 adults cost 18 and 5 children cost 30, which is 48.
  84. 5. Letters for numbers: variables and expressions · Practice problems · ProblemExpand and simplify (x+5)2−(x−5)2. Then use your answer to work out 1052−952 without a calculator.(x+5)2−(x−5)2= 20*x; 1052−952= 2000
    1. Expand each square:
    2. (x+5)2=x2+10x+25(x−5)2=x2−10x+25
    3. Subtract, minding that the minus applies to every term of the second:
    4. x2+10x+25−x2+10x−25=20x
    5. With x=100: 1052−952=20×100=2000. Check: 11025−9025=2000.
  85. 6. Solving linear equations · Undo what was done to the unknown, in reverse order · Put in orderPut the steps for solving x2−3=4 in order.1. Start: x2−3=4 2. Add 3 to both sides: x2=7 3. Multiply both sides by 2: x=14 4. Check: 142−3=7−3=4, as it should beThe recipe was “halve, then subtract 3”, so you undo the subtraction first, then the halving. Multiplying by 2 first also works, but then you must multiply every term: x−6=8. Forgetting the 3 there, writing x−3=8, is the common slip. The check at the end catches it.
  86. 6. Solving linear equations · Gather the unknowns on one side · QuizSolve 7−2x=3x−8.A. x=3Add 2x to both sides: 7=5x−8. Add 8: 15=5x. Divide by 5: x=3. Check: 7−6=1 and 9−8=1. x=15 comes from moving −2x across as −2x instead of +2x, which leaves 7=x−8: a term changes sign when it moves, because you added its opposite to both sides. x=−3 is a sign lost at the last step, which the check catches.
  87. 6. Solving linear equations · Gather the unknowns on one side · ProblemSolve 7x−4=3x+18.x= 11/2 ≈ 5.5
    1. 7x−4=3x+184x−4=18subtract 3x4x=22add 4x=224=112divide by 4
    2. Check with x=5.5: 7(5.5)−4=34.5 and 3(5.5)+18=34.5.
  88. 6. Solving linear equations · Always check by substituting back · Find the bugThis solution of 4x+6=2x−10 gives x=−2, which fails the check. Which line has the mistake?Line 3: 2x = -16From 2x+6=−10, subtracting 6 from both sides gives 2x=−16, not −4: the 6 was added to −10 instead of subtracted. Then x=−8. Check in the original: 4(−8)+6=−26 and 2(−8)−10=−26. And x=−2 fails: −2 on the left, −14 on the right.
  89. 6. Solving linear equations · Expand brackets first · QuizSolve 3(2x−1)−2(x−4)=13.A. x=2Expand: 6x−3−2x+8=13. The −2 multiplies both terms, so −2×−4=+8. Collect: 4x+5=13, so 4x=8 and x=2. Check: 3(3)−2(−2)=9+4=13. Writing −2x−8, the classic sign slip, gives 4x−11=13 and x=6; dropping the sign on the 3 gives other wrong answers.
  90. 6. Solving linear equations · Clear fractions by multiplying through · QuizSolve x+12=x−25.A. x=−3Multiply both sides by 10: 5(x+1)=2(x−2). Expand: 5x+5=2x−4. So 3x=−9 and x=−3. Check: −22=−1 and −55=−1. Keep the brackets when you multiply a fraction with a sum on top: 5x+1 instead of 5x+5 is the slip to avoid.
  91. 6. Solving linear equations · Clear fractions by multiplying through · ProblemSolve 2x−13−x+24=1.x= 22/5 ≈ 4.4
    1. Multiply every term by 12:
    2. 4(2x−1)−3(x+2)=128x−4−3x−6=12expand5x−10=125x=22,x=225
    3. Check with x=4.4: 8.8−13=2.6 and 6.44=1.6, and 2.6−1.6=1.
  92. 6. Solving linear equations · Some equations have no solution, some have every number · QuizHow many solutions does 3(x−2)+x=4x−6 have?C. Every number is a solutionExpand the left: 3x−6+x=4x−6. That is the right side exactly, so the equation is an identity and every x works; subtracting 4x from both sides leaves −6=−6, always true. A linear equation can never have exactly two solutions: two lines that meet twice are the same line.
  93. 6. Solving linear equations · Try it: a solver for every linear equation · Code challengeFinish solveLinear(a, b, c, d), which solves ax+b=cx+d. Return a Solution whose kind is "one" (with the solution in x), "none" when there is none, or "all" when every number is one.One solution:
    Solution
    #include <string>
    struct Solution {  std::string kind; // "one", "none" or "all"  double x;         // the solution, when kind is "one"};
    Solution solveLinear(double a, double b, double c, double d) {  if (a == c) {    if (b == d) return {"all", 0};    return {"none", 0};  }  return {"one", (d - b) / (a - c)};}
    The starter is right whenever a≠c, which is why it looks finished. With a=c it divides by zero, and a double gives inf for 20 and nan (“not a number”) for 00, rather than an error. (Dividing ints by zero is worse: it is undefined behaviour, and here it stops the program.) Those two are the computer’s versions of “no solution” and “any number”, so the cases must be checked before dividing. Comparing with == is safe here because the inputs are given exactly; after a long calculation you would compare with a small tolerance instead.
  94. 6. Solving linear equations · Rearranging a formula is solving for a letter · Fill the blanksFahrenheit from Celsius is F=95C+32. Rearrange it to write celsius(f): subtract first, then undo the multiplication.1: 32, 2: 5, 3: 9Undo in reverse: F−32=95C, then multiply both sides by 59, the reciprocal: C=59(F−32). Subtracting 32 after multiplying, 59F−32, is the usual mistake: it undoes the steps in the wrong order. Check with 212: 180×59=100. In C++, keep the order of the code: 5 / 9 * (f - 32) would be 0 for every temperature, because 5 / 9 divides two ints.
  95. 6. Solving linear equations · Rearranging a formula is solving for a letter · QuizThe area of a circle is A=πr2. What is r in terms of A?B. r=AπDivide by π: r2=Aπ. Then undo the square with a square root: r=Aπ, taking the positive root because a radius is a length. A2π treats the square as a doubling. Aπ roots the A but not the π: A=πr, so dividing it by π does not leave r.
  96. 6. Solving linear equations · Word problems: name, write, solve, check · QuizA taxi charges 3.50 euros to start plus 1.80 euros per kilometre. A ride costs 21.50 euros. How long was it?A. 10 kmLet k be the kilometres: 3.50+1.80k=21.50. Subtract the starting fee: 1.80k=18, so k=10. Check: 3.50+18=21.50. 11.9 comes from dividing the whole fare by 1.80 and forgetting the fixed part, and 13.9 from adding it instead of subtracting.
  97. 6. Solving linear equations · Practice problems · ProblemSolve 5(2x−3)−4(x+1)=2(x+7).x= 33/4 ≈ 8.25
    1. 5(2x−3)−4(x+1)=2(x+7)10x−15−4x−4=2x+14expand6x−19=2x+14collect4x=33subtract 2x, add 19x=334
    2. Check with x=8.25: the left is 5(13.5)−4(9.25)=67.5−37=30.5, and the right is 2(15.25)=30.5.
  98. 6. Solving linear equations · Practice problems · ProblemThe perimeter of a rectangle is P=2(l+w), where l is its length and w its width. Make w the subject. Then find w when P=46 cm and l=15 cm.w= P/2 - l; When P=46, l=15 8 cm
    1. P=2(l+w)P2=l+wdivide by 2w=P2−lsubtract l
    2. That is the same as w=P−2l2. With P=46 and l=15: w=23−15=8 cm.
    3. Check: 2(15+8)=46.
  99. 6. Solving linear equations · Practice problems · ProblemA mother is 3 times as old as her son. In 12 years she will be twice as old as he will be. How old are they now?The son 12 years; The mother 36 years
    1. Let s be the son’s age now; the mother is 3s. In 12 years they will be s+12 and 3s+12:
    2. 3s+12=2(s+12)3s+12=2s+24s=12
    3. The son is 12 and the mother is 36. Check against the words: in 12 years they will be 24 and 48, and 48 is twice 24.
  100. 6. Solving linear equations · More practice problems · ProblemPhone plan A costs 15 euros a month plus 0.10 euros a minute. Plan B costs 25 euros a month plus 0.05 euros a minute. For how many minutes a month do they cost the same, and what is that cost?Minutes 200 min; Cost 35 euros
    1. 15+0.10m=25+0.05m0.05m=10subtract 0.05m and 15m=200divide by 0.05
    2. At 200 minutes, plan A costs 15+0.10×200=35 euros, and plan B 25+0.05×200=35 euros.
    3. Below 200 minutes plan A is cheaper; above it, plan B.
  101. 6. Solving linear equations · More practice problems · ProblemThree consecutive odd numbers (odd numbers that follow each other, each 2 more than the last) add up to 159. What are the smallest and the largest?Smallest 51; Largest 55
    1. n+(n+2)+(n+4)=1593n+6=1593n=153,n=51
    2. The numbers are 51, 53 and 55. Check against the words: all three are odd, and 51+53+55=159.
  102. 7. Inequalities and absolute value · An inequality has a range of solutions · QuizWhich of these numbers satisfy x≤−2? Choose all that do.A. −3; B. −2; E. −2.5x≤−2 means “−2 or anything to its left”. −3 and −2.5 are left of −2, and −2 itself is allowed by the “or equal”. −1.5 is to the right of −2, so it is bigger, even though 1.5 is smaller than 2: compare positions on the line, not the digits.
  103. 7. Inequalities and absolute value · Multiplying by a negative flips the inequality · QuizSolve 5−2x>11.B. x<−3Subtract 5: −2x>6. Divide by −2 and flip: x<−3. Check x=−4: 5+8=13>11, true. Check x=0, which x>−3 would include: 5>11, false. Forgetting the flip is the single most common mistake with inequalities.
  104. 7. Inequalities and absolute value · Multiplying by a negative flips the inequality · ProblemSolve 3(x−2)−5≥7x+9. What is the largest number that satisfies it?The largest -5
    1. 3(x−2)−5≥7x+93x−11≥7x+9expand and collect−4x≥20subtract 7x and 11x≤−5divide by −4, and flip
    2. So every x≤−5 works, and the largest is −5 itself, since ≤ includes it.
    3. Check two numbers: x=−6 gives −29≥−33, true; x=0 gives −11≥9, false.
  105. 7. Inequalities and absolute value · Find the missing flip · Find the bugThis solves x−4+1≤3, but the answer is wrong. Which line is the mistake?Line 3: x >= -8Going from x−4≤2 to an answer for x multiplies both sides by −4, a negative, so the sign must flip: x≥−8. Check with x=0, which is ≥−8: 0+1=1≤3, true. And x=−12, which the wrong answer allows: 3+1=4≤3, false.
  106. 7. Inequalities and absolute value · Interval notation writes a range in brackets · QuizWhich interval is −5≤x<0?B. [−5,0)−5 is included (≤), so its bracket is square: [−5. 0 is not (<), so its bracket is round: 0). The brackets go with their own ends, read left to right just like the inequality.
  107. 7. Inequalities and absolute value · Compound inequalities: and, or · Put in orderPut the steps for solving 1≤7−3x<13 in order.1. Subtract 7 from all three parts: −6≤−3x<6 2. Divide all three by −3 and flip both signs: 2≥x>−2 3. Rewrite smallest first: −2<x≤2 4. As an interval: (−2,2]Each step is done to all three parts. Dividing by −3 flips both signs, which reverses the order of the ends; writing it again with the smaller end on the left makes it readable. Note which end is included: the ≤ that was next to 1 became the ≥ next to 2, so 2 is in and −2 is out.
  108. 7. Inequalities and absolute value · Try it: solve any linear inequality · Code challengeWrite solveLess(a, b, c), which solves ax+b<c and returns the open interval of solutions as an Interval{lower, upper}, using -inf or inf (infinity, already defined) for no end. Return std::nullopt when nothing is a solution: a std::optional<Interval> holds an Interval or nothing, s.has_value() says which, and s->lower reads its member.One solution:
    Solution
    #include <limits>#include <optional>
    struct Interval {  double lower;  double upper;};const double inf = std::numeric_limits<double>::infinity();
    std::optional<Interval> solveLess(double a, double b, double c) {  if (a == 0) {    if (b < c) return Interval{-inf, inf};    return std::nullopt;  }  double edge = (c - b) / a;  if (a > 0) return Interval{-inf, edge};  return Interval{edge, inf};}
    The sign of a decides which side the solutions are on: −3x<6 gives x>−2, so the edge becomes the lower end. With a = 0 the starter divides by zero: when b<c it happens to land on inf, the right end, but otherwise it answers an interval ending at -inf or nan instead of std::nullopt. The two cases have to be caught first, as in the equation solver of Module 6. (Comparing with inf exactly is fine: infinity is a value a double holds exactly.)
  109. 7. Inequalities and absolute value · An absolute value equation usually has two answers · QuizSolve |2x+1|=7.B. x=3 or x=−4Split it: 2x+1=7 gives x=3, and 2x+1=−7 gives 2x=−8, x=−4. Check: |7|=7 and |−7|=7. The answers are not ± the same number, because the +1 shifts the centre: they sit either side of −12, where 2x+1=0.
  110. 7. Inequalities and absolute value · An absolute value equation usually has two answers · Code challengeWrite absSolutions(a, b, r): every solution of |ax+b|=r, smallest first, for a≠0. Return {} when there is none and one number when r=0. std::min and std::max (from <algorithm>) give the smaller and bigger of two.One solution:
    Solution
    #include <algorithm>#include <vector>
    std::vector<double> absSolutions(double a, double b, double r) {  if (r < 0) return {};  if (r == 0) return {-b / a};  double one = (r - b) / a;  double other = (-r - b) / a;  return {std::min(one, other), std::max(one, other)};}
    Split into ax+b=r and ax+b=−r and solve each. When a is negative, dividing reverses which one is smaller, so sort them instead of assuming. r=0 needs its own case: both equations are the same, and listing the answer twice would claim two solutions where there is one.
  111. 7. Inequalities and absolute value · An absolute value equation usually has two answers · ProblemSolve |3x−4|=11. Give both solutions.The smaller -7/3 ≈ −2.33333; The larger 5
    1. What is inside the bars is either 11 or −11:
    2. 3x−4=11⇒3x=15⇒x=5
    3. 3x−4=−11⇒3x=−7⇒x=−73
    4. Check: |15−4|=11 and |−7−4|=|−11|=11.
  112. 7. Inequalities and absolute value · Absolute value inequalities: inside or outside · QuizSolve |x−2|≥3.B. x≤−1 or x≥5“At least 3 away from 2”: either x≤2−3=−1 or x≥2+3=5, two pieces, an “or”. −1≤x≤5 is the opposite, the numbers within 3 of 2. x≥5 alone forgets the left side, where x−2 is negative but its distance is still large.
  113. 7. Inequalities and absolute value · Practice problems · ProblemSolve −7<3−2x≤9 and write the answer as an interval. What are its left and right ends? How many integers are in it?Left end -3; Right end 5; Integers in it 8
    1. −7<3−2x≤9−10<−2x≤6subtract 3 from all three5>x≥−3divide by −2, flip both
    2. Smallest first: −3≤x<5, the interval [−3,5): −3 is in, 5 is not.
    3. The integers in it are −3,−2,−1,0,1,2,3,4: 8 of them. 5 is left out, because the right end is open.
  114. 7. Inequalities and absolute value · Practice problems · ProblemSolve |2x+3|<9. The answer is an interval (a,b): what are a and b?a= -6; b= 3
    1. Being less than 9 from zero means lying between −9 and 9:
    2. −9<2x+3<9−12<2x<6subtract 3−6<x<3divide by 2
    3. So a=−6 and b=3. Check the middle, x=−1.5: |0|<9, true; and x=4, outside: |11|<9, false.
  115. 7. Inequalities and absolute value · Practice problems · ProblemA phone plan costs 12 euros a month plus 0.08 euros for each text message. You want to spend at most 20 euros in a month. What is the largest number of texts you can send?Texts 100
    1. 12+0.08n≤200.08n≤8subtract 12n≤100divide by 0.08, a positive number
    2. You can send up to 100 texts. Check: 100 texts cost 12+8=20 euros, exactly the limit, and one more would go over.
  116. 7. Inequalities and absolute value · More practice problems · ProblemA tank holds 500 litres when a tap at its bottom is opened at t=0. It drains at 15 litres a minute. For which times t, in minutes, does it hold between 200 and 380 litres (both included)?From t= 8 min; To t= 20 min
    1. 200≤500−15t≤380−300≤−15t≤−120subtract 50020≥t≥8divide by −15, flip both
    2. So 8≤t≤20. Check: at t=8 the tank holds 500−120=380 litres, and at t=20 it holds 500−300=200.
  117. 7. Inequalities and absolute value · More practice problems · ProblemA bag of flour is sold as 1000 g, and the law allows its weight w to be off by at most 15 g: |w−1000|≤15. What are the lightest and the heaviest weights allowed? A bag weighs 984 g: by how many grams is it outside the allowed range?Lightest 985 g; Heaviest 1015 g; The 984 g bag is outside by 1 g
    1. Within 15 g of 1000 g:
    2. 1000−15≤w≤1000+15⟹985≤w≤1015
    3. A bag of 984 g is |984−1000|=16 g off, 1 g more than allowed: it is 1 g below the lightest legal weight, 985 g.
  118. 8. Functions: a rule from inputs to outputs · f(x) names the output · QuizIf f(x)=x2−3x, what is f(−2)?A. 10Substitute −2 in brackets: (−2)2−3(−2)=4+6=10. The two places x appears both get −2. 2 comes from writing −22=−4, but the whole input is squared, (−2)2=4; −10 also loses the sign of −3×−2. This is the same thing as calling f(-2) in code.
  119. 8. Functions: a rule from inputs to outputs · f(x) names the output · ProblemFor f(x)=3x2−5x+2, find f(−2) and f(13). Then find f(a−1) in terms of a, expanded and simplified.f(−2)= 24; f(13)= 2/3 ≈ 0.666667; f(a−1)= 3*a^2 - 11*a + 10
    1. f(−2)=3(−2)2−5(−2)+2=12+10+2=24
    2. f(13)=3×19−53+2=13−53+63=23
    3. The input a−1 replaces every x, in brackets:
    4. f(a−1)=3(a−1)2−5(a−1)+2=3a2−6a+3−5a+5+2=3a2−11a+10
    5. Check with a=−1, which makes the input −2: 3+11+10=24, the same as f(−2).
  120. 8. Functions: a rule from inputs to outputs · Domain is what goes in, range is what comes out · QuizWhat is the domain of f(x)=x−3?B. x≥3The square root needs what is inside to be at least 0: x−3≥0, so x≥3, the interval [3,∞) (Module 7). x=3 is allowed, since 0=0. x≥0 is the domain of x, but 1−3 is not real.
  121. 8. Functions: a rule from inputs to outputs · The vertical line test · QuizWhich of these give y as a function of x? Choose all that do.A. y=x2; D. y=|x|y=x2 and y=|x| give one y for each x. x=y2 fails: at x=4, both y=2 and y=−2 work, so a vertical line at 4 crosses twice. The circle fails the same way. Note x=y2 is a function if you read it the other way, x from y: which variable is the input matters.
  122. 8. Functions: a rule from inputs to outputs · Piecewise functions use different rules on different inputs · Code challengeWrite postage(grams) from the rule above. Its domain is 0<w≤2000: for any weight outside it, return std::nullopt, no value at all. (A std::optional<double>, from <optional>, holds a double or nothing.)One solution:
    Solution
    #include <optional>
    std::optional<double> postage(double grams) {  if (grams <= 0 || grams > 2000) return std::nullopt;  if (grams <= 100) return 1.2;  if (grams <= 500) return 2.5;  return 4.8;}
    Checking the pieces in order, smallest first, means each if only has to test the upper end: by the time you reach grams <= 500, you already know it is over 100. The boundaries are where piecewise functions go wrong: “up to 100 g” includes 100, so it is <=. Returning std::nullopt outside the domain says the function has no value there, instead of quietly making one up. (The prices are compared exactly because they are copied, not computed: 1.2 returned is the same double as 1.2 expected.)
  123. 8. Functions: a rule from inputs to outputs · Composition feeds one function into another · QuizIf f(x)=x2 and g(x)=x−4, what is f(g(1))?A. 9Inside first: g(1)=1−4=−3. Then f(−3)=(−3)2=9. Doing them the other way, g(f(1))=1−4=−3, is a different function. −15 comes from squaring the two parts separately, 12−42, but f(g(x))=(x−4)2: the whole of g(x) is squared.
  124. 8. Functions: a rule from inputs to outputs · Composition feeds one function into another · Code challengeFix compose(f, g): it must return the function f∘g, which runs g first and then f. Fn is a function from double to double (a std::function, from <functional>), and [f, g](double x) { … } is a lambda, a function made on the spot that keeps f and g.One solution:
    Solution
    #include <functional>
    using Fn = std::function<double(double)>;
    Fn compose(Fn f, Fn g) {  return [f, g](double x) { return f(g(x)); };}
    f∘g is written with f first but runs g first, because in f(g(x)) the inner call is evaluated before the outer one. The starter does the opposite, which only looks right when the order happens not to matter. The answer is itself a function: compose takes two functions and returns a third, which is what composition is.
  125. 8. Functions: a rule from inputs to outputs · An inverse function runs the machine backwards · Fill the blanksWrite the inverse of f(x)=5x−2, so that the check is true.1: 2, 2: 5f multiplies by 5 and then subtracts 2, so its inverse adds 2 and then divides by 5: the steps undone in reverse order, as in solving an equation. x5+2 undoes them in the wrong order, and f−1(f(1))=35+2 is not 1.
  126. 8. Functions: a rule from inputs to outputs · An inverse function runs the machine backwards · QuizWhy does f(x)=x2, on all real numbers, have no inverse?B. Because two inputs give the same output, so an inverse would not know which to give backf(2)=f(−2)=4, so f−1(4) would have to be both 2 and −2, and a function gives one output. Only one-to-one functions, where different inputs give different outputs, have inverses. The fix is to restrict the domain: on x≥0, x2 is one-to-one and its inverse is x (the curves of Module 4).
  127. 8. Functions: a rule from inputs to outputs · An inverse function runs the machine backwards · ProblemFind the inverse of f(x)=3x+42. Then work out f−1(5).f−1(x)= (2*x - 4)/3; f−1(5)= 2
    1. y=3x+422y=3x+4multiply by 22y−4=3xsubtract 4x=2y−43divide by 3
    2. Renaming, f−1(x)=2x−43. So f−1(5)=10−43=2.
    3. Check: f(2)=6+42=5, so the inverse sends 5 back to 2.
  128. 8. Functions: a rule from inputs to outputs · Shift, stretch and reflect a graph · QuizHow is the graph of y=(x+2)2−3 made from y=x2?B. 2 left, 3 downWrite it as (x−h)2+k: x+2=x−(−2), so h=−2, a move left by 2. k=−3 moves it down by 3. The turning point is at (−2,−3): check that x=−2 gives 0−3. The plus sign inside looking like “right” is the trap; changes inside the bracket act on x, and so go the opposite way to how they look.
  129. 8. Functions: a rule from inputs to outputs · Practice problems · ProblemLet f(x)=2x−1 and g(x)=x2+3. Find f(g(2)) and g(f(2)), and write f(g(x)) as one simplified expression.f(g(2))= 13; g(f(2))= 12; f(g(x))= 2*x^2 + 5
    1. g(2)=4+3=7, then f(7)=14−1=13.
    2. f(2)=4−1=3, then g(3)=9+3=12. A different answer: the order matters.
    3. f(g(x))=2(x2+3)−1=2x2+6−1=2x2+5
    4. Check at x=2: 8+5=13, as found above.
  130. 8. Functions: a rule from inputs to outputs · Practice problems · ProblemLet f(x)=12−3x. What is the largest number in its domain? Find f(−4), exactly. What is the smallest number in its range?Largest input 4; f(−4)= 2*sqrt(6) ≈ 4.89898; Smallest output 0
    1. The inside must not be negative: 12−3x≥0, so 12≥3x, and x≤4. The domain is (−∞,4], and its largest number is 4.
    2. f(−4)=12+12=24=4×6=26
    3. A square root is never negative, and f(4)=0=0, so the smallest output is 0. The range is [0,∞).
  131. 8. Functions: a rule from inputs to outputs · Practice problems · ProblemAn electricity tariff charges 0.20 euros per kWh for the first 100 kWh used in a month, and 0.30 euros for each kWh after that. What does a month of 80 kWh cost? And of 250 kWh? A household’s bill is 50 euros: how many kWh did it use?80 kWh 16 euros; 250 kWh 65 euros; A bill of 50 euros 200 kWh
    1. With k kWh, the cost in euros is
    2. c(k)={0.20k0≤k≤10020+0.30(k−100)k>100
    3. 80 kWh is in the first piece: 0.20×80=16 euros. 250 kWh is in the second: 20+0.30×150=20+45=65 euros.
    4. 50 euros is more than 20, so the household used over 100 kWh: 20+0.30(k−100)=50, so 0.30(k−100)=30, k−100=100 and k=200 kWh.
  132. 8. Functions: a rule from inputs to outputs · Practice problems · ProblemThe graph of y=x2 is moved 3 to the left, stretched upright by a factor of 2, and then moved 5 down. Write the equation of the new graph, and give its turning point.y= 2*(x + 3)^2 - 5; Turning point, x= -3; Turning point, y= -5
    1. Left 3: y=(x+3)2. Stretched by 2: y=2(x+3)2. Down 5:
    2. y=2(x+3)2−5
    3. This is a(x−h)2+k with a=2, h=−3 and k=−5, so the turning point is (−3,−5).
    4. Check: at x=−3 the bracket is 0 and y=−5, the lowest point, since 2(x+3)2 is never negative.
  133. 9. Lines and slope · Two number lines make a plane · QuizIn which quadrant is the point (−3,2)?B. Second (top left)x=−3 is 3 to the left, y=2 is 2 up: top left, the second quadrant. Swapping the coordinates, reading (−3,2) as 3 down and 2 across, would put it in the fourth. Across always comes first, the same order as in the alphabet: x before y.
  134. 9. Lines and slope · Slope is rise over run · QuizWhat is the slope of the line through (1,2) and (4,−7)?A. −3m=−7−24−1=−93=−3: down 3 for each step right. Taking the points in the same order on top and bottom is essential; −7−21−4 mixes them and gives 3. Putting run over rise gives −13.
  135. 9. Lines and slope · Slope-intercept form: y = mx + c · QuizA line crosses the y axis at 4 and goes down 2 for every 1 across. What is its equation?B. y=−2x+4Down 2 per 1 across is a slope of −2; the intercept is 4. So y=−2x+4. Swapping the two numbers, 4x−2, is the common slip: the number multiplying x is always the slope. Check: at x=0, y=4; at x=1, y=2, two lower.
  136. 9. Lines and slope · Try it: the line through two points · Code challengeFinish lineThrough(x1, y1, x2, y2): return a Line{m, c} for the line y=mx+c through the two points, or std::nullopt when the line is vertical.One solution:
    Solution
    #include <optional>
    struct Line {  double m;  double c;};
    std::optional<Line> lineThrough(double x1, double y1,                                double x2, double y2) {  if (x1 == x2) return std::nullopt;  double m = (y2 - y1) / (x2 - x1);  return Line{m, y1 - m * x1};}
    With m=−3 and the point (1,2): c=2−(−3)(1)=5, so y=−3x+5; check with the other point, −12+5=−7. The starter forgets c, which is only right for lines through the origin. With x1 == x2 the slope would be rise0, which is why vertical lines are written x=k instead.
  137. 9. Lines and slope · Try it: the line through two points · ProblemA line passes through (−3,−4) and (3,5). Find its slope m, its y-intercept c, and where it crosses the x axis.m= 3/2 ≈ 1.5; c= 1/2 ≈ 0.5; x-intercept, x= -1/3 ≈ −0.333333
    1. m=5−(−4)3−(−3)=96=32
    2. From the point (3,5): c=5−32×3=5−92=12. The line is y=32x+12.
    3. It crosses the x axis where 0=32x+12, so 32x=−12 and x=−13.
    4. Check with the other point: 32×(−3)+12=−92+12=−4.
  138. 9. Lines and slope · Point-slope form starts from any point · QuizWhich is the line with slope −12 through (4,5)?A. y=−12x+7y−5=−12(x−4)=−12x+2, so y=−12x+7. Check: at x=4, −2+7=5. +5 uses the point’s y as if it were the intercept, which is only true when the point is on the y axis.
  139. 9. Lines and slope · Standard form handles every line, vertical ones too · QuizWhat is the slope of 4x−5y=20?C. 45Solve for y: −5y=−4x+20, so y=45x−4. The slope is 45; with A=4 and B=−5, −AB=45 agrees. Reading the coefficient of x in standard form as the slope is the usual mistake: it is the slope only once y stands alone.
  140. 9. Lines and slope · Parallel lines share a slope; perpendicular slopes multiply to −1 · QuizWhat slope does a line perpendicular to y=23x+1 have?D. −32Flip the fraction and change the sign: −32. Check: 23×−32=−1. Changing only the sign, −23, gives a line that leans the other way at the same steepness, which is not at a right angle; flipping only gives 32, still leaning the same way.
  141. 9. Lines and slope · Parallel lines share a slope; perpendicular slopes multiply to −1 · ProblemFind the line through (4,−1) that is perpendicular to 2x−3y=6. Write it as y=mx+c: what are m and c?m= -3/2 ≈ −1.5; c= 5
    1. Solve for y: −3y=−2x+6, so y=23x−2. Its slope is 23.
    2. The perpendicular slope is m=−32. Check: 23×(−32)=−1.
    3. Through (4,−1), in point-slope form:
    4. y−(−1)=−32(x−4)⇒y+1=−32x+6⇒y=−32x+5
    5. So m=−32 and c=5.
  142. 9. Lines and slope · Distance and midpoint between two points · Code challengeWrite distance(x1, y1, x2, y2), the straight-line distance between two points, and midpoint(x1, y1, x2, y2), the point halfway, as a Point{x, y}.One solution:
    Solution
    #include <cmath>
    struct Point {  double x;  double y;};
    double distance(double x1, double y1, double x2, double y2) {  double dx = x2 - x1;  double dy = y2 - y1;  return std::sqrt(dx * dx + dy * dy);}
    Point midpoint(double x1, double y1, double x2, double y2) {  return {(x1 + x2) / 2, (y1 + y2) / 2};}
    The starter measures the taxicab distance, going along the grid like a car in a city of square blocks: 7 for the 3-4-5 triangle instead of 5. A straight line cuts the corner, and Pythagoras says by how much. The starter’s midpoint is half the gap, which is the midpoint only when the first point is the origin; averaging the coordinates works everywhere. Squaring makes the order of the points irrelevant, since (−6)2=62.
  143. 9. Lines and slope · A line is a model of steady change · QuizA phone plan costs C=0.05n+12 euros a month for n minutes of calls. What does the 0.05 mean?B. The cost of each minute of calls, in eurosThe slope is the change in cost per minute: each extra minute adds 0.05 euros, so its units are euros per minute. The 12 is the intercept: the cost when n=0, the fixed monthly fee. Reading the units of the slope, “output units per input unit”, is the quickest way to say what it means.
  144. 9. Lines and slope · Practice problems · ProblemFor the points A(2,−1) and B(−4,3), find the distance AB, exactly (as a simplified surd), and the midpoint of AB.AB= 2*sqrt(13) ≈ 7.2111; Midpoint, x= -1; Midpoint, y= 1
    1. AB=(−4−2)2+(3−(−1))2=36+16=52=4×13=213
    2. That is about 7.21.
    3. M=(2+(−4)2, −1+32)=(−1,1)
  145. 9. Lines and slope · Practice problems · ProblemFor the line 5x−2y=20, find where it crosses the x axis and the y axis, and its slope.x-intercept, x= 4; y-intercept, y= -10; Slope 5/2 ≈ 2.5
    1. Set y=0: 5x=20, so x=4. Set x=0: −2y=20, so y=−10.
    2. Solve for y: −2y=−5x+20, so y=52x−10. The slope is 52.
    3. Check with m=−AB=−5−2=52, and with the intercepts: from (0,−10) to (4,0) rises 10 over a run of 4.
  146. 9. Lines and slope · Practice problems · ProblemA plumber charges a fixed call-out fee plus a rate per hour. A 2-hour job costs 110 euros and a 5-hour job costs 215 euros. What is the hourly rate, what is the call-out fee, and what does a 3.5-hour job cost?Rate 35 euros per hour; Call-out fee 40 euros; 3.5 hours 162.5 euros
    1. The slope between (2,110) and (5,215) is the rate:
    2. m=215−1105−2=1053=35 euros per hour
    3. The fee is the intercept: c=110−35×2=40 euros. So the cost is C=35h+40.
    4. For 3.5 hours: 35×3.5+40=122.5+40=162.5 euros. Check with the 5-hour job: 175+40=215.
  147. 9. Lines and slope · More practice problems · ProblemThe points (1,2), (3,8) and (k,17) lie on one straight line. Find k.k= 6
    1. The slope from (1,2) to (3,8) is 8−23−1=3.
    2. From (1,2) to (k,17) it must also be 3:
    3. 17−2k−1=3⇒15=3(k−1)⇒k−1=5⇒k=6
    4. Check: from (3,8) to (6,17) the slope is 93=3.
  148. 9. Lines and slope · More practice problems · ProblemFind the line parallel to y=4x−1 that passes through (2,3). What is its y-intercept, and where does it cross the x axis?y-intercept, c= -5; x-intercept, x= 5/4 ≈ 1.25
    1. The new line is y=4x+c. Through (2,3): 3=8+c, so c=−5, and the line is y=4x−5.
    2. It crosses the x axis where 0=4x−5, at x=54.
  149. 10. Systems of equations · Two unknowns need two facts · QuizWhich pair (x,y) solves both 2x+y=8 and x−y=1?A. (3,2)Check each in both equations. (3,2): 6+2=8 and 3−2=1, both true. (2,4) and (4,0) satisfy the first only, and (1,0) the second only. A solution of a system has to pass every equation; passing one is not enough.
  150. 10. Systems of equations · Substitution: solve one, put it into the other · Put in orderPut the steps for solving y=x+1 and 2x+y=10 in order.1. Replace y in the second equation: 2x+(x+1)=10 2. Solve for x: 3x+1=10, so x=3 3. Put x back into y=x+1: y=4 4. Check in both: 4=3+1 and 6+4=10Substitute, solve the one-unknown equation, back-substitute, check. Substituting into the same equation you solved, y=x+1, gets you nowhere: it turns into x+1=x+1, true but empty. The expression must go into the other equation.
  151. 10. Systems of equations · Substitution: solve one, put it into the other · ProblemSolve by substitution: y=3x−5 and 4x+3y=24.x= 3; y= 4
    1. 4x+3(3x−5)=24substitute for y4x+9x−15=2413x=39,x=3y=3(3)−5=4back-substitute
    2. Check in the second equation: 4(3)+3(4)=12+12=24.
  152. 10. Systems of equations · Elimination: add the equations to cancel a variable · QuizSolve 2x+y=7 and x−y=2.A. x=3, y=1The y terms are +y and −y, so add: 3x=9, x=3. Then 3−y=2, so y=1. Check in the first: 6+1=7. Subtracting instead of adding gives x+2y=5, which still has both variables: choose the operation that makes the chosen terms cancel.
  153. 10. Systems of equations · Elimination: add the equations to cancel a variable · ProblemSolve by elimination: 3x+4y=5 and 5x−6y=21.x= 3; y= -1
    1. 9x+12y=15first×310x−12y=42second×219x=57add: the y terms cancelx=3
    2. Back into the first: 9+4y=5, so 4y=−4 and y=−1.
    3. Check in the second: 5(3)−6(−1)=15+6=21.
  154. 10. Systems of equations · One solution, none, or infinitely many · QuizHow many solutions does the system 2x+4y=6, x+2y=5 have?A. NoneDouble the second: 2x+4y=10. Subtract it from the first: 0=−4, which is false, so there is no solution. Both lines have slope −12 but different intercepts: parallel. If the second had been x+2y=3, doubling it would give the first equation exactly, the same line, and infinitely many solutions.
  155. 10. Systems of equations · Try it: solve any two-by-two system · Code challengeFinish solveTwo(a, b, c, d, e, f) for ax+by=e, cx+dy=f. Return a Solution whose kind is "one" (with x and y), "none" or "infinite". When ad−bc=0: if both tops, ed−bf and af−ec, are 0 too, it is the same line.One solution:
    Solution
    #include <string>
    struct Solution {  std::string kind; // "one", "none" or "infinite"  double x;  double y;};
    Solution solveTwo(double a, double b, double c, double d,                  double e, double f) {  double det = a * d - b * c;  double topX = e * d - b * f;  double topY = a * f - e * c;  if (det == 0) {    if (topX == 0 && topY == 0) return {"infinite", 0, 0};    return {"none", 0, 0};  }  return {"one", topX / det, topY / det};}
    This is Cramer’s rule for two equations, and ad−bc is the determinant of the system, which comes back in Module 19 as how much a matrix scales area. Computing the two tops first lets the zero case use them: with a zero determinant, the equations are multiples of each other on the left, and they agree on the right exactly when both tops vanish. Checking det == 0 before dividing matters, as in Module 6: dividing by 0 would give inf or nan, not an answer.
  156. 10. Systems of equations · Word problems with two unknowns · QuizTwo numbers add up to 30 and one is 8 more than the other. What are they?A. 19 and 11x+y=30 and x−y=8. Add them: 2x=38, so x=19 and y=11. Check: 19+11=30 and 19−11=8. 22 and 8 satisfy “add to 30” but differ by 14; 20 and 12 differ by 8 but add to 32. Each answer has to pass both facts.
  157. 10. Systems of equations · Three unknowns need three equations · QuizTo solve a system in x, y and z, you add equations (1) and (2) and get rid of z. What do you need to do next, before you can find x and y?B. Eliminate z from a different pair, to get a second equation in x and yOne equation in two unknowns has endless solutions (the first slide of this module). A second equation in the same two unknowns is needed, and it must come from a different pair, say (1) and (3) or (2) and (3), so that it carries new information. Then it is a two-by-two system. Module 18 turns this bookkeeping into an algorithm, Gaussian elimination, that works for any number of unknowns.
  158. 10. Systems of equations · Systems of inequalities mark out a region · Code challengeEach rule {a, b, c} means ax+by≤c. Fix feasible(x, y, rules) so it is true only when the point satisfies every rule.One solution:
    Solution
    #include <vector>
    struct Rule {  double a, b, c; // a x + b y <= c};
    bool feasible(double x, double y, const std::vector<Rule>& rules) {  for (const Rule& r : rules) {    if (r.a * x + r.b * y > r.c) return false;  }  return true;}
    A system means and: every rule must hold, so the first broken rule settles it, false, and only a point that breaks none gets true. The starter returns true as soon as one rule holds, which is the “or” of Module 7. Writing every rule as ax+by≤c makes them uniform: y≥2x−3 becomes 2x−y≤3, and x≥0 becomes −x≤0 (multiplying by −1 flips it). The corner (3,3) is on two lines, and ≤ includes it.
  159. 10. Systems of equations · Practice problems · ProblemA theatre sells 350 tickets for one show: adult tickets at 18 euros and child tickets at 11 euros. The takings are 5390 euros. How many of each kind were sold?Adult tickets 220; Child tickets 130
    1. a+c=350tickets18a+11c=5390euros18a+11(350−a)=5390c=350−a7a+3850=5390,7a=1540,a=220
    2. Then c=350−220=130. Check against the words: 18×220+11×130=3960+1430=5390 euros.
  160. 10. Systems of equations · Practice problems · ProblemA drink that is 20% juice is mixed with a drink that is 50% juice, to make 30 litres of a drink that is 30% juice. How many litres of each are used?Of the 20% drink 20 L; Of the 50% drink 10 L
    1. x+y=30litres of drink0.2x+0.5y=9litres of juice
    2. Multiply the second by 10 to clear decimals, 2x+5y=90, and the first by 2, 2x+2y=60. Subtract: 3y=30, so y=10 and x=20.
    3. Check: 0.2×20+0.5×10=4+5=9 litres of juice, which is 30% of 30 litres.
  161. 10. Systems of equations · Practice problems · ProblemSolve x+y+z=2, 2x−y+3z=9 and x+3y−z=−4.x= 1; y= -1; z= 2
    1. Number them (1), (2), (3). Two different pairs, each without z:
    2. (1)+(3):2x+4y=−2, so x+2y=−1(2)+3×(3):5x+8y=−3
    3. From the first, x=−1−2y. Then 5(−1−2y)+8y=−3, so −5−2y=−3, y=−1 and x=1.
    4. Back in (1): 1−1+z=2, so z=2. Check (2): 2+1+6=9. Check (3): 1−3−2=−4.
  162. 10. Systems of equations · More practice problems · ProblemFor which number k does the system 2x+ky=7, 6x+9y=4 have no solution?k= 3
    1. There is not exactly one solution when ad−bc=0:
    2. 2×9−k×6=0⇒18=6k⇒k=3
    3. With k=3, three times the first equation is 6x+9y=21, but the second says 6x+9y=4. Both cannot hold, so the lines are parallel and there is no solution.
  163. 10. Systems of equations · More practice problems · ProblemThe region y≤−x+8, y≥x−2, x≥0 is a triangle. Two of its corners are on the y axis. Find the third corner, where the two slanted lines meet, and the area of the triangle.Corner, x= 5; Corner, y= 3; Area 25
    1. Where the slanted lines meet: −x+8=x−2, so 10=2x, x=5 and y=3.
    2. On the y axis (x=0) the lines are at y=8 and y=−2: the corners (0,8) and (0,−2).
    3. The base along the axis is 8−(−2)=10, and the third corner is 5 from the axis, so:
    4. area=12×10×5=25
  164. 11. Polynomials and factoring · A polynomial is a sum of powers of one letter · QuizWhat is the degree of 4x+2x3−9+x2?B. 3The degree is the highest power present, wherever it is written: 2x3 makes it 3. In standard form it reads 2x3+x2+4x−9, so the leading term is first and the degree is easy to see. The number of terms has nothing to do with it: x10 has one term and degree 10.
  165. 11. Polynomials and factoring · Adding and subtracting means collecting like terms · Fill the blanksSubtract: (4x2−3x+7)−(x2+2x−5). Fill in the coefficients of the answer (a negative one with its minus sign).1: 3, 2: -5, 3: 12Flip every sign in the second bracket first: −x2−2x+5. Then collect: 4−1=3 for x2, −3−2=−5 for x, 7+5=12 for the constant. If you got −1 for x or 2 for the constant, a sign inside the bracket was not flipped.
  166. 11. Polynomials and factoring · Multiplying means every term times every term · Code challengeWrite multiply(p, q): the coefficients of the product of two polynomials with whole-number coefficients, both given constant first. The result has p.size() + q.size() - 1 coefficients; std::vector<int> out(n, 0) makes a vector of n zeros.One solution:
    Solution
    #include <vector>
    std::vector<int> multiply(const std::vector<int>& p,                          const std::vector<int>& q) {  std::vector<int> out(p.size() + q.size() - 1, 0);  for (std::size_t i = 0; i < p.size(); i++) {    for (std::size_t j = 0; j < q.size(); j++) {      out[i + j] += p[i] * q[j];    }  }  return out;}
    Index is power, and xi⋅xj=xi+j, so each product is added into out[i + j]. The += is the collecting of like terms: several pairs land on the same power, as 2x⋅4 and −3⋅x did above. Writing = instead keeps only the last pair and gives wrong middle coefficients. This double loop is called a convolution; it shows up again in signal processing and probability.
  167. 11. Polynomials and factoring · Three products worth knowing by heart · Find the bugThis expansion of (x−5)2 goes wrong on one line. Which?Line 3: = x^2 - 5x - 5x + 25The last product is (−5)(−5)=+25: a negative times a negative is positive. The pattern (a−b)2=a2−2ab+b2 says so too: the b2 term is always positive. A quick check with a number catches it: at x=0, (0−5)2=25, but x2−10x−25 gives −25.
  168. 11. Polynomials and factoring · Three products worth knowing by heart · ProblemUse the special products to work out 103×97 and 992 without a calculator.103×97= 9991; 992= 9801
    1. Both numbers are 100±3, so the difference of two squares applies:
    2. 103×97=(100+3)(100−3)=1002−32=10000−9=9991
    3. For the square, use (a−b)2 with a=100 and b=1; the middle term is the one not to forget:
    4. 992=(100−1)2=10000−200+1=9801
    5. So 103×97=9991 and 992=9801.
  169. 11. Polynomials and factoring · Evaluate a polynomial the fast way · Code challengeWrite evaluate(p, x): the value of the polynomial with coefficients p (constant first) at x, using Horner’s method. An empty list is the zero polynomial.One solution:
    Solution
    #include <vector>
    double evaluate(const std::vector<double>& p, double x) {  double result = 0;  int n = p.size();  for (int k = n - 1; k >= 0; k--) {    result = result * x + p[k];  }  return result;}
    The loop goes from the highest power down, because Horner’s nesting starts with the leading coefficient. (n is an int copy of p.size(), so that k can go below 0 and stop the loop; the size itself is never negative.) For a polynomial of degree n it needs only n multiplications, where working out each power separately needs about n2/2. Looping from index 0 upwards with the same line computes the coefficients in the wrong order: it evaluates the polynomial with its coefficients reversed.
  170. 11. Polynomials and factoring · Factoring undoes multiplying · Put in orderPut the steps for factoring x3−3x2+4x−12 by grouping in order.1. Split it into two pairs: (x3−3x2)+(4x−12) 2. Take a common factor out of each pair: x2(x−3)+4(x−3) 3. Notice both pairs share the factor (x−3) 4. Take it out: (x−3)(x2+4) 5. Check by multiplying back: x3+4x−3x2−12Grouping only works when, after the first factoring, the brackets match exactly. Here both are (x−3). Checking by multiplying back is never wasted: factoring is easy to get almost right. Note that x2+4 does not factor further using real numbers, since x2+4 is never 0.
  171. 11. Polynomials and factoring · Differences of squares and trinomials · QuizWhich is the factored form of x2+2x−15?A. (x+5)(x−3)You need a product of −15 and a sum of +2: 5 and −3 work. (x−5)(x+3) has the right product but sums to −2, giving x2−2x−15. When c is negative the two numbers have opposite signs, and the bigger one takes the sign of b.
  172. 11. Polynomials and factoring · Differences of squares and trinomials · Fill the blanksFactor completely: x4−16. It is a difference of squares twice.1: 4, 2: 2x4=(x2)2 and 16=42, so the first step is (x2−4)(x2+4). Then x2−4 is itself a difference of squares, (x−2)(x+2). The sum x2+4 stays as it is. “Completely” means keep going until no factor can be split further.
  173. 11. Polynomials and factoring · Dividing one polynomial by another · Code challengeWrite divideByLinear(p, r): divide the polynomial p (whole-number coefficients, constant first) by x−r, returning a Division: a struct holding the quotient, also constant first, and the remainder.One solution:
    Solution
    #include <vector>
    struct Division {  std::vector<int> quotient;  int remainder;};
    Division divideByLinear(const std::vector<int>& p, int r) {  int n = p.size() - 1;  std::vector<int> quotient(n, 0);  int carry = 0;  for (int k = n; k >= 1; k--) {    carry = p[k] + r * carry;    quotient[k - 1] = carry;  }  return Division{quotient, p[0] + r * carry};}
    Each step is “coefficient plus r times the last result”, from the highest power down, which is Horner’s method again: the numbers you write down on the way are the quotient’s coefficients, and the last one is p(r). Using +3 instead of −3 for x+3 is the usual slip: x+3=x−(−3), so r=−3. The quotient has one coefficient fewer than p, because its degree is one less.
  174. 11. Polynomials and factoring · The remainder and factor theorems · QuizWhat is the remainder when x3−4x+1 is divided by x−2?A. 1No division needed: the remainder is p(2)=23−4⋅2+1=8−8+1=1. The answer 17 comes from adding 4⋅2 instead of subtracting it. Dividing by x−2 means evaluating at +2, not −2. Since the remainder is not 0, x−2 is not a factor.
  175. 11. Polynomials and factoring · The remainder and factor theorems · QuizWhich of these is a factor of x3+1?B. x+1Test the root: x+1=x−(−1), and (−1)3+1=0, so x+1 is a factor. For x−1, 13+1=2≠0. Dividing gives x3+1=(x+1)(x2−x+1), the sum of cubes pattern.
  176. 11. Polynomials and factoring · The remainder and factor theorems · ProblemLet p(x)=x3+2x2−5x−6. Find the remainder when p(x) is divided by x−1. Then show that x−2 is a factor, and find all three roots of p(x)=0.Remainder on dividing by x−1 -8; Smallest root -3; Middle root -1; Largest root 2
    1. By the remainder theorem, the remainder on dividing by x−1 is p(1):
    2. p(1)=1+2−5−6=−8
    3. And p(2)=8+8−10−6=0, so x−2 is a factor. Synthetic division by x−2 on the coefficients 1,2,−5,−6: bring down 1; then 2+2⋅1=4, −5+2⋅4=3 and −6+2⋅3=0. The quotient is x2+4x+3.
    4. p(x)=(x−2)(x2+4x+3)=(x−2)(x+1)(x+3)
    5. The remainder is −8, and the roots are x=−3, x=−1 and x=2.
  177. 11. Polynomials and factoring · Roots, touching and the ends of the graph · QuizAs x grows large and positive, what does p(x)=−2x5+100x4+3 do?B. It falls without limitFor large enough x, the leading term always wins: −2x5 beats 100x4 once x>50, since then 2x5>100x4. Its coefficient is negative, so p falls without limit. For moderate x, say 10, the 100x4 term does dominate, which is why end behaviour is only about the far ends.
  178. 11. Polynomials and factoring · Practice problems · ProblemMultiply out (3x−2)(x2+4x−1) and collect like terms. Give each coefficient of the result.Coefficient of x3 3; Coefficient of x2 10; Coefficient of x -11; Constant term 2
    1. Multiply each term of 3x−2 by each term of x2+4x−1:
    2. 3x(x2+4x−1)=3x3+12x2−3x−2(x2+4x−1)=−2x2−8x+2
    3. Collect like terms: for x2, 12−2=10; for x, −3−8=−11.
    4. (3x−2)(x2+4x−1)=3x3+10x2−11x+2
    5. Check at x=1: the left is 1⋅4=4 and the right is 3+10−11+2=4.
  179. 11. Polynomials and factoring · Practice problems · ProblemDivide x3−3x2+5x−7 by x−2. Give the quotient and the remainder.Quotient x^2 - x + 3; Remainder -1
    1. Synthetic division with r=2: bring down the leading coefficient, then each next number is the coefficient above plus 2 times the last result.
    2. 1,−3+2⋅1=−1,5+2⋅(−1)=3,−7+2⋅3=−1
    3. The first three numbers are the quotient’s coefficients and the last is the remainder:
    4. x3−3x2+5x−7=(x−2)(x2−x+3)−1
    5. Check with the remainder theorem: p(2)=8−12+10−7=−1. The quotient is x2−x+3 and the remainder is −1.
  180. 11. Polynomials and factoring · Practice problems · ProblemFind the number k for which x−3 is a factor of x3−4x2+kx+6. With that k, find the other two roots.k= 1; The smaller other root -1; The larger other root 2
    1. By the factor theorem, x−3 is a factor exactly when p(3)=0:
    2. p(3)=27−36+3k+6=3k−3=0⇒k=1
    3. Divide x3−4x2+x+6 by x−3 (synthetic division, r=3): 1, then −4+3=−1, 1−3=−2 and 6−6=0. The quotient is x2−x−2:
    4. x3−4x2+x+6=(x−3)(x2−x−2)=(x−3)(x−2)(x+1)
    5. So k=1, and the other roots are −1 and 2.
  181. 11. Polynomials and factoring · More practice problems · ProblemFind all three roots of 2x3−3x2−11x+6=0. One of them is a fraction.Smallest root -2; Middle root 1/2 ≈ 0.5; Largest root 3
    1. Try divisors of 6: p(1)=2−3−11+6=−6, p(−1)=−2−3+11+6=12, p(2)=16−12−22+6=−12, and p(3)=54−27−33+6=0. So x−3 is a factor.
    2. Synthetic division with r=3 on 2,−3,−11,6: 2, then −3+6=3, −11+9=−2 and 6−6=0.
    3. 2x3−3x2−11x+6=(x−3)(2x2+3x−2)
    4. For 2x2+3x−2, look for two numbers with product ac=−4 and sum 3: 4 and −1.
    5. 2x2+4x−x−2=2x(x+2)−(x+2)=(2x−1)(x+2)
    6. The roots are x=−2, x=12 and x=3.
  182. 11. Polynomials and factoring · More practice problems · ProblemAn open box is made from a 20cm by 12cm sheet of card: cut a square of side xcm from each corner and fold up the sides. Its volume is V(x)=x(20−2x)(12−2x). Find the volume when x=2, and write V(x) in standard form.V(2) 256 cm³; Leading coefficient of V 4; Coefficient of x2 -64; Coefficient of x 240
    1. At x=2 the box is 2 high, on a base 20−4=16 by 12−4=8:
    2. V(2)=2⋅16⋅8=256cm3
    3. For standard form, multiply the brackets, then the x:
    4. (20−2x)(12−2x)=240−40x−24x+4x2=4x2−64x+240V(x)=4x3−64x2+240x
    5. It is a cubic with leading coefficient 4. Only 0<x<6 makes a real box, since the 12cm side needs 12−2x>0.
  183. 12. Quadratic equations and parabolas · A quadratic draws a parabola · QuizWhich of these is a quadratic equation?B. x(x−4)=1Multiply out: x(x−4)=1 is x2−4x−1=0, degree 2. Hidden quadratics like this are common, so expand before you decide. x3=8x2 has degree 3, and 1/x2 is not a polynomial at all, although multiplying by x2 turns that one into 4x2=1 (for x≠0).
  184. 12. Quadratic equations and parabolas · Vertex form shows the turning point · QuizWhere is the vertex of y=−(x+4)2+1, and does it open up or down?B. (−4,1), opening downMatch it to a(x−h)2+k: x+4=x−(−4), so h=−4, and k=1. The leading − means a=−1<0, so it opens down and (−4,1) is the highest point. Reading h=4 is the classic slip: the sign inside the bracket is the opposite of the shift.
  185. 12. Quadratic equations and parabolas · Solving by factoring · Find the bugThis solution of x2=5x finds only one of its two solutions. Which line loses the other?Line 2: x^2 - 5x = 0, so x(x - 5) = 0, and x = 0 or x = 5Dividing by x is only allowed when x≠0, and x=0 is a solution: 02=5⋅0. Never divide by something that could be zero; move everything to one side and factor instead. Then x(x−5)=0 gives both x=0 and x=5.
  186. 12. Quadratic equations and parabolas · A square has two square roots · QuizSolve 3(x+1)2=12.B. x=1 or x=−3Divide by 3: (x+1)2=4. Then x+1=±2, so x=1 or x=−3. Answering only x=1 forgets the negative root. −1±4 divides by 3 but then forgets the square root: (x+1)2=4 means x+1=±2, not ±4.
  187. 12. Quadratic equations and parabolas · Completing the square · Put in orderPut the steps for solving x2−8x+3=0 by completing the square in order.1. Move the constant across: x2−8x=−3 2. Halve the coefficient of x and square it: (−4)2=16 3. Add 16 to both sides: x2−8x+16=13 4. Write the left as a square: (x−4)2=13 5. Take square roots, both signs: x=4±13Adding 16 to both sides keeps the equation true; adding it on one side only is the common slip. The half of −8 is −4, so the square is (x−4)2, and the sign inside matches the sign of the x term. If the leading coefficient is not 1, divide everything by it first.
  188. 12. Quadratic equations and parabolas · Completing the square · ProblemWrite x2−10x+18 in vertex form (x−h)2+k, then solve x2−10x+18=0 exactly.h= 5; k= -7; Smaller root 5 - sqrt(7) ≈ 2.35425; Larger root 5 + sqrt(7) ≈ 7.64575
    1. Half the coefficient of x is −5, and (−5)2=25. Add it and take it away:
    2. x2−10x+18=(x2−10x+25)−25+18=(x−5)2−7
    3. So h=5 and k=−7: the vertex is (5,−7). To solve, set it to zero:
    4. (x−5)2=7⇒x−5=±7⇒x=5±7
    5. The roots are 5−7≈2.354 and 5+7≈7.646.
  189. 12. Quadratic equations and parabolas · The quadratic formula, derived · Fill the blanksFinish the larger root, for a>0.1: 4, 2: sqrt, 3: 2 * aThe part under the root is b2−4ac, so 4. The brackets around 2 * a matter: without them, x / 2 * a divides by 2 and then multiplies by a, because / and * go left to right. That bracket bug gives right answers whenever a=1, so tests with a=1 alone never catch it.
  190. 12. Quadratic equations and parabolas · Using the formula, step by step · Code challengeWrite solveQuadratic(a, b, c): the real roots of ax2+bx+c=0 (a≠0) in increasing order. Return two roots, one when b2−4ac=0, or none (an empty vector, {}).One solution:
    Solution
    #include <cmath>#include <vector>
    std::vector<double> solveQuadratic(double a, double b, double c) {  double d = b * b - 4 * a * c;  if (d < 0) return {};  if (d == 0) return {-b / (2 * a)};  double r1 = (-b - std::sqrt(d)) / (2 * a);  double r2 = (-b + std::sqrt(d)) / (2 * a);  if (r1 < r2) return {r1, r2};  return {r2, r1};}
    The discriminant decides how many roots there are before you take any square root; std::sqrt of a negative number is nan (“not a number”), not an error, so skipping the check returns {nan, nan}. When a<0, the + root is the smaller one, which is why the last lines put them in order. Comparing a double with == 0 is fine here because these inputs are exact; with measured data you would treat a tiny discriminant as zero.
  191. 12. Quadratic equations and parabolas · Using the formula, step by step · ProblemSolve 3x2−5x−4=0 with the quadratic formula. Give the discriminant, and the two roots exactly.b2−4ac= 73; Smaller root (5 - sqrt(73))/6 ≈ −0.590667; Larger root (5 + sqrt(73))/6 ≈ 2.25733
    1. Here a=3, b=−5 and c=−4. The discriminant first:
    2. b2−4ac=(−5)2−4⋅3⋅(−4)=25+48=73
    3. 73 is not a perfect square, so the roots are irrational:
    4. x=−(−5)±732⋅3=5±736
    5. That is x≈−0.591 or x≈2.257. Check with Vieta: they add up to 106=53, which is −ba.
  192. 12. Quadratic equations and parabolas · The discriminant counts the roots · QuizHow many real solutions does x2+4x+5=0 have?C. NoneΔ=42−4⋅1⋅5=16−20=−4<0, so none. Completing the square agrees: x2+4x+5=(x+2)2+1, which is at least 1 for every x. A common slip is 4⋅1⋅5 read as 4+5, or forgetting to square b.
  193. 12. Quadratic equations and parabolas · When the textbook formula fails a computer · Code challengeThe starter uses the textbook formula. Rewrite stableRoots(a, b, c) with the stable version above, returning both roots in increasing order. Assume b2−4ac>0 and c≠0; take sign⁡(0) as 1. b >= 0 ? d : -d is d when b >= 0, and -d otherwise.One solution:
    Solution
    #include <algorithm>#include <cmath>#include <vector>
    std::vector<double> stableRoots(double a, double b, double c) {  double d = std::sqrt(b * b - 4 * a * c);  double q = -(b + (b >= 0 ? d : -d)) / 2;  double r1 = q / a;  double r2 = c / q;  return {std::min(r1, r2), std::max(r1, r2)};}
    Choosing the sign of Δ to match b makes b+sign⁡(b)Δ a sum of two numbers with the same sign, so no digits cancel. The other root then comes from a division, c/q, which is also safe. The tests multiply the small root by 108 so that EXPECT_NEAR’s tolerance, 5×10−11, is relative to its size; comparing 10−8 itself within that tolerance would pass almost anything. Library root finders do exactly this.
  194. 12. Quadratic equations and parabolas · The vertex answers biggest and smallest · QuizA ball thrown straight up at 20 m/s has height h(t)=20t−4.9t2 metres after t seconds. What is its greatest height, to one decimal place?B. 20.4 mThe vertex is at t=−202⋅(−4.9)=209.8≈2.04 s; that is when, not how high. Put it back in: h=20⋅2.041−4.9⋅2.0412≈20.4 m, or exactly k=c−b24a=40019.6. 40.8 comes from dividing b2 by 2|a| instead of 4|a|, mixing up the formula for the time with the one for the height.
  195. 12. Quadratic equations and parabolas · Practice problems · ProblemFor which positive number k does x2+kx+9=0 have exactly one real solution? What is that solution?k= 6; x= -3
    1. One real solution means a zero discriminant:
    2. k2−4⋅1⋅9=0⇒k2=36⇒k=±6
    3. The positive one is k=6. Then the equation is x2+6x+9=(x+3)2=0, a double root:
    4. x=−b2a=−62=−3
    5. So k=6, and the solution is x=−3, where the parabola touches the axis at its vertex.
  196. 12. Quadratic equations and parabolas · Practice problems · ProblemA rectangle is 3cm longer than it is wide, and its area is 40cm2. Find its width and its length.Width 5 cm; Length 8 cm
    1. With width w, the length is w+3, so:
    2. w(w+3)=40w2+3w−40=0(w+8)(w−5)=0
    3. So w=5 or w=−8. A width cannot be negative, so the second solution of the equation is not an answer to the problem.
    4. The rectangle is 5cm wide and 8cm long. Check: 5⋅8=40.
  197. 12. Quadratic equations and parabolas · Practice problems · ProblemOne solution of 2x2+bx−15=0 is x=3. Find b and the other solution.b= -1; The other solution -5/2 ≈ −2.5
    1. Put x=3 in:
    2. 2⋅9+3b−15=0⇒3b+3=0⇒b=−1
    3. The roots multiply to ca=−152, so the other is −152÷3=−52. Factoring agrees:
    4. 2x2−x−15=(x−3)(2x+5)
    5. So b=−1, and the other solution is x=−52.
  198. 12. Quadratic equations and parabolas · More practice problems · ProblemA ball is thrown upwards from 1.8m above the ground. Its height after t seconds is h(t)=−5t2+20t+1.8 metres. When is it highest, how high is that, and when does it hit the ground?Time of the highest point 2 s; Greatest height 21.8 m; Time it hits the ground (20 + sqrt(436))/10 ≈ 4.08806 s
    1. The parabola opens down (a=−5), so the vertex is the highest point:
    2. t=−202⋅(−5)=2s,h(2)=−20+40+1.8=21.8m
    3. It lands when −5t2+20t+1.8=0. With a=−5, b=20 and c=1.8:
    4. b2−4ac=400+36=436t=−20±436−10=20∓43610
    5. That gives t≈4.088 or t≈−0.088. The negative time is before the throw, so the ball lands after about 4.09s.
  199. 12. Quadratic equations and parabolas · More practice problems · ProblemA shop sells 200 mugs a week at 8 euros each. For every 1 euro it adds to the price, it sells 10 fewer mugs a week. Which price brings in the most money, and how much is that a week?Best price 14 euros; Weekly takings 1960 euros
    1. Let the price rise by x euros. Then the takings are:
    2. R(x)=(8+x)(200−10x)=−10x2+120x+1600
    3. The parabola opens down, so the maximum is at the vertex:
    4. x=−1202⋅(−10)=6,R(6)=14⋅140=1960
    5. The best price is 8+6=14 euros: 140 mugs, for 1960 euros a week. Rises of 5 and of 7 euros both give 1950, either side of the vertex.
  200. 13. Rational and radical expressions · A rational expression is a fraction of polynomials · QuizWhat is the domain of x−5x2−5x?B. All x except 0 and 5Factor the denominator: x2−5x=x(x−5), which is zero at x=0 and at x=5. The tempting answer is “except 0”, because x−5 cancels and leaves 1x. But the domain belongs to the expression you were given: at x=5 the original divides 0 by 0, which has no value. Cancelling never brings an excluded value back.
  201. 13. Rational and radical expressions · Simplify by cancelling factors, never terms · QuizWhich simplification is right?B. 2x+62=x+3Only the second cancels a factor: 2x+6=2(x+3), and the 2 is multiplied on top and bottom. The first cancels a term (the 6 is added, not multiplied). The third mixes up x2+4, which does not factor over the reals, with x2−4=(x−2)(x+2). The fourth cancels x2 from a sum. A quick test catches all three: put in x=1 and see if both sides agree.
  202. 13. Rational and radical expressions · Simplify by cancelling factors, never terms · ProblemSimplify x2−5x+6x2−9, and give the two values of x it excludes.Simplified (x - 2)/(x + 3); The excluded value whose factor cancels 3; The other excluded value -3
    1. Factor the top and the bottom, then cancel the common factor:
    2. x2−5x+6x2−9=(x−2)(x−3)(x−3)(x+3)=x−2x+3
    3. The original bottom, x2−9, is zero at x=3 and at x=−3. The factor x−3 cancelled, but x=3 stays excluded all the same.
    4. The simplified form is x−2x+3, with x≠3 and x≠−3.
  203. 13. Rational and radical expressions · Excluded values are holes or walls · Code challengeFinish evalRational(num, den, x). Each polynomial is a list of coefficients, highest power first ({1, 0, -1} is x2−1). Return its value at x, or std::nullopt where the denominator is zero: a std::optional<double> (from <optional>) holds a double or nothing, so return value; fills it and return std::nullopt; leaves it empty.One solution:
    Solution
    #include <optional>#include <vector>
    double evalPoly(const std::vector<double>& coeffs, double x) {  double value = 0;  for (double c : coeffs) value = value * x + c;  return value;}
    std::optional<double> evalRational(const std::vector<double>& num,                                   const std::vector<double>& den,                                   double x) {  double bottom = evalPoly(den, x);  if (bottom == 0) return std::nullopt;  return evalPoly(num, x) / bottom;}
    The loop is Horner’s method: start from 0 and, for each coefficient, multiply by x and add it. For {1,0,−1} at 3 that is ((0⋅3+1)⋅3+0)⋅3−1=8. Check the denominator first: dividing a double by zero in C++ does not stop the program, it quietly gives inf or nan (“not a number”), so the excluded value would slip through as a number. (Dividing an int by zero is worse: it is undefined behaviour, and here it stops the program.) Note that x=1 gives std::nullopt even though the factor cancels: the expression as written has no value there.
  204. 13. Rational and radical expressions · Multiply and divide as you would fractions · QuizWhich values are excluded from 1x÷x−2x+5?C. 0, 2 and −5Three things can go wrong. x=0 makes the first denominator zero; x=−5 makes the second denominator zero; and x=2 makes the divisor x−2x+5 equal to zero, and you cannot divide by zero. After flipping, the result is x+5x(x−2), which only shows 0 and 2: −5 has moved to the top, which is why it is easy to forget.
  205. 13. Rational and radical expressions · Add and subtract over a common denominator · QuizWhat is 3x−2−1x+2?B. 2x+8x2−4Over (x−2)(x+2)=x2−4 the top is 3(x+2)−(x−2)=3x+6−x+2=2x+8. The usual slip gives 2x+4: writing −x−2 instead of −x+2, because the minus was only applied to the x. The first option subtracts the tops, 3−1, without rewriting each fraction over the common denominator first, and the last subtracts tops and bottoms separately, which is never allowed.
  206. 13. Rational and radical expressions · Solve rational equations by clearing the denominators · Put in orderPut the steps for solving a rational equation in order.1. Factor every denominator 2. Write down the excluded values 3. Multiply both sides by the least common denominator 4. Solve the polynomial equation that is left 5. Throw out any answer that is an excluded valueYou need the factors to see both the excluded values and the common denominator, so factoring comes first. Write the excluded values down before multiplying: once the fractions are gone, nothing in the new equation reminds you of them. The check comes last, on every candidate.
  207. 13. Rational and radical expressions · Solve rational equations by clearing the denominators · Code challengeFinish checkSolutions(candidates, lhs, rhs): keep only the candidates where lhs(x) and rhs(x) are both finite numbers (std::isfinite) and differ by less than 1e-9. The two sides are functions passed in, as std::function<double(double)> (from <functional>): something you call with a double that returns a double. The tests write them in place as lambdas, [](double x) { return x + 1; }.One solution:
    Solution
    #include <cmath>#include <functional>#include <vector>
    std::vector<double> checkSolutions(    const std::vector<double>& candidates,    std::function<double(double)> lhs,    std::function<double(double)> rhs) {  std::vector<double> kept;  for (double x : candidates) {    double l = lhs(x);    double r = rhs(x);    bool finite = std::isfinite(l) && std::isfinite(r);    if (finite && std::abs(l - r) < 1e-9) kept.push_back(x);  }  return kept;}
    At x=2 both sides divide by zero, and a double divided by zero is inf, not an error; inf - inf is nan, and nan < 1e-9 is false, but relying on that is fragile, so test std::isfinite first. Comparing with a tolerance instead of == matters for answers that are not whole numbers: floating-point arithmetic rounds, so a true solution can be off by a tiny amount.
  208. 13. Rational and radical expressions · Simplify radicals and rationalise the denominator · QuizWhich is 72 in simplest form?A. 62Take out the largest square factor: 72=36⋅2, so 72=62. The second and fourth are equal to 72 too, but still have square factors under the root (8=4⋅2, 18=9⋅2), so they are not finished. 89=24, which is far too big: 72 is between 8 and 9.
  209. 13. Rational and radical expressions · Radical equations: isolate, square, check · Find the bugThis solves x+a=x+b by squaring, then tries to drop the extraneous roots. It still returns −3 for a=7, b=1. Which line is wrong?Line 12: if (x + b >= 0) roots.push_back(x);Every root of the squared equation has x+a=(x+b)2≥0, so checking x+a≥0 never throws anything out. What squaring lost is the sign of the right side: a square root is never negative, so a real solution needs x+b≥0. For x=−3, x+b=−2, which a square root can never equal.
  210. 13. Rational and radical expressions · Radical equations: isolate, square, check · ProblemSolve 2x+3=x. Squaring gives two candidates: which one is the solution, and which is extraneous?The solution 3; The extraneous candidate -1
    1. Square both sides and solve the quadratic:
    2. 2x+3=x2x2−2x−3=0(x−3)(x+1)=0
    3. Check each in the original. At x=3: 9=3, which matches. At x=−1: 1=1, but the right side is −1.
    4. So x=3 is the solution, and x=−1 is extraneous: it solves −2x+3=x, which squaring mixed in.
  211. 13. Rational and radical expressions · Far from zero, the leading terms decide · QuizWhich line does 3x2−x6x2+5 approach as x grows?B. y=12The degrees are equal (2 and 2), so far out it is 3x26x2=12. Dividing top and bottom by x2 shows why: 3−1/x6+5/x2, and both small fractions shrink to 0. y=3 reads only the top; y=0 is the rule for a top of lower degree.
  212. 13. Rational and radical expressions · Practice problems · ProblemWrite 2x−1−1x+1 as one fraction over the common denominator x2−1. What is its numerator, and what is the expression’s value at x=3?Numerator x + 3; Value at x=3 3/4 ≈ 0.75
    1. The common denominator is (x−1)(x+1)=x2−1. Rewrite each fraction over it:
    2. 2x−1−1x+1=2(x+1)−(x−1)(x−1)(x+1)=2x+2−x+1x2−1=x+3x2−1
    3. The numerator is x+3. At x=3 the fraction is 68=34, and the original agrees: 22−14=34.
  213. 13. Rational and radical expressions · Practice problems · ProblemSolve 3x+2x−1=2.Smaller solution 1/2 ≈ 0.5; Larger solution 3
    1. Excluded: x=0 and x=1. Multiply both sides by x(x−1):
    2. 3(x−1)+2x=2x(x−1)5x−3=2x2−2x2x2−7x+3=0(2x−1)(x−3)=0
    3. So x=12 or x=3, and neither is excluded. Check x=3: 1+1=2. Check x=12: 6+2−1/2=6−4=2.
    4. The solutions are x=12 and x=3.
  214. 13. Rational and radical expressions · Practice problems · ProblemSolve 1x−2+xx+2=4x2−4.x= -1
    1. Factor: x2−4=(x−2)(x+2), so x=2 and x=−2 are excluded. Multiply both sides by (x−2)(x+2):
    2. (x+2)+x(x−2)=4x2−x+2=4x2−x−2=0(x−2)(x+1)=0
    3. x=2 is excluded: it makes two of the denominators zero. That leaves x=−1. Check: 1−3+−11=−43, and 41−4=−43.
    4. The only solution is x=−1.
  215. 13. Rational and radical expressions · Practice problems · ProblemFor f(x)=2x2−8x2−x−6, find the vertical asymptote, the horizontal asymptote, and the hole in the graph.Vertical asymptote x= 3; Horizontal asymptote y= 2; The hole’s x -2; The hole’s y 8/5 ≈ 1.6
    1. Factor the top and the bottom:
    2. f(x)=2(x−2)(x+2)(x−3)(x+2)=2(x−2)x−3,x≠−2, x≠3
    3. The factor x+2 cancels: a hole at x=−2, at the height of the simplified form there, 2(−4)−5=85. The factor x−3 stays in the bottom: a vertical asymptote at x=3.
    4. The degrees are equal, so far out f behaves like 2x2x2=2: the horizontal asymptote is y=2.
    5. So: a vertical asymptote x=3, a horizontal asymptote y=2, and a hole at (−2,85).
  216. 13. Rational and radical expressions · More practice problems · ProblemRationalise the denominator of 65−2, and write the result as a5+b2.a= 2; b= 2
    1. Multiply the top and the bottom by the conjugate 5+2:
    2. 65−2⋅5+25+2=6(5+2)5−2=2(5+2)
    3. So it is 25+22≈7.301: a=2 and b=2.
  217. 13. Rational and radical expressions · More practice problems · ProblemTwo pipes together fill a tank in 4 hours. Alone, the larger pipe would fill it 6 hours faster than the smaller one. How long does each take alone?The smaller pipe 12 hours; The larger pipe 6 hours
    1. Let the smaller pipe take t hours, so the larger takes t−6. In one hour they fill 1t and 1t−6 of the tank, and together 14:
    2. 1t+1t−6=14
    3. Multiply both sides by 4t(t−6):
    4. 4(t−6)+4t=t(t−6)8t−24=t2−6tt2−14t+24=0(t−2)(t−12)=0
    5. t=2 solves the equation but not the problem: the larger pipe would take −4 hours. So t=12: the smaller pipe takes 12 hours and the larger 6. Check: 112+16=14.
  218. 14. Exponentials and logarithms · Exponential growth multiplies by the same factor · QuizSavings grow by 3% each year. What is the growth factor b?B. 1.03Each year you keep all of last year’s money (the 1) and gain 3% of it (the 0.03): 1+0.03=1.03. Multiplying by 0.03 would leave you with 3% of your money. 1.3 is a 30% rise, a slip of one decimal place.
  219. 14. Exponentials and logarithms · The base decides growth or decay · QuizA car worth 20 000 euros loses 15% of its value each year. Which models its value after t years?A. 20000⋅0.85tLosing 15% means keeping 85%, so each year multiplies by 1−0.15=0.85. Multiplying by 0.15 would keep only 15%, a car worth 3000 euros after a year. 20000−0.15t is linear and loses almost nothing; 1.15 is growth.
  220. 14. Exponentials and logarithms · Compound interest is exponential growth · Code challengeWrite compound(P, r, n, t): the amount after t years when P earns the yearly rate r (0.05 for 5%), compounded n times a year.One solution:
    Solution
    #include <cmath>
    double compound(double P, double r, double n, double t) {  return P * std::pow(1 + r / n, n * t);}
    std::pow(base, exponent) makes the brackets plain: the base is all of 1 + r / n, the exponent all of n * t. The usual slip is 1 + std::pow(r / n, n * t), which raises only the interest to the power. And (1 + r / n) ^ (n * t) is no power at all: ^ is exclusive or, on whole numbers, so on doubles it does not even compile. Another slip is using the percentage, 5, as the rate: compounded yearly, each step would multiply by 6.
  221. 14. Exponentials and logarithms · Compound interest is exponential growth · ProblemYou put 2500 euros in an account paying 4% a year, compounded quarterly. How much is there after 6 years, and how much of that is interest?Amount 2500*1.01^24 ≈ 3174.34 euros; Interest earned 2500*1.01^24 - 2500 ≈ 674.337 euros
    1. Here P=2500, r=0.04, n=4 and t=6, so each of the nt=24 steps multiplies by 1+0.044=1.01:
    2. A=2500(1.01)24≈2500⋅1.26973≈3174.34
    3. The interest is what was added: 3174.34−2500=674.34 euros.
  222. 14. Exponentials and logarithms · The number e is compounding without end · QuizAbout how much do 1000 euros become at 5% compounded continuously for 10 years?D. 1648.721000⋅e0.05⋅10=1000⋅e0.5≈1648.72. It is the most the 5% can give: yearly (1628.89) and monthly (1647.01) compounding are below it, and continuous is the limit they climb toward. 1500 is simple interest, 50 euros a year with no interest on interest.
  223. 14. Exponentials and logarithms · A logarithm asks which power · QuizWhat is log3⁡81?B. 4Ask “3 to which power gives 81?”: 3⋅3⋅3⋅3=81, so 4. The tempting 27 comes from dividing 81 by 3; a logarithm counts how many times you multiply, not what you get.
  224. 14. Exponentials and logarithms · The laws of logarithms come from the laws of exponents · QuizWhat is log2⁡40−log2⁡5?B. 3A difference of logs is the log of a quotient: log2⁡405=log2⁡8=3. 8 is the number inside, not its logarithm. log2⁡35 subtracts inside the log, which is not a law, and the last option is the classic mix-up of log⁡xy with log⁡xlog⁡y.
  225. 14. Exponentials and logarithms · Change of base: any logarithm from one you have · Fill the blanksIn C++, std::log (from <cmath>) is the natural logarithm. Finish logBase with the change-of-base rule.1: log, 2: b, 3: 3Divide ln⁡x by ln⁡b. Swapping them gives ln⁡bln⁡x=logx⁡b, the reciprocal. std::log10 and std::log2 exist too, and any base works on both top and bottom, as long as it is the same base. Printed in full, the answer can be a hair from 4, such as 4.000000000000001: floating-point rounding, not a mistake.
  226. 14. Exponentials and logarithms · Change of base: any logarithm from one you have · QuizWhat is log5⁡20, to three decimals?A. 1.861ln⁡20ln⁡5≈2.9961.609≈1.861. It should be a bit less than 2, since 52=25 is a bit more than 20: estimating first catches mistakes. 0.537 is the ratio upside down, and 1.301 is log10⁡20.
  227. 14. Exponentials and logarithms · Solve exponential equations by taking logarithms · Code challengeThe starter uses the rule of 72. Make doublingTime(r) exact: the number of years for an amount to double at the yearly rate r, compounded yearly.One solution:
    Solution
    #include <cmath>
    double doublingTime(double r) {  return std::log(2) / std::log(1 + r);}
    Solve (1+r)t=2: tln⁡(1+r)=ln⁡2. Use 1+r, the growth factor, not r: std::log(0.05) is negative and gives a negative time. The rule of 72 works because ln⁡2≈0.693 and ln⁡(1+r)≈r for small r; 72 is used instead of 69.3 because it divides by many rates evenly and corrects a little for the approximation. At 100% it is far off: 0.72 years instead of 1.
  228. 14. Exponentials and logarithms · Solve exponential equations by taking logarithms · ProblemSolve 5⋅3x=135 exactly, and 2x+1=7 to three significant figures.5⋅3x=135: x= 3; 2x+1=7: x= ln(7)/ln(2) - 1 ≈ 1.80735
    1. Divide by 5, then recognise the power:
    2. 3x=27=33⇒x=3
    3. For the second, take ln⁡ of both sides:
    4. (x+1)ln⁡2=ln⁡7x+1=ln⁡7ln⁡2≈2.807x≈1.807
    5. So x=3, and x=log2⁡7−1≈1.81. Check: 22.807≈7.
  229. 14. Exponentials and logarithms · Half-life: decay measured in halvings · QuizWhat fraction of a sample is left after three half-lives?C. 18Each half-life halves what is left: 12⋅12⋅12=18. Decay multiplies, so the fractions do not shrink in equal steps: 16 comes from dividing by 2⋅3, and 13 from thinking a third goes each time.
  230. 14. Exponentials and logarithms · Half-life: decay measured in halvings · Code challengeWrite ageFromFraction(fraction, halfLife): how long ago a sample started decaying, if fraction of it is left now (0.25 for a quarter).One solution:
    Solution
    #include <cmath>
    double ageFromFraction(double fraction, double halfLife) {  return halfLife * std::log2(1 / fraction);}
    The number of half-lives is the number of halvings from 1 down to fraction, which is log2⁡1fraction; multiply by the half-life for the time. std::log2(fraction) alone is negative, a sign slip that gives a time in the future. With std::log you would need to divide by std::log(2) too: change of base. (1 / fraction is safe because fraction is a double; with two ints, 1 / 4 would be 0.)
  231. 14. Exponentials and logarithms · Log scales put huge ranges on one ruler · QuizA drink has pH 3 and water pH 5. How do their hydrogen ion concentrations compare?B. The drink has 100 times as muchpH 3 means [H+]=10−3 and pH 5 means 10−5; the ratio is 10−3/10−5=102=100. Two steps on a log scale are two factors of ten, not a difference of 2. The minus sign in the definition is why a lower pH means more acid.
  232. 14. Exponentials and logarithms · Practice problems · ProblemWithout a calculator, find log3⁡54−log3⁡2 and 2log5⁡10−log5⁡4.log3⁡54−log3⁡2= 3; 2log5⁡10−log5⁡4= 2
    1. A difference of logs is the log of the quotient:
    2. log3⁡54−log3⁡2=log3⁡542=log3⁡27=3
    3. For the second, move the 2 inside as a power, then combine:
    4. 2log5⁡10−log5⁡4=log5⁡100−log5⁡4=log5⁡1004=log5⁡25=2
    5. The answers are 3, since 33=27, and 2, since 52=25.
  233. 14. Exponentials and logarithms · Practice problems · ProblemSolve log2⁡x+log2⁡(x+6)=4.x= 2
    1. Combine, then undo the logarithm:
    2. log2⁡(x(x+6))=4x2+6x=16x2+6x−16=0(x+8)(x−2)=0
    3. x=−8 is extraneous: log2⁡(−8) has no value. Check x=2: log2⁡2+log2⁡8=1+3=4.
    4. The solution is x=2.
  234. 14. Exponentials and logarithms · Practice problems · ProblemA medicine has a half-life of 6 hours in the body. After a dose of 400 mg, how much is left after 15 hours, and how long until only 50 mg is left?Left after 15 hours 400*0.5^(15/6) ≈ 70.7107 mg; Time to fall to 50 mg 18 hours
    1. With N0=400 and T=6, 15 hours is 156=2.5 half-lives:
    2. N(15)=400(12)2.5≈400⋅0.17678≈70.7mg
    3. For 50 mg: 50400=18=(12)3, so three half-lives:
    4. (12)t/6=(12)3⇒t6=3⇒t=18hours
    5. About 70.7 mg is left after 15 hours, and 50 mg after 18 hours.
  235. 14. Exponentials and logarithms · More practice problems · ProblemA town had 12 000 people in 2020 and 13 500 in 2025. If it grows exponentially, what is its yearly growth factor, and how many years after 2020 does it reach 20 000?Growth factor b 1.125^(1/5) ≈ 1.02384; Years after 2020 5*ln(5/3)/ln(1.125) ≈ 21.685 years
    1. Five years multiply the population by b5:
    2. 12000b5=13500⇒b5=1.125⇒b=1.1251/5≈1.02384
    3. That is about 2.4% a year. Now solve for the time to reach 20 000:
    4. 12000bt=20000bt=53t=ln⁡(5/3)ln⁡b=5ln⁡(5/3)ln⁡1.125≈21.7
    5. Since ln⁡b=15ln⁡1.125, the fifth root never has to be rounded. The town reaches 20 000 about 21.7 years after 2020, during 2041.
  236. 14. Exponentials and logarithms · More practice problems · ProblemSound level is L=10log10⁡II0 decibels. How many times more intense is a 70 dB sound than a 40 dB one? And if one speaker plays at 80 dB, what level do two identical speakers make together (twice the intensity)?Intensity ratio 1000; Two speakers 80 + 10*log(2) ≈ 83.0103 dB
    1. 30 dB more is three steps of 10 dB, each a factor of 10:
    2. I70I40=10(70−40)/10=103=1000
    3. Two speakers give twice the intensity, and the product law splits the logarithm:
    4. L=10log10⁡2II0=10log10⁡2+10log10⁡II0≈3.0+80=83.0dB
    5. The 70 dB sound is 1000 times more intense, and two speakers make about 83 dB, not 160: doubling the intensity adds only about 3 dB.
  237. 15. Sequences, series and induction · A sequence is a list that follows a rule · QuizWhich explicit rule gives 3, 7, 11, 15, …?B. an=4n−1Check it on the first terms: 4⋅1−1=3, 4⋅2−1=7, 4⋅3−1=11. The terms go up by 4, so the rule has 4n in it; the −1 makes the first one land on 3. 4n+3 is the usual slip: it gives 7 first, because it forgets that n starts at 1, not 0.
  238. 15. Sequences, series and induction · Arithmetic sequences add the same amount each time · QuizThe sequence 7, 12, 17, … has which term equal to 102?B. The 20thSolve 7+(n−1)⋅5=102: (n−1)⋅5=95, so n−1=19 and n=20. Answering 19 means stopping at n−1; the number of steps is one less than the index.
  239. 15. Sequences, series and induction · Geometric sequences multiply by the same amount · QuizWhat is the 5th term of 3, 6, 12, …?C. 48r=2, so a5=3⋅24=48. Counting along works too: 3, 6, 12, 24, 48. 96 is 3⋅25, using n instead of n−1 as the power; 30 is 3⋅2⋅5, multiplying by n where the formula raises r to a power.
  240. 15. Sequences, series and induction · Recursive rules build each term from the last · QuizWith a1=2 and an+1=3an−1, what is a4?C. 41Step by step: a2=3⋅2−1=5, a3=3⋅5−1=14, a4=3⋅14−1=41. A recursive rule has to be walked one term at a time; 14 is a3, one step short.
  241. 15. Sequences, series and induction · Recursive rules build each term from the last · Code challengeWrite arithmeticTerm(first, d, n) and geometricTerm(first, r, n): the n-th term (counting from 1) of each kind of sequence.One solution:
    Solution
    #include <cmath>
    double arithmeticTerm(double first, double d, int n) {  return first + (n - 1) * d;}
    double geometricTerm(double first, double r, int n) {  return first * std::pow(r, n - 1);}
    Both formulas use n−1, the number of steps from the first term. Using n instead passes no test except by luck: it skips one term ahead. C++ has no power operator: std::pow(r, n - 1) raises r to the whole of n - 1. Writing r ^ (n - 1) is the classic slip, and on a double it does not even compile, because ^ is exclusive or, an operation on whole numbers.
  242. 15. Sequences, series and induction · Sigma notation writes a long sum in a line · Fill the blanksTurn ∑k=1nk2 into a loop.1: 1, 2: n, 3: k * kThe bottom of the sigma is where k starts, 1; the top is the last value it takes, so the test is k <= n, not k < n, which would leave out the last term. The term k2 is added once per pass. sumOfSquares(4) is 30.
  243. 15. Sequences, series and induction · An arithmetic series is pairs that add to the same total · QuizWhat is 2+4+6+⋯+20?B. 110There are 10 terms (20 ÷ 2), the first is 2 and the last 20, so S=10⋅(2+20)/2=110. 220 forgets to halve: it counts each pair twice. Count the terms carefully: for a1,…,an with difference d, n=(an−a1)/d+1.
  244. 15. Sequences, series and induction · An arithmetic series is pairs that add to the same total · Find the bugThis sums the first n terms of an arithmetic sequence, but arithmeticSum(3, 4, 10) gives 230 instead of 210. Which line is wrong?Line 2: double last = first + (n - 1) * d;The last of n terms is a1+(n−1)d: 3, 7, …, 39 for ten terms. With n * d the “last” term is 43, one past the end, and the sum comes out 10⋅(3+43)/2=230. Off-by-one errors live wherever you count steps between terms.
  245. 15. Sequences, series and induction · An arithmetic series is pairs that add to the same total · ProblemFind the sum 7+11+15+⋯+203.Number of terms 50; Sum 5250
    1. Count the terms first: the last term is an=7+(n−1)⋅4.
    2. 7+4(n−1)=203⇒4(n−1)=196⇒n=50
    3. Then multiply the number of terms by the average of the first and the last:
    4. S50=50(7+203)2=25⋅210=5250
    5. There are 50 terms, and they add up to 5250.
  246. 15. Sequences, series and induction · A geometric series collapses when you multiply it by r · Code challengeWrite geometricSum(a, r, n): the sum of the first n terms of the geometric sequence that starts at a with ratio r. Remember the case r=1.One solution:
    Solution
    #include <cmath>
    double geometricSum(double a, double r, int n) {  if (r == 1) return a * n;  return a * (1 - std::pow(r, n)) / (1 - r);}
    The formula is right for every r except 1, where 1−r=0 and the double division gives nan (0/0, “not a number”) instead of stopping. Handle the special case first, as the derivation did. A formula with a division always deserves the question: what if the bottom is 0? (With ints it is worse: an integer division by zero is undefined behaviour, and here it stops the program.)
  247. 15. Sequences, series and induction · Some infinite sums have a finite total · QuizWhat is 6+2+23+29+…?B. 9Each term is a third of the last, so a=6, r=13, and the sum is 6/(1−13)=6/23=9. 8 is the first two terms; the rest add up to the missing 1. The terms shrink fast enough because |r|<1.
  248. 15. Sequences, series and induction · Some infinite sums have a finite total · ProblemWrite the recurring decimal 0.272727… as a fraction in lowest terms, by treating it as an infinite geometric series.Common ratio r 1/100 ≈ 0.01; As a fraction 3/11 ≈ 0.272727
    1. Split it into blocks of two digits:
    2. 0.2727…=27100+2710000+271000000+…
    3. That is a geometric series with a=27100 and r=1100, and |r|<1, so:
    4. a1−r=27/10099/100=2799=311
    5. So 0.2727…=311. Check: 3÷11=0.2727…
  249. 15. Sequences, series and induction · Induction proves a rule for every whole number · Put in orderPut the parts of a proof by induction in order.1. State the claim P(n) for every whole number n≥1 2. Base case: show P(1) is true 3. Inductive hypothesis: assume P(n) is true for some n 4. Inductive step: use it to show P(n+1) is true 5. Conclude that P(n) holds for every n≥1You must know exactly what you are proving first, then the base case starts the chain. The hypothesis is only an assumption inside the step: you never assume what you want to prove for all n. Skipping the base case is a classic error: a step can be valid while the statement is false everywhere (try “n=n+1”).
  250. 15. Sequences, series and induction · Pascal’s triangle expands any power of a sum · QuizWhat is the coefficient of x2 in (2x+1)3?D. 12The x2 term is (31)(2x)2⋅11=3⋅4x2=12x2. Reading 3 straight off Pascal’s triangle forgets that the 2 in 2x is squared too. The full expansion is 8x3+12x2+6x+1.
  251. 15. Sequences, series and induction · Compute the triangle, row by row · Code challengeWrite choose(n, k): the binomial coefficient (nk) for whole numbers 0≤k≤n, as a long long. Pascal’s rule or the product n1⋅n−12⋯ both work.One solution:
    Solution
    #include <vector>
    long long choose(int n, int k) {  std::vector<long long> row = {1};  for (int i = 0; i < n; i++) {    std::vector<long long> next = {1};    for (std::size_t j = 1; j < row.size(); j++) {      next.push_back(row[j - 1] + row[j]);    }    next.push_back(1);    row = next;  }  return row[k];}
    Each pass turns row i into row i+1, so after n passes row is row n, and row[k] is (nk). The symmetry (nk)=(nn−k) says choosing k to take is the same as choosing n−k to leave. Computing n! directly works for small n, but a long long overflows from 21!, and in doubles the factorials are rounded from n=23: 23!2!21! comes out as 253.00000000000003 instead of 253. The product form works in whole numbers too, if each step multiplies before it divides: c * (n - i) / (i + 1) is always exact, while c * ((n - i) / (i + 1)) loses the fraction to integer division.
  252. 15. Sequences, series and induction · Practice problems · ProblemA geometric sequence has a2=12 and a5=324. Find the common ratio, the first term and a7.r= 3; a1= 4; a7= 2916
    1. From a2 to a5 is three steps of multiplying by r:
    2. 12r3=324⇒r3=27⇒r=3
    3. One step back from a2: a1=12÷3=4. Then:
    4. a7=a1r6=4⋅36=4⋅729=2916
    5. So r=3, a1=4 and a7=2916: the sequence is 4, 12, 36, 108, 324, 972, 2916.
  253. 15. Sequences, series and induction · Practice problems · ProblemFind ∑k=120(3k−2). Then use 1+2+⋯+n=n(n+1)2 to find 51+52+⋯+100.∑k=120(3k−2)= 590; 51+52+⋯+100= 3775
    1. Split and scale, as sums allow:
    2. ∑k=120(3k−2)=3∑k=120k−20⋅2=3⋅20⋅212−40=630−40=590
    3. For the second, the sum up to 100 minus the sum up to 50:
    4. 100⋅1012−50⋅512=5050−1275=3775
    5. The answers are 590 and 3775. The first is also an arithmetic series, 1+4+⋯+58, and 20(1+58)2=590 agrees.
  254. 15. Sequences, series and induction · Practice problems · ProblemIn the expansion of (2x−1)5, find the coefficient of x3 and the coefficient of x2.Coefficient of x3 80; Coefficient of x2 -40
    1. With a=2x and b=−1, each term is (5k)(2x)5−k(−1)k. For x3, 5−k=3, so k=2:
    2. (52)(2x)3(−1)2=10⋅8x3⋅1=80x3
    3. For x2, k=3:
    4. (53)(2x)2(−1)3=10⋅4x2⋅(−1)=−40x2
    5. The coefficients are 80 and −40.
  255. 15. Sequences, series and induction · More practice problems · ProblemA job pays 30 000 euros in its first year, with a 3% rise every year. What is the pay in year 10, and how much is earned over the first 10 years in all?Pay in year 10 30000*1.03^9 ≈ 39143.2 euros; Total over 10 years 30000*(1.03^10 - 1)/0.03 ≈ 343916 euros
    1. Each year multiplies the pay by 1.03, so year 10 is 9 steps from year 1:
    2. a10=30000⋅1.039≈39143
    3. The total is the sum of the first 10 terms:
    4. S10=30000(1−1.0310)1−1.03=30000(1.0310−1)0.03≈343916
    5. Year 10 pays about 39 143 euros, and the ten years together about 343 916 euros, against 300 000 with no rises.
  256. 15. Sequences, series and induction · More practice problems · ProblemA ball is dropped from 10 m. After each bounce it rises to 60% of the height it fell from. How high does it rise after the third bounce, and how far does it travel, up and down, before it comes to rest?Height after the third bounce 2.16 m; Total distance 40 m
    1. Each rebound is 0.6 of the height before, so after the third bounce:
    2. 10⋅0.63=2.16m
    3. The ball falls 10 m, then goes up and down each rebound height. The rebounds form an infinite geometric series with a=6 and r=0.6:
    4. 10+2(6+3.6+2.16+…)=10+2⋅61−0.6=10+2⋅15=40m
    5. It rises 2.16 m after the third bounce, and travels 40 m in all: infinitely many bounces, but a finite distance.
  257. 16. Angles, triangles and trigonometry · An angle measures a turn · QuizTwo angles of a triangle are 35∘ and 90∘. What is the third?B. 55∘The three add to 180∘: 180−35−90=55. In a right triangle the two other angles always add to 90∘, so each one fixes the other. 235 subtracts from 360∘, the full turn, which is the total around a point, not inside a triangle.
  258. 16. Angles, triangles and trigonometry · Radians measure an angle by the arc it cuts · QuizHow many radians is 90∘?B. π2A quarter of a full turn is a quarter of 2π: π2≈1.571. A handy anchor: π radians is 180∘, so π4 is 45∘ and π is a half turn.
  259. 16. Angles, triangles and trigonometry · Radians measure an angle by the arc it cuts · Code challengeWrite toRadians(degrees) and toDegrees(radians). Use std::numbers::pi, from <numbers>, for π.One solution:
    Solution
    #include <numbers>
    double toRadians(double degrees) {  return degrees * std::numbers::pi / 180;}
    double toDegrees(double radians) {  return radians * 180 / std::numbers::pi;}
    Both are the same proportion, π radians to 180∘, turned one way or the other. If you mix them up, toRadians(180) gives about 10313 instead of 3.14: a good habit is to check one value you know. C++’s std::sin and its friends in <cmath> take radians, which is why you need this.
  260. 16. Angles, triangles and trigonometry · In a right triangle, the angle fixes the ratios of the sides · QuizA right triangle has sides 3, 4 and 5. For the angle θ opposite the side of length 3, what is tan⁡θ?C. 34The hypotenuse is the longest side, 5; opposite θ is 3, so the adjacent is 4. tan⁡θ=34. 35 is sin⁡θ and 45 is cos⁡θ; 43 is the tangent of the other acute angle, whose opposite and adjacent are swapped.
  261. 16. Angles, triangles and trigonometry · In a right triangle, the angle fixes the ratios of the sides · Fill the blanksFind the two short sides of a right triangle from its hypotenuse and an angle in radians.1: sin, 2: cos, 3: tanRearranging sin⁡θ=opp/hyp gives opp=hyp⋅sin⁡θ, here 5⋅0.5=2.5; likewise adj=5cos⁡30∘≈4.330. Their ratio is tan⁡θ, about 0.577, which is why tan⁡θ=sin⁡θ/cos⁡θ.
  262. 16. Angles, triangles and trigonometry · Solve a right triangle step by step · Find the bugheightOf(5, 70) should give about 4.70 but gives about 3.87. Which line is wrong?Line 2: double height = ladder * std::sin(angleDegrees * std::numbers::pi / 180);std::sin reads its argument as radians, so std::sin(70) is the sine of 70 radians, about 11 full turns plus a bit, which happens to be 0.774. Convert first. This is the most common trigonometry bug in code, and calculators set to the wrong mode make the same mistake on paper.
  263. 16. Angles, triangles and trigonometry · Solve a right triangle step by step · ProblemA kite flies on a straight 30m string that makes 50∘ with the ground. How high is the kite above the hand holding the string, and how far away is it horizontally?Height 30*sin(50*pi/180) ≈ 22.9813 m; Horizontal distance 30*cos(50*pi/180) ≈ 19.2836 m
    1. The string is the hypotenuse. The height is opposite the angle, and the horizontal distance is adjacent to it:
    2. height=30sin⁡50∘≈30⋅0.7660≈22.98macross=30cos⁡50∘≈30⋅0.6428≈19.28m
    3. Check with Pythagoras: 22.982+19.282≈528.1+371.7=899.8≈302.
    4. The kite is about 23.0m up and 19.3m away.
  264. 16. Angles, triangles and trigonometry · The unit circle defines sine and cosine for any angle · QuizWhat is cos⁡120∘?B. −12120∘ is 60∘ short of a half turn, so the point is the mirror image of the 60∘ point across the y axis: (−12,32). Its x coordinate, the cosine, is −12. Getting the size right but the sign wrong is the usual slip: ask which quarter the angle is in.
  265. 16. Angles, triangles and trigonometry · Sine and cosine are waves; tangent repeats with gaps · QuizWhat is the period of y=3sin⁡(2x)?B. πThe period is 2πk=2π2=π: doubling x runs through the wave twice as fast. The 3 is the amplitude and doesn’t change the period. 4π is the mistake of multiplying by k instead of dividing.
  266. 16. Angles, triangles and trigonometry · Sine squared plus cosine squared is always 1 · QuizIf sin⁡θ=35 and θ is between 90∘ and 180∘, what is cos⁡θ?B. −45cos2⁡θ=1−925=1625, so cos⁡θ=±45. The identity only gives the size; the quarter gives the sign. Between 90∘ and 180∘ the point is left of the y axis, so cosine is negative. 25 comes from 1−35, forgetting to square.
  267. 16. Angles, triangles and trigonometry · The laws of sines and cosines solve any triangle · Code challengeWrite thirdSide(a, b, angleDegrees): the side across from the angle between sides a and b, by the law of cosines.One solution:
    Solution
    #include <cmath>#include <numbers>
    double thirdSide(double a, double b, double angleDegrees) {  double C = angleDegrees * std::numbers::pi / 180;  return std::sqrt(a * a + b * b - 2 * a * b * std::cos(C));}
    The starter is Pythagoras, right only at 90∘, where cos⁡C=0. The correction −2abcos⁡C makes c shorter for an acute angle and longer for an obtuse one, where cosine is negative. Remember to convert to radians before std::cos.
  268. 16. Angles, triangles and trigonometry · The laws of sines and cosines solve any triangle · Put in orderYou know sides a, b and the angle C between them. Put the steps to find everything else in order.1. Find side c with the law of cosines 2. Find the angle opposite the shorter of a and b with the law of sines 3. Find the last angle: the three add up to 180∘ 4. Check: the longest side should face the largest angleThe law of sines needs a side with its opposite angle, so you need c (opposite the known C) first. Take the angle opposite the shorter side next: it must be acute, so arcsin⁡ gives it without ambiguity, while the larger one might be obtuse. The last angle comes free.
  269. 16. Angles, triangles and trigonometry · The laws of sines and cosines solve any triangle · ProblemA triangle has angles A=40∘ and B=65∘, and the side opposite A is a=8cm. Find the third angle and the other two sides.C 75 °; b 8*sin(65*pi/180)/sin(40*pi/180) ≈ 11.2797 cm; c 8*sin(75*pi/180)/sin(40*pi/180) ≈ 12.0217 cm
    1. The angles add up to 180∘: C=180∘−40∘−65∘=75∘.
    2. Each side over the sine of its opposite angle is the same number, 8sin⁡40∘≈80.6428≈12.45:
    3. b=8sin⁡65∘sin⁡40∘≈8⋅0.90630.6428≈11.28cmc=8sin⁡75∘sin⁡40∘≈8⋅0.96590.6428≈12.02cm
    4. Check: the longest side, c, faces the largest angle, 75∘.
  270. 16. Angles, triangles and trigonometry · Inverse functions turn a ratio back into an angle · QuizWhat is arcsin⁡(sin⁡150∘)?B. 30∘sin⁡150∘=12, and arcsin⁡12 is the angle in [−90∘,90∘] with that sine: 30∘. The inverse undoes the function only on its chosen stretch, so arcsin⁡(sin⁡θ)=θ only when θ is in it.
  271. 16. Angles, triangles and trigonometry · Inverse functions turn a ratio back into an angle · Code challengeWrite angleOf(x, y): the angle in degrees, from 0 up to (not including) 360, from the positive x axis to the point (x,y). std::atan2(y, x) gives an angle in radians between −π and π that knows the quarter.One solution:
    Solution
    #include <cmath>#include <numbers>
    double angleOf(double x, double y) {  double degrees = std::atan2(y, x) * 180 / std::numbers::pi;  if (degrees < 0) degrees += 360;  return degrees;}
    The starter’s arctan⁡(y/x) can’t tell (1,1) from (−1,−1): both have y/x=1, and it answers 45∘ for both. std::atan2 looks at the signs of x and y separately, so it knows the quarter. It answers between −180∘ and 180∘; adding 360 to negative answers moves them into the range asked for.
  272. 16. Angles, triangles and trigonometry · Practice problems · ProblemFind the exact values of sin⁡210∘, cos⁡3π4 and tan⁡π3.sin⁡210∘= -1/2 ≈ −0.5; cos⁡3π4= -sqrt(2)/2 ≈ −0.707107; tan⁡π3= sqrt(3) ≈ 1.73205
    1. 210∘ is 30∘ past a half turn, in the third quarter, where the point is below the axis: sin⁡210∘=−sin⁡30∘=−12.
    2. 3π4 is 135∘, 45∘ short of a half turn, in the second quarter, left of the y axis: cos⁡3π4=−cos⁡π4=−22.
    3. tan⁡π3=sin⁡(π/3)cos⁡(π/3)=3/21/2=3
    4. So the values are −12, −22 and 3.
  273. 16. Angles, triangles and trigonometry · Practice problems · ProblemAn angle θ lies between 180∘ and 270∘, and cos⁡θ=−513. Find sin⁡θ, tan⁡θ and sin⁡2θ exactly.sin⁡θ= -12/13 ≈ −0.923077; tan⁡θ= 12/5 ≈ 2.4; sin⁡2θ= 120/169 ≈ 0.710059
    1. From the Pythagorean identity:
    2. sin2⁡θ=1−25169=144169⇒sin⁡θ=±1213
    3. Between 180∘ and 270∘ the point is below the axis, so sin⁡θ=−1213. Then:
    4. tan⁡θ=−12/13−5/13=125,sin⁡2θ=2⋅(−1213)(−513)=120169
    5. So sin⁡θ=−1213, tan⁡θ=125 (positive, since sine and cosine are both negative) and sin⁡2θ=120169.
  274. 16. Angles, triangles and trigonometry · Practice problems · ProblemFor y=3sin⁡(4x), with x in radians, find the amplitude, the period, and the smallest positive x where y is at its maximum.Amplitude 3; Period pi/2 ≈ 1.5708; First maximum at x= pi/8 ≈ 0.392699
    1. In Asin⁡(kx), A=3 is the amplitude, and with k=4:
    2. period=2π4=π2
    3. Sine is largest, 1, first at π2, so y=3 first where:
    4. 4x=π2⇒x=π8≈0.393
    5. Amplitude 3, period π2, and the first maximum at x=π8, a quarter of the way through the first period.
  275. 16. Angles, triangles and trigonometry · More practice problems · ProblemA ramp rises 1.2m over a horizontal distance of 5m. What angle does it make with the ground, in degrees, and how long is the ramp?Angle atan(1.2/5)*180/pi ≈ 13.4957 °; Length sqrt(26.44) ≈ 5.14198 m
    1. The rise is opposite the angle and the run is adjacent, so use the tangent and its inverse:
    2. tan⁡θ=1.25=0.24⇒θ=arctan⁡0.24≈13.5∘
    3. The ramp itself is the hypotenuse:
    4. 1.22+52=1.44+25=26.44≈5.14m
    5. The ramp makes about 13.5∘ with the ground and is about 5.14m long. Check: 5.14sin⁡13.5∘≈1.2.
  276. 16. Angles, triangles and trigonometry · More practice problems · ProblemFind every angle x from 0∘ up to 360∘ with sin⁡x=0.6, in degrees.Smaller angle asin(0.6)*180/pi ≈ 36.8699 °; Larger angle 180 - asin(0.6)*180/pi ≈ 143.13 °
    1. The inverse function gives one angle:
    2. x=arcsin⁡0.6≈36.87∘
    3. The point at 180∘−x is its mirror image across the y axis, at the same height, so it has the same sine:
    4. x=180∘−36.87∘=143.13∘
    5. Sine is negative from 180∘ to 360∘, so there are no more. The angles are about 36.9∘ and 143.1∘.
  277. 16. Angles, triangles and trigonometry · More practice problems · ProblemTwo straight paths leave a point at an angle of 110∘ to each other. One is 5km long and the other 8km. How far apart are their ends, and what angle does the straight line between the ends make with the 5km path?Distance between the ends sqrt(89 - 80*cos(110*pi/180)) ≈ 10.7871 km; Angle asin(8*sin(110*pi/180)/sqrt(89 - 80*cos(110*pi/180)))*180/pi ≈ 44.1789 °
    1. The law of cosines, with a=5, b=8 and C=110∘, where cos⁡110∘≈−0.3420:
    2. c2=25+64−2⋅5⋅8cos⁡110∘≈89+27.36=116.36⇒c≈10.79km
    3. The angle at the end of the 5km path faces the 8km path. By the law of sines:
    4. sin⁡B=8sin⁡110∘10.79≈8⋅0.939710.79≈0.697⇒B≈44.2∘
    5. B cannot be obtuse, since the triangle already has a 110∘ angle, so arcsin⁡ gives it directly. The ends are about 10.8km apart, and the angle is about 44.2∘.
  278. 17. Complex numbers · Adding and multiplying work as you expect · QuizWhat is i10?C. −110=2⋅4+2, so i10=(i4)2⋅i2=1⋅(−1)=−1. A tempting slip is to think of i10 as “ten times i” or to stop the cycle at 3; write out i1 to i4 once and reduce the exponent modulo 4.
  279. 17. Complex numbers · The conjugate makes division possible · Fill the blanksA complex number in code is a struct C holding two doubles, its real part re and its imaginary part im; C{a, b} makes a+bi. Finish divide(z, w), which works out zw‾ww‾. With z=a+bi and w=c+di, zw‾=(ac+bd)+(bc−ad)i.1: +, 2: +, 3: -The bottom is ww‾=c2+d2, a sum of squares, so it is a plus (a minus would be the classic mistake of treating i2 as +1). The top is zw‾: the real part ac+bd gains a plus because bi⋅(−di)=−bdi2=+bd, and the imaginary part is bc−ad, the cross terms with the conjugate’s minus sign.
  280. 17. Complex numbers · The conjugate makes division possible · ProblemWrite 5+i2−3i in the form a+bi.a= 7/13 ≈ 0.538462; b= 17/13 ≈ 1.30769
    1. Multiply the top and the bottom by 2+3i:
    2. 5+i2−3i⋅2+3i2+3i=10+15i+2i+3i222+32=7+17i13
    3. So a=713 and b=1713. Check by multiplying back: (2−3i)(7+17i)=14+34i−21i−51i2=65+13i, and 65+13i13=5+i.
  281. 17. Complex numbers · Size and direction: modulus and argument · QuizWhat is the principal argument of −1−i?D. −3π4The point (−1,−1) is in the third quadrant, below the real axis, so the angle is negative and past a right angle: −3π4, or −135∘. arctan⁡−1−1=arctan⁡1=π4 is the trap: dividing b by a throws away both signs. Always look at the quadrant.
  282. 17. Complex numbers · Size and direction: modulus and argument · Find the bugThis gives the wrong argument for −1−i. Which line is wrong?Line 8: return std::atan2(z.im, z.re);std::atan(im / re) only answers between −π2 and π2, so every point left of the imaginary axis gets the angle of its opposite point, and re = 0 divides by zero (an infinity, or nan at 0 itself). std::atan2(y, x) takes the two parts separately, sees both signs, and returns the angle in (−π,π]. std::hypot is right: it is a2+b2, computed without overflowing for huge parts.
  283. 17. Complex numbers · Size and direction: modulus and argument · ProblemFind the modulus and the principal argument, in radians, of z=−3+i.|z|= 2; arg⁡z= 5*pi/6 ≈ 2.61799
    1. |z|=(−3)2+12=3+1=2
    2. The point (−3,1) is left of the imaginary axis and above the real one: the second quadrant. Its angle with the negative real axis has tangent 13, which is the tangent of π6, so:
    3. arg⁡z=π−π6=5π6(150∘)
    4. Check: cos⁡5π6=−32=a|z| and sin⁡5π6=12=b|z|. So |z|=2 and arg⁡z=5π6.
  284. 17. Complex numbers · Multiplying multiplies sizes and adds angles · QuizWhat is i(3+4i), and what happened to the point (3,4)?A. −4+3i: turned a quarter turn anticlockwisei(3+4i)=3i+4i2=−4+3i. Its modulus is still 5 (since |i|=1) and its argument is π2 more, so it is the same arrow turned 90° anticlockwise. Forgetting that 4i2=−4 gives 4+3i, which is a reflection, not a rotation.
  285. 17. Complex numbers · Try it: complex arithmetic in code · Code challengeFinish multiply(z, w), which returns the product of two complex numbers, and modulus(z), which returns its distance from 0.One solution:
    Solution
    #include <cmath>
    struct C { double re; double im; };
    C multiply(C z, C w) {  return C{z.re * w.re - z.im * w.im,           z.re * w.im + z.im * w.re};}
    double modulus(C z) {  return std::sqrt(z.re * z.re + z.im * z.im);}
    The starter multiplies part by part, which is how you add, not multiply: it forgets the cross terms ad and bc, and that bi⋅di=−bd. The last test checks a fact from the previous slide, |zw|=|z||w|, which the starter fails. Doubles are compared with EXPECT_NEAR, since square roots are rarely exact. With std::complex<double> the same product is just z * w, and the modulus std::abs(z).
  286. 17. Complex numbers · Powers, roots and the roots of unity · Put in orderPut the steps for solving z3=8i in order.1. Write 8i in polar form: 8eiπ/2 2. Take the real cube root of the modulus: 83=2 3. Divide the argument by 3: π6 4. Add 2π3 twice for the other angles: 5π6 and 3π2 5. Convert back: 3+i, −3+i and −2iPolar form first, because powers are easy there: cubing cubes the modulus and triples the angle, so the cube root takes the cube root of 8 and a third of the angle. A third of π2+2πk gives three different angles, 2π3 apart; stopping after the first root is the usual mistake. Check one: (−2i)3=−8i3=8i.
  287. 17. Complex numbers · Powers, roots and the roots of unity · Code challengeFinish rootsOfUnity(n): return the n solutions of zn=1 as a vector of C{re, im}, for k=0 to n−1 in order, where root k has angle 2πkn.One solution:
    Solution
    #include <cmath>#include <numbers>#include <vector>
    struct C { double re; double im; };
    std::vector<C> rootsOfUnity(int n) {  std::vector<C> roots;  for (int k = 0; k < n; k++) {    double angle = 2 * std::numbers::pi * k / n;    roots.push_back(C{std::cos(angle), std::sin(angle)});  }  return roots;}
    Each root is e2πik/n=cos⁡2πkn+isin⁡2πkn. The loop stops at n−1: k=n would be angle 2π, the root 1 again. The last test is a lovely fact: the roots sit symmetrically round 0, so they balance and their sum is 0 for any n>1. Note std::cos(std::numbers::pi / 2) is about 6×10−17, not 0, which is why the tests use EXPECT_NEAR.
  288. 17. Complex numbers · Every polynomial has all its roots in the complex numbers · QuizA cubic with real coefficients has roots 2+i and 4. What is its third root?B. 2−iReal coefficients force the conjugate of 2+i to be a root too, and a cubic has exactly three roots, so the third is 2−i. −2−i is the negative, not the conjugate: the conjugate keeps the real part and flips only the sign of the imaginary part.
  289. 17. Complex numbers · Every polynomial has all its roots in the complex numbers · QuizHow many complex roots, counted with multiplicity, does x5−x4+7x−3 have?B. Exactly 5Degree 5, so exactly 5 roots in ℂ, counted with multiplicity. Some may be real; since the coefficients are real and 5 is odd, at least one is. The theorem says the roots exist; it does not give a formula, and for degree 5 and above there is no general formula with roots, which is a theorem of Galois theory.
  290. 17. Complex numbers · Practice problems · ProblemLet z=3−2i and w=1+4i. Find zw, and the modulus of z2.Re⁡(zw)= 11; Im⁡(zw)= 10; |z2|= 13
    1. zw=(3−2i)(1+4i)=3+12i−2i−8i2=11+10i
    2. For z2, either expand, z2=9−12i+4i2=5−12i, so |z2|=25+144=13; or use that moduli multiply:
    3. |z2|=|z|2=32+(−2)2=13
    4. So zw=11+10i and |z2|=13.
  291. 17. Complex numbers · Practice problems · ProblemSolve z2+4z+13=0. Give the real part of the roots, the positive imaginary part, and the product of the two roots.Real part -2; Positive imaginary part 3; Product of the roots 13
    1. Use the quadratic formula; the discriminant is 16−52=−36:
    2. z=−4±−362=−4±6i2=−2±3i
    3. The roots are the conjugates −2+3i and −2−3i. Their product is zz‾=(−2)2+32=13, which is ca, as Vieta’s formulas say.
    4. Real part −2, imaginary parts ±3, and product 13.
  292. 17. Complex numbers · Practice problems · ProblemUse polar form to find (1+i)8, and the imaginary part of (1+i)6.(1+i)8= 16; Im⁡((1+i)6)= -8
    1. In polar form, 1+i=2eiπ/4. By de Moivre’s theorem:
    2. (1+i)8=(2)8ei⋅8π/4=16e2πi=16(1+i)6=(2)6ei⋅6π/4=8e3πi/2=8(0−i)=−8i
    3. So (1+i)8=16, and (1+i)6=−8i, whose imaginary part is −8. Check the first another way: (1+i)2=2i, and (2i)4=16i4=16.
  293. 17. Complex numbers · More practice problems · ProblemFind the three cube roots of −8: give the real one, and the one in the first quadrant as a+bi.The real root -2; First-quadrant root: a= 1; First-quadrant root: b= sqrt(3) ≈ 1.73205
    1. Write −8 in polar form, 8eiπ. A cube root has modulus 83=2 and a third of the angle, π3; the others are 2π3 further round:
    2. π3,π3+2π3=π,π+2π3=5π3
    3. Convert back to a+bi:
    4. 2eiπ/3=2(12+32i)=1+3i,2eiπ=−2,2e5πi/3=1−3i
    5. The real root is −2 and the first-quadrant root is 1+3i. Check: (1+3i)2=−2+23i, and multiplying by 1+3i again gives −2+6i2=−8.
  294. 17. Complex numbers · More practice problems · ProblemIn a game, a sprite at the point (4,1) is turned 60∘ anticlockwise about the origin. Use complex multiplication to find where it lands.New x 2 - sqrt(3)/2 ≈ 1.13397; New y 2*sqrt(3) + 1/2 ≈ 3.9641
    1. Turning by 60∘=π3 is multiplying by eiπ/3=12+32i, whose modulus is 1, so the distance from the origin does not change:
    2. (4+i)(12+32i)=2+23i+12i+32i2=(2−32)+(23+12)i
    3. The sprite lands at about (1.134,3.964). Check: its distance from the origin is still 1.1342+3.9642≈4.12=17.
  295. 18. Vectors and matrices · Adding vectors goes tip to tail · QuizWhat is 2(1,−3)−(4,1)?A. (−2,−7)Scale first: 2(1,−3)=(2,−6). Then subtract component by component: (2−4,−6−1)=(−2,−7). (−2,−5) comes from adding the 1 instead of subtracting it; subtracting a vector subtracts every component.
  296. 18. Vectors and matrices · The length of a vector comes from Pythagoras · Fill the blanksFinish unit(v), which returns the vector in the same direction with length 1, for any number of components.1: x, 2: sqrt, 3: /The first loop adds up the squares of the components; the square root of that sum is the length. Dividing every component by the length scales the vector to length 1 without turning it. The zero vector has length 0 and no direction, so it has no unit vector: here 0.0 / 0 would give nans (“not a number”), and real code should check for it.
  297. 18. Vectors and matrices · The dot product measures how much two vectors agree · QuizWhich vector is perpendicular to (2,3)?B. (−3,2)(2,3)⋅(−3,2)=−6+6=0, so the angle is 90°. In the plane, swapping the components and negating one always gives a perpendicular vector. (3,2) only swaps them (dot product 12), and (−2,−3) points exactly the opposite way (dot product −13, angle 180°).
  298. 18. Vectors and matrices · The dot product measures how much two vectors agree · ProblemFind the dot product of u→=(2,−1,2) and v→=(1,1,4), and the angle between them in degrees.u→⋅v→= 9; Angle 45 °
    1. u→⋅v→=2⋅1+(−1)⋅1+2⋅4=2−1+8=9
    2. ‖u→‖=4+1+4=3,‖v→‖=1+1+16=18=32
    3. cos⁡θ=93⋅32=12⇒θ=45∘
    4. The dot product is 9, and the vectors are 45∘ apart.
  299. 18. Vectors and matrices · Try it: the angle between two vectors · Code challengeFinish dot(u, v) and angleBetween(u, v), which returns the angle between two non-zero vectors in degrees. They work for any number of components. (using Vec = std::vector<double>; gives the type a short name.)One solution:
    Solution
    #include <algorithm>#include <cmath>#include <numbers>#include <vector>
    using Vec = std::vector<double>;
    double dot(const Vec& u, const Vec& v) {  double s = 0;  for (std::size_t i = 0; i < u.size(); i++) s += u[i] * v[i];  return s;}
    double angleBetween(const Vec& u, const Vec& v) {  double c = dot(u, v) / std::sqrt(dot(u, u) * dot(v, v));  double clamped = std::clamp(c, -1.0, 1.0);  return std::acos(clamped) * 180 / std::numbers::pi;}
    dot(u, u) is the length squared, so std::sqrt(dot(u, u) * dot(v, v)) is the two lengths multiplied. The clamp matters: for parallel vectors rounding can make the cosine 1.0000000000000002, and std::acos of anything above 1 is nan; std::clamp(c, -1.0, 1.0), from <algorithm>, keeps it within [−1,1]. Forgetting to convert from radians, which std::acos returns, gives 1.5708 instead of 90.
  300. 18. Vectors and matrices · A matrix is a grid of numbers · QuizIn A above, what is a21?B. 3Row 2, column 1: the first number of the second row, 3. a12=2 is the trap: the first index is always the row. “Rows first” holds for sizes too: 2×3 is 2 rows, 3 columns.
  301. 18. Vectors and matrices · Matrix multiplication is rows times columns · QuizA is 2×3 and B is 3×4. Which is true?A. AB is 2×4, and BA is not defined(2×3)(3×4): the inner 3s match, the outer sizes give 2×4. BA is (3×4)(2×3): the inner sizes 4 and 2 differ, so the rows of B (length 4) can’t be dotted with the columns of A (length 2).
  302. 18. Vectors and matrices · Matrix multiplication is rows times columns · Code challengeFinish matMul(a, b): the product of an m×n and an n×p matrix, as a vector of rows. Entry [i][j] is row i of a dotted with column j of b.One solution:
    Solution
    #include <vector>
    using Matrix = std::vector<std::vector<double>>;
    Matrix matMul(const Matrix& a, const Matrix& b) {  Matrix result;  for (std::size_t i = 0; i < a.size(); i++) {    std::vector<double> row;    for (std::size_t j = 0; j < b[0].size(); j++) {      double sum = 0;      for (std::size_t k = 0; k < b.size(); k++)        sum += a[i][k] * b[k][j];      row.push_back(sum);    }    result.push_back(row);  }  return result;}
    Three loops: i over the rows of a, j over the columns of b (b[0].size()), and k along the shared size n (b.size(), which equals a[0].size()) for the dot product. The result is a.size() by b[0].size(), the outer sizes. For 3×1: (1⋅1+2⋅1+0⋅2, 3−1+8)=(3,10). (The tests can compare whole matrices exactly because every entry here is a small whole number, which a double holds exactly.)
  303. 18. Vectors and matrices · Matrix multiplication is rows times columns · Find the bugmatVec(a, v) should multiply a matrix by a column vector, but gives wrong answers for a 2×3 matrix. Which line is wrong?Line 8: for (std::size_t k = 0; k < v.size(); k++) sum += row[k] * v[k];The dot product runs along a row, which has as many entries as there are columns (v.size(), or row.size()), not as many as there are rows (a.size()). For a square matrix the two are equal, which is why the bug hides until a non-square one comes along: here it stops after 2 of the 3 terms and gives a wrong answer, and for a tall matrix it reads past the end of each row. In C++ row[k] past the end is undefined behaviour: it may read whatever memory is there (here, the library’s checks stop the program instead).
  304. 18. Vectors and matrices · Matrix multiplication is rows times columns · ProblemMultiply A=(2−103) by B=(14−21). Give each entry of AB.Row 1, column 1 4; Row 1, column 2 7; Row 2, column 1 -6; Row 2, column 2 3
    1. Each entry is a row of A dotted with a column of B:
    2. AB=(2⋅1+(−1)(−2)2⋅4+(−1)⋅10⋅1+3⋅(−2)0⋅4+3⋅1)=(47−63)
    3. So AB has rows (4,7) and (−6,3).
  305. 18. Vectors and matrices · The identity matrix and the transpose · QuizA is 2×3. What size is ATA, and is it symmetric?A. 3×3, and symmetricAT is 3×2, and (3×2)(2×3) is 3×3. It is always symmetric: (ATA)T=AT(AT)T=ATA. AAT would be the 2×2 one. Matrices like ATA appear wherever data is fitted by least squares.
  306. 18. Vectors and matrices · A matrix moves every point of the plane · QuizWhat does (0−110) do to the plane?A. Rotates it a quarter turn anticlockwiseRead the columns: e→1=(1,0) goes to (0,1) and e→2=(0,1) goes to (−1,0). Both turned 90° anticlockwise: it is the rotation matrix with θ=90∘, and the same as multiplying by i in the complex plane. Swapping x and y (a reflection in y=x) is (0110), with no minus sign.
  307. 18. Vectors and matrices · A system of equations is one matrix equation · QuizRead Ax→=b→ by columns. With x=2, y=1, which is true?A. 2(21)+1(1−1)=(51)Ax→ is x times the first column plus y times the second: (4,2)+(1,−1)=(5,1). So solving the system asks “which mix of the columns makes b→?”, the column picture, while the plot above is the row picture, one line per equation. Both describe the same solution.
  308. 18. Vectors and matrices · Gaussian elimination solves any system step by step · Put in orderPut the steps of Gaussian elimination in order.1. Write the system as an augmented matrix 2. Pick a non-zero pivot in the first column, swapping rows if needed 3. Subtract multiples of the pivot row to make zeros below the pivot 4. Repeat for each next column until the matrix is triangular 5. Solve the last row, then substitute upwardsEverything happens on the augmented matrix, so the right-hand side changes along with the rows. Each column needs a non-zero pivot first, since you divide by it; a 0 there is fixed by swapping in a lower row. Back substitution only works once the triangle is complete, so it comes last. If a whole row becomes 0=c with c≠0, there is no solution; if it becomes 0=0, there are infinitely many.
  309. 18. Vectors and matrices · Try it: solve a system by elimination · Code challengeFinish solve(a, b), which solves Ax→=b→ for a square system with one solution. Forward elimination is written, with pivoting; write the back substitution: for each row from the last up, xi=1mii(min−∑j>imijxj), where m[i][n] is the right-hand side.One solution:
    Solution
    #include <cmath>#include <utility>#include <vector>
    using Vec = std::vector<double>;using Matrix = std::vector<Vec>;
    Vec solve(const Matrix& a, const Vec& b) {  int n = b.size();  Matrix m = a; // a copy, with b as an extra column  for (int i = 0; i < n; i++) m[i].push_back(b[i]);  for (int col = 0; col < n; col++) {    int p = col;    for (int r = col + 1; r < n; r++)      if (std::abs(m[r][col]) > std::abs(m[p][col])) p = r;    std::swap(m[col], m[p]);    for (int r = col + 1; r < n; r++) {      double f = m[r][col] / m[col][col];      for (int c = col; c <= n; c++) m[r][c] -= f * m[col][c];    }  }  Vec x(n, 0.0); // n zeros  for (int i = n - 1; i >= 0; i--) {    double s = m[i][n];    for (int j = i + 1; j < n; j++) s -= m[i][j] * x[j];    x[i] = s / m[i][i];  }  return x;}
    After elimination the matrix is upper triangular, so the last row has one unknown: xn−1=mn−1,n/mn−1,n−1. Each row above has one new unknown once the ones below are known: subtract their terms from the right-hand side and divide by the diagonal entry. The loop must run from the bottom up; going top down uses values of x that are still 0. Counting down is why i is an int: a std::size_t can’t go below 0, so i >= 0 would always be true. The third test only passes because of the row swap: without it the first pivot is 0, a double divided by 0 is infinite, and everything becomes nan.
  310. 18. Vectors and matrices · Practice problems · ProblemFind the length of v→=(6,−8), and the vector of length 5 that points the same way.‖v→‖= 10; Its first component 3; Its second component -4
    1. ‖v→‖=62+(−8)2=100=10
    2. The unit vector is vˆ=(6,−8)10=(0.6,−0.8). Scale it to length 5:
    3. 5vˆ=(3,−4)
    4. Its length is 9+16=5, as it should be. The vector is (3,−4), half of v→.
  311. 18. Vectors and matrices · Practice problems · ProblemFor which k is (k,3) perpendicular to (4,−6)? And for which k is it parallel to (4,−6)?Perpendicular: k= 9/2 ≈ 4.5; Parallel: k= -2
    1. Perpendicular: the dot product is zero.
    2. 4k+3⋅(−6)=0⇒4k=18⇒k=92
    3. Parallel: (k,3)=c(4,−6). The second components give 3=−6c, so c=−12, and then k=4c=−2.
    4. So k=92 for perpendicular, and k=−2 for parallel: (−2,3) is −12(4,−6).
  312. 18. Vectors and matrices · Practice problems · ProblemSolve by Gaussian elimination: x+y+z=4, 2x−y+3z=13 and x+2y−z=−1.x= 3; y= -1; z= 2
    1. Write the augmented matrix and clear the first column:
    2. (11142−131312−1−1)→R3−R1R2−2R1(11140−31501−2−5)
    3. Swap the last two rows, so the pivot is 1, then clear below it:
    4. →R2↔R3(111401−2−50−315)→R3+3R2(111401−2−500−5−10)
    5. Back substitution: z=−10−5=2, then y=−5+2z=−1, then x=4−y−z=3.
    6. Check in the second equation: 2⋅3−(−1)+3⋅2=13. The solution is x=3, y=−1, z=2.
  313. 18. Vectors and matrices · More practice problems · ProblemThe point (3,1) is turned 90∘ anticlockwise about the origin, then reflected in the x axis. Where does it end up? And where would it end up with the two moves done the other way round?Turn, then reflect: x= -1; Turn, then reflect: y= -3; Reflect, then turn: x= 1; Reflect, then turn: y= 3
    1. Turn first, then reflect, FRv→, one step at a time:
    2. R(31)=(−13),F(−13)=(−1−3)
    3. The other way round, RFv→:
    4. F(31)=(3−1),R(3−1)=(13)
    5. So (−1,−3) one way and (1,3) the other: FR≠RF. In fact FR=(0−1−10), the reflection in the line y=−x.
  314. 18. Vectors and matrices · More practice problems · ProblemA café sells coffee at 3 euros, tea at 2 euros and cake at 4 euros. On Monday it sells 20 coffees, 15 teas and 10 cakes; on Tuesday 25, 10 and 12. Put the sales in a 2×3 matrix Q, one row per day, and the prices in a vector p→. What is Qp→?Monday’s takings 130 euros; Tuesday’s takings 143 euros
    1. Qp→=(201510251012)(324)=(60+30+4075+20+48)=(130143)
    2. A 2×3 matrix times a 3×1 vector is 2×1: one total per day. Monday took 130 euros and Tuesday 143 euros.
  315. 19. Linear maps, determinants and eigenvectors · Mixing vectors: combinations and span · QuizWhat is the span of the single vector (1,2) in the plane?B. The line through the origin in the direction (1,2)With one vector you can only scale it: a(1,2)=(a,2a), every point of the line y=2x as a runs over all numbers, including a=0, the origin. A span always passes through the origin, so y=2x+1 cannot be one. To fill the plane you need a second vector off that line.
  316. 19. Linear maps, determinants and eigenvectors · Independent vectors add something new · QuizWhich set of vectors is linearly dependent?C. (1,1), (1,−1) and (5,1)Three vectors in the plane are always dependent: the plane has room for only two independent directions. Here (5,1)=3(1,1)+2(1,−1). The first two pairs point in different directions, so each pair is independent, and a single nonzero vector is independent on its own. (3,1) and (1,3) look alike, but neither is a multiple of the other.
  317. 19. Linear maps, determinants and eigenvectors · A basis is a coordinate system · QuizWhat are the coordinates of (4,2) in the basis (1,1), (1,−1)?B. (3,1)Solve a+b=4 and a−b=2: adding gives 2a=6, so a=3 and b=1. Check: 3(1,1)+1(1,−1)=(4,2). The answer (4,2) is the coordinates in the usual basis, not this one: the same point has different coordinates in different bases.
  318. 19. Linear maps, determinants and eigenvectors · A linear map keeps lines straight and the origin still · QuizWhich of these maps of the plane is linear?C. T(x,y)=(3x−y,2y)Each output of a linear map is a fixed mix of x and y, with no constants and no products: (3x−y,2y) has matrix with rows (3,−1) and (0,2). Adding 1 moves the origin (T(0,0)=(1,0)), and a linear map always sends 0→ to 0→. Squares and products break T(2u→)=2T(u→): doubling x quadruples x2.
  319. 19. Linear maps, determinants and eigenvectors · A linear map keeps lines straight and the origin still · Fill the blanksA linear map sends e→1 to (2,1) and e→2 to (−1,3). Fill in where it sends any (x,y).1: 2, 2: -1, 3: 1, 4: 3The first output is x times the first coordinate of T(e→1) plus y times the first coordinate of T(e→2): 2x−y. The second is x+3y. The matrix has the images as columns, (2,1) then (−1,3), so reading it row by row gives these two lines. Putting the images in rows instead is the usual slip; it gives the transpose, a different map. (A std::pair, from <utility>, holds the two outputs together.)
  320. 19. Linear maps, determinants and eigenvectors · The determinant is how much area scales · ProblemA linear map has matrix (3114). By what factor does it scale areas, and what area does a shape of area 2.5 have after it? What is the area of the triangle with corners (0,0), (3,1) and (1,4)?Area factor 11; Area of the image 27.5; Area of the triangle 11/2 ≈ 5.5
    1. det⁡(3114)=3⋅4−1⋅1=11
    2. Every area is multiplied by 11, so a shape of area 2.5 becomes one of area 27.5.
    3. The columns (3,1) and (1,4) are the sides of a parallelogram of area 11, and the triangle with corners (0,0), (3,1) and (1,4) is half of it, cut along a diagonal:
    4. area=12⋅11=5.5
    5. The factor is 11 (positive, so the orientation is kept), the image has area 27.5, and the triangle has area 5.5.
  321. 19. Linear maps, determinants and eigenvectors · Try it: a three by three determinant · Code challengeFinish det3(m): the determinant of a 3×3 matrix given as a vector of rows, m[row][column].One solution:
    Solution
    #include <vector>
    using Matrix = std::vector<std::vector<double>>;
    double det3(const Matrix& m) {  double a = m[0][0], b = m[0][1], c = m[0][2];  double d = m[1][0], e = m[1][1], f = m[1][2];  double g = m[2][0], h = m[2][1], i = m[2][2];  return a * (e * i - f * h) - b * (d * i - f * g) +         c * (d * h - e * g);}
    For the general matrix: 1(50−48)−2(40−42)+3(32−35)=2+4−9=−3. The usual mistake is the middle sign: the second term is subtracted, because the signs follow a checkerboard +,−,+. The matrix with rows 1..9 gives 0 because its third row is twice the second minus the first, so the rows are dependent and the box is flat.
  322. 19. Linear maps, determinants and eigenvectors · An inverse undoes the map · Find the bugThis inverse gives a matrix that does not undo A. Which line is wrong?Line 7: {-c / det, a / det},Both off-diagonal entries are negated, b and c. With c left positive, A−1A has a nonzero entry below the diagonal. Line 4 is right (a std::optional holds a value or none, std::nullopt): with doubles you might prefer std::abs(det) < 1e-12, because a matrix that is nearly singular gives a huge, unreliable inverse.
  323. 19. Linear maps, determinants and eigenvectors · Eigenvectors keep their direction · QuizFor A with rows (2,1) and (1,2), is (1,−1) an eigenvector, and with which eigenvalue?C. Yes, with λ=1Multiply: A(1,−1)=(2−1,1−2)=(1,−1), the same vector, so λ=1. Checking an eigenvector is always this easy: multiply and see whether the answer is a multiple of what went in. λ=3 belongs to (1,1), since A(1,1)=(3,3).
  324. 19. Linear maps, determinants and eigenvectors · Finding eigenvalues with a determinant · QuizWhat are the eigenvalues of the matrix with rows (5,2) and (0,−3)?B. 5 and −3det⁡(A−λI)=(5−λ)(−3−λ)−2⋅0=(5−λ)(−3−λ), with roots 5 and −3. For a triangular matrix the eigenvalues are always the diagonal entries. 2 and −15 are the trace and the determinant, the sum and product of the eigenvalues, not the eigenvalues themselves.
  325. 19. Linear maps, determinants and eigenvectors · Finding eigenvalues with a determinant · ProblemFind the eigenvalues of A=(4123), and an eigenvector for each, written as (1,y).Smaller eigenvalue 2; Its eigenvector: y= -2; Larger eigenvalue 5; Its eigenvector: y= 1
    1. det⁡(A−λI)=(4−λ)(3−λ)−1⋅2=λ2−7λ+10=(λ−2)(λ−5)
    2. So λ=2 or λ=5. Check: they add up to 7, the trace, and multiply to 10, the determinant 12−2.
    3. For λ=2, A−2I has first row (2,1), so 2⋅1+y=0 and y=−2. For λ=5, the first row is (−1,1), so −1+y=0 and y=1.
    4. A(1−2)=(2−4)=2(1−2),A(11)=(55)=5(11)
    5. Eigenvalue 2 goes with (1,−2), and eigenvalue 5 with (1,1).
  326. 19. Linear maps, determinants and eigenvectors · Diagonalising: the matrix in its own basis · Put in orderPut the steps of diagonalising a matrix in order.1. Write the characteristic polynomial det⁡(A−λI) 2. Find its roots, the eigenvalues 3. For each eigenvalue, solve (A−λI)v→=0→ for an eigenvector 4. Put the eigenvectors as the columns of P and the eigenvalues on the diagonal of D 5. Check AP=PD, then write A=PDP−1Eigenvalues come first, because each eigenvector is found from its eigenvalue. The order inside P and D must match: the k-th column of P goes with the k-th diagonal entry of D. Checking AP=PD avoids computing an inverse, and it is the equation Av→=λv→ for all columns at once.
  327. 19. Linear maps, determinants and eigenvectors · Try it: run a Markov chain · Code challengeFinish runChain(m, x, steps): apply the matrix m (a vector of rows) to the vector x, steps times, and return the result. One step is y[i] = Σ m[i][j] * x[j].One solution:
    Solution
    #include <vector>
    using Vec = std::vector<double>;using Matrix = std::vector<Vec>;
    Vec runChain(const Matrix& m, Vec x, int steps) {  for (int k = 0; k < steps; k++) {    Vec y(x.size(), 0.0); // the next vector, all zeros    for (std::size_t i = 0; i < m.size(); i++)      for (std::size_t j = 0; j < x.size(); j++)        y[i] += m[i][j] * x[j];    x = y;  }  return x;}
    Each step is a matrix times a vector: entry i of the result is row i of m dotted with the current vector. The gap to the steady state shrinks by a factor 0.4 each step, so after 60 steps it is about 0.460≈10−24. A common slip is updating x in place while still reading it: the second entry would then use the new first entry. Building a new vector y each step avoids that. (x is taken by value, without const &: the function gets its own copy, free to change.)
  328. 19. Linear maps, determinants and eigenvectors · Practice problems · ProblemFind the inverse of A=(3512), and use it to solve 3x+5y=4, x+2y=1.det⁡A= 1; x= 3; y= -1
    1. det⁡A=3⋅2−5⋅1=1,A−1=11(2−5−13)
    2. The system is Ax→=(4,1), so:
    3. x→=A−1(41)=(2⋅4−5⋅1−1⋅4+3⋅1)=(3−1)
    4. Check: 3⋅3+5⋅(−1)=4 and 3+2⋅(−1)=1. So x=3 and y=−1.
  329. 19. Linear maps, determinants and eigenvectors · Practice problems · ProblemFor which k does (2k36) have no inverse? And what is the determinant of (120013201)?k= 4; The 3×3 determinant 13
    1. 2⋅6−3k=0⇒k=4
    2. With k=4 the columns (2,3) and (4,6) are dependent, the second twice the first, so the map squashes the plane onto a line.
    3. Expand the 3×3 along its first row:
    4. 1⋅(1⋅1−3⋅0)−2⋅(0⋅1−3⋅2)+0=1+12=13
    5. So k=4, and the determinant is 13.
  330. 19. Linear maps, determinants and eigenvectors · Practice problems · ProblemWhat are the coordinates of the point (7,11) in the basis b→1=(2,1), b→2=(1,3)?Amount of b→1 2; Amount of b→2 3
    1. a(21)+b(13)=(711)⟺{2a+b=7a+3b=11
    2. From the first, b=7−2a. Then a+21−6a=11, so a=2 and b=3.
    3. Check: 2(2,1)+3(1,3)=(4+3,2+9)=(7,11). The coordinates are (2,3).
  331. 19. Linear maps, determinants and eigenvectors · More practice problems · ProblemA car-hire firm has 700 cars and two offices, A and B. Each day, of the cars at A, 70% end up back at A and 30% at B; of the cars at B, 40% end up at A and 60% at B. If all 700 start at A, how many are at A after one day? In the long run, how many are at A, and what is the other eigenvalue of the matrix?At A after one day 490; At A in the long run 400; The other eigenvalue 0.3
    1. Each column of M holds where one office’s cars go. After one day:
    2. M(7000)=(0.70.40.30.6)(7000)=(490210)
    3. The steady state is the eigenvector for eigenvalue 1: 0.7a+0.4b=a, so 0.4b=0.3a and a=43b. With a+b=700, 73b=700:
    4. b=300,a=400
    5. The eigenvalues add up to the trace, 0.7+0.6=1.3, and one of them is 1, so the other is 0.3: each day the gap to the steady state shrinks to 30% of what it was.
    6. So 490 cars are at A after a day, 400 in the long run, and the other eigenvalue is 0.3.
  332. 19. Linear maps, determinants and eigenvectors · More practice problems · ProblemFor A=(2112), diagonalising gave An=12(3n+13n−13n−13n+1). Use it to find the entries of A5, and the largest eigenvalue of A5.Top-left entry of A5 122; Top-right entry of A5 121; Largest eigenvalue of A5 243
    1. With n=5 and 35=243:
    2. A5=12(244242242244)=(122121121122)
    3. Check one entry the long way: A2 has rows (5,4) and (4,5), A4=(A2)2 has top row (25+16,20+20)=(41,40), and the top-left entry of A5=A4A is 41⋅2+40⋅1=122.
    4. The eigenvalues of A5 are the diagonal of D5: 35=243 and 15=1. So A5 has rows (122,121) and (121,122), and its largest eigenvalue is 243.
  333. 20. Abstract algebra and thinking like a mathematician · A proof covers every case at once · QuizYou check that n2+n+41 is prime for n=0,1,2,…,10. What have you shown about all whole numbers n?C. Nothing yet: examples can suggest a rule but not prove itThis formula really is prime for n=0 up to 39, which looks convincing, and yet at n=40 it gives 1600+40+41=1681=412. Forty examples did not prove it, because no number of examples can. One counterexample, on the other hand, is enough to disprove a claim about all n.
  334. 20. Abstract algebra and thinking like a mathematician · Proving the other way round, and by contradiction · Fill the blanksProve "if n2 is even, then n is even" through its contrapositive.1: odd, 2: odd, 3: 2k² + 2kNot even is odd, for integers, so the contrapositive turns both halves around: odd n gives odd n2. That direction is easy, because "odd" hands you a formula, n=2k+1, to square. n2=2(2k2+2k)+1 is twice an integer plus one, so it is odd. Proving the claim head on would mean starting from "n2 is even", which says little about n directly.
  335. 20. Abstract algebra and thinking like a mathematician · Proving the other way round, and by contradiction · Put in orderPut the classic proof that 2 is irrational in order.1. Suppose 2=p/q, a fraction in lowest terms 2. Square both sides: p2=2q2 3. So p2 is even, hence p is even: write p=2k 4. Then 4k2=2q2, so q2=2k2 and q is even too 5. Both p and q even contradicts lowest terms, so 2 is irrationalThe assumption comes first, and "lowest terms" is the part that will break. "p2 even, so p even" is the claim you just proved by contrapositive: proofs build on proofs. The contradiction is that 2 divides both p and q, which lowest terms forbid, so no such fraction exists.
  336. 20. Abstract algebra and thinking like a mathematician · Sets and maps: the words every structure uses · QuizWhich describes f(x)=x2 as a map from ℝ to ℝ?D. Neither injective nor surjectiveNot injective: f(−2)=f(2)=4. Not surjective: no real number squares to −1. The same formula from [0,∞) to [0,∞) is a bijection, with inverse x. A map is the formula and its sets, which is exactly why inverses in earlier modules needed a restricted domain.
  337. 20. Abstract algebra and thinking like a mathematician · Modular arithmetic: numbers on a clock · QuizWhat is 210mod7? Try it without working out 210.B. 223=8≡1(mod7), so powers of 2 repeat every 3. 10=3⋅3+1, so 210=(23)3⋅2≡1⋅2=2. Check: 1024=7⋅146+2. Finding a power that is 1 and splitting the exponent is the trick behind fast modular arithmetic.
  338. 20. Abstract algebra and thinking like a mathematician · Modular arithmetic: numbers on a clock · ProblemFind the last digit of 72026, and 3100mod7.Last digit of 72026 9; 3100mod7= 4
    1. The last digit is the number mod 10. Powers of 7 mod 10 run 7,9,3,1 and then repeat, since 74=2401≡1:
    2. 2026=4⋅506+2⇒72026=(74)506⋅72≡1⋅49≡9(mod10)
    3. For the second, 36≡1(mod7), and 100=6⋅16+4:
    4. 3100=(36)16⋅34≡34=81≡4(mod7)
    5. The last digit of 72026 is 9, and 3100mod7=4, the same as 34 in the list of powers above.
  339. 20. Abstract algebra and thinking like a mathematician · Try it: fast powers modulo n · Code challengeFinish modPow(base, exp, mod): return base to the power exp, modulo mod, by square and multiply. exp is a whole number, mod is at least 2 and below 10 000 000.One solution:
    Solution
    long long modPow(long long base, long long exp, long long mod) {  long long result = 1;  long long square = base % mod;  long long e = exp;  while (e > 0) {    if (e % 2 == 1) result = result * square % mod;    square = square * square % mod;    e = e / 2;  }  return result;}
    Writing e in binary, be is the product of the b2i for the bits that are 1, and square holds b2i at step i; e / 2 on whole numbers drops the bit just used. Reducing after each multiplication keeps every number below n2, here under 1014, which a long long holds exactly (up to about 9.2×1018; an int stops at about 2.1×109, which is why it is not used here). Computing the whole power first and reducing at the end fails: be overflows a long long, which in C++ is undefined behaviour (in practice, a wrong number), and std::pow gives a double that keeps only about 16 digits, long before the %.
  340. 20. Abstract algebra and thinking like a mathematician · A group: one operation, four rules · QuizWhich of these is a group?C. {1,−1,i,−i} under ×{1,−1,i,−i} is closed (i⋅i=−1, i⋅(−i)=1, …), has identity 1, and every element has an inverse in the set (i−1=−i): it is the fourth roots of unity from the complex numbers module. The whole numbers have no −3 to undo +3; the integers under × have no inverse for 2; and among the reals, 0 has no inverse under ×.
  341. 20. Abstract algebra and thinking like a mathematician · Symmetries form groups, and order matters · Code challengeFinish compose(p, q): the permutation "first q, then p", so element i goes to p[q[i]].One solution:
    Solution
    #include <vector>
    using Perm = std::vector<int>; // p[i] is where i goes
    Perm compose(const Perm& p, const Perm& q) {  Perm result;  for (int qi : q) result.push_back(p[qi]);  return result;}
    Like composing functions, (p∘q)(i)=p(q(i)): the right-hand one acts first. compose(turn, flip) is [1,0,2] but compose(flip, turn) is [2,1,0], two different flips, so the group is not commutative. The usual slip is q[p[i]], which does p first and gives the other answer.
  342. 20. Abstract algebra and thinking like a mathematician · Rings and fields: two operations that get along · Code challengeFinish modInverse(a, n): the number x from 0 to n - 1 with a * x % n == 1, or std::nullopt if there is none (a std::optional<int> holds an int or nothing). Use the extended Euclidean algorithm.One solution:
    Solution
    #include <optional>
    std::optional<int> modInverse(int a, int n) {  int r0 = n, r1 = a % n;  int t0 = 0, t1 = 1;  while (r1 != 0) {    int q = r0 / r1;    int r2 = r0 - q * r1;    r0 = r1;    r1 = r2;    int t2 = t0 - q * t1;    t0 = t1;    t1 = t2;  }  if (r0 != 1) return std::nullopt;  return (t0 % n + n) % n;}
    Each pair (r,t) keeps the promise r≡t⋅a(modn); the remainders shrink exactly as in Euclid's gcd (r0 / r1 on ints is the whole quotient), and when the last nonzero remainder is 1, its t is the inverse. It can come out negative (−2 for 3 mod 7), so the last line moves it into 0..n−1: −2+7=5, and 3⋅5=15≡1. C++'s % keeps the sign of the left side (-2 % 7 is −2, not 5), which is why t0 % n alone is not enough.
  343. 20. Abstract algebra and thinking like a mathematician · Rings and fields: two operations that get along · ProblemFind the inverse of 5 modulo 17, and use it to solve 5x≡3(mod17), with x from 0 to 16.Inverse of 5 7; x= 4
    1. Euclid on 17 and 5: 17=3⋅5+2, then 5=2⋅2+1. Working back up:
    2. 1=5−2⋅2=5−2(17−3⋅5)=7⋅5−2⋅17
    3. So 7⋅5≡1(mod17), and the inverse of 5 is 7 (indeed 35=2⋅17+1). Multiply both sides of 5x≡3 by 7:
    4. x≡7⋅3=21≡4(mod17)
    5. Check: 5⋅4=20=17+3. The inverse is 7, and x=4.
  344. 20. Abstract algebra and thinking like a mathematician · Isomorphic structures are the same in disguise · QuizAre ℤ4 and ℤ2×ℤ2 (pairs of bits, added mod 2 in each place) isomorphic? Both have 4 elements.B. No: in ℤ2×ℤ2 every element added to itself gives 0, but in ℤ4, 1+1=2≠0An isomorphism keeps every structural fact, including "x+x=0 for all x", which holds in ℤ2×ℤ2 and fails for 1 in ℤ4. So no bijection can work. Both groups are abelian, and k↦(kmod2,kmod2) is not even a bijection: 0 and 2 both go to (0,0). To show two structures differ, find a property one has and the other lacks.
  345. 20. Abstract algebra and thinking like a mathematician · Where algebra goes next · QuizWith φ(n)=40 and public exponent e=7, which d is the private exponent?C. 23d is the inverse of e mod φ(n): 7⋅23=161=4⋅40+1. The others give remainders 9, 39 and 31. Decryption works because med=m1+kφ(n)=m⋅(mφ(n))k≡m, by Euler's theorem.
  346. 20. Abstract algebra and thinking like a mathematician · Mixed problems from the whole course · QuizWhat are the roots of x2−2x+5=0?A. 1±2iThe discriminant is 4−20=−16, so x=2±−162=2±4i2=1±2i. Forgetting to halve the 4i gives 1±4i. "No roots" is true only over ℝ: over ℂ, every polynomial of degree n has n roots, counted with multiplicity.
  347. 20. Abstract algebra and thinking like a mathematician · Mixed problems from the whole course · QuizSolve log2⁡x+log2⁡(x−2)=3.B. x=4Combine: log2⁡(x(x−2))=3, so x2−2x=8, (x−4)(x+2)=0. But log2⁡x needs x>0 and log2⁡(x−2) needs x>2, so −2 is extraneous. Check: log2⁡4+log2⁡2=2+1=3.
  348. 20. Abstract algebra and thinking like a mathematician · Mixed problems from the whole course · QuizWhat is ∑k=0∞(13)k?C. 32A geometric series with ratio r=13, |r|<1, sums to 11−r=12/3=32. Starting from k=1 would give 12; check the first term before using the formula.
  349. 20. Abstract algebra and thinking like a mathematician · Mixed problems from the whole course · QuizR turns the plane by 90°. What is R2026?B. −IFour quarter turns are a full turn, R4=I, so only the exponent mod 4 matters: 2026=4⋅506+2, and R2026=R2, a half turn, which sends every v→ to −v→: that is −I. The turns form the group ℤ4, and this is modular arithmetic on exponents, as with 210mod7.
  350. 20. Abstract algebra and thinking like a mathematician · Practice problems · ProblemFind all the roots of x3−4x2+9x−10=0: one is real and two are complex.The real root 2; Real part of the complex roots 1; Their positive imaginary part 2
    1. Try divisors of 10: p(1)=1−4+9−10=−4, and p(2)=8−16+18−10=0. So x−2 is a factor.
    2. Synthetic division with r=2 on 1,−4,9,−10: 1, then −4+2=−2, 9−4=5 and −10+10=0:
    3. x3−4x2+9x−10=(x−2)(x2−2x+5)
    4. The quadratic has discriminant 4−20=−16:
    5. x=2±−162=2±4i2=1±2i
    6. The roots are 2 and 1±2i: three roots for a cubic, the complex ones a conjugate pair, as the fundamental theorem and the real coefficients promise.
  351. 20. Abstract algebra and thinking like a mathematician · Practice problems · ProblemAn angle θ has cos⁡θ=35 and sin⁡θ=45. Expand (cos⁡θ+isin⁡θ)3 with the binomial theorem, and use de Moivre’s theorem to read off cos⁡3θ and sin⁡3θ.cos⁡3θ= -117/125 ≈ −0.936; sin⁡3θ= 44/125 ≈ 0.352
    1. With c=cos⁡θ and s=sin⁡θ, the binomial theorem gives:
    2. (c+is)3=c3+3c2(is)+3c(is)2+(is)3=(c3−3cs2)+i(3c2s−s3)
    3. By de Moivre, the left side is cos⁡3θ+isin⁡3θ, so match the real and the imaginary parts:
    4. cos⁡3θ=27125−3⋅35⋅1625=27−144125=−117125sin⁡3θ=3⋅925⋅45−64125=108−64125=44125
    5. Check with the Pythagorean identity: 1172+442=13689+1936=15625=1252. So cos⁡3θ=−117125 and sin⁡3θ=44125.
  352. 20. Abstract algebra and thinking like a mathematician · Practice problems · ProblemWhere does the line y=2x+1 meet the parabola y=x2−2? Give both points, the left one first.Left point: x= -1; Left point: y= -1; Right point: x= 3; Right point: y= 7
    1. Substitute the line into the parabola, as with any system:
    2. x2−2=2x+1⇒x2−2x−3=0⇒(x−3)(x+1)=0
    3. So x=−1 or x=3. The line gives their heights: y=2(−1)+1=−1 and y=2⋅3+1=7.
    4. Check on the parabola: (−1)2−2=−1 and 32−2=7. The points are (−1,−1) and (3,7).
  353. 20. Abstract algebra and thinking like a mathematician · More practice problems · ProblemA loan of 10 000 euros charges 1% interest a month and is repaid by 24 equal monthly payments P, the first one month after the loan. The payments, each grown with interest to the end, must add up to what the loan grows to: P(1+1.01+⋯+1.0123)=10000⋅1.0124. Find P, and the total interest paid.P 10000*1.01^24*0.01/(1.01^24 - 1) ≈ 470.735 euros; Total interest 24*10000*1.01^24*0.01/(1.01^24 - 1) - 10000 ≈ 1297.63 euros
    1. The bracket is a geometric series with 24 terms:
    2. 1+1.01+⋯+1.0123=1.0124−11.01−1=1.0124−10.01≈26.9735
    3. So:
    4. P=10000⋅1.012426.9735≈12697.3526.9735≈470.73
    5. In all, 24⋅470.73≈11297.63 euros is paid back, so the interest is about 1297.63 euros.
  354. 20. Abstract algebra and thinking like a mathematician · More practice problems · ProblemThe Fibonacci rule Fn+1=Fn+Fn−1 is the matrix step (Fn+1Fn)=(1110)(FnFn−1). Find the eigenvalues of that matrix, and compare the larger one with F11/F10.Larger eigenvalue (1 + sqrt(5))/2 ≈ 1.61803; Smaller eigenvalue (1 - sqrt(5))/2 ≈ −0.618034; F11/F10= 89/55 ≈ 1.61818
    1. det⁡(1−λ11−λ)=−λ(1−λ)−1=λ2−λ−1=0
    2. The quadratic formula gives:
    3. λ=1±52≈1.618 or −0.618
    4. The Fibonacci numbers run 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, so F11/F10=8955≈1.6182. Applying the matrix again and again is the power method, so the ratio of neighbouring terms settles on the larger eigenvalue, 1+52≈1.6180, the golden ratio.
  355. 20. Abstract algebra and thinking like a mathematician · More practice problems · ProblemLet f(x)=3⋅2x−1. Find its inverse f−1(x), and f−1(23).f−1(x)= log2((x + 1)/3); f−1(23)= 3
    1. Write y=f(x) and undo each step in reverse order:
    2. y=3⋅2x−1y+1=3⋅2xy+13=2xx=log2⁡y+13
    3. Rename: f−1(x)=log2⁡x+13, defined for x>−1, which is exactly the range of f.
    4. Then f−1(23)=log2⁡8=3. Check: f(3)=3⋅8−1=23.