xaktly | Functions

Compositions of
functions



Putting functions together to make new ones


To compose two functions is to put one inside the other. We already know that $f(x)$ means to take $x$ and follow the instructions in $f(x)$ for what to do with it to get the corresponding y-value. But what if we replace $x$ with another function?

Let's do this by a simple example. Let $f(x)=x+2$ and $g(x) = x^2$.

To find $f(g(x))$, we just put in $g(x)$ everywhere there's an $x$ in $f(x)$:

$$f(g(x)) = (x^2 + 2) + 2 = x^2 + 4$$

Likewise,

$$ \begin{align} g(f(x)) &= (x + 2)^2 + 2 \\[5pt] &= (x + 2)(x + 2) + 2 \\[5pt] &= x^2 + 4x + 6 \end{align}$$

Why are function compositions useful?

Making compositions of functions can be a really powerful way of solving all kinds of problems, and it's not too difficult after some practice.

Here's an example: You probably recall that the area of a circle is a function of its radius, $A = \pi r^2$. But how about finding the area of a circle as a function of its circumference, $A(c)$ ?

Recall that $c = 2\pi r$, so then $r = c/2\pi$. That last equation is $r$ as a function of $c$, or $r(c)$.

Now let's find the composition $A(r(c))$:   $A(r(c))=\pi (c/2\pi)^2 = c^2/4\pi$.

The function we were looking for, $A(c) = c^2/4\pi$ is a composition. Compositions of functions will be extremely useful as we go along.


Example 1

Given functions   $f(x) = x + 1$   and   $g(x) = 3x - 1,$   find the composite functions   $f(g(x))$   and   $g(f(x))$.


Solutions: We start with our two original functions

$$f(x) = x + 1 \;\;\;\; g(x) = 3x - 1$$

For $f(g(x))$, we're just plugging in the definition of $g(x)$ wherever there is an $x$ in the definition of $f(x)$, like this.

$$f(g(x)) = f(3x - 1)$$

Now just put in the rest of $f(x)$:

$$f(g(x)) = (3x - 1) + 1$$

and simplify (1 - 1 = 0) to get the result:

$$f(g(x)) = 3x$$

For $g(f(x))$ we follow the same pattern: First insert $f(x)$ anywhere into $g(x)$ where there's an $x$:

$$g(f(x)) = g(x + 1)$$

The instructions for $g(x)$ say to multiply the input by 3 and subtract 1, so we'll do that:

$$g(f(x)) = 3(x + 1) + 1$$

Finally, simplifying yields our new composite function:

$$ \begin{align} g(f(x)) &= 3x + 3 - 1 \\[5pt] &= 3x + 2 \end{align}$$

Example 2

Now let's look at some more complicated functions. If   $f(x) = x^2 + 1$   and   $g(x) = -2x - 1$, find the composite functions   $f(g(x)), \, g(f(x)), \, f(f(x))$, and $g(g(x)).$   The last two are sometimes called self-referential functions, or recursive functions. They can be very important, especially in computer programming.


Solutions: Here's   $f(g(x))$

$$ \begin{align} f(g(x)) &= (-2x - 1)^2 + 1 \\[5pt] &= (4x^2 + 4x + 1) + 1 \\[5pt] &= 4x^2 + 4x + 2 \end{align}$$

$g(f(x))$   goes like this:

$$ \begin{align} g(f(x)) &= -2 (x^2 + 1) - 1 \\[5pt] &= -2x^2 - 2 - 1 \\[5pt] &= -2x^2 - 3 \end{align}$$

$f(f(x))$   seems weird, but you're really just following the same instructions:

$$ \begin{align} f(f(x)) &= (x^2 + 1)^2 + 1 \\[5pt] &= x^4 + 2x^2 + 1 + 1 \\[5pt] &= x^4 + 2x^2 + 2 \end{align}$$

... and likewise for   $g(g(x))$:

$$ \begin{align} g(g(x)) &= -2(-2x - 1) - 1 \\[5pt] &= 4x + 2 - 1 \\[5pt] &= 4x + 1 \end{align}$$

Example 3

The number of widgets* $(n)$ produced by a factory after $t$ hours of operation is modeled by the function  $n(t) = 1000t - 8t^2$. If the cost ($C$, in dollars) of producing $n$ widgets is $C(n) = 10,000 + 350n$, find the cost $C(t)$ as a function of the time of factory operation.


Solution: What we're trying to do here is make $C(t)$ from $C(n)$ and $n(t)$, which means finding the composition $C(t) = C(n(t))$.

If we take $C(n)$ and plug the function $n(t)$ in everywhere we see an $n$, we get:

$$ \begin{align} C(t) &= 10,000 + 350(1000t - 8t^2) \\[5pt] &= 10,000 + 350,000t - 2800t^2 \end{align}$$

Now we've got a new function for cost as a function of time. We made it by knowing how cost changes with number of widgets made, and how number of widgets depends on time — $n(t)$. That kind of thing can be pretty useful.

* "widget" is often used in economics to describe some fictional product.


Example 4

A conical water tank has a radius of 10 meters and a height of 12 m, as shown below. If water is flowing into the tank at a rate of 0.5 m3 per hour, find a function for the height of the water in the tank over time. That is, find h(t) from V(t) and the known volume of a cone.


Solution: Here's a picture of what's going on:

The volume of a cone is

Now the problem with that definition of a cone is that it is a function of two variables, r and h. Because we eventually want a function $h(t)$, we'll need to 'get rid' of $r$, which means we'll need a piece of information relating $r$ to $h$. Luckily we have one.

Notice that the cone and the inner cone of liquid are similar, exactly in the sense of the similar triangles you learned in geometry, so the ratio of their radii and heights are the same. So we have:

$$\frac{H}{R} = \frac{h}{r} \; \longrightarrow \; r = \frac{Rh}{H}$$

Rearranging gives us $r(h)$,

$$r = \frac{10 h}{12} = \frac{5h}{6}$$

We'll need $r^2$, which is

$$r^2 = \frac{25 h^2}{36}$$

which we can insert into our volume function to get $V(r)$:

$$V(h) = \frac{25 \pi h^3}{108}$$

Now we have two functions that give us the tank volume, the one we just made and the one that was given originally: Water flows into the tank at a rate of 0.5 m·h-1, which gives us the function

$$V(t) = 0.5 t$$

We can equate the two functions (after all, they represent exactly the same thing) like this:

$$0.5 t = \frac{25 \pi h^3}{108}$$

Now solving for $h$ gives us

$$h^3 = \frac{54 t}{25 \pi}$$

Taking the third (cube) root of each side gives us our final function for the height of water in the tank as a function of time.

$$h = \sqrt[3]{\frac{54 t}{25 \pi}}$$

Here's how that looks on a graph, and it makes sense. At first, when the tank is narrow, the height grows rapidly, but as the area of the top of the water gets larger, it fills more slowly, and slowest right at the top, at a height of 12 m.

Pro tip

Always take a minute to ask, at the end of the problem, does my answer make sense?

Practice problems

Here are some simple problems to practice putting one function inside of another. Practice these to get the hang of it. Given the functions $f(x)$, $g(x)$, $h(x)$ and $k(x)$ below, find each of the values or compositions indicated in the problems that follow.


$$f(x) = x-1$$

$$g(x) = -3x+4$$

$$h(x) = -x-9$$

$$k(x) = 2x^2$$


  1. $f(-1)$


  2. $g(3)$


  3. $h(7)$


  4. $k(-3)$


  5. $f(g(x))$

  1. $g(f(x))$


  2. $h(k(x))$


  3. $k(f(x))$


  4. $k(g(x))$


  5. $g(g(x))$

  1. $h(h(-6))$


  2. $k(k(1))$


  3. $k(g(-2))$


  4. $h(h(h(x)))$


  5. $f(k(x))$

Solutions to 1-15

$$ \begin{matrix} f(x) = x - 1 && h(x) = -x - 9 \\[5pt] g(x) = -3x + 4 && k(x) = 2x^2 \end{matrix}$$

1. $f(-1) = -1 - 1 = -2$
2. $g(3) = -3(3) + 4 = -9 + 4 = -5$
3. $h(7) = -7 - 9 = -16$
4. $k(-3) = 2(-3)^2 = 2(9) = 18$
5. $f(g(x)) = -3x + 4 - 1 = -3x + 3 = 3(1 - x)$
6. $g(f(x)) = -3(x - 1) + 4 = -3x + 3 + 4 = -3x + 7$
7. $h(k(x)) = -(2x^2) - 9 = -2x^2 - 9$
8. $k(f(x)) = 2(x - 1)^2$
9. $k(g(x)) = 2(-3x + 4)^2 = 2(9x^2 - 24x + 16) = 18x^2 - 24x + 32$
10. $g(g(x)) = -3(-3x + 4) + 4 = 9x - 12 + 4 = 9x - 8$
11. $h(h(-6)) = -(6 - 9) - 9 = 3 - 9 = -6$
12. $k(k(1)) = 2(2\cdot 1^2)^2 = 2 \cdot 4 = 8$
13. $k(g(-2)) = 2(-3(-2) + 4)^2 = 2(6 + 4)^2 = 2(100) = 200$
14.

$h(h(h(x))) = -[-(x - 9) - 9] - 9 = -[x + 9 - 9] - 9 = -x - 9 = h(x)$

(This doesn't always happen.)

15. $f(k(x)) = 2x^2 - 1$

  1. The area of a circle as a function of its radius, $r$, is $A = \pi r^2$. Express the area of a circle as a function of its circumference, $c = 2\pi r$.

    Solution

    The area is $A = \pi r^2$ and the circumference is $c = 2\pi r$. Solving the latter for $r$, we get

    $$r = \frac{c}{2\pi}$$

    If we plug that version of $r$ into the area formula, we get

    $$ \begin{align} \require{cancel} A &= \pi \left( \frac{c}{2\pi} \right)^2 = \frac{\cancel{\pi} c^2}{4\pi^{\cancel{2}}} \\[5pt] A &= \frac{c^2}{4\pi} \end{align}$$


    Here's an example: If the area of a circle of radius $r = 3$ is $A = \pi r^2 = \pi\cdot 3^2 = 9 \pi \, \text{units}^2$.

    With our new formula, the area of such a circle (with $c = 2\pi r = 6\pi$) is

    $$A = \frac{c^2}{4\pi} = \frac{36 \pi^2}{4\pi} = 9\pi$$


  2. The volume of a sphere of radius $r$ is $V = (4/3)\pi r^3$. The surface area of a sphere is $A = 4\pi r^2$. Write a function for the volume of a sphere as a function of the surface area, $V(A)$.

    Solution

    The volume of a sphere of radius $r$ is $V = (4/3)\pi r^3$. The surface area of a sphere is $A = 4\pi r^2$. Solving the latter for the radius gives

    $$A = 4\pi r^2 \rightarrow r^2 = \frac{A}{4\pi} \rightarrow r = \frac{\sqrt{A}}{2\sqrt{\pi}}$$

    Now if we plug that version of $r$ into the the volume formula, we eliminate $r$ and create a function of area:

    $$ \begin{align} V &= \frac{\cancel{4}\cancel{\pi}}{3} \left( \frac{A^{\frac{3}{2}}}{2^{\cancel{3}}} \pi^{\frac{\cancel{3}\rightarrow 1}{2}} \right) \\[5pt] &= \frac{A^{\frac{3}{2}}}{6\pi^{\frac{1}{2}}} = \frac{\sqrt{A^3}}{6 \sqrt{\pi}} \end{align}$$

    Now let's check our new function with an example. The volume of a sphere of radius $r = 3$ is

    $$V = \frac{4}{3} \pi (3^3) = 36\pi \, \text{units}^3$$

    and the surface area is

    $$A = 4\pi r^2 = 4\pi (9) = 36\pi \, \text{units}^3$$


  3. The volume of a cube is $V=L^3$, where $L$ is the length of one edge. Write a function $V(d)$ for the volume of a cube as a function of the length of a diagonal ($d$) drawn between opposite corners of the cube, as shown:

    Solution

    Here is a picture of our box with a diagonal ($e$) drawn across the base of the box and the box-diagonal $d$, which connects opposite corners, shown.

    We can find the length of diagonal $d$ using the Pythagorean Theorem:

    $$ \begin{align} e^2 &= L^2 + L^2 \\[5pt] e &= \sqrt{2 L^2} \\[5pt] e &= L \sqrt{2} \end{align}$$

    Using that length we can get to the box diagonal:

    $$ \begin{align} d &= \sqrt{(L \sqrt{2})^2 + L^2} \\[5pt] &= \sqrt{2L^2 + L^2} \\[5pt] &= L \sqrt{3} \end{align}$$

    Solving for $L$ gives us

    $$L = \frac{d}{\sqrt{3}}$$


    Now plugging that version of $L$ into the volume formula give us;

    $$V = L^3 = \frac{d^3}{(3^{\frac{1}{2}})^3} \tag{1}$$

    So our function is

    $$V(d) = \frac{d^3}{3^{\frac{3}{2}}}$$

    Now let's do an example. Let $L = 2$, a $2\times 2\times 2$ cube with a volume of $2^3 = 8$ units3. For a $2\times 2\times 2$ cube, the main diagonal has length

    $$d = L \sqrt{3} = 2 \sqrt{3}$$

    Plugging that into function (1) gives

    $$
    \begin{align} V(d) &= \frac{d^3}{3^{\frac{3}{2}}} \\[5pt] &= \frac{(2\sqrt{3})^3}{3^{\frac{3}{2}}} \\[5pt] &= \frac{8 \cdot \cancel{3^{\frac{3}{2}}}}{\cancel{3^{\frac{3}{2}}}} = 8 \text{ units}^3 \end{align}$$


  4. The area of an isosceles triangle is $A = \frac{1}{2}bh$, where $b$ and $h$ are the lengths of the base and the height of the triangle, respectively. Write a function for the area of an isosceles triangle with independent variables $b$, the width of the base and $\theta$, one of the two (equivalent) base angles.

    Solution

    Here's a picture of our isosceles triangle. Recall that both of the upper sides are congruent, as are the base angles, $\theta$.

    The area of a triangle is $A = \frac{1}{2}bh$, where $b$ is the length of the base and $h$ is the height. The altitude (dashed line, $h$) divides the triangle into two right triangles. from that we can write the tangent of angle $\theta$:

    $$\tan(\theta) = \frac{h}{\frac{1}{2} b} = \frac{2h}{b}$$

    Solving for $h$ gives us

    $$h = \frac{b \tan(\theta)}{2}$$


    Plugging that height into our area formula gives

    $$ \begin{align} A &= \frac{1}{2} b \left( \frac{b \tan(\theta)}{2} \right) \\[5pt] &= \frac{b^2 \tan(\theta)}{4} \\[5pt] A &= \frac{1}{4} b^2 \tan(\theta) \end{align}$$

    Let's check this out using an isosceles triangle with a base of 2 units and a height of 2 units. Using the orignial area formula, the area is 2 units2. Now $h = \tan^{-1}(\theta) = \tan^{-1}(2/1) = 1.1071 \text{ rad}$. Now using our new function we get

    $$ \begin{align} A &= \frac{1}{4} b^2 \tan(\theta) \\[5pt] &= \frac{1}{4} 2^2 \tan(1.1071) \\[5pt] &= 1.9998 \end{align}$$

    The small error comes from rounding the angle calculation above.


  5. The cost of maufacturing $n$ widgets depends on the number of widgets made, $n$, and on the cost of one material, $m$. The cost function is $C(n, m) = 2.4n^{3/2}m$. The cost of that material is, in turn, a function of two factors, the cost of raw material $r$, and the cost of labor, $L$, according to the function $m = 9.2 Lr$. Write a function for the cost of manufacturing $n$ widgets with independent variables $n$, $r$ and $L$.

    Solution

    This is a pretty straightforward substitution. We substitute the $m$ variable in $C(n, m)$ with the function $m = 9.2 Lr$:

    $$ \begin{align} C(n, m) &= 2.4 n^{\frac{3}{2}} m \\[5pt] C(n,L,r) &= 2.4 n^{\frac{3}{2}} \cdot 9.2 r \\[5pt] &= 22.08 \, n^{\frac{3}{2}} L r \end{align}$$

Functions

Introduction to the all-important function concept

Domain & range

What values can a function take and what values can it return?

Creative Commons License   optimized for firefox
xaktly.com by Dr. Jeff Cruzan is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. ©2012, 2025, Jeff Cruzan. All text and images on this website not specifically attributed to another source were created by me and I reserve all rights as to their use. Any opinions expressed on this website are entirely mine, and do not necessarily reflect the views of any of my employers. Please feel free to send any questions or comments to jeff.cruzan@verizon.net.