The graph of \(y = c\), or

\[f(x) = c\]

a horizontal line is the graph of a function. We call such a function a constant function. A constant function is one whose output value is the same for every input value. The graph of \(x = a\) is a vertical line, and \(x = a\) is not a function.

import matplotlib.pyplot as plt


def constant(x):
  return 4
  
y_values = [constant(x) for x in range(1,10)]

plt.plot(y_values)

The graph of the function given by \(y = mx\), or

\[f(x) = mx\]

is a straight line through the origin (0, 0) and the point (1, \(m\)). The constant \(m\) is called the slope of the line. You could interpret the slope as the common ratio between your variables. Positive slope (\(m > 0\)), lead to lines slanting upwards, flat slopes (\(m = 0\)), lead to horizontal lines, and negative slopes (\(m < 0\)) lead to lines slanting downwards.

def line(m, x):
  return m * x
  
a_values = [line(3, x) for x in range(-10, 10)]
b_values = [line(0, x) for x in range(-10, 10)]
c_values = [line(-1, x) for x in range(-10, 10)]

plt.plot(a_values, label="$f(x) = 3x$")
plt.plot(b_values, label="$f(x) = 0x$")
plt.plot(c_values, label="$f(x) = -1x$")
plt.legend(frameon=False)

In applications where \(m\) is positive for the equation \(f(x) = mx\) we say that we have direct variation, and \(m\) is called the variation constant, or constant of proportionality. Inverse variation is related to the opposite case, where \(f(x) = \frac{m}{x}\).

A linear function is given by

\[f(x) = mx + b\]

and has a graph that is the straight line parallel to the graph of \(f(x) = mx\) and crossing the \(y\)-axis at (0, \(b\)), also called the y-intercept.

def linear(m, b, x):
  return (m * x) + b
  
d_values = [linear(3, 2, x) for x in range(-10, 10)]
e_values = [linear(-3, -1, x) for x in range(-10, 10)]
f_values = [linear(3, 1, x) for x in range(-10, 10)]

plt.plot(d_values, label="$f(x) = 3x + 2$")
plt.plot(e_values, label="$f(x) = -3x -1$")
plt.plot(f_values, label="$f(x) = 3x + 1$")
plt.legend(frameon=False)

A linear function has a couple of forms. The Slope-Intercept Equation form \(f(x) = mx + b\), and the Point Slope Equation form \(y - y_1 = m(x - x_1)\). Both of these forms can be used to find the equation of a line, given some prior information (e.g. a couple of points, a slope, an intercept).

The slope of a line containing points (\(x_1\), \(y_1\)) and (\(x_2\), \(y_2\)) is

\[m = \frac{y_2 - y_1}{x_2 - x_1}\]

it’s a change in \(y\) over a change in \(x\), which can be read as “for every horizontal change \(\Delta x\), we have a vertical change \(\Delta y\).”