Calculus is the mathematics of how functions change. Before we can study change, we have to be genuinely fluent with the thing that changes.
Prerequisites
- chapter-01-why-calculus
Learning Objectives
- Define a function precisely and distinguish the rule from its representations (formula, graph, table, algorithm)
- Determine the natural domain and range of a given function
- Recognize the standard function families and their characteristic shapes, growth rates, and special values
- Apply function transformations (shift, scale, reflect) to predict the graph of a related function
- Write, evaluate, and plot a piecewise function, and reason about continuity at the seams
- Compose and invert functions, and recognize when an inverse exists
- Translate a real-world scenario into a function that models it, and judge the model critically
- Plot any function in Python using numpy and matplotlib
In This Chapter
Chapter 2 — Functions and Models: The Language Calculus Speaks
2.0 Why a Whole Chapter on Functions?
Calculus is the mathematics of how functions change. Before we can study change, we have to be genuinely fluent with the thing that changes.
Most students arrive at calculus convinced they already are fluent. They have met functions in algebra and trigonometry. They can compute $f(3)$ when $f(x) = x^2 + 1$, graph $y = \sin x$, and tell an even function from an odd one. So why open a calculus textbook with an entire chapter on functions?
Two reasons, and they shape the whole book.
First, calculus places new demands on the function concept. The derivative is itself a function whose values are slopes. The integral is a function whose values are accumulated quantities. We will compose functions, invert them, restrict their domains, and interrogate their behavior at endpoints, asymptotes, and discontinuities. The fluency that carried you through algebra is necessary but not sufficient; we need to sharpen it.
Second, this chapter installs the modeling viewpoint that underlies everything to come. A function is not merely a formula. A function is a model of a relationship in the world — between time and position, price and demand, dose and response, input and output of any quantitative process. Calculus is the toolkit for analyzing those relationships once they are captured as functions. This connects directly to two of our recurring themes: that calculus is the mathematics of change, and that calculus appears in every quantitative field. Whether you model a bacterial colony, a bond yield, or a falling stone, the function comes first and the calculus comes second.
This chapter also introduces Python's matplotlib — the tool we will use throughout the book to see functions. Plotting is to calculus what diagrams are to geometry: not decoration, but a primary way of knowing. That reflects our theme that geometry and algebra are inseparable — every formula has a picture, and we will refuse to present one without the other.
We move briskly. If any topic feels rusty, work the exercises and consult Appendix A — Precalculus Review before continuing.
The Key Insight. A function is a rule, not a formula and not a graph. The formula and the graph are two representations of the same underlying rule. Internalizing this distinction now will save you confusion for the next 38 chapters — because the derivative and the integral are new rules built from old rules, and you cannot build on what you cannot cleanly name.
2.1 What Is a Function?
A function is a rule that assigns to each input a unique output.
Every word in that sentence is load-bearing.
-
Rule. A function tells you, given an input, what the output is. The rule can be specified by a formula ($f(x) = x^2$), a table of values, a graph, words ("$f(x)$ is the temperature at time $x$"), or an algorithm. These are representations; the function itself is the underlying correspondence.
-
Each input. The set of allowed inputs is the domain. The domain is part of the function's identity: two rules that agree on most inputs but differ in their domains are different functions. The squaring rule on all of $\mathbb{R}$ and the squaring rule on $[0,\infty)$ are not the same function.
-
A unique output. This is the defining constraint. A function returns exactly one output per input — never two. Ask for $\sqrt{4}$ and the answer is $2$, not "$2$ or $-2$." The function $\sqrt{\,\cdot\,}$ returns only the non-negative root, precisely so that it qualifies as a function.
-
Output. The set of all outputs actually produced is the range.
Geometric Intuition. Picture a function $f:\mathbb{R}\to\mathbb{R}$ as its graph — the set of points $(x,y)$ with $y = f(x)$. The vertical line test says a curve is the graph of a function exactly when every vertical line meets it at most once. The "unique output" rule is geometrically the statement that no two graph points are stacked directly above each other. A circle fails this test (a vertical line through the interior hits it twice); a parabola passes it. This is the first of many places where an algebraic rule has a visual fingerprint.
Common Pitfall. Students routinely conflate a function with its formula. The formula $f(x)=x^2$ is one representation of the squaring function. The function itself is the rule "map each number to its square." You could write the same function as $g(x)=x\cdot x$, define it in code as
def f(x): return x**2, or draw it as a parabola — all four are the same function. When a later chapter asks you to differentiate "the function," it means the rule, however it is dressed.
Notation
We write $f: A \to B$ to mean "$f$ is a function from $A$ to $B$": inputs come from $A$, outputs land in $B$. Here $A$ is the domain and $B$ is the codomain, the declared destination set. The range is the part of $B$ actually hit; it can be smaller than the codomain.
The value of $f$ at input $x$ is $f(x)$, read "$f$ of $x$" — never "$f$ times $x$." For $f:\mathbb{R}\to\mathbb{R}$, $f(x)=x^2$, the domain is $\mathbb{R}$, the codomain is $\mathbb{R}$, and the range is $[0,\infty)$ because squares are never negative.
Finding the Natural Domain
When a formula is given without an explicit domain, we adopt the natural domain: the largest set of real inputs for which the formula produces a real output. Three restrictions account for nearly every case:
- No division by zero. For $f(x)=1/(x-3)$, the natural domain is $\{x\in\mathbb{R}: x\neq 3\}$.
- No even root of a negative number (over the reals). For $f(x)=\sqrt{x-4}$, we need $x-4\ge 0$, so the natural domain is $[4,\infty)$.
- No logarithm of a non-positive number. For $f(x)=\ln x$, the natural domain is $(0,\infty)$.
Real problems often combine these. Tackle each restriction separately, then intersect.
Check Your Understanding. Find the natural domain of $f(x)=\dfrac{\sqrt{x+2}}{x-5}$.
Answer
The numerator requires $x+2\ge 0$, i.e. $x\ge -2$. The denominator requires $x-5\ne 0$, i.e. $x\ne 5$. Intersecting: $[-2,\infty)$ with the point $5$ removed, giving $[-2,5)\cup(5,\infty)$.Math Major Sidebar — Functions as sets of ordered pairs. The "rule" language is intuitive but informal. In the foundations of mathematics, a function $f:A\to B$ is a subset $f\subseteq A\times B$ such that for every $a\in A$ there is exactly one $b\in B$ with $(a,b)\in f$. This definition needs no notion of "rule" or "process"; it works for functions with no formula at all, including pathological ones built by the axiom of choice. The vertical line test is then literally the single-valuedness condition on the set of pairs. We will not need this level of austerity, but it is reassuring that the casual word "rule" can be cashed out in pure set theory whenever rigor demands it.
2.2 The Standard Library of Functions
Calculus draws on a surprisingly small collection of standard functions. Knowing their shapes, growth rates, and special values cold is non-negotiable — these are the verbs and nouns of the language. Every function we differentiate or integrate for the next 38 chapters is built from these by adding, multiplying, composing, and inverting.
Polynomials
A polynomial has the form $$p(x) = a_n x^n + a_{n-1}x^{n-1} + \cdots + a_1 x + a_0,$$ with constant coefficients $a_i$ and leading power $n$, the degree. Low degrees have names: $0$ constant, $1$ linear, $2$ quadratic, $3$ cubic, $4$ quartic.
Facts to keep at hand. - Domain: always $\mathbb{R}$. - A degree-$n$ polynomial has at most $n$ real roots. - It has at most $n-1$ turning points (places where it changes between rising and falling). - For large $|x|$, it behaves like its leading term $a_n x^n$ — everything else is a rounding error.
Rational Functions
A rational function is a ratio of polynomials, $r(x) = p(x)/q(x)$. The natural domain excludes the zeros of $q$. Rational functions can have vertical asymptotes (where $q$ vanishes but $p$ does not) and horizontal asymptotes (the value approached as $x\to\pm\infty$).
For example, $r(x) = \dfrac{x^2+1}{x^2-4}$ has vertical asymptotes at $x=\pm 2$ and a horizontal asymptote at $y=1$, since the ratio of leading coefficients is $1/1$. We will make "behavior near an asymptote" precise with limits in Chapter 3.
Power Functions
A power function is $f(x)=x^a$ for a fixed exponent $a$. The exponent decides everything: - $a$ a positive integer: a polynomial ($x^2$, $x^3$). - $a$ a negative integer: a rational function ($x^{-1}=1/x$, $x^{-2}=1/x^2$). - $a=1/n$ for a positive integer $n$: the $n$-th root ($x^{1/2}=\sqrt{x}$, defined for $x\ge 0$ when $n$ is even). - general $a>0$: defined for $x>0$ (and at $0$ when $a>0$), growing like a fractional power.
A single picture organizes these: the larger the exponent, the more aggressively the function climbs for $x>1$ and the flatter it hugs the axis for $0 An exponential function is $f(x)=b^x$ with base $b>0$, $b\ne 1$. The single most important base is $e\approx 2.71828\ldots$, Euler's number. In Chapter 7 we will prove that $f(x)=e^x$ has the extraordinary property that its own derivative equals itself: $\frac{d}{dx}\,e^x = e^x$. That self-reproducing quality is exactly why $e^x$ sits at the center of calculus and of every growth-and-decay model in science. Facts about $e^x$.
- Domain $\mathbb{R}$; range $(0,\infty)$ — it is always positive.
- $e^0=1$, $e^1=e$, and $e^{x+y}=e^x e^y$.
- $\lim_{x\to-\infty}e^x = 0$ and $\lim_{x\to\infty}e^x=\infty$.
- $e^x$ outgrows every polynomial as $x\to\infty$, no matter how high the polynomial's degree. A logarithm inverts an exponential: if $b^y=x$, then $y=\log_b x$. The natural logarithm $\ln x = \log_e x$ is the inverse of $e^x$, and it is the logarithm calculus cares about. Facts about $\ln$.
- Domain $(0,\infty)$; range $\mathbb{R}$.
- $\ln 1 = 0$, $\ln e = 1$.
- $\ln(xy)=\ln x+\ln y$, $\ln(x/y)=\ln x-\ln y$, $\ln(x^a)=a\ln x$.
- $\ln x$ grows more slowly than any positive power of $x$ — the mirror image of how $e^x$ grows faster than any power. Historical Note. John Napier introduced logarithms in 1614 to turn multiplication into addition, slashing the labor of astronomical calculation. The exponential-as-inverse view came later. The constant $e$ first surfaced not in Napier's tables but in Jacob Bernoulli's 1683 study of continuously compounded interest: $\left(1+\tfrac1n\right)^n\to e$ as $n\to\infty$. Money, not abstraction, midwifed the most important number in calculus. The trigonometric functions $\sin,\cos,\tan,\sec,\csc,\cot$ are the workhorses of periodic phenomena — waves, oscillations, orbits, alternating current. Unit-circle definition. For an angle $\theta$, draw the ray from the origin at that angle and find where it meets the unit circle. That point's coordinates are $(\cos\theta,\sin\theta)$. From this, $\tan\theta=\sin\theta/\cos\theta$ is the slope of the ray. Identities to know cold.
- $\sin^2\theta+\cos^2\theta=1$ (Pythagorean)
- $\sin(\alpha+\beta)=\sin\alpha\cos\beta+\cos\alpha\sin\beta$
- $\cos(\alpha+\beta)=\cos\alpha\cos\beta-\sin\alpha\sin\beta$
- $\sin 2\theta = 2\sin\theta\cos\theta$
- $\cos 2\theta = \cos^2\theta-\sin^2\theta = 1-2\sin^2\theta = 2\cos^2\theta-1$
- $\sin(-\theta)=-\sin\theta$ (odd), $\cos(-\theta)=\cos\theta$ (even)
- period $2\pi$: $\sin(\theta+2\pi)=\sin\theta$ Special values. If these are not memorized, memorize them now; they recur in nearly every chapter. Common Pitfall. In calculus, all angles are in radians, never degrees. The clean formulas $\frac{d}{dx}\sin x=\cos x$ and $\int\sin x\,dx=-\cos x+C$ hold only in radians. In degrees, the chain rule injects an ugly factor of $\pi/180$ everywhere (because $\sin(x^\circ)=\sin(\pi x/180)$). The radian is not a unit choice for convenience — it is the unit that makes the derivative of $\sin$ equal to $\cos$ with no constant attached. When in doubt, radians. Check Your Understanding. Without graphing, which is larger for large $x$: $x^{100}$ or $e^x$? Which is larger for large $x$: $\ln x$ or $x^{0.01}$?
If you know the graph of $f(x)$, you can predict the graph of related functions like $f(x-3)$, $2f(x)$, $f(x)+5$, or $f(-x)$ without computing anything. This is the language of transformations, and it lets one known shape generate an entire family. Warning. The horizontal shift runs opposite to the sign, and this trips up nearly everyone. Here is the honest reason: $f(x-3)$ takes the value $f(0)$ when $x=3$. So whatever $f$ did at input $0$ now happens at input $3$ — the graph moved right by $3$. The minus sign produces a positive shift. The rule of thumb: inside the function, everything is backwards, because you are changing the input, not the output. Again the inside is backwards: multiplying the input by $c>1$ compresses the graph, because the function reaches each of its values "sooner." For a stacked transformation like $g(x)=2f\big(3(x-4)\big)+5$, decompose it from the input outward:
1. Start with $f$.
2. Replace $x$ by $3x$: compress horizontally by $3$.
3. Replace input by $3(x-4)$: shift right by $4$.
4. Multiply outside by $2$: stretch vertically by $2$.
5. Add $5$ outside: shift up by $5$. Order matters: operations inside the function (acting on $x$) resolve before operations outside (acting on the output). Geometric Intuition. Every transformation is a rigid or scaled motion of the plane, not of the formula. Shifts slide the whole picture; scalings stretch the grid lines; reflections flip across an axis. If you can see the motion, you never need to memorize the algebra — you read it off the picture. This is the geometry-and-algebra theme in miniature: the symbol $f(x-3)$ and the act of sliding the graph rightward are the same statement in two languages. Check Your Understanding. With $f(x)=x^2$, describe $g(x)=-3f(x+1)-2 = -3(x+1)^2-2$. Where is the vertex, and does it open up or down?
A piecewise function is defined by different formulas on different parts of its domain. They are not exotic — they are how the real world's rules usually look. $$f(x)=\begin{cases} x^2 & x<0 \\ x & 0\le x\le 1 \\ 2-x & x>1 \end{cases}$$ To evaluate, find the clause whose condition holds and use its formula: $f(-2)=(-2)^2=4$, $f(0.5)=0.5$, $f(3)=2-3=-1$. The absolute value is the most fundamental piecewise function:
$$|x| = \begin{cases} x & x\ge 0 \\ -x & x<0. \end{cases}$$ Piecewise rules are everywhere. Income tax is piecewise — each bracket applies a different marginal rate. Shipping costs, electricity tariffs, and overtime pay are piecewise. The interesting calculus questions about a piecewise function always live at the seams, where two clauses meet: Is the function continuous there? Is it differentiable there? A corner (like the one $|x|$ has at $0$) is continuous but not differentiable — a distinction we will sharpen in Chapter 4 (continuity) and Chapter 6 (the derivative). Real-World Application — Progressive taxation (economics). A simplified tax schedule might charge $10\%$ on income up to \$10{,}000 and $20\%$ on income above that. The *total tax* $T(I)$ is piecewise: $T(I)=0.10\,I$ for $I\le 10{,}000$, and $T(I)=1{,}000+0.20\,(I-10{,}000)$ for $I>10{,}000$. The two pieces are deliberately glued so $T$ is *continuous* at \$10{,}000 (both give \$1{,}000) — nobody's total tax jumps when they earn one extra dollar — but the *slope* jumps from $0.10$ to $0.20$. That slope is the marginal tax rate, and the jump in slope is exactly a non-differentiable corner. Economists reason about this corner constantly; calculus gives it a name. The composition of $f$ and $g$ is
$$(f\circ g)(x) = f\big(g(x)\big):$$
apply $g$ first, then $f$. For $f(x)=x^2$ and $g(x)=x+3$,
$$(f\circ g)(x)=f(x+3)=(x+3)^2,\qquad (g\circ f)(x)=g(x^2)=x^2+3.$$
Composition is not commutative: $f\circ g\ne g\circ f$ in general. It is the operation that builds complicated functions out of simple ones, and it drives the chain rule — the most important differentiation rule — which we meet in Chapter 7. Almost every function you will ever differentiate is secretly a composition; learning to see the inner and outer function now pays off enormously there. The inverse $f^{-1}$ "undoes" $f$: if $f(a)=b$ then $f^{-1}(b)=a$. For an inverse to exist, $f$ must be one-to-one (injective): distinct inputs give distinct outputs. Geometrically, $f$ passes the horizontal line test — no horizontal line meets the graph twice. When $f^{-1}$ exists,
$$f^{-1}\big(f(x)\big)=x,\qquad f\big(f^{-1}(y)\big)=y,$$
and the graph of $f^{-1}$ is the reflection of the graph of $f$ across the line $y=x$ (the line that swaps inputs and outputs). Examples.
- $f(x)=x^3$, $f^{-1}(y)=y^{1/3}$.
- $f(x)=e^x$, $f^{-1}(y)=\ln y$ — this is the definition of the natural logarithm.
- $f(x)=\sin x$ restricted to $[-\pi/2,\pi/2]$ has inverse $\arcsin y$. The unrestricted $\sin x$ has no inverse: it fails the horizontal line test badly, since infinitely many inputs share each output in $[-1,1]$. To define $\arcsin$, we restrict $\sin$ to an interval on which it is one-to-one. This restrict-then-invert move recurs whenever a function is not globally one-to-one. Common Pitfall. $f^{-1}(x)$ is the inverse function, not the reciprocal $1/f(x)$. The notation is genuinely unfortunate — the $-1$ looks like a power. But $\sin^{-1}x$ means $\arcsin x$, while $(\sin x)^{-1}=\csc x$. In calculus, $f^{-1}$ almost always means the inverse function; reserve $1/f$ or $f(x)^{-1}$ for the reciprocal, and read context carefully. Finding an inverse algebraically. The mechanical recipe is: write $y=f(x)$, swap the roles of $x$ and $y$, and solve for $y$. For $f(x)=\dfrac{2x-1}{x+3}$ (a rational function, one-to-one on its domain), set $y=\dfrac{2x-1}{x+3}$, swap to get $x=\dfrac{2y-1}{y+3}$, then clear the denominator:
$$x(y+3)=2y-1 \;\Longrightarrow\; xy+3x=2y-1 \;\Longrightarrow\; y(x-2)=-1-3x \;\Longrightarrow\; y=\frac{-1-3x}{x-2}=\frac{3x+1}{2-x}.$$
So $f^{-1}(x)=\dfrac{3x+1}{2-x}$. Notice the swap of $2$ and $-3$ between the formulas — the vertical asymptote of $f$ at $x=-3$ has become the horizontal asymptote of $f^{-1}$ at $y=-3$, and vice versa. That swap is the reflection across $y=x$ showing up in the algebra. You will spend a great deal of this book looking at functions: where they rise and fall, change concavity, blow up, or level off. That intuition comes from pictures, and Python's Our convention throughout the book is three tiers: state the function, evaluate it numerically over a grid, then plot. The engine is This produces Figure 2.1: an upward-opening parabola crossing the axis at $x=1$ and $x=3$, with its lowest point at the green vertex $(2,-1)$. Run it. Seeing the roots and vertex appear where algebra predicts is the first small payoff of the geometry-and-algebra theme. Computational Note. A single picture can settle the growth-rate hierarchy from §2.2. We plot several power functions against the exponential on shared axes. Figure 2.2 shows the verdict. For small $|x|$ the powers cluster near zero while $e^x$ passes through $1$; for $x>1$ the exponential climbs above every power and never looks back; and for $x<0$, $x^3$ dives to $-\infty$ while $x^2$ stays positive. The crossings you see by eye are exactly the inequalities you reasoned about earlier — the picture and the algebra agreeing, as they always will. The piecewise function from §2.4 needs Computational Note. Beware: Both compositions collapse to Check Your Understanding. Using the recipe from §2.5, find the inverse of $f(x)=\sqrt{x-1}+2$ (domain $x\ge 1$), and state the inverse's domain.
A mathematical model is a function (or system of functions) that stands in for a real-world relationship. This is where functions stop being algebra exercises and become the working language of every quantitative science — the theme that calculus appears in every field. Here are five models you will meet repeatedly, one from each of our portfolio tracks plus medicine: Population growth (biology): $P(t)=P_0\,e^{rt}$, where $P_0$ is the initial population and $r$ the per-capita growth rate. It assumes constant per-capita growth — fine for early bacterial growth, wrong for the long run in a finite environment. Chapter 19 repairs it with the logistic model, which our SIR-model anchor builds on. Drug concentration (medicine): $C(t)=D\,e^{-kt}$, with dose $D$ and elimination constant $k$ — the simplest pharmacokinetic model, an exponential decay. Projectile height (physics): $h(t)=h_0+v_0 t-\tfrac12 g t^2$, launched from height $h_0$ at speed $v_0$ under gravity $g$. It ignores air resistance — a refinement requiring a differential equation (Chapter 19). Linear demand (economics): $Q(p)=a-bp$, quantity demanded at price $p$ with positive constants $a,b$. Useful, deliberately oversimplified. Logistic regression (data science): the sigmoid $\sigma(z)=\dfrac{1}{1+e^{-z}}$, which squashes any real $z$ into $(0,1)$ to act as a probability. It is the output layer of countless machine-learning classifiers, and it is built entirely from $e^x$. In every case, the function is not the world — it is a deliberate simplification, chosen to capture the essential behavior while staying tractable. That choice is the art of modeling. The Key Insight. Calculus is the mathematics of analyzing models. To use it, you first need a model — a function or system of functions representing your situation. Then calculus delivers the rates (derivatives), the optima, the accumulations (integrals), and the long-run behavior. The function is the input to calculus; the analysis is the output. No model, no calculus. These criteria fight. A more complex model often fits better but resists analysis; a simple one is tractable but may miss essential features. Good modeling is the disciplined management of that trade-off — a judgment we will practice all book long. Real-World Application — Curve-fitting a cooling cup of coffee (data science / physics). Suppose you record a coffee cup's temperature every minute as it cools toward room temperature $T_{\text{room}}=20^\circ$C. Newton's law of cooling predicts $T(t)=T_{\text{room}}+(T_0-T_{\text{room}})e^{-kt}$ — again an exponential, shifted. Fitting this model to data means choosing the parameters $T_0$ and $k$ so the curve hugs the measurements. With Add to Your Modeling Portfolio. In Chapter 1 you chose a track — Biology, Economics, Physics, or Data Science — and named a system you want to model. Now write down a candidate function for it, however rough. This is the seed your portfolio will grow from; you will refine it with derivatives, integrals, and (in Chapter 19) differential equations.
Biology: if a colony doubles every six hours, start with $P(t)=P_0\,2^{t/6}$ (equivalently $P_0 e^{rt}$ with $r=\tfrac{\ln 2}{6}$).
Economics: if revenue rises roughly linearly with marketing spend $s$, start with $R(s)=R_0+\mu s$, and note where that must eventually fail.
Physics: for a launched object, start with $h(t)=h_0+v_0 t-4.9\,t^2$ (taking $g=9.8\,\text{m/s}^2$).
Data Science: for a binary classifier, start with the sigmoid $\sigma(z)=1/(1+e^{-z})$ and ask what the input $z$ should be built from.
Keep this candidate; every later chapter hands you one tool to analyze and improve it. By the end of this chapter you should be fluent with: In Chapter 3 we introduce the limit — the single idea that makes derivatives and integrals rigorous, and the doorway from precalculus into calculus proper. The function fluency you built here is the foundation everything else stands on. For most of your mathematical life, a function has been a formula to plug numbers into. This chapter asked you to see it as something larger: a rule, captured equally well by a graph, a table, or a few lines of Python — and, more importantly, a model of some piece of the world. That shift in viewpoint is what separates calculus from the algebra that preceded it. We are no longer manipulating symbols for their own sake; we are describing change in populations, prices, motion, and probability, and preparing to measure it. The functions in §2.2 are the words; the models in §2.7 are the sentences. In the next chapter we learn to read what those sentences say at the infinitely small scale — and calculus begins. Continue to: Exercises · Quiz · Case Study 1 · Case Study 2 · Key Takeaways · Further ReadingExponential Functions
Logarithmic Functions
Trigonometric Functions
$\theta$
$0$
$\pi/6$
$\pi/4$
$\pi/3$
$\pi/2$
$\pi$
$\sin\theta$
$0$
$1/2$
$\sqrt{2}/2$
$\sqrt{3}/2$
$1$
$0$
$\cos\theta$
$1$
$\sqrt{3}/2$
$\sqrt{2}/2$
$1/2$
$0$
$-1$
The Standard Library at a Glance
Family
Form
Domain
Range
Polynomial
$a_n x^n+\cdots+a_0$
$\mathbb{R}$
varies
Rational
$p(x)/q(x)$
$\mathbb{R}\setminus\{q=0\}$
varies
Power
$x^a$
$[0,\infty)$ or $\mathbb{R}$ by $a$
varies
Exponential
$e^x,\ b^x$
$\mathbb{R}$
$(0,\infty)$
Logarithmic
$\ln x,\ \log_b x$
$(0,\infty)$
$\mathbb{R}$
Sine, cosine
$\sin x,\ \cos x$
$\mathbb{R}$
$[-1,1]$
Tangent
$\tan x$
$\mathbb{R}\setminus\{(2k+1)\pi/2\}$
$\mathbb{R}$
Answer
$e^x$ eventually dominates $x^{100}$ — exponential growth beats every power, even degree 100; the crossover is just very far out. And $x^{0.01}$ eventually dominates $\ln x$ — logarithmic growth is slower than every positive power, even $x^{0.01}$. These two facts are the "growth-rate hierarchy" that will settle countless limits and convergence questions later: $\ln x \prec x^a \prec e^x$ for any $a>0$.
2.3 Function Transformations
Shifts
Scalings
Reflections
Composing Transformations
Answer
Start with $y=x^2$ (vertex $(0,0)$, opens up). Shift left by $1$: vertex $\to(-1,0)$. Multiply by $-3$: reflect across the $x$-axis (now opens down) and stretch vertically by $3$; vertex unchanged at $(-1,0)$. Shift down by $2$: vertex $\to(-1,-2)$. Final answer: a downward parabola, vertically stretched by $3$, with vertex $(-1,-2)$.
2.4 Piecewise Functions
2.5 Composition and Inverses
Composition
Inverses
2.6 Plotting Functions in Python
matplotlib is how we draw them. This is the chapter's computational centerpiece, and the pattern below recurs in every plotting cell from here on.numpy's linspace (an evenly spaced grid) combined with vectorization (applying a function to a whole array at once).import numpy as np
import matplotlib.pyplot as plt
# Plot a single quadratic and mark its roots and vertex.
def f(x: np.ndarray) -> np.ndarray:
return x**2 - 4*x + 3 # = (x-1)(x-3), vertex at (2, -1)
x = np.linspace(-1, 5, 400) # 400 grid points from -1 to 5
y = f(x) # vectorized: y is also a 400-element array
plt.figure(figsize=(8, 5))
plt.plot(x, y, 'b-', linewidth=2, label='$f(x) = x^2 - 4x + 3$')
plt.axhline(0, color='gray', linewidth=0.5) # x-axis
plt.axvline(0, color='gray', linewidth=0.5) # y-axis
plt.scatter([1, 3], [0, 0], color='red', zorder=5, label='roots')
plt.scatter([2], [-1], color='green', zorder=5, label='vertex')
plt.xlabel('$x$'); plt.ylabel('$f(x)$')
plt.title('A simple quadratic')
plt.legend(); plt.grid(True, alpha=0.3)
plt.show()
# Output: an upward parabola crossing the x-axis at x=1 and x=3,
# bottoming out at the vertex (2, -1).
x = np.linspace(-1, 5, 400) builds an array of $400$ evenly spaced numbers. The line y = f(x) is vectorized: numpy applies f to every element at once and hands back an array, with no Python for-loop. Vectorization is what makes numpy fast and what keeps our plotting code to a few lines. If you ever find yourself writing a loop to evaluate a function at many points, stop — linspace plus vectorization is almost always the right move.Comparing Growth Rates Visually
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-2, 3, 400)
plt.figure(figsize=(8, 5))
plt.plot(x, x, label='$y = x$')
plt.plot(x, x**2, label='$y = x^2$')
plt.plot(x, x**3, label='$y = x^3$')
plt.plot(x, np.exp(x), label='$y = e^x$')
plt.ylim(-3, 12) # clip so the shapes stay readable
plt.xlabel('$x$'); plt.ylabel('$y$')
plt.title('Power functions vs. the exponential')
plt.legend(); plt.grid(True, alpha=0.3)
plt.show()
# Output: near x=0 the powers hug zero while e^x passes through 1;
# for x>1 the exponential pulls away above all the powers.
Plotting a Piecewise Function
np.where, which selects between arrays elementwise.import numpy as np
import matplotlib.pyplot as plt
def f(x: np.ndarray) -> np.ndarray:
# f(x) = x^2 (x<0); x (0<=x<=1); 2-x (x>1)
return np.where(x < 0, x**2,
np.where(x <= 1, x, 2 - x))
x = np.linspace(-2, 3, 600)
y = f(x)
plt.figure(figsize=(8, 5))
plt.plot(x, y, 'b-', linewidth=2)
plt.axhline(0, color='gray', lw=0.5); plt.axvline(0, color='gray', lw=0.5)
plt.xlabel('$x$'); plt.ylabel('$f(x)$')
plt.title('A piecewise function')
plt.grid(True, alpha=0.3)
plt.show()
# Output: a parabola arc for x<0 meeting the line y=x at the origin,
# then a peak at (1,1), then the line 2-x sloping down.
np.where(condition, a, b) returns a where the condition holds and b elsewhere; nesting handles three or more clauses. Figure 2.3 reveals the seams: the pieces join smoothly at $x=0$ (both give $0$) but meet at a corner at $x=1$, where the rising line $y=x$ abruptly becomes the falling line $y=2-x$. The function is continuous there but has no single tangent slope — precisely the kind of seam Chapter 4 will dissect.
np.where(cond, a, b) evaluates both a and b everywhere before selecting, so an expression like np.where(x>0, np.log(x), 0) still computes np.log(x) at $x\le 0$ and may emit a warning about invalid values. The selected output is correct, but for genuinely undefined branches you sometimes need masking instead. For the well-behaved pieces above, plain nested np.where is fine.Verifying Algebra with sympy
numpy and matplotlib handle the numerical and visual tiers; sympy handles the symbolic tier — it does algebra exactly, so you can check work by hand against the machine. We will lean on this constantly once derivatives and integrals arrive; here we use it to confirm the inverse and composition facts from §2.5.import sympy as sp
x = sp.symbols('x')
# Confirm the inverse from §2.5: f(x) = (2x-1)/(x+3), claimed inverse g(x) = (3x+1)/(2-x)
f = (2*x - 1) / (x + 3)
g = (3*x + 1) / (2 - x)
print(sp.simplify(f.subs(x, g))) # f(g(x)) should simplify to x
print(sp.simplify(g.subs(x, f))) # g(f(x)) should simplify to x
# Output:
# x
# x
x, which is exactly the defining property $f(f^{-1}(x))=x$ and $f^{-1}(f(x))=x$. When the machine simplifies your candidate inverse to the identity, the algebra is correct — no graphing required.
Answer
Set $y=\sqrt{x-1}+2$, swap to $x=\sqrt{y-1}+2$, isolate the root $x-2=\sqrt{y-1}$, and square: $y-1=(x-2)^2$, so $f^{-1}(x)=(x-2)^2+1$. Its domain is the range of $f$, namely $[2,\infty)$ — the squaring would otherwise produce spurious values below $2$. The domain restriction on the inverse is what keeps the reflection across $y=x$ honest.
2.7 The Modeling Viewpoint
What Makes a Good Model
scipy.optimize.curve_fit you hand Python the model function and the data, and it returns the best-fit parameters. The same pipeline — propose a function, fit its parameters to data — underlies regression, machine learning, and most of empirical science. The function is the hypothesis; the data decides its constants.
2.8 The Calculus Vocabulary So Far
linspace $\to$ vectorize $\to$ plotReflection