Why This Matters
A rational function is a ratio of two polynomials, like f(x) = (x + 1) / (x - 2). These functions model real situations where quantities have natural limits or forbidden values: the rate of a chemical reaction approaching a maximum, the cost per unit as production scales, or the response time of a server as load approaches capacity.
The most distinctive features of rational functions are asymptotes -- invisible boundary lines that the function approaches but never reaches -- and holes, single missing points where both numerator and denominator equal zero. Understanding these discontinuities is critical for writing robust code: they correspond to division-by-zero errors, undefined behavior, and edge cases that crash programs.
Define Terms
Visual Model
The full process at a glance. Click Start tour to walk through each step.
A rational function is a ratio of polynomials. Its key features are vertical asymptotes, holes, and horizontal asymptotes.
Code Example
// Rational function: f(x) = (x^2 - 4) / (x^2 - x - 2)
// Numerator: x^2 - 4 = (x-2)(x+2)
// Denominator: x^2 - x - 2 = (x-2)(x+1)
// Hole at x=2 (common factor), vertical asymptote at x=-1
function evalRational(x) {
const numer = x * x - 4;
const denom = x * x - x - 2;
if (Math.abs(denom) < 1e-10) return null; // undefined
return numer / denom;
}
console.log("f(0):", evalRational(0)); // -4/-2 = 2
console.log("f(3):", evalRational(3)); // 5/4 = 1.25
console.log("f(2):", evalRational(2)); // null (hole)
console.log("f(-1):", evalRational(-1)); // null (asymptote)
// Find vertical asymptotes
function findVerticalAsymptotes(numerCoeffs, denomCoeffs, lo, hi, step) {
const asymptotes = [];
function evalPoly(coeffs, x) {
let r = 0;
for (const c of coeffs) r = r * x + c;
return r;
}
for (let x = lo; x <= hi; x += step) {
const d = evalPoly(denomCoeffs, x);
const n = evalPoly(numerCoeffs, x);
if (Math.abs(d) < 0.01 && Math.abs(n) > 0.01) {
asymptotes.push(Math.round(x * 10) / 10);
}
}
return asymptotes;
}
// numer = x^2 - 4, denom = x^2 - x - 2
console.log("vertical asymptotes:",
findVerticalAsymptotes([1,0,-4], [1,-1,-2], -10, 10, 0.1));
// [-1]
// Horizontal asymptote: compare leading coefficients
console.log("f(1000):", evalRational(1000)); // approaches 1
console.log("f(10000):", evalRational(10000)); // even closer to 1Interactive Experiment
Try these exercises:
- Evaluate f(x) = 1/(x - 3) for x = 2.9, 2.99, 2.999, 3.001, 3.01, 3.1. What happens near x = 3?
- For f(x) = (x^2 - 9)/(x - 3), simplify by hand. What is the hole? What does the simplified form look like?
- Evaluate f(x) = (2x^2 + 1)/(x^2 - 1) for x = 100, 1000, 10000. What horizontal asymptote does it approach?
- What happens if the numerator has a higher degree than the denominator? Try f(x) = x^2 / x for large x.
- Write code to detect whether a given x-value produces a hole versus a vertical asymptote.
Quick Quiz
Coding Challenge
Write a function called `findAsymptotes` that takes two arrays of polynomial coefficients (numerator and denominator, highest degree first) and returns an array of x-values where vertical asymptotes occur. A vertical asymptote is at x where the denominator is zero but the numerator is not. Scan integer x-values from -10 to 10. Return only integer asymptote locations.
Real-World Usage
Rational functions model situations with natural limits and singularities:
- Server response modeling: Response time as a function of load often follows a rational function: as load approaches capacity, response time shoots toward infinity (vertical asymptote).
- Electronics: Impedance in circuits is modeled by rational functions of frequency. Resonance peaks correspond to asymptotic behavior.
- Economics: Average cost functions (total cost / units produced) are rational functions showing economies of scale.
- Control theory: Transfer functions in control systems are ratios of polynomials. Poles (denominator zeros) determine system stability.
- Algorithm analysis: Some recurrence relations solve to rational functions, describing average-case performance.