Functions & Graphs22/09/2026Núcleo de Matemática4 min readUpdated on 26/09/2026

Affine function from two points: find the equation and check the graph

Learn to calculate a and b from two points, verify the equation on a graph, and recognize when a vertical line is not a function of x.

Plano cartesiano com reta vermelha e dois pontos azuis, fórmulas para calcular a e b, exemplos com frações e uma reta vertical.

To find the equation of an affine function from two distinct points A(x₁, y₁) and B(x₂, y₂), first calculate a = (y₂ − y₁)/(x₂ − x₁), then use either point to obtain b = y₁ − ax₁. The required equation is f(x) = ax + b. This method requires x₁ and x₂ to differ; when the x-coordinates are equal and the y-coordinates differ, the line is vertical and does not represent a function of x.

What do the coefficients a and b mean?

In f(x) = ax + b, the coefficient a measures the change in y for each unit change in x and determines the slope of the line. If a is positive, the line rises from left to right; if negative, it falls; if zero, it is horizontal. The coefficient b is f(0), the height at which the line crosses the y-axis, at (0, b). When a = 0, the expression describes a constant function, not a first-degree polynomial function.

Step by step: find the equation from two points

  1. Identify the coordinates A(x₁, y₁) and B(x₂, y₂), keeping each x paired with its corresponding y.
  2. Check that x₂ − x₁ is not zero. If it is zero, consider the vertical-line case before attempting division.
  3. Calculate the slope: a = (y₂ − y₁)/(x₂ − x₁). Use the same subtraction order in numerator and denominator.
  4. Substitute either point into y = ax + b and isolate b = y₁ − ax₁.
  5. Write f(x) = ax + b and substitute both original x-values to check that the resulting y-values match the given ones.

Example 1: two points with integer coordinates

Take A(1, 2) and B(4, 5). The change in y is 5 − 2 = 3, and the change in x is 4 − 1 = 3. Therefore, a = 3/3 = 1. Using A gives 2 = 1 · 1 + b, so b = 1. The equation is f(x) = x + 1.

Check by substituting both points: f(1) = 1 + 1 = 2 and f(4) = 4 + 1 = 5. On the graph, plot A and B, also plot (0, 1), the y-intercept, and draw the unique line through the two distinct points. Moving three units along x produces a rise of three units in y.

Example 2: points with fractional coordinates

Now use A(0, 1/2) and B(2, 3/2). The calculation is a = [(3/2) − (1/2)]/(2 − 0) = 1/2. Because the first point already has x = 0, its y-value immediately gives b = 1/2. Thus, f(x) = (1/2)x + 1/2.

Check: f(0) = 1/2 and f(2) = 1 + 1/2 = 3/2. On the coordinate plane, the line crosses the y-axis at 1/2 and rises one unit in y for every two units added to x. Fractions do not change the method: simply preserve the arithmetic and the graph scales.

Example 3: when the points do not define a function of x

Consider A(2, 1) and B(2, 4). The denominator of the slope formula would be 2 − 2 = 0, and division by zero is undefined. The points determine the vertical line x = 2, but not an equation of the form f(x) = ax + b: the same x = 2 would have both y = 1 and y = 4. On the graph, the points line up vertically, showing that the relation also fails the vertical line test.

There is an important qualification: if the two ordered pairs were exactly the same, they would not be two distinct points determining a unique line. In that case, the supplied information likewise cannot establish a unique equation.

How to check the answer on the graph and by substitution

  • Find the intercept (0, b) and plot it on the y-axis.
  • Use a = Δy/Δx to identify the vertical and horizontal changes; for example, a = 1/2 means rising 1 while moving 2 to the right.
  • Plot the two original points, respecting each axis scale. Both points and (0, b) must lie on the same line.
  • Compute f(x₁) and f(x₂); the results must be exactly y₁ and y₂. If either check fails, revisit signs, fractions, and coordinate pairings.

Common mistakes that change the result

Do not reverse only the y-subtraction when finding a: if you change y₂ − y₁ to y₁ − y₂, you must also change x₂ − x₁ to x₁ − x₂. Do not mistake b for the y-value at any arbitrary point: b is the value at x = 0. Do not reject a horizontal line, because y = b is a constant function. And do not assign a finite slope to a vertical line.

For a reference on equation form, the meaning of slope, and vertical lines, see OpenStax's Linear Functions section. The three numerical examples above were developed for this exercise.

Topics in this articlecoeficiente angularcoeficiente lineardois pontosexercícios resolvidosfunção afimgráfico cartesiano