If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Composing functions

Walk through examples, explanations, and practice problems to learn how to find and evaluate composite functions.
Given two functions, we can combine them in such a way so that the outputs of one function become the inputs of the other. This action defines a composite function. Let's take a look at what this means!

Evaluating composite functions

Example

If f, left parenthesis, x, right parenthesis, equals, 3, x, minus, 1 and g, left parenthesis, x, right parenthesis, equals, x, cubed, plus, 2, then what is f, left parenthesis, g, left parenthesis, 3, right parenthesis, right parenthesis?

Solution

One way to evaluate f, left parenthesis, g, left parenthesis, 3, right parenthesis, right parenthesis is to work from the "inside out". In other words, let's evaluate g, left parenthesis, 3, right parenthesis first and then substitute that result into f to find our answer.
Let's evaluate g, left parenthesis, 3, right parenthesis.
g(x)=x3+2g(3)=(3)3+2                   Plug in x=3.=29\begin{aligned}g(x)&=x^3+2\\\\ g(3)&=({3})^3 +2~~~~~~~~~~~~~~~~~~~\small{\gray{\text{Plug in }x={3.}}}\\\\ &={29}\end{aligned}
Since g, left parenthesis, 3, right parenthesis, equals, 29, then f, left parenthesis, g, left parenthesis, 3, right parenthesis, right parenthesis, equals, f, left parenthesis, 29, right parenthesis.
Now let's evaluate f, left parenthesis, 29, right parenthesis.
f(x)=3x1f(29)=3(29)1               Plug in x=29.=86\begin{aligned}f(x)&=3x-1\\\\ f( {{29}})&=3({29}) - 1~~~~~~~~~~~~~~~\small{\gray{\text{Plug in }x= {29.}}}\\\\ &={86}\\\\ \end{aligned}
It follows that f, left parenthesis, g, left parenthesis, 3, right parenthesis, right parenthesis, equals, f, left parenthesis, 29, right parenthesis, equals, 86.

Finding the composite function

In the above example, function g took 3 to 29, and then function f took 29 to 86. Let's find the function that takes 3 directly to 86.
To do this, we must compose the two functions and find f, left parenthesis, g, left parenthesis, x, right parenthesis, right parenthesis.

Example

What is f, left parenthesis, g, left parenthesis, x, right parenthesis, right parenthesis?
For reference, remember that f, left parenthesis, x, right parenthesis, equals, 3, x, minus, 1 and g, left parenthesis, x, right parenthesis, equals, x, cubed, plus, 2.

Solution

If we look at the expressionf, left parenthesis, start color #ca337c, g, left parenthesis, x, right parenthesis, end color #ca337c, right parenthesis, we can see that start color #ca337c, g, left parenthesis, x, right parenthesis, end color #ca337c is the input of function f. So, let's substitute start color #ca337c, g, left parenthesis, x, right parenthesis, end color #ca337c everywhere we see start color #0c7f99, x, end color #0c7f99 in function f.
f(x)=3x1f(g(x))=3(g(x))1\begin{aligned}f(\blueE x)&=3\blueE x-1\\\\ f(\maroonD{g(x)}) &= 3(\maroonD{g(x)})-1 \\ \end{aligned}
Since g, left parenthesis, x, right parenthesis, equals, x, cubed, plus, 2, we can substitute x, cubed, plus, 2 in for g, left parenthesis, x, right parenthesis.
f(g(x))=3(g(x))1=3(x3+2)1=3x3+61=3x3+5\begin{aligned}{f(g(x))}&=3(g(x))-1 \\\\ &=3({x^3+2})-1 \\\\ &=3x^3+6-1\\\\ &=3x^3+5 \end{aligned}
This new function should take 3 directly to 86. Let's verify this.
f(g(x))=3x3+5f(g(3))=3(3)3+5=86\begin{aligned} f( g(x))&= 3x^3+5\\ \\ f( g( 3))&= 3( 3)^3+5 \\\\ &= {86} \end{aligned}
Excellent!

Let's practice

Problem 1

f, left parenthesis, x, right parenthesis, equals, 3, x, minus, 1
g, left parenthesis, x, right parenthesis, equals, x, cubed, plus, 2
Evaluate g, left parenthesis, f, left parenthesis, 1, right parenthesis, right parenthesis.
  • Your answer should be
  • an integer, like 6
  • a simplified proper fraction, like 3, slash, 5
  • a simplified improper fraction, like 7, slash, 4
  • a mixed number, like 1, space, 3, slash, 4
  • an exact decimal, like 0, point, 75
  • a multiple of pi, like 12, space, start text, p, i, end text or 2, slash, 3, space, start text, p, i, end text

Problem 2

m, left parenthesis, x, right parenthesis, equals, 3, x, minus, 2
n, left parenthesis, x, right parenthesis, equals, x, plus, 4
Find m, left parenthesis, n, left parenthesis, x, right parenthesis, right parenthesis.

Composite functions: a formal definition

In the above example, we found and evaluated a composite function.
In general, to indicate function f composed with function g, we can write f, circle, g, read as "f composed with g". This composition is defined by the following rule:
left parenthesis, f, circle, g, right parenthesis, left parenthesis, x, right parenthesis, equals, f, left parenthesis, g, left parenthesis, x, right parenthesis, right parenthesis
The diagram below shows the relationship between left parenthesis, f, circle, g, right parenthesis, left parenthesis, x, right parenthesis and f, left parenthesis, g, left parenthesis, x, right parenthesis, right parenthesis.
Now let's look at another example with this new definition in mind.

Example

g, left parenthesis, x, right parenthesis, equals, x, plus, 4
h, left parenthesis, x, right parenthesis, equals, x, squared, minus, 2, x
Find left parenthesis, h, circle, g, right parenthesis, left parenthesis, x, right parenthesis and left parenthesis, h, circle, g, right parenthesis, left parenthesis, minus, 2, right parenthesis.

Solution

We can find left parenthesis, h, circle, g, right parenthesis, left parenthesis, x, right parenthesis as follows:
(hg)(x)=h(g(x))Define.=(g(x))22(g(x))Plug g(x) in for x in function h.=(x+4)22(x+4)Substitute x+4 for g(x).=x2+8x+162x8Distribute.=x2+6x+8Combine like terms.\begin{aligned}(h\circ g)(x)&=h(g(x))&\small{\gray{\text{Define.}}}\\\\ &=(g(x))^2-2(g(x))&\small{\gray{\text{Plug } g(x) \text{ in for } x\text{ in function }h.}}\\\\ &=({x+4})^2 -2({x+4})&\small{\gray{\text{Substitute } x+4 \text{ for } g(x).}}\\\\ &=x^2+8x+16-2x-8&\small{\gray{\text{Distribute.}}}\\\\ &=x^2+6x+8&\small{\gray{\text{Combine like terms.}}}\end{aligned}
Since we now have function h, circle, g, we can simply substitute minus, 2 in for x to find left parenthesis, h, circle, g, right parenthesis, left parenthesis, minus, 2, right parenthesis.
(hg)(x)=x2+6x+8(hg)(2)=(2)2+6(2)+8=412+8=0\begin{aligned}(h\circ g)(x)&=x^2+6x+8\\\\ (h\circ g)(-2)&=(-2)^2+6(-2)+8\\\\ &=4-12+8\\\\ &=0\\\\ \end{aligned}
Of course, we could have also found left parenthesis, h, circle, g, right parenthesis, left parenthesis, minus, 2, right parenthesis by evaluating h, left parenthesis, g, left parenthesis, minus, 2, right parenthesis, right parenthesis. This is shown below:
(hg)(2)=h(g(2))=h(2)        Since g(2)=2+4=2=0             Since h(2)=222(2)=0\begin{aligned}(h\circ g)(-2)&=h(g(-2))\\\\ &=h(2)~~~~~~~~\small{\gray{\text{Since }g(-2)=-2+4=2}}\\\\ &=0~~~~~~~~~~~~~\small{\gray{\text{Since }h(2)=2^2-2(2)=0}}\\\\ \end{aligned}
The diagram below shows how left parenthesis, h, circle, g, right parenthesis, left parenthesis, minus, 2, right parenthesis is related to h, left parenthesis, g, left parenthesis, minus, 2, right parenthesis, right parenthesis.
Here we can see that function g takes minus, 2 to 2 and then function h takes 2 to 0, while function h, circle, g takes minus, 2 directly to 0.

Now let's practice some problems

Problem 3

f, left parenthesis, x, right parenthesis, equals, 3, x, minus, 5
g, left parenthesis, x, right parenthesis, equals, 3, minus, 2, x
Evaluate left parenthesis, g, circle, f, right parenthesis, left parenthesis, 3, right parenthesis.
  • Your answer should be
  • an integer, like 6
  • a simplified proper fraction, like 3, slash, 5
  • a simplified improper fraction, like 7, slash, 4
  • a mixed number, like 1, space, 3, slash, 4
  • an exact decimal, like 0, point, 75
  • a multiple of pi, like 12, space, start text, p, i, end text or 2, slash, 3, space, start text, p, i, end text

In problems 4 and 5, let f, left parenthesis, t, right parenthesis, equals, t, minus, 2 and g, left parenthesis, t, right parenthesis, equals, t, squared, plus, 5.

Problem 4

Find left parenthesis, g, circle, f, right parenthesis, left parenthesis, t, right parenthesis.

Problem 5

Find left parenthesis, f, circle, g, right parenthesis, left parenthesis, t, right parenthesis.

Challenge Problem

The graphs of the equations y, equals, f, left parenthesis, x, right parenthesis and y, equals, g, left parenthesis, x, right parenthesis are shown in the grid below.
Which of the following best approximates the value of left parenthesis, f, circle, g, right parenthesis, left parenthesis, 8, right parenthesis?
Choose 1 answer:

Want to join the conversation?

  • blobby green style avatar for user Tess Van Horn
    In practice Q 4, where is 4t created? I see where t^2 and 4 come from, but am not sure what puts 4t in
    (56 votes)
    Default Khan Academy avatar avatar for user
  • starky ultimate style avatar for user Nigar Kainath
    (f ∘ g)(x)
    here, what does the sign ∘ mean?
    (2 votes)
    Default Khan Academy avatar avatar for user
  • hopper jumping style avatar for user Rory Avera
    How do you know when to use the "inside out property" or the composing function?
    (8 votes)
    Default Khan Academy avatar avatar for user
  • aqualine ultimate style avatar for user Aditya Mahajan
    May someone please explain the challenge problem to me?
    (2 votes)
    Default Khan Academy avatar avatar for user
    • mr pink orange style avatar for user Dylan Chan
      The challenge problem says, "The graphs of the equations y=f(x) and y=g(x) are shown in the grid below." So basically the two graphs is a visual representation of what the two different functions would look like if graphed and they're asking us to find (f∘g)(8), which is combining the two functions and inputting 8. From the definition, we know (f∘g)(8)=f(g(8)). So let's work "inside out". If we look at the graph of "g", we see that g(8) is 2 (look at the 8 at the x-axis and if you go up to where it meets the line, the y value would be 2). Because g(8)=2, then when you substitute it back in the equation, f(g(8)) would equal f(2). Then if we look at the graph of "f", we can see that f(2) is -3. (when you look at the 2 in the x-axis, it will correspond to -3 on the y-axis). So by looking at the graph, you can figure out that (f∘g)(8) is approximately -3.
      ~Dylan
      (12 votes)
  • male robot hal style avatar for user magk2006
    in the example question "g(x)= x+4, h(x)= x(squared)-2x" how does it get the +8x and -2x in the distribute section ?
    here's the distribute equation =(x(squared)+8x+16−2x−8)
    (4 votes)
    Default Khan Academy avatar avatar for user
    • stelly blue style avatar for user Kim Seidel
      h(g(x)) = (x+4)^2 - 2(x+4)
      Basically each "x" in h(x) gets replaced with (x+4), which if g(x). Then, you simplify.

      1) FOIL out (x+4)^2:
      h(g(x)) = x^2+4x+4x+16 - 2(x+4) = x^2 + 8x + 16 - 2(x+4)

      2) Distribute -2: h(g(x)) = x^2 + 8x + 16 - 2x - 8

      3) Combine like terms: x^2 + 6x + 8

      Hope this helps.
      (5 votes)
  • blobby green style avatar for user flowermap21
    In question 4 how do people get the 4t in tsquered-t4+9?
    (2 votes)
    Default Khan Academy avatar avatar for user
  • leaf blue style avatar for user ScribofThoth
    I still can't get this. I think my problem is them showing multiple ways to do this instead of focusing on how to combine it into one equation. Either I have to work each function alone then combine them at the end or have more help figuring out how to make one equation.
    (2 votes)
    Default Khan Academy avatar avatar for user
    • blobby green style avatar for user ersepsi
      I don't think their aim is to show you the multiple ways you can evaluate the composite function.

      The first example they basically show what evaluating a composite function really means, it's like you said "work each function alone". In the second example they showed a more faster and efficient way to evaluate the composite function by combining them into one equation.

      If you're still confused about composite functions, I'll explain this way:

      we have a function f(x), this function takes "x" as "input". Now, I'm certain you're used to the variable x being substituted for a number, but in maths, you can pretty much substitute it for anything you like. (Expressions for example)

      Like I can let x = 5, but I can also let x = 2h. Doesn't that mean I can also substitute x for some function? In other words x = g(x).

      Say if g(k) = 4k, then this would become: x = 4k. (Because x = g(k) = 4k)

      Since we let x = g(k) = 4k, then our function f can be written as: f( g(k) ) or f(5k) (We substituted x for g(k) )

      if f(x) = 5x, by substituting x for g(k), this becomes:

      f( g(x) ) = 5g(x) ---> f( 4k ) = 5(4k) = 20k

      This also means that our composite function changes value depending on the value of k.


      Conclusion: g(k) becomes input for function f.
      (7 votes)
  • mr pants green style avatar for user awesomeness.RM
    Can someone please simplify all of this for me cause i am so confused!
    (2 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user Jennifer Laessig
    If f(x)=(1/x) and (f/g)(x)=((x+4)/(x^2+2x)), what is the function g?
    (4 votes)
    Default Khan Academy avatar avatar for user
    • stelly blue style avatar for user Kim Seidel
      Based upon the rules for dividing with fractions: f/g = (1/x) / g = (1/x) * the reciprocal of g

      We need to work in reverse
      1) Factor denominator to undo the multiplication: (x+4)/(x^2+2x) = (x+4)/[x(x+2)]
      We can see there is a factor of X in the denominator. This would have been from multiplying 1/x * the reciprocal of g.
      2) Separate the factor 1/x: (1/x) * (x+4)/(x+2)
      This tells us the reciprocal of g = (x+4)/(x+2)

      3) Flip it to find g: g(x) = (x+2)/(x+4)

      Hope this helps.
      (2 votes)
  • boggle blue style avatar for user x.asper
    How do we know that g = 3 in the first example study? I looked multiple times, and couldn't see where we found that value. Any help?
    (3 votes)
    Default Khan Academy avatar avatar for user
    • stelly blue style avatar for user Kim Seidel
      I assume you are asking about the first example on the page. The initial problem statement gives you the equations for f(x) and g(x). It then asks you to find f(g(3)).

      g(3) is part of what the problem is asking you to find. It doesn't say that g=3. It says uses the function g(x) with an input value of x=3.

      Hope this clarifies thing.
      (3 votes)