Composition of Functions

April 12, 2026

Problem

If f(x)=x²+1 and g(x)=3x−2, find f(g(x)) and g(f(x)).

Explanation

What is function composition?

Composition means plugging one function into another. The notation f(g(x))f(g(x)) (read "f of g of x") means: first apply gg to xx, then apply ff to the result. It's like a pipeline — input goes through gg first, then the output of gg goes through ff.

Important: f(g(x))f(g(x)) and g(f(x))g(f(x)) are generally NOT the same. Order matters!

Step-by-step solution

Given f(x)=x2+1f(x) = x^2 + 1 and g(x)=3x2g(x) = 3x - 2.

Finding f(g(x))f(g(x))

Step 1 — Start with the outer function ff. f(something)=(something)2+1f(\text{something}) = (\text{something})^2 + 1.

Step 2 — Replace "something" with g(x)=3x2g(x) = 3x - 2:

f(g(x))=f(3x2)=(3x2)2+1f(g(x)) = f(3x - 2) = (3x - 2)^2 + 1

Step 3 — Expand:

(3x2)2+1=9x212x+4+1=9x212x+5(3x - 2)^2 + 1 = 9x^2 - 12x + 4 + 1 = 9x^2 - 12x + 5

Finding g(f(x))g(f(x))

Step 1 — Start with the outer function gg. g(something)=3(something)2g(\text{something}) = 3(\text{something}) - 2.

Step 2 — Replace "something" with f(x)=x2+1f(x) = x^2 + 1:

g(f(x))=g(x2+1)=3(x2+1)2g(f(x)) = g(x^2 + 1) = 3(x^2 + 1) - 2

Step 3 — Simplify:

=3x2+32=3x2+1= 3x^2 + 3 - 2 = 3x^2 + 1

Comparison

f(g(x))=9x212x+5g(f(x))=3x2+1f(g(x)) = 9x^2 - 12x + 5 \neq g(f(x)) = 3x^2 + 1

They are different! For example, at x=1x = 1: f(g(1))=912+5=2f(g(1)) = 9 - 12 + 5 = 2, but g(f(1))=3+1=4g(f(1)) = 3 + 1 = 4.

Numerical verification

Tracing x=2x = 2 through both compositions:

  • f(g(2))f(g(2)): First g(2)=3(2)2=4g(2) = 3(2) - 2 = 4. Then f(4)=42+1=17f(4) = 4^2 + 1 = 17. ✓ Matches 9(4)12(2)+5=3624+5=179(4) - 12(2) + 5 = 36 - 24 + 5 = 17.
  • g(f(2))g(f(2)): First f(2)=4+1=5f(2) = 4 + 1 = 5. Then g(5)=3(5)2=13g(5) = 3(5) - 2 = 13. ✓ Matches 3(4)+1=133(4) + 1 = 13.

Common mistakes

  • Confusing the order. In f(g(x))f(g(x)), apply gg FIRST, then ff. The inner function goes first.
  • Not fully expanding. (3x2)2=9x212x+4(3x - 2)^2 = 9x^2 - 12x + 4, not 9x249x^2 - 4 or 9x2+49x^2 + 4.

Try it in the visualization

Both compositions are graphed. Trace a specific xx-value through the pipeline: see it enter gg, then the output enters ff. The two resulting curves are visibly different, proving composition isn't commutative.

They're different! Composition is not commutative.

Interactive Visualization

Parameters

2.00
Your turn

Got your own math or physics problem?

Turn any problem into an interactive visualization like this one — powered by AI, generated in seconds. Free to try, no credit card required.

Sign Up Free to Try It30 free visualizations every day
Composition of Functions | MathSpin