Int 3 for Programmers

Functions, transformations, composition and inverses

8 / 396
Contents

Contents

Int 3 for Programmers

0 of 396 complete

11 min read

Drawing a piecewise rule, and reading one back

Sketching each piece over its own stretch, the hollow and filled circles, and writing the rule from a picture.

Evaluating a piecewise rule answers one input at a time. An exam also wants the picture, and it wants the reverse trip: here is the picture, write the rule.

Sketching one is a short routine, and it never changes. Take each piece in turn, draw only the part of it that its own condition allows, and mark both ends of that part.

  1. Take the first piece together with its condition, and work out its value at each end of that stretch of inputs.
  2. Draw that piece between those two ends and nowhere else. The rest of that formula is not part of this function.
  3. Mark each end with a filled circle if the condition includes that input, and a hollow circle if it excludes it.
  4. Repeat for every remaining piece.
  5. Check each boundary: exactly one filled circle should sit above it. Two would mean one input with two outputs, and none would mean an input with no output at all.

One worked example in full. Sketch the function below.

f(x)={x+1x<26−xx≥2f(x) = \begin{cases} x + 1 & x < 2 \\ 6 - x & x \ge 2 \end{cases}
Two pieces, with the boundary at the input 2.
  1. First piece, x+1x + 1, on the stretch x<2x < 2. At x=−1x = -1 it gives −1+1=0-1 + 1 = 0, so the point (−1,0)(-1, 0) is on the graph.
  2. At x=2x = 2 that formula would give 2+1=32 + 1 = 3, but the condition x<2x < 2 does not allow the input 2.
  3. So draw the straight line from (−1,0)(-1, 0) heading up towards (2,3)(2, 3), and put a hollow circle at (2,3)(2, 3) to show that end is not included.
  4. Second piece, 6−x6 - x, on the stretch x≥2x \ge 2. At x=2x = 2 it gives 6−2=46 - 2 = 4, and the condition does allow the input 2, so that end gets a filled circle at (2,4)(2, 4).
  5. At x=5x = 5 it gives 6−5=16 - 5 = 1, so draw the line from (2,4)(2, 4) down through (5,1)(5, 1) and onwards to the right.
  6. Check the boundary: one filled circle at (2,4)(2, 4), one hollow circle at (2,3)(2, 3). The input 2 has exactly one output, which is 4, so the promise holds.

The distance between the hollow circle and the filled one is 4−3=14 - 3 = 1, and that is the size of the jump at the boundary. A piecewise graph with no jump anywhere is called continuous, which happens when both pieces agree at the boundary.

The same two numbers can be got out of a program, which is worth doing once so that the circles stop being a convention and start being arithmetic.

Try CodePython

Change the second piece from 6 - x to 5 - x and run it again. The value at the boundary drops to 3, which is exactly where the left piece was heading, so the jump disappears.

The left column climbs 2.9, then 2.99, closing in on 3 without ever reaching it, which is the hollow circle. The boundary row reads 4, which is the filled circle.

The same two pieces, drawn
f(x)={x+1x<26−xx≥2f(x) = \begin{cases} x + 1 & x < 2 \\ 6 - x & x \ge 2 \end{cases}
-3-0.252.55.258-20246
Where the left piece is heading at x=2x = 2
3
What the right piece gives at x=2x = 2
4
Size of the jump
1

Drag j down to 5. The jump reads 0 and the break closes, because the hollow circle and the filled circle have landed on the same point. Anywhere else there is a visible step.

The other direction: a rule from a picture

Reading a rule off a graph is the same routine run backwards. Take one piece at a time, work out its equation from two points you can read exactly, and then write the stretch of inputs it covers.

  1. Find the boundaries. They are the inputs where the graph changes character, jumps, or has a corner.
  2. For each piece, read two points off it. The slope is the change in height divided by the change in input, and substituting one of the points into y=mx+cy = mx + c then gives cc.
  3. Write the condition for that piece. Use ≤\le or ≥\ge at an end that carries a filled circle, and << or >> at an end that carries a hollow one.

One worked example in full. A graph runs flat at height 2 from the far left up to a hollow circle at (1,2)(1, 2). From a filled circle at (1,3)(1, 3) it then climbs in a straight line through (4,9)(4, 9).

  1. There is one boundary, at the input 1, because that is where the graph jumps.
  2. The left piece is flat at height 2, so every input there gives the output 2 and its rule is the constant y=2y = 2.
  3. That piece ends in a hollow circle, so the input 1 is not included, and the condition is x<1x < 1.
  4. The right piece passes through (1,3)(1, 3) and (4,9)(4, 9). Slope: 9−34−1=63=2\frac{9 - 3}{4 - 1} = \frac{6}{3} = 2.
  5. Substitute (1,3)(1, 3) into y=2x+cy = 2x + c: 3=2×1+c3 = 2 \times 1 + c, so 3=2+c3 = 2 + c and c=1c = 1. The rule is y=2x+1y = 2x + 1.
  6. That piece starts with a filled circle, so the input 1 is included, and the condition is x≥1x \ge 1.
f(x)={2x<12x+1x≥1f(x) = \begin{cases} 2 & x < 1 \\ 2x + 1 & x \ge 1 \end{cases}
The rule read off that picture.

Check it at the boundary before writing it down. The second piece gives 2×1+1=32 \times 1 + 1 = 3, which is the filled circle at (1,3)(1, 3). The first piece heads for 2, which is the hollow circle at (1,2)(1, 2). Both agree with the picture, so the rule is right.

Drawing a step function

A step function is drawn by the same routine, with one flat piece per whole number. Nothing new is needed; the routine just repeats many times.

Take y=⌈x⌉y = \lceil x \rceil, the ceiling. For every input strictly between 0 and 1 the ceiling is 1, and the input 1 itself also gives 1, since ⌈1⌉=1\lceil 1 \rceil = 1. The input 0 does not, since ⌈0⌉=0\lceil 0 \rceil = 0. So that flat piece runs from a hollow circle at (0,1)(0, 1) across to a filled circle at (1,1)(1, 1).

The floor has its circles the other way round. For every input from 0 up to but not including 1 the floor is 0, since ⌊0⌋=0\lfloor 0 \rfloor = 0 and ⌊1⌋=1\lfloor 1 \rfloor = 1. So that flat piece runs from a filled circle at (0,0)(0, 0) to a hollow one at (1,0)(1, 0).

Try CodePython

Add -1 and -1.5 to the front of the list and run it again. Both columns still change value only when the input passes a whole number, but check which of the two changes at the whole number itself.

Sketching g(x)=2xg(x) = 2x for x≤1x \le 1 and g(x)=5g(x) = 5 for x>1x > 1: which circles go at the boundary, and what is g(1)g(1)?

g(1)=2g(1) = 2, because the input 1 satisfies x≤1x \le 1, so the first piece applies and gives 2×1=22 \times 1 = 2. The first piece therefore ends with a filled circle at (1,2)(1, 2), and the second piece begins with a hollow circle at (1,5)(1, 5), since x>1x > 1 excludes the input 1. The jump at the boundary is 5−2=35 - 2 = 3.

Check yourself

A graph is flat at height 4 for every input up to and including 3, then jumps and runs flat at height 1 after that. Which rule is it?

All lessons in Int 3 for Programmers