Crayonbird
Menu

Maths

What is a composite function, and how do you work out f(g(x))?

Quick answer

A composite function applies one function and then another. f(g(x)), also written (f ∘ g)(x) or fg(x), means do g first, then put the answer into f.

Ages 14–18Secondary

In one sentence

A composite function is two functions joined in a chain: the output of the first becomes the input of the second.

Explained

Imagine two function machines in a row on a conveyor belt. The first, g, doubles a number. The second, f, adds 3. Drop in 4: g turns it into 8, and f turns 8 into 11. The whole chain is one new function, the composite function, and it turns 4 into 11.

  • robot
  • box
  • train
Two machines in a row: the answer from the first goes straight into the second.

We write this chain as f(g(x)), read "f of g of x". You will also see (f ∘ g)(x), read "f composed with g" or "f circle g", and in UK exams simply fg(x). All three mean the same thing: do g first, then f. The function closest to x acts first, just like working out the inner brackets first.

There are two kinds of question.

1. A number. Work from the inside out. If f(x) = 2x + 1 and g(x) = x², then f(g(3)) means g(3) = 9 first, then f(9) = 19.

2. An expression. Put the whole of g(x) into f wherever there is an x, in brackets. f(g(x)) = f(x²) = 2x² + 1. Check with 3: 2 × 9 + 1 = 19, as before.

Order matters. g(f(x)) means f first: g(2x + 1) = (2x + 1)² = 4x² + 4x + 1, and g(f(3)) = 7² = 49, not 19. In most cases f(g(x)) and g(f(x)) are different functions.

Watch the domain. The output of the inner function must be an allowed input for the outer one. With f(x) = √x and g(x) = x − 3, f(g(x)) = √(x − 3) only works for x ≥ 3, because you cannot take the square root of a negative number (with real numbers).

Composite functions also run backwards. Spotting that h(x) = (3x + 1)⁵ is "first 3x + 1, then the fifth power" is called decomposing the function. It is the key to the chain rule in calculus. A function and its inverse are a special pair: f(f⁻¹(x)) = x, because the second machine undoes the first.

Examples

With f(x) = 2x + 1 and g(x) = x²:

Composite Inner step first Result
f(g(3)) g(3) = 9 f(9) = 19
g(f(3)) f(3) = 7 g(7) = 49
f(g(x)) g(x) = x² 2x² + 1
g(f(x)) f(x) = 2x + 1 (2x + 1)² = 4x² + 4x + 1
f(f(x)) f(x) = 2x + 1 2(2x + 1) + 1 = 4x + 3
g(g(x)) g(x) = x² (x²)² = x⁴

Worked example: a jacket costs $50. The shop takes $10 off, d(p) = p − 10, and then adds 20% tax, t(p) = 1.2p. Discount first: t(d(50)) = 1.2 × 40 = $48. Tax first: d(t(50)) = 60 − 10 = $50. As formulas, t(d(p)) = 1.2p − 12 but d(t(p)) = 1.2p − 10: the same two steps in a different order give a different price.

Common mistakes

  • Doing the outside function first. In f(g(x)), g acts first. Fix: start with the function next to x and work outwards.
  • Multiplying instead of composing. f(g(x)) is not f(x) × g(x). Fix: substitute g(x) into f; do not put the two side by side.
  • Losing the brackets. With f(x) = x² − 1 and g(x) = x + 3, f(g(x)) = (x + 3)² − 1 = x² + 6x + 8, not x + 3² − 1. Fix: always write g(x) in brackets when you substitute it.
  • Assuming fg = gf. Fix: test with one number. If the answers differ, the orders give different functions.

Step by step

Step by step

  1. Find the inner functionIn f(g(x)), it is g: the one written next to x.
  2. Work out the insideFor a number, calculate g(a). For an expression, write g(x) down.
  3. Feed it to the outer functionReplace every x in f with that answer, in brackets.
  4. SimplifyExpand the brackets and collect like terms.
  5. Check the domainMake sure every output of g is an allowed input of f.

To decompose a function, ask "what happens to x first?" In h(x) = √(x² + 9), x is squared and 9 is added first, so g(x) = x² + 9, and then the square root is taken, so f(x) = √x.

Practice questions

Work out composite functions

Try each one, then check your answer.

  1. f(x) = 3x − 1 and g(x) = x + 4. Find f(g(2)).
    Show answer
    g(2) = 6, then f(6) = 18 − 1 = 17
  2. With the same f and g, find g(f(2)).
    Show answer
    f(2) = 5, then g(5) = 9
  3. With the same f and g, find f(g(x)).
    Show answer
    3(x + 4) − 1 = 3x + 11 (check: x = 2 gives 17)
  4. With the same f and g, find g(f(x)).
    Show answer
    (3x − 1) + 4 = 3x + 3 (check: x = 2 gives 9)
  5. With f(x) = 3x − 1, find f(f(x)).
    Show answer
    3(3x − 1) − 1 = 9x − 4
  6. f(x) = x² and g(x) = x − 5. Find f(g(1)).
    Show answer
    g(1) = −4, then f(−4) = 16
  7. With the same f and g, find g(f(1)).
    Show answer
    f(1) = 1, then g(1) = −4
  8. With the same f and g, find f(g(x)).
    Show answer
    (x − 5)² = x² − 10x + 25
  9. With the same f and g, find g(f(x)).
    Show answer
    x² − 5
  10. f(x) = 2x + 1 and g(x) = 1/x. Find f(g(x)) and g(f(x)).
    Show answer
    f(g(x)) = 2/x + 1 (x ≠ 0); g(f(x)) = 1/(2x + 1) (x ≠ −1/2)
  11. f(x) = 4x − 3 and g(x) = x/2. Solve f(g(x)) = 9.
    Show answer
    f(g(x)) = 2x − 3, so 2x − 3 = 9: x = 6
  12. f(x) = x + 1 and g(x) = x². Solve f(g(x)) = g(f(x)).
    Show answer
    x² + 1 = x² + 2x + 1, so 2x = 0: x = 0
  13. Write h(x) = (5x − 2)³ as f(g(x)).
    Show answer
    g(x) = 5x − 2 and f(x) = x³
  14. Write h(x) = √(x² + 9) as f(g(x)).
    Show answer
    g(x) = x² + 9 and f(x) = √x
  15. f(x) = √x and g(x) = x − 3. What is the domain of f(g(x))?
    Show answer
    √(x − 3) needs x − 3 ≥ 0: x ≥ 3
  16. Use the chain rule to differentiate h(x) = (3x + 1)⁵.
    Show answer
    Outer 5u⁴ times inner derivative 3: h′(x) = 15(3x + 1)⁴

Word problems

Composite functions in real life

Try each one, then check your answer.

  1. A car uses f(d) = d/15 litres of fuel for d km, and fuel costs c(f) = 2f dollars. What does a 300 km trip cost?
    Show answer
    f(300) = 20 litres, then c(20) = $40 (in one formula: c(f(d)) = 2d/15)
  2. C(K) = K − 273 changes kelvin into Celsius and F(C) = 1.8C + 32 changes Celsius into Fahrenheit. What is 298 K in °F?
    Show answer
    C(298) = 25, then F(25) = 45 + 32 = 77 °F
  3. A ripple's radius is r(t) = 3t cm after t seconds, and a circle's area is A(r) = πr². Find A(r(t)) and the area after 2 seconds.
    Show answer
    A(r(t)) = π(3t)² = 9πt², so after 2 s: 36π ≈ 113.1 cm²
  4. A $80 game is 20% off and you also have a $10 coupon. Which order is cheaper: discount then coupon, or coupon then discount?
    Show answer
    0.8 × 80 − 10 = $54; 0.8 × (80 − 10) = $56: discount first, then the coupon ($54)
  5. A factory makes n(t) = 40t phones in t hours, and the cost of n phones is C(n) = 500 + 6n dollars. Find C(n(t)) and the cost of an 8-hour shift.
    Show answer
    C(n(t)) = 500 + 240t, so C = 500 + 1,920 = $2,420

Questions people ask

What is a composite function in simple words?

It is a function made by doing one function and then another. The answer from the first one is fed straight into the second.

How do you read f(g(x)) or f ∘ g?

Say "f of g of x" or "f composed with g". Both mean: apply g to x first, then apply f to the result.

Is f(g(x)) the same as g(f(x))?

Usually not. With f(x) = x + 1 and g(x) = x², f(g(x)) = x² + 1 but g(f(x)) = (x + 1)², which is x² + 2x + 1. They are only equal for some special pairs, such as a function and its inverse.

How do you find the domain of a composite function?

Start with the domain of the inner function g, then remove any x whose output g(x) is not allowed in f. For f(x) = 1/x and g(x) = x − 2, x = 2 must go, because g(2) = 0.

How do you find a composite function from a graph?

Read the inner value first: find g(a) on the graph of g. Then find that number on the x-axis of the graph of f and read off f(g(a)).

How do you differentiate a composite function?

Use the chain rule: the derivative of f(g(x)) is f′(g(x)) × g′(x). For (3x + 1)⁵, that is 5(3x + 1)⁴ × 3 = 15(3x + 1)⁴.

How are composite and inverse functions connected?

Composing a function with its inverse undoes it: f(f⁻¹(x)) = x. The inverse of a composite reverses the order: (f ∘ g)⁻¹ = g⁻¹ ∘ f⁻¹, just as you take off your shoes before your socks.

Quick quiz

Composite functions

Check what you know with 5 quick questions.

Question 1 of 5

f(x) = x + 3 and g(x) = 2x. What is f(g(4))?

Practise it

Try it

Practise composite functions with unlimited questions

Algebra worksheets

Ages 11–12

One-step equations · Small positive numbers

Ages 11–13

Substitution · Small positive numbers

Ages 12–13

Two-step equations · Small positive numbers

Ages 12–15

nth term of a sequence · Bigger numbers

Ages 13–14

x on both sides · Bigger numbers

Ages 13–14

Expanding brackets · KS3, ages 13–14

See more in the library

All Algebra sheets

Practise it step by step in a full course: Grade 11 Maths

For grown-ups

Functions (maths)

A function is a rule that gives exactly one output for each input. In f(x) = 2x + 3, the input 4 gives the output 2 × 4 + 3 = 11.

Maths · Ages 12–16

Inverse functions

An inverse function f⁻¹ undoes f: if f(3) = 7, then f⁻¹(7) = 3. To find it, write y = f(x), swap x and y, then solve for y.

Maths · Ages 14–18

Equations

An equation says two things are equal, using an = sign, like 2x + 1 = 9. Solving it means finding the value of the letter that makes it true, here x = 4.

Maths · Ages 10–16

Algebra

Algebra is maths that uses letters, like x or n, to stand for numbers we don't know yet or numbers that can change. For example, if n + 3 = 10, then n = 7.

Maths · Ages 10–16

Completing the square

Completing the square rewrites x² + bx + c as (x + b/2)² − (b/2)² + c. It solves quadratics, finds the vertex (turning point) of a parabola and proves the quadratic formula.

Maths · Ages 13–17

Inequalities

An inequality compares two values with <, >, ≤ or ≥, like x + 2 > 5. Solve it like an equation, but flip the sign if you multiply or divide both sides by a negative number.

Maths · Ages 11–16

Back to the Learning Wiki