algebra25 min

Graphing Functions

Plotting functions on the coordinate plane, understanding slope-intercept form, and visualizing parabolas

0/9Not Started

Why This Matters

A coordinate plane turns abstract equations into pictures you can see and reason about. When you plot y = 2x + 1, you get a straight line that rises 2 units for every 1 unit to the right. The visual immediately reveals information -- where the function is positive, negative, increasing, or decreasing -- that would take many computations to figure out from the equation alone.

The slope-intercept form y = mx + b is the standard way to express a linear function for graphing. The slope m tells you the steepness and direction of the line, and b tells you where it crosses the y-axis. For quadratic functions, the graph is a parabola -- a U-shaped curve that opens up or down depending on the sign of the leading coefficient. The vertex of the parabola is its highest or lowest point.

In programming, graphing is essential for data visualization. Every chart library -- from matplotlib to D3.js -- works by mapping data points to coordinates on a plane. Understanding how equations relate to shapes gives you the mental model to predict what a graph will look like before you render it, and to debug charts when they look wrong.

Define Terms

Visual Model

Function f(x)Rule mapping x to y
Value Tablex: -2,-1,0,1,2
Plot Points(x, y) coordinates
Linear: y=mx+bStraight line
Quadratic: y=ax^2+bx+cParabola curve
VertexPeak or valley
Connect PointsDraw the curve

The full process at a glance. Click Start tour to walk through each step.

Graphing turns equations into pictures. Plot points from a value table, then connect them to see the shape.

Code Example

Code
// Generate y-values for a function over a range
function generatePoints(fn, xMin, xMax, step) {
  const points = [];
  for (let x = xMin; x <= xMax; x += step) {
    points.push({ x: Math.round(x * 100) / 100, y: fn(x) });
  }
  return points;
}

// Linear function: y = 2x + 1
const linear = x => 2 * x + 1;
const linearPoints = generatePoints(linear, -3, 3, 1);
console.log("y = 2x + 1:");
linearPoints.forEach(p => console.log(`  (${p.x}, ${p.y})`));

// Quadratic function: y = x^2 - 4
const quadratic = x => x * x - 4;
const quadPoints = generatePoints(quadratic, -3, 3, 1);
console.log("\ny = x^2 - 4:");
quadPoints.forEach(p => console.log(`  (${p.x}, ${p.y})`));

// Slope from two points
function slope(x1, y1, x2, y2) {
  return (y2 - y1) / (x2 - x1);
}
console.log("\nSlope of y=2x+1:", slope(0, 1, 1, 3)); // 2

// Vertex of parabola y = ax^2 + bx + c
function vertex(a, b, c) {
  const vx = -b / (2 * a);
  const vy = a * vx * vx + b * vx + c;
  return { x: vx, y: vy };
}
console.log("Vertex of x^2 - 4:", vertex(1, 0, -4)); // (0, -4)
console.log("Vertex of x^2 - 6x + 5:", vertex(1, -6, 5)); // (3, -4)

// Simple ASCII plot
function asciiPlot(fn, xMin, xMax) {
  for (let x = xMin; x <= xMax; x++) {
    const y = Math.round(fn(x));
    const bar = y >= 0 ? " ".repeat(10) + "*".repeat(y + 1) : " ".repeat(10 + y) + "*";
    console.log(`x=${x.toString().padStart(3)}: ${bar}`);
  }
}

console.log("\nASCII plot of y = x + 3:");
asciiPlot(x => x + 3, -3, 3);

Interactive Experiment

Try these exercises:

  • Generate points for y = -x + 5 from x = -2 to x = 6. Where does the line cross the x-axis?
  • Plot y = x^2 and y = 2x on the same range. At which x values do they intersect?
  • Find the vertex of y = -x^2 + 4x - 3. Is it a maximum or minimum? How do you know?
  • Compute the slope between (1, 3) and (4, 15). What linear function passes through those points?
  • Generate points for y = x^3 - 3x from x = -2 to x = 2. How is the shape different from a parabola?

Quick Quiz

Coding Challenge

Function Point Generator

Write a function called `generateYValues` that takes an array of coefficients (representing a polynomial in ascending power order: [a0, a1, a2, ...]), a start x value, an end x value, and a step size. Return an array of y-values computed at each x from start to end (inclusive). For example, generateYValues([1, 2], -1, 2, 1) evaluates y = 2x + 1 at x = -1, 0, 1, 2, giving [-1, 1, 3, 5].

Loading editor...

Real-World Usage

Graphing functions is the foundation of all data visualization:

  • Data dashboards: Business metrics plotted over time are function graphs. Slope shows growth rate; curvature shows acceleration.
  • Machine learning: Loss curves, learning rates, and decision boundaries are all visualized as function graphs.
  • Signal processing: Audio waveforms and frequency spectra are graphed functions of time and frequency.
  • Game development: Easing functions (ease-in, ease-out) are graphed curves that control animation smoothness.
  • Scientific computing: Plotting simulation results -- temperature over time, concentration over distance -- requires graphing functions from computed data.

Connections