Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 68 ยท Getting Started

Functions and Graphs

Review function notation, domain and range, composition, inverse functions and even/odd symmetry, and plot functions with numpy and matplotlib.

A function is a rule that turns each input into exactly one output. Calculus is the study of how functions change, so before differentiating anything you need to read functions fluently: what inputs are allowed, what outputs come back, how functions combine, and how their graphs look.

This lesson is a working review. Each idea is paired with code, because plotting a function is the fastest way to build intuition about it. You will use these skills in every later chapter.

Notation, domain and range

We write f(x) = x**2 + 1 to say: take an input x, square it, add one. The letter x is the independent variable, and the output y = f(x) is the dependent variable.

  • The domain is the set of inputs the rule accepts.
  • The range is the set of outputs it produces.

The domain is limited by two things: division by zero and even roots of negative numbers (in real numbers), plus logarithms of non-positive numbers. For f(x) = 1/(x - 2) the domain is every real number except 2. For g(x) = sqrt(x) it is x >= 0, and the range is also y >= 0.

Python Evaluate and test the domain

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

When a program raises an error for a particular input, that input is usually outside the domain. Treat these errors as information about the function.

Plotting with numpy and matplotlib

To draw a curve, evaluate the function at many closely spaced inputs and connect the dots. np.linspace(a, b, n) gives n evenly spaced points from a to b, and NumPy applies a formula to the whole array at once.

Python Plot three basic functions

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The parabola x**2 opens upward and stays at or above zero. The cubic x**3 swoops from the lower left to the upper right. The absolute value has a sharp corner at the origin; remember that corner, because it will matter when we meet derivatives.

A function can also be given by a graph alone, and the vertical line test tells you if a curve is a function: if some vertical line crosses it twice, one input has two outputs, so it is not a function of x.

Combining functions: composition

Composition feeds the output of one function into another. The notation (f โˆ˜ g)(x) = f(g(x)) means "do g first, then f". Order matters.

flowchart LR
    X["x"] -->|"g: add 1"| G["g(x) = x + 1"]
    G -->|"f: square"| F["f(g(x)) = (x + 1)^2"]

Composition is a pipeline: the output of the inner function becomes the input of the outer function.

With f(x) = x**2 and g(x) = x + 1, we get f(g(x)) = (x + 1)**2, but g(f(x)) = x**2 + 1. These are different functions. Composition will be central to the chain rule later: The Chain Rule.

Python Composition is not commutative

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

You can verify f(g(3)) = 16 and g(f(3)) = 10 by hand: one pipeline gives (3 + 1)**2, the other 3**2 + 1.

Inverse functions

An inverse function fโปยน undoes f: fโปยน(f(x)) = x. The graph of the inverse is the mirror image of the original across the line y = x. A function has an inverse only if it is one-to-one: different inputs give different outputs (the horizontal line test). x**2 fails this on all real numbers, but if you restrict it to x >= 0 the inverse is sqrt(x).

To find an inverse: write y = f(x), solve for x, then swap names. For y = 2x + 3, solve x = (y - 3)/2, so fโปยน(x) = (x - 3)/2.

Python A function and its inverse

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The two curves are mirror images across the dashed diagonal. Note that sqrt(f(3)) returns 3 only because 3 is positive; for -3 you would get 3 again, which shows why the restriction on the domain is essential.

Even and odd functions

Symmetry saves work.

  • Even: f(-x) = f(x). The graph mirrors across the y-axis. Examples: x**2, cos(x), |x|.
  • Odd: f(-x) = -f(x). The graph is unchanged by a half-turn about the origin. Examples: x**3, sin(x).

Most functions are neither. Later, symmetry will let you skip half of an integral over [-a, a].

Python Test for even and odd

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Numerical testing at sample points is a quick check, not a proof; a proof uses algebra. For x**2 + x, replacing x by -x gives x**2 - x, which is neither f(x) nor -f(x).

Reading a graph

When you sketch or inspect a graph, ask the same short list of questions:

  1. Where is the function defined (domain)? Any gaps or asymptotes?
  2. Where does it cross the axes (zeros, intercept)?
  3. Where is it increasing or decreasing?
  4. What happens far to the left and right?
  5. Is there symmetry?

You will turn these questions into precise tools with derivatives. For now, practise producing graphs quickly, and keep the algebra review handy: The Algebra Toolkit for Calculus.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the domain of f(x) = sqrt(x - 3) over the real numbers?

    The square root needs a non-negative argument, so x - 3 >= 0, which means x >= 3. At x = 3 the value is 0, so 3 is included.
  2. 2. If f(x) = x**2 and g(x) = x + 1, what is g(f(2))?

    Do f first: f(2) = 4. Then g(4) = 5. The other order, f(g(2)) = 9, is a different result.
  3. 3. Which statement about inverse functions is correct?

    Reflecting across y = x swaps inputs and outputs. Only one-to-one functions have inverses, and f inverse is different from 1/f.
  4. 4. Which function is odd?

    sin(-x) = -sin(x), so sine is odd. cos, x**2 and |x| satisfy f(-x) = f(x), so they are even.

Summary

  • A function maps each input to one output; its domain is the allowed inputs and its range the outputs produced.
  • Plot with np.linspace and plt.plot; evaluate formulas on whole arrays at once.
  • Composition f(g(x)) applies g first; order matters.
  • An inverse undoes a function, exists only for one-to-one functions, and mirrors the graph across y = x.
  • Even functions satisfy f(-x) = f(x); odd functions satisfy f(-x) = -f(x).

Next: The Algebra Toolkit for Calculus.