Skip to main content
Back to module
Math for Tech & STEM · Functions and Graphs

What a function is

Reading32mLesson 1 of 3 in this module

Read inputs and outputs from a function rule, table and graph, and use function notation.

Why this matters

A function is a rule that turns an input into exactly one output. That idea runs through all of technical work: a sensor turns temperature into voltage, a pricing rule turns usage into cost, and a program function turns arguments into a return value. Learning to read functions as rules, tables and graphs lets you move between a formula, a spreadsheet and a chart without losing the meaning.

The core idea

A function takes an input, applies a rule, and gives one output for each input.

  • The input is often called x (the independent variable).
  • The output is often called y or f(x) (the dependent variable), because it depends on the input.

Function notation names the rule. f(x) = 2x + 3 reads "f of x equals 2x plus 3". Then f(4) means "the output when the input is 4":

f(4) = 2(4) + 3 = 11

The parentheses here do not mean multiply. f(4) is "f applied to 4", just like calling a function in code.

Three views of the same function

1. The rule: f(x) = 2x + 3

2. The table:

xf(x)
03
15
27
39

3. The graph: plot each (x, f(x)) pair as a point. For this rule the points lie on a straight line that crosses the vertical axis at 3 and rises 2 for every 1 step to the right.

Reading the graph: to find f(2), go to x = 2 on the horizontal axis, move up to the line, then read across to the vertical axis: 7. To answer "which input gives 9?", go the other way: find 9 on the vertical axis, across to the line, down to x = 3.

Is it a function?

The rule is "one output per input". A table where x = 2 appears twice with outputs 7 and 8 is not a function, because the input 2 does not determine a single output. On a graph, the vertical line test checks this: if any vertical line crosses the graph more than once, it is not a function.

Different inputs may share an output, though. g(x) = x² gives g(3) = 9 and g(−3) = 9, and g is still a function.

Domain and range

The domain is the set of inputs that make sense; the range is the set of outputs you can get. For a phone plan cost(m) = 10 + 0.25m, minutes m cannot be negative, so the domain is m ≥ 0 and the range is cost ≥ 10. Real-world functions almost always have limited domains.

Worked example: a pricing function

A phone plan charges a $10 base fee plus $0.25 per minute.

  • Rule: cost(m) = 10 + 0.25m
  • cost(0) = 10, cost(40) = 20, cost(100) = 35
  • Which m gives a $30 bill? Solve 10 + 0.25m = 30, so m = 80.

Functions in code

A JavaScript function is the same idea: inputs in, one output back.

function f(x) {
  return 2 * x + 3;
}

console.log(f(4));        // 11

// Build a table of inputs and outputs
const table = [0, 1, 2, 3].map(x => [x, f(x)]);
console.log(table);       // [[0,3],[1,5],[2,7],[3,9]]

Code functions can do things maths functions do not (print, save files, change variables). A function with no side effects that always returns the same output for the same input is called pure, and it behaves exactly like a maths function.

Common mistakes

  • Reading f(4) as f × 4. It means "evaluate f at 4".
  • Swapping axes on a graph. Inputs go along the horizontal axis; outputs go up the vertical axis.
  • Forgetting the domain. A formula may give an output for x = −5 minutes, but that input is meaningless.
  • Thinking two inputs cannot share an output. They can; it is one input with two outputs that breaks the rule.

Quick recap

  • A function gives exactly one output for each input.
  • f(x) notation names the rule; f(4) means "the output for input 4".
  • The rule, table and graph are three views of the same function.
  • Domain = sensible inputs, range = possible outputs.

Try it

In the Do tab, write the rule for the phone plan as a JavaScript function. A helper that builds an input/output table is already written.

Also in this lesson: