Int 3 for Programmers

Functions, transformations, composition and inverses

18 / 396
Contents

Contents

Int 3 for Programmers

0 of 396 complete

10 min read

Where two functions meet

Solving f(x) = g(x) by graph, by table and by algebra, and checking the answer.

Two phone plans, two hire companies, two savings schemes: the useful question is almost never what does this cost, but at what point does the cheaper one stop being cheaper. That is a question about where two functions agree.

Put both functions in one table, with their difference beside them, and look for the moment the difference changes sign.

Try CodePython

Change the 20 to 30 and run it again. The crossing moves further right, which is what a bigger fixed charge should do.

The difference runs 20, 16, 12, 8, 4, 0, -4, -8. It hits exactly zero at x=5x = 5, and that is where the two functions agree. Before 5, ff is the larger. After 5, gg is.

That is the first of the three methods, and it also shows the idea underneath all of them: solving f(x)=g(x)f(x) = g(x) is the same as solving f(x)−g(x)=0f(x) - g(x) = 0. The crossings of two graphs are the zeros of one function.

Method one: read it off the graphs

Draw both curves on the same axes and look at where they cross. Each crossing point gives one solution, and the solution is its horizontal coordinate. The vertical coordinate is the common value, which is often the second half of the question: at what number of units, and at what cost.

A curve and a line, meeting
x2−2=2x+(−1)x^2 - 2 = 2x + (-1)
-6-22610-4-2024
the line
Difference at x=2x = 2
-1
Difference at x=−2x = -2
7

Leave m at 2 and drag c downwards. At c=−3c = -3 the line touches the curve at exactly one point, and below that they miss each other entirely. Two solutions become one, then none at all.

A graph is quick and it shows how many solutions there are, which the algebra can hide. It is also only as accurate as the drawing, so a graphical answer is usually a check or an estimate rather than the final word.

Method two: narrow it down numerically

When the crossing is not at a whole number, the table method can be repeated on a smaller interval. Watch it close in.

Try CodePython

Change x + 5 to x + 7 and run it again. The bracket [2, 3] no longer contains a crossing, and the search reports nonsense. Widen it to [2, 4] and it recovers.

Each pass halves the interval, so after twelve passes the answer is pinned down to about a thousandth. This is how a calculator finds an intersection, and it is worth knowing that the number on the screen was found this way rather than exactly.

Method three: do the algebra

The exact answer comes from setting the two rules equal and rearranging. One worked example in full: solve 20+4x=8x20 + 4x = 8x.

  1. Get the xx terms on one side: subtract 4x4x from both sides, giving 20=4x20 = 4x.
  2. Divide both sides by 4: x=5x = 5.
  3. Check by substituting into both original rules: f(5)=20+20=40f(5) = 20 + 20 = 40 and g(5)=40g(5) = 40.
  4. They agree, so the crossing point is (5,40)(5, 40) and the answer is confirmed.

A second worked example, where the two functions are not both lines. Solve x2=x+6x^2 = x + 6.

  1. Bring everything to one side: x2−x−6=0x^2 - x - 6 = 0.
  2. The left-hand side is the difference function, so its zeros are the answers.
  3. Testing whole numbers: at x=3x = 3 it is 9−3−6=09 - 3 - 6 = 0, and at x=−2x = -2 it is 4+2−6=04 + 2 - 6 = 0.
  4. Check both in the original equation: 32=93^2 = 9 and 3+6=93 + 6 = 9, then (−2)2=4(-2)^2 = 4 and −2+6=4-2 + 6 = 4.
  5. Both work, so the solutions are x=3x = 3 and x=−2x = -2.
Two graphs cross at (4,9)(4, 9). What is the solution of f(x)=g(x)f(x) = g(x), and what is f(4)f(4)?

The solution is x=4x = 4, the horizontal coordinate. The common height gives f(4)=9f(4) = 9, and also g(4)=9g(4) = 9. Answering that the solution is 9 is the standard mistake: 9 is what the two functions agree on, not the input where they agree.

Check yourself

Plan A costs 30+2x30 + 2x and plan B costs 6x6x. For which values of xx is plan B cheaper?

All lessons in Int 3 for Programmers