# Composite Functions

A composite function is formed from two functions in the following way.

$$(g \circ f)(x) = g(f(x))$$
If $f(x)=x+3$ and $g(x)=2x$ are two functions, then we combine the two functions to form the composite function:
\begin{align} (g \circ f)(x) &= g(f(x)) \\ &= 2f(x) \\ &= 2(x+3) \\ &= 2x+6 \end{align}
That is, $f(x)$ replaces $x$ in the function $g(x)$.
The composite function reads $g$ of $f$ and can be written $g \circ f$.

$$(f \circ g)(x) = f(g(x))$$
Another composite function is:
\begin{align} (f \circ g)(x) &= f(g(x)) \\ &= g(x) + 3 \\ &= 2x+3 \end{align}
In this case, $g(x)$ replaces $x$ in $f(x)$. This composite reads $f$ of $g$ and can be written $f \circ g$.

For the composite function $f(g(x))$ to be defined, the range of $g$ must be a subset of (or equal to) the domain of $f$. It is easiest first to list the domain and function of both $f(x)$ and $g(x)$ when dealing with composite function problems.

### Example 1

Given $f(x)=2x-1$ and $g(x)=3x+5$, find the simplest expression of $(f \circ g)(x)$.

\begin{align} \displaystyle (f \circ g)(x) &= f(g(x)) \\ &= 2g(x)-1 \\ &= 2(3x+5)-1 \\ &= 6x+10-1 \\ &= 6x+9 \end{align}

### Example 2

Given $f(x)=4x-5$, find the simplest expression of $(f \circ f)(x)$.

\begin{align} \displaystyle (f \circ f)(x) &= f(f(x)) \\ &= 4f(x)-5 \\ &= 4(4x-5)-5 \\ &= 16x-20-5 \\ &= 16x-25 \end{align}

### Example 3

Given $f(x)=2x+7$ and $g(x)=-x+2$, find the simplest expression of $(g \circ f)(2)$.

\begin{align} \displaystyle (g \circ f)(2) &= g(f(2)) \\ &= -f(2) + 2 \\ &= -(2 \times 2+7)+2 \\ &= -11 +2 \\ &= -9 \end{align}

### Example 4

Given $f(x)=\sqrt{x}$ and $g(x)=x+1$, find the domain and range of $(g \circ f)(x)$.

$\begin{array}{|c|c|c|} \hline & \textit{Domain} & \textit{Range} \\ \hline f(x)=\sqrt{x} & x \ge 0 & y \ge 0 \\ \hline g(x)=x+1 & x \in \mathbb{R} & y \in \mathbb{R} \\ \hline (g \circ f)(x) & x \ge 0 & y \ge 0 \\ \hline \end{array}$

### Example 5

Given $f(x)=-2x+3$, $g(x)=5x+k$ and $(g \circ f)(x)=(f \circ g)(x)$, find $k$.

\begin{align} \displaystyle (g \circ f)(x) &= (f \circ g)(x) \\ g(f(x)) &= f(g(x)) \\ 5f(x)+k &= -2g(x)+3 \\ 5(-2x+3)+k &= -2(5x+k)+3 \\ -10x+15+k &= -10x-2k+3 \\ 3k &= 3-15 \\ \therefore k &= -4 \end{align}