Step by step
The question
Question: find f(g(x)) and g(f(x)) for f(x) = x + 2 and g(x) = 3x.
1 Find f(g(x))
f(g(x)) is a function inside a function.
Like with brackets, we start inside.
First g(x).
g(x) is 3x.
So f(g(x)) is f(3x).
Put (3x) in place of every x in f.
We keep it in brackets.
A bracket with a plus or nothing in front can just be removed.
Now we have 3x + 2.
2 Find g(f(x))
g(f(x)) is a function inside a function.
Like with brackets, we start inside.
First f(x).
f(x) is x + 2.
So g(f(x)) is g(x + 2).
Put (x + 2) in place of every x in g.
We keep it in brackets.
The 3 in front of the bracket multiplies every part inside.
So we write 3 times each part.
3 times x is 3x.
3 times 2 is 6.
3 Compare
3x + 2 and 3x + 6 are not the same.
So the order matters!
Careful!
Inside first, then outside.
Swap them, and you usually get a different rule.
4 Check
Let's check with a number: x = 1.
g of 1 is 3, then f of 3 is 5.
f of 1 is 3, then g of 3 is 9.
Different, as we found.
And our rules give the same numbers: 3x + 2 gives 5, 3x + 6 gives 9.
They are right!
Let's look back.
First: find f(g(x)).
Then: find g(f(x)).
Then: compare.
Last: check.