TExcelTAD
Home › Pre-Calculus, Geometry & Trigonometry › Rational Functions

Rational Functions

A rational function is one polynomial divided by another. Dividing introduces something polynomials never have: places where the function blows up, and lines the graph approaches but never quite reaches. This lesson shows how to find these asymptotes and holes and sketch the graph from the formula.

Definition and domain

f(x)=p(x)q(x),p and q polynomials, q not the zero polynomialf(x) = \frac{p(x)}{q(x)}, \qquad p \text{ and } q \text{ polynomials, } q \text{ not the zero polynomial}

The domain is every xx with q(x)≠0q(x) \ne 0. The simplest example is f(x)=1/xf(x) = 1/x: it is undefined at 0, huge for xx near 0, and tiny for large ∣x∣\lvert x \rvert. Simplifying algebraic fractions is covered in Reducing Fractions; here we study the graphs.

Vertical asymptotes and holes

Factor numerator and denominator completely and cancel common factors.

  • A zero of the denominator that survives cancellation is a vertical asymptote x=ax = a: as x→ax \to a the values grow without bound (→+∞\to +\infty or −∞-\infty).
  • A zero that cancels is a hole: a single missing point in an otherwise smooth curve.
f(x)=x2−1x2−3x+2=(x−1)(x+1)(x−1)(x−2)=x+1x−2,x≠1hole at x=1 (the point (1,−2) is missing), vertical asymptote x=2\begin{aligned} f(x) &= \frac{x^2 - 1}{x^2 - 3x + 2} = \frac{(x - 1)(x + 1)}{(x - 1)(x - 2)} \\ &= \frac{x + 1}{x - 2}, \quad x \ne 1 \\ &\text{hole at } x = 1 \text{ (the point } (1, -2) \text{ is missing), vertical asymptote } x = 2 \end{aligned}

Horizontal and slant asymptotes

What happens for large ∣x∣\lvert x \rvert depends on the degrees nn (top) and mm (bottom), since the leading terms dominate:

Degrees Behaviour for large ∣x∣\lvert x \rvert Example
n<mn < m horizontal asymptote y=0y = 0 3xx2+1\frac{3x}{x^2 + 1}
n=mn = m horizontal asymptote y=(leading coeff. of p)/(leading coeff. of q)y = (\text{leading coeff. of } p)/(\text{leading coeff. of } q) 2x2+1x2−4→y=2\frac{2x^2 + 1}{x^2 - 4} \to y = 2
n=m+1n = m + 1 slant (oblique) asymptote: the quotient of polynomial division x2+1x−1→y=x+1\frac{x^2 + 1}{x - 1} \to y = x + 1
n>m+1n > m + 1 grows like a polynomial, no line asymptote x3x−1\frac{x^3}{x - 1}

Unlike vertical asymptotes, a graph may cross a horizontal asymptote; the asymptote only describes the far ends. 3xx2+1\frac{3x}{x^2 + 1} crosses y=0y = 0 at x=0x = 0.

python · try it yourself
import sympy as sp

x = sp.Symbol("x")
f = (x**2 - 1) / (x**2 - 3*x + 2)
print("simplified:", sp.cancel(f))
print("hole value at x=1:", sp.limit(f, x, 1))
print("near x=2: from left", sp.limit(f, x, 2, "-"), " from right", sp.limit(f, x, 2, "+"))
print("as x → ∞:", sp.limit(f, x, sp.oo))

g = (x**2 + 1) / (x - 1)
q, r = sp.div(sp.Poly(x**2 + 1, x), sp.Poly(x - 1, x))
print("slant asymptote of (x²+1)/(x−1): y =", q.as_expr(), " remainder", r.as_expr())
simplified: (x + 1)/(x - 2)
hole value at x=1: -2
near x=2: from left -oo  from right oo
as x → ∞: 1
slant asymptote of (x²+1)/(x−1): y = x + 1  remainder 2

So x2+1x−1=x+1+2x−1\frac{x^2 + 1}{x - 1} = x + 1 + \frac{2}{x - 1}, and the last term shrinks to 0 for large ∣x∣\lvert x \rvert. These limits are previewed in Introduction to Limits and done properly in limits at infinity.

Sketching a rational function

A checklist for f(x)=p(x)/q(x)f(x) = p(x)/q(x):

  1. Factor, cancel, note holes.
  2. Vertical asymptotes: zeros of the reduced denominator.
  3. x-intercepts: zeros of the reduced numerator. y-intercept: f(0)f(0), if defined.
  4. Horizontal or slant asymptote from the degrees.
  5. Signs: test a point in each interval between zeros and asymptotes.

Example: f(x)=2x2−2x2−4=2(x−1)(x+1)(x−2)(x+2)f(x) = \frac{2x^2 - 2}{x^2 - 4} = \frac{2(x - 1)(x + 1)}{(x - 2)(x + 2)}. Vertical asymptotes x=±2x = \pm 2, x-intercepts ±1\pm 1, y-intercept f(0)=−2−4=12f(0) = \frac{-2}{-4} = \frac{1}{2}, horizontal asymptote y=2y = 2. The function is even, so the picture is symmetric.

python · try it yourself
import numpy as np
import matplotlib.pyplot as plt

f = lambda x: (2 * x**2 - 2) / (x**2 - 4)
x = np.linspace(-6, 6, 2400)
y = f(x)
y[np.abs(y) > 12] = np.nan                     # do not join across asymptotes

plt.figure(figsize=(6, 4))
plt.plot(x, y, color="purple")
for a in (-2, 2):
    plt.axvline(a, color="gray", ls=":")
plt.axhline(2, color="orange", ls="--", lw=1, label="y = 2")
plt.axhline(0, color="black", lw=0.6)
plt.ylim(-10, 10); plt.legend(); plt.grid(alpha=0.3)
plt.title("(2x² − 2)/(x² − 4)")
print("f(0) =", f(0), " f(±1) =", f(1) + 0.0, f(-1) + 0.0, " f(100) =", round(f(100), 4))
f(0) = 0.5  f(±1) = 0.0 0.0  f(100) = 2.0006

In software

Rational functions appear wherever a quantity is "something per something":

  • Amdahl's law. If a fraction pp of a program can be parallelised over nn cores, the speedup is S(n)=1(1−p)+p/nS(n) = \frac{1}{(1 - p) + p/n}. Its horizontal asymptote 11−p\frac{1}{1 - p} is the hard limit on speedup, however many cores you add.
  • Tone mapping. The Reinhard operator L1+L\frac{L}{1 + L} squeezes unbounded HDR brightness into [0,1)[0, 1): it has asymptote 1.
  • Inverse-square falloff. Light, sound and gravity weaken like k/d2k/d^2, which has a vertical asymptote at d=0d = 0; games clamp the distance or add a constant (k/(d2+ε)k/(d^2 + \varepsilon)) to avoid dividing by zero.
  • Averages and rates: cost per user, frames per second from milliseconds per frame (1000/ms).
python · try it yourself
def amdahl(p, n):
    return 1 / ((1 - p) + p / n)

for n in (1, 2, 4, 16, 64, 1024):
    print(f"{n:>5} cores: speedup {amdahl(0.9, n):6.3f}")
print("limit for p = 0.9:", round(1 / (1 - 0.9), 6))

reinhard = lambda L: L / (1 + L)
print("tone mapped:", [round(reinhard(L), 4) for L in (0.1, 1, 4, 50)])
    1 cores: speedup  1.000
    2 cores: speedup  1.818
    4 cores: speedup  3.077
   16 cores: speedup  6.400
   64 cores: speedup  8.767
 1024 cores: speedup  9.913
limit for p = 0.9: 10.0
tone mapped: [0.0909, 0.5, 0.8, 0.9804]

With 90% parallel code you can never beat a 10× speedup.

Exercises

Exercise 1: Asymptotes and holes

For f(x)=x2+x−6x2−4f(x) = \frac{x^2 + x - 6}{x^2 - 4}, find the domain, any holes and the vertical and horizontal asymptotes.

Answer

Domain x≠±2x \ne \pm 2. Hole at (2,54)(2, \frac{5}{4}). Vertical asymptote x=−2x = -2. Horizontal asymptote y=1y = 1.

Solution
f(x)=(x+3)(x−2)(x−2)(x+2)=x+3x+2,x≠2hole at x=2: value 2+32+2=54vertical asymptote: x=−2degrees equal, leading coefficients 1/1: y=1\begin{aligned} &f(x) = \frac{(x + 3)(x - 2)}{(x - 2)(x + 2)} = \frac{x + 3}{x + 2}, \quad x \ne 2 \\ &\text{hole at } x = 2{:}\ \text{value } \frac{2 + 3}{2 + 2} = \frac{5}{4} \\ &\text{vertical asymptote: } x = -2 \\ &\text{degrees equal, leading coefficients } 1/1{:}\ y = 1 \end{aligned}
python · try it yourself
import sympy as sp
x = sp.Symbol("x")
f = (x**2 + x - 6) / (x**2 - 4)
print(sp.cancel(f), sp.limit(f, x, 2), sp.limit(f, x, sp.oo))
(x + 3)/(x + 2) 5/4 1

Exercise 2: Slant asymptote

Find the slant asymptote of f(x)=2x2−3x+4x−2f(x) = \frac{2x^2 - 3x + 4}{x - 2}.

Answer

y=2x+1y = 2x + 1.

Solution

Divide: 2x2−3x+4=(x−2)(2x+1)+62x^2 - 3x + 4 = (x - 2)(2x + 1) + 6, so f(x)=2x+1+6x−2f(x) = 2x + 1 + \frac{6}{x - 2}. The fraction tends to 0, leaving y=2x+1y = 2x + 1.

Exercise 3: Build a function

Write a rational function with vertical asymptotes x=1x = 1 and x=−3x = -3, an x-intercept at 2, and horizontal asymptote y=0y = 0.

Answer

One answer: f(x)=x−2(x−1)(x+3)f(x) = \frac{x - 2}{(x - 1)(x + 3)}.

Solution

The denominator must vanish at 1 and −3-3, the numerator at 2. Numerator degree 1<denominator degree 2\text{Numerator degree } 1 < \text{denominator degree } 2 gives y=0y = 0. Any nonzero multiple also works.

Exercise 4: Signs

Solve x−3x+1≥0\frac{x - 3}{x + 1} \ge 0.

Answer

(−∞,−1)∪[3,∞)(-\infty, -1) \cup [3, \infty).

Solution

Critical points: x=3x = 3 (zero, included since ≥\ge) and x=−1x = -1 (asymptote, never included).

x=−2:(−)/(−)>0✓x=0:(−)/(+)<0x=4:(+)/(+)>0✓\begin{aligned} x = -2{:} &\quad (-)/(-) > 0 && \checkmark \\ x = 0{:} &\quad (-)/(+) < 0 \\ x = 4{:} &\quad (+)/(+) > 0 && \checkmark \end{aligned}

Exercise 5: How many cores?

With Amdahl's law and p=0.95p = 0.95, find the smallest number of cores giving a speedup of at least 10. What is the maximum possible speedup?

Answer

19 cores (speedup ≈10.0\approx 10.0). Maximum 20.

Solution

Solve 10.05+0.95/n≥10\frac{1}{0.05 + 0.95/n} \ge 10: 0.05+0.95/n≤0.10.05 + 0.95/n \le 0.1, so 0.95/n≤0.050.95/n \le 0.05 and n≥19n \ge 19.

python · try it yourself
amdahl = lambda p, n: 1 / ((1 - p) + p / n)
n = 1
while amdahl(0.95, n) < 10 - 1e-12:
    n += 1
print(n, round(amdahl(0.95, n), 4), round(1 / 0.05, 4))
19 10.0 20.0

Test yourself

What is the horizontal asymptote of 6x3−x2x3+5\frac{6x^3 - x}{2x^3 + 5}?

  1. y=0y = 0
  2. y=3y = 3
  3. y=6y = 6
  4. There is none

f(x)=x−4(x−4)(x+1)f(x) = \frac{x - 4}{(x - 4)(x + 1)}. What happens at x=4x = 4?

  1. Vertical asymptote
  2. x-intercept
  3. A hole
  4. Nothing special

Can the graph of a rational function cross its horizontal asymptote?

  1. Never
  2. Yes, the asymptote only describes behaviour for large ∣x∣\lvert x \rvert
  3. Only if it has no vertical asymptotes
  4. Only at x=0x = 0