Ran Wei/ Calculus/Module 1
中文
Calculus · Part I · Functions, limits and continuity

Module 1Functions and change

Learn what calculus is for, then build its raw material, functions, and the families of functions it uses most. You will finish by computing average speeds over shorter and shorter time intervals, the first step towards the derivative, and, if you like, by setting up Python to check your work.

⏱ 240 minYou need: School algebra (fractions, powers, equations, graphs of straight lines)

In this module you will

  • Explain the two central problems of calculus, rates of change and accumulation
  • Find the domain and range of a function and write them in interval notation
  • Recognise and sketch the standard functions, including exponentials, logarithms and the trigonometric functions in radians
  • Transform, compose and invert functions, and predict the effect on a graph
  • Compute average rates of change and simplify difference quotients
  • Set up Python with SymPy, NumPy and matplotlib, and use them to check your work
1

What calculus is about

Calculus is the mathematics of change. Whenever a quantity varies (the position of a car, the temperature of a cup of tea, the error of a machine-learning model as it trains), calculus asks two questions about it:

  1. How fast is it changing at this instant? The answer is a rate of change.
  2. How much has built up over a stretch of time, when the rate itself keeps changing? The answer is an accumulation.
Think of it like this

A car’s dashboard answers both questions. The speedometer shows how fast the distance travelled is changing at this instant; the odometer shows how much distance has built up. Add up the speedometer readings over time and you get the odometer reading; ask how fast the odometer reading grows and you get the speedometer reading. Calculus calls these processes integration and differentiation, and its central theorem, the Fundamental Theorem of Calculus (Module 10), says that each undoes the other.

The tangent problem and the area problem

The two questions become two problems about graphs (Figure 1.1).

The tangent problem. A straight line has one slope, but a curve is steeper in some places than in others. What is the slope of a curve at a point P?P\mathclose{\text{?}} Draw the line through PP and a second point QQ of the curve, a secant line; its slope is easy to compute. Now let QQ slide along the curve towards P.P\mathclose{\text{.}} The secant lines settle on one line, the tangent line at P,P\mathclose{\text{,}} and its slope is the slope of the curve at P.P\mathclose{\text{.}} On a graph of distance against time, that slope is the speed at that instant.

The area problem. What is the area under a curve, between x=ax = a and x=b?x = b\mathclose{\text{?}} Fill the region with thin rectangles: their total area is easy to compute and close to the area wanted. Thinner rectangles fit better, and the area is the number that their totals approach. On a graph of speed against time, that area is the distance travelled.

The two problems of calculus. Left: as Q slides along the curve towards P, the secant lines through P and Q approach the tangent line at P. Right: as the rectangles under the curve between a and b get thinner, their total area approaches the area under the curve.
Figure 1.1

The two problems of calculus. Left: as QQ slides along the curve towards P,P\mathclose{\text{,}} the secant lines through PP and QQ approach the tangent line at P.P\mathclose{\text{.}} Right: as the rectangles under the curve between aa and bb get thinner, their total area approaches the area under the curve.

Both problems are solved by the same new idea: improve an approximation (the slope of a secant, a total of rectangles) step by step, and ask what number the approximations approach. That number is a limit, the subject of Module 2. The slope of the tangent is the derivative (Part II of the series); the area is the integral (Part III).

A short history

The area problem is ancient. Archimedes, in the 3rd century BC, found areas and volumes with the method of exhaustion, approximating a region by simpler shapes that fill it more and more completely: an ancestor of the rectangles in Figure 1.1.

Calculus as a general method arrived in the seventeenth century, from two people working independently. Newton developed his calculus, which he called the method of fluxions, in 1665–1666, but published it late. Leibniz published the first account of the differential calculus in 1684 and of the integral calculus in 1686; his notation, with dxdx and ∫,\int\mathclose{\text{,}} is the one used today. The priority dispute that followed was bitter. Later, Cauchy in the 1820s and Weierstrass in the 1860s and 1870s gave calculus its rigorous foundation, the ε–δ definition of a limit that Module 2 presents, and Riemann defined the integral named after him in 1854 (published in 1868).

Where calculus is used

In science, velocity is the rate of change of position and acceleration that of velocity, so the laws of motion, like those of cooling and radioactive decay, are statements about rates: differential equations (Module 13). In engineering, electric current is the rate of change of charge, and beams, control systems and signal filters are described with derivatives and integrals. In computing, machine learning trains a model by gradient descent, repeatedly adjusting its parameters in the direction that reduces its error fastest, a direction computed from derivatives (Modules 8 and 17); backpropagation, which computes those derivatives in neural networks, is the chain rule (Modules 5 and 17).

All these quantities are functions of something else, so this module studies functions (Sections 1.3 to 1.5) and then takes the first step towards the derivative (Section 1.6).

2

How this series works

Every idea arrives in the same order: a picture or a table of numbers, a precise definition, worked examples, and the mistakes that learners commonly make. The main theorems are proved; harder proofs and extensions sit in Going deeper boxes, which a first reading may skip.

The pages use these boxes:

Box What it holds
Definition, Theorem, Example a new term, a precise statement, a worked example
Proof why a theorem is true; it ends with ∎
Key idea, Tip, Good to know the point to remember, practical advice, a side remark
Watch out a common mistake, why it is wrong, and the fix
Think of it like this an analogy
Going deeper optional, harder material
Try it an interactive graph to experiment with
Compute it optional Python

Boxes, sections and figures are numbered within each module: Definition 1.2 is the second definition of Module 1, and Figure 1.3 its third figure.

The Checked mark. Worked examples and exercise solutions carry the mark ✓ Checked: their results, and the steps that lead to them, were verified with SymPy, a computer algebra system. Tables of values are computed from their formulas, and figures are drawn by plotting the functions they show.

Exercises and quiz. Each module ends with a summary, 10 to 12 exercises and an 8-question quiz. The exercises come at three levels: ★ check your understanding, ★★ apply, ★★★ stretch (a proof, a harder problem or an application). Each has a full worked solution under Show solution: try the exercise first.

What you need. Paper, a pencil and a scientific calculator, set to radians (Section 1.4 explains why). Python is optional: Section 1.7 shows how to install it, and every output in the Compute it boxes is what the code printed. The rest of the series makes sense without Python.

If your algebra is rusty, first work through the Optional algebra refresher of Mathematical Foundations for Computer Science and AI. That series also has compact calculus modules aimed at computing, from its Module 15 on; this series is the full course.

Tip

Read with a pencil. When an example shows a step, do it yourself before you read on; when it says “expand and collect”, do the expanding.

3

Functions

Drop a ball from rest. Near the Earth’s surface, if air resistance is negligible, the distance it has fallen after tt seconds is

s(t)=4.9t2 metres.s(t) = 4.9t^2 \text{ metres}.

(The 4.9 is half of g≈9.8g \approx 9.8 m/s², the acceleration due to gravity.) Here is the distance at half-second intervals:

tt000.50.5111.51.5222.52.533
s(t)s(t)001.2251.2254.94.911.02511.02519.619.630.62530.62544.144.1

Each time tt gives exactly one distance s(t).s(t)\mathclose{\text{.}} That is what makes ss a function.

Definition 1.1Function

A function ff is a rule that assigns to each number xx in a set DD exactly one number f(x).f(x)\mathclose{\text{.}} The set DD is the domain of f.f\mathclose{\text{.}} The number f(x),f(x)\mathclose{\text{,}} read “f of x”, is the value of ff at x.x\mathclose{\text{.}} The set of all values f(x),f(x)\mathclose{\text{,}} as xx runs through the domain, is the range of f.f\mathclose{\text{.}}

The input xx is the independent variable and the output y=f(x)y = f(x) the dependent variable. In Parts I to IV of this series, inputs and outputs are real numbers, apart from a look at complex numbers in Module 15; the set of all real numbers is written R.\R\mathclose{\text{.}} To say that xx belongs to a set D,D\mathclose{\text{,}} write x∈D,x \in D\mathclose{\text{,}} read “x is in D”.

“Exactly one” is the heart of the definition. The rule “the number whose square is xx” is not a function: for x=9x = 9 it gives two numbers, 3 and −3.-3\mathclose{\text{.}} A function may, however, give the same output for different inputs: x2x^2 gives 4 for both x=2x = 2 and x=−2.x = -2\mathclose{\text{.}}

Intervals

Domains and ranges are usually intervals: all the real numbers between two ends.

Definition 1.2Intervals

For real numbers a<b:a < b\mathclose{\text{:}}

Interval The numbers xx with
[a,b][a, b] a≤x≤ba \le x \le b
(a,b)(a, b) a<x<ba < x < b
[a,b)[a, b) a≤x<ba \le x < b
(a,b](a, b] a<x≤ba < x \le b
[a,∞)[a, \infty) x≥ax \ge a
(a,∞)(a, \infty) x>ax > a
(−∞,b](-\infty, b] x≤bx \le b
(−∞,b)(-\infty, b) x<bx < b
(−∞,∞)(-\infty, \infty) every real x:x\mathclose{\text{:}} this is R\R

A square bracket means that the endpoint belongs to the interval; a round bracket means that it does not.

[a,b][a, b] is a closed interval, read “the closed interval from a to b”; (a,b)(a, b) is an open interval. The symbol ∞,\infty\mathclose{\text{,}} read “infinity”, is not a number: [a,∞)[a, \infty) is shorthand for “all x≥ax \ge a”, so the bracket beside ∞\infty is always round. To join intervals, use ∪,\cup\mathclose{\text{,}} read “union”: (−∞,2)∪(2,∞)(-\infty, 2) \cup (2, \infty) is the set of numbers in either interval, that is, every real number except 2.

Watch out

Writing [3,∞)[3, \infty) for “x>3x > 3”. The 3 is not included, so its bracket must be round: (3,∞).(3, \infty)\mathclose{\text{.}} And never write [3,∞]:[3, \infty]\mathclose{\text{:}} ∞\infty is not a number, so it cannot belong to an interval.

The domain of a formula

When a function is given by a formula and nothing is said about its domain, the convention is this:

Key idea

The domain of a formula is the set of all real numbers for which the formula gives a real number. To find it, look for what could go wrong: so far, division by zero and the square root of a negative number (more generally, any even root). Section 1.4 adds a third: the logarithm of a number that is not positive.

A model can have a smaller domain than its formula. s(t)=4.9t2s(t) = 4.9t^2 is defined for every real t,t\mathclose{\text{,}} but as a description of the falling ball it applies only from t=0,t = 0\mathclose{\text{,}} when the ball is dropped, until the ball lands.

Example 1.1Domains from formulas✓ Checked

Find the domain of each function, in interval notation.

  • (a) f(x)=1x−2f(x) = \dfrac{1}{x - 2}
  • (b) g(x)=3−xg(x) = \sqrt{3 - x}
  • (c) h(x)=xx−1h(x) = \dfrac{\sqrt{x}}{x - 1}

(a) The only danger is division by zero, which happens when x−2=0,x - 2 = 0\mathclose{\text{,}} that is, at x=2.x = 2\mathclose{\text{.}} Every other number is allowed: the domain is (−∞,2)∪(2,∞).(-\infty, 2) \cup (2, \infty)\mathclose{\text{.}}

(b) The square root needs 3−x≥0,3 - x \ge 0\mathclose{\text{,}} that is, x≤3x \le 3 (add xx to both sides). The domain is (−∞,3].(-\infty, 3]\mathclose{\text{.}} The 3 is included, because 0=0.\sqrt{0} = 0\mathclose{\text{.}}

(c) Two conditions: x\sqrt{x} needs x≥0,x \ge 0\mathclose{\text{,}} and the denominator needs x≠1.x \ne 1\mathclose{\text{.}} Both must hold, so the domain is [0,1)∪(1,∞).[0, 1) \cup (1, \infty)\mathclose{\text{.}}

Finding a range takes more work, because you must find which outputs actually occur. That takes two arguments: every value lies in the set you claim, and every number in that set is a value.

Example 1.2Domain and range of a semicircle✓ Checked

Find the domain and the range of f(x)=4−x2.f(x) = \sqrt{4 - x^2}\mathclose{\text{.}}

Domain. The square root needs 4−x2≥0,4 - x^2 \ge 0\mathclose{\text{,}} that is, x2≤4,x^2 \le 4\mathclose{\text{,}} which holds exactly when −2≤x≤2.-2 \le x \le 2\mathclose{\text{.}} The domain is [−2,2].[-2, 2]\mathclose{\text{.}}

Range. For xx in [−2,2],[-2, 2]\mathclose{\text{,}} x2x^2 lies between 0 and 4, so 4−x24 - x^2 lies between 0 and 4, and its square root lies between 0=0\sqrt0 = 0 and 4=2.\sqrt4 = 2\mathclose{\text{.}} So every value is in [0,2].[0, 2]\mathclose{\text{.}} Conversely, every yy in [0,2][0, 2] is a value. To find an input that gives it, solve y=4−x2y = \sqrt{4 - x^2} for x:x\mathclose{\text{:}} squaring gives y2=4−x2,y^2 = 4 - x^2\mathclose{\text{,}} so try x=4−y2.x = \sqrt{4 - y^2}\mathclose{\text{.}} This xx lies in [0,2],[0, 2]\mathclose{\text{,}} and, since y≥0,y \ge 0\mathclose{\text{,}}

f(x)=4−(4−y2)=y2=y.f(x) = \sqrt{4 - (4 - y^2)} = \sqrt{y^2} = y.

The range is [0,2].[0, 2]\mathclose{\text{.}} Squaring y=4−x2y = \sqrt{4 - x^2} gives x2+y2=4x^2 + y^2 = 4 with y≥0.y \ge 0\mathclose{\text{.}} By Pythagoras’ theorem, x2+y2x^2 + y^2 is the square of the distance from (x,y)(x, y) to the origin, so the points with x2+y2=4x^2 + y^2 = 4 form the circle of radius 2 centred at the origin, and the graph is its upper half. Figure 1.2 shows it with its domain and range.

Graphs

Definition 1.3Graph

The graph of a function ff is the set of all points (x,f(x))(x, f(x)) in the coordinate plane with xx in the domain of f.f\mathclose{\text{.}} It is the curve with equation y=f(x).y = f(x)\mathclose{\text{.}}

To read f(a)f(a) from a graph, go to x=ax = a on the horizontal axis and then up or down to the graph: f(a)f(a) is the height there. The domain is the set of xx where the graph has a point, its shadow on the xx-axis; the range is its shadow on the yy-axis.

The vertical line test. A curve in the plane is the graph of a function of xx exactly when no vertical line meets it more than once: the line x=ax = a meets the graph of ff only at (a,f(a))(a, f(a)) if aa is in the domain, and not at all otherwise, and a second meeting point would give aa two values. The whole circle x2+y2=4x^2 + y^2 = 4 fails the test: the line x=1x = 1 meets it at (1,3)(1, \sqrt3) and at (1,−3).(1, -\sqrt3)\mathclose{\text{.}} Its upper half passes: it is the graph of Example 1.2.

Left: the graph of y = sqrt{4 - x^2} from Example 1.2. Its shadow on the x-axis (orange) is the domain [-2, 2]; its shadow on the y-axis (green) is the range [0, 2]. Right: the piecewise function of Example 1.3. The filled dot at (1, 2) is on the graph; the hollow dot at (1, 1) is not.
Figure 1.2

Left: the graph of y=4−x2y = \sqrt{4 - x^2} from Example 1.2. Its shadow on the xx-axis (orange) is the domain [−2,2];[-2, 2]\mathclose{\text{;}} its shadow on the yy-axis (green) is the range [0,2].[0, 2]\mathclose{\text{.}} Right: the piecewise function of Example 1.3. The filled dot at (1,2)(1, 2) is on the graph; the hollow dot at (1,1)(1, 1) is not.

Piecewise functions

A piecewise function uses different formulas on different parts of its domain. The most important one is the absolute value, ∣x∣,\abs{x}\mathclose{\text{,}} read “the absolute value of x”:

∣x∣={xif x≥0,−xif x<0.\abs{x} = \begin{cases} x & \text{if } x \ge 0, \\ -x & \text{if } x < 0. \end{cases}

It makes every number non-negative: ∣5∣=5\abs{5} = 5 and ∣−3∣=−(−3)=3.\abs{-3} = -(-3) = 3\mathclose{\text{.}} Geometrically, ∣x∣\abs{x} is the distance from xx to 0 on the number line, and ∣a−b∣\abs{a - b} the distance between aa and b;b\mathclose{\text{;}} the graph of ∣x∣\abs{x} is a V with its corner at the origin. Neural networks use another piecewise function, the rectified linear unit:

ReLU⁡(x)={0if x<0,xif x≥0.\operatorname{ReLU}(x) = \begin{cases} 0 & \text{if } x < 0, \\ x & \text{if } x \ge 0. \end{cases}

It is the same as max⁡(0,x),\max(0, x)\mathclose{\text{,}} the larger of 0 and x.x\mathclose{\text{.}}

Example 1.3A piecewise function✓ Checked

Let

f(x)={x2if x<1,3−xif x≥1.f(x) = \begin{cases} x^2 & \text{if } x < 1, \\ 3 - x & \text{if } x \ge 1. \end{cases}

Find f(−1),f(-1)\mathclose{\text{,}} f(0.5),f(0.5)\mathclose{\text{,}} f(1)f(1) and f(2),f(2)\mathclose{\text{,}} and sketch the graph.

For each input, first decide which piece applies, then use its formula.

  • −1<1,-1 < 1\mathclose{\text{,}} so f(−1)=(−1)2=1.f(-1) = (-1)^2 = 1\mathclose{\text{.}}
  • 0.5<1,0.5 < 1\mathclose{\text{,}} so f(0.5)=0.52=0.25.f(0.5) = 0.5^2 = 0.25\mathclose{\text{.}}
  • 1≥1,1 \ge 1\mathclose{\text{,}} so f(1)=3−1=2.f(1) = 3 - 1 = 2\mathclose{\text{.}} A boundary point belongs to the piece whose condition includes it, here the second.
  • 2≥1,2 \ge 1\mathclose{\text{,}} so f(2)=3−2=1.f(2) = 3 - 2 = 1\mathclose{\text{.}}

The graph (Figure 1.2, right) is the parabola y=x2y = x^2 to the left of x=1x = 1 and the line y=3−xy = 3 - x from x=1x = 1 on. The parabola heads for the point (1,1),(1, 1)\mathclose{\text{,}} but x=1x = 1 is not in its piece, so a hollow dot marks the gap; the filled dot at (1,2)(1, 2) shows the value f(1)=2.f(1) = 2\mathclose{\text{.}} The graph jumps at x=1.x = 1\mathclose{\text{.}}

Going deeperWhat a function is, precisely

Definition 1.1 speaks of a “rule”, but only the pairing of inputs with outputs matters. So mathematicians define a function to be its graph: a set ff of ordered pairs (x,y)(x, y) in which each xx of the domain appears exactly once, with f(x)=yf(x) = y meaning that (x,y)(x, y) belongs to f.f\mathclose{\text{.}} Then (x+1)2(x + 1)^2 and x2+2x+1x^2 + 2x + 1 define the same function. One also writes f ⁣:D→R,f\colon D \to \R\mathclose{\text{,}} read “f maps D to R”.

A function in a program can read the clock, or a variable that other code changes, so equal inputs may give different outputs; it can also do things besides computing its output, such as printing. Programmers call a function pure if its output depends only on its input and it does nothing else; mathematical functions are pure.

4

A catalogue of functions

A handful of families supplies almost every function in this series; Figure 1.3 shows them, and the function explorer of Section 1.5 draws most of them. Learn their shapes: recognising a shape saves work throughout calculus.

The catalogue. Top row: lines with slopes 2 and -tfrac12; the powers x^2 and x^3; the cubic of Example 1.4 with its zeros -2, 0 and 3; the rational function 1/x. Bottom row: sqrt x and sqrt[3]{x}; the exponentials 2^x, e^x and (tfrac12)^x, all through (0, 1); e^x and its inverse ln x, mirror images in the line y = x; and tan x, undefined where cos x = 0, as at x = pmtfrac{pi}{2} (dashed).
Figure 1.3

The catalogue. Top row: lines with slopes 2 and −12;-\tfrac12\mathclose{\text{;}} the powers x2x^2 and x3;x^3\mathclose{\text{;}} the cubic of Example 1.4 with its zeros −2,-2\mathclose{\text{,}} 0 and 3; the rational function 1/x.1/x\mathclose{\text{.}} Bottom row: x\sqrt x and x3;\sqrt[3]{x}\mathclose{\text{;}} the exponentials 2x,2^x\mathclose{\text{,}} exe^x and (12)x,(\tfrac12)^x\mathclose{\text{,}} all through (0,1);(0, 1)\mathclose{\text{;}} exe^x and its inverse ln⁡x,\ln x\mathclose{\text{,}} mirror images in the line y=x;y = x\mathclose{\text{;}} and tan⁡x,\tan x\mathclose{\text{,}} undefined where cos⁡x=0,\cos x = 0\mathclose{\text{,}} as at x=±π2x = \pm\tfrac{\pi}{2} (dashed).

Linear functions

A linear function has the form f(x)=mx+b,f(x) = mx + b\mathclose{\text{,}} where mm and bb are constants. Its graph is a straight line that crosses the yy-axis at height bb (the intercept) and has slope m.m\mathclose{\text{.}} The slope is the change in yy per unit change in x:x\mathclose{\text{:}} for any two points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) on the line (read “x one, y one” and so on), with x1≠x2,x_1 \ne x_2\mathclose{\text{,}}

m=y2−y1x2−x1.m = \frac{y_2 - y_1}{x_2 - x_1}.

The answer does not depend on which two points you take: y2−y1=(mx2+b)−(mx1+b)=m(x2−x1),y_2 - y_1 = (mx_2 + b) - (mx_1 + b) = m(x_2 - x_1)\mathclose{\text{,}} and dividing by x2−x1x_2 - x_1 leaves m.m\mathclose{\text{.}}

So a linear function changes at the same rate everywhere: each step of 1 in xx changes yy by m.m\mathclose{\text{.}} The conversion from degrees Celsius to degrees Fahrenheit, F=1.8C+32,F = 1.8C + 32\mathclose{\text{,}} is an example: a rise of 1 °C is a rise of 1.8 °F, whatever the temperature. For a line, “rate of change” needs no calculus. Calculus is what extends the idea to curves, whose steepness changes from point to point.

The line through (x1,y1)(x_1, y_1) with slope mm has the point-slope equation y−y1=m(x−x1).y - y_1 = m(x - x_1)\mathclose{\text{.}} For example, the line through (1,3)(1, 3) and (4,9)(4, 9) has slope 9−34−1=2,\tfrac{9 - 3}{4 - 1} = 2\mathclose{\text{,}} so its equation is y−3=2(x−1),y - 3 = 2(x - 1)\mathclose{\text{,}} that is, y=2x+1.y = 2x + 1\mathclose{\text{.}}

Powers and polynomials

A power function is f(x)=xn.f(x) = x^n\mathclose{\text{.}} For n=1,2,3,…n = 1, 2, 3, \dots it is defined for every real x.x\mathclose{\text{.}} Figure 1.3 shows the two basic shapes: x2x^2 is a U-shaped parabola, symmetric about the yy-axis, and x3x^3 climbs through the origin, symmetric about the origin. Higher even powers (x4,x6,…)x^4, x^6, \dots\mathclose{\text{)}} look like x2,x^2\mathclose{\text{,}} and higher odd powers like x3,x^3\mathclose{\text{,}} but flatter near 0 and steeper further out. Negative powers are reciprocals, x−n=1/xn,x^{-n} = 1/x^n\mathclose{\text{,}} defined for x≠0;x \ne 0\mathclose{\text{;}} fractional powers are roots (below).

The two symmetries have names. A function is even if f(−x)=f(x)f(-x) = f(x) for every xx in its domain: its graph is its own mirror image in the yy-axis. It is odd if f(−x)=−f(x):f(-x) = -f(x)\mathclose{\text{:}} a half turn about the origin leaves its graph unchanged. x2x^2 is even, since (−x)2=x2;(-x)^2 = x^2\mathclose{\text{;}} x3x^3 is odd, since (−x)3=−x3.(-x)^3 = -x^3\mathclose{\text{.}}

Definition 1.4Polynomial

A polynomial is a function of the form

p(x)=anxn+an−1xn−1+⋯+a1x+a0,p(x) = a_n x^n + a_{n-1} x^{n-1} + \dots + a_1 x + a_0,

where n≥0n \ge 0 is a whole number and the coefficients a0,a1,…,ana_0, a_1, \dots, a_n are constants. If an≠0,a_n \ne 0\mathclose{\text{,}} the polynomial has degree n.n\mathclose{\text{.}} Its domain is R.\R\mathclose{\text{.}}

Polynomials of degree 1, 2 and 3 are linear, quadratic and cubic. A number rr with p(r)=0p(r) = 0 is a zero (or root) of p:p\mathclose{\text{:}} the graph meets the xx-axis at x=r.x = r\mathclose{\text{.}} Factoring finds zeros.

Example 1.4Zeros of a cubic✓ Checked

Find the zeros of p(x)=x3−x2−6x.p(x) = x^3 - x^2 - 6x\mathclose{\text{.}}

Every term contains x,x\mathclose{\text{,}} so take it out: p(x)=x(x2−x−6).p(x) = x(x^2 - x - 6)\mathclose{\text{.}} To factor the quadratic, look for two numbers with product −6-6 and sum −1:-1\mathclose{\text{:}} they are −3-3 and 2.2\mathclose{\text{.}} So

p(x)=x(x−3)(x+2).p(x) = x(x - 3)(x + 2).

A product is 0 exactly when one of its factors is 0, so the zeros are x=0,x = 0\mathclose{\text{,}} x=3x = 3 and x=−2.x = -2\mathclose{\text{.}} Check by expanding: x(x−3)(x+2)=x(x2−x−6)=x3−x2−6x.x(x - 3)(x + 2) = x(x^2 - x - 6) = x^3 - x^2 - 6x\mathclose{\text{.}} The graph in Figure 1.3 meets the xx-axis at these three points.

Rational functions

Definition 1.5Rational function

A rational function is a quotient f(x)=p(x)q(x)f(x) = \dfrac{p(x)}{q(x)} of two polynomials, where qq is not the zero polynomial. Its domain is the set of all xx with q(x)≠0.q(x) \ne 0\mathclose{\text{.}}

The simplest is f(x)=1/x,f(x) = 1/x\mathclose{\text{,}} with domain (−∞,0)∪(0,∞).(-\infty, 0) \cup (0, \infty)\mathclose{\text{.}} Its graph (Figure 1.3) has two branches. Near x=0x = 0 the values become huge, positive on the right and negative on the left; far from 0 they shrink towards 0. Module 3 studies such behaviour.

Example 1.5A rational function with a hole✓ Checked

Find the domain of r(x)=x2−4x2−x−2,r(x) = \dfrac{x^2 - 4}{x^2 - x - 2}\mathclose{\text{,}} and simplify the formula.

Factor the top and the bottom: x2−4=(x−2)(x+2)x^2 - 4 = (x - 2)(x + 2) (a difference of squares) and x2−x−2=(x−2)(x+1).x^2 - x - 2 = (x - 2)(x + 1)\mathclose{\text{.}} The denominator is 0 at x=2x = 2 and at x=−1,x = -1\mathclose{\text{,}} so the domain is (−∞,−1)∪(−1,2)∪(2,∞).(-\infty, -1) \cup (-1, 2) \cup (2, \infty)\mathclose{\text{.}}

For xx in the domain, x−2≠0,x - 2 \ne 0\mathclose{\text{,}} so you may cancel it: for x≠2x \ne 2 and x≠−1,x \ne -1\mathclose{\text{,}}

r(x)=(x−2)(x+2)(x−2)(x+1)=x+2x+1.r(x) = \frac{(x - 2)(x + 2)}{(x - 2)(x + 1)} = \frac{x + 2}{x + 1}.

The conditions matter. The formula x+2x+1\dfrac{x + 2}{x + 1} makes sense at x=2,x = 2\mathclose{\text{,}} where it gives 43,\tfrac43\mathclose{\text{,}} but r(2)r(2) is not defined. So the graph of rr is the graph of x+2x+1\dfrac{x + 2}{x + 1} with one point missing: a hole at (2,43).\big(2, \tfrac43\big)\mathclose{\text{.}} What rr does near x=2x = 2 is the kind of question that limits answer (Module 2).

Watch out

Cancelling a factor can change the domain: carry the condition along, as in r(x)=x+2x+1r(x) = \dfrac{x + 2}{x + 1} for x≠2.x \ne 2\mathclose{\text{.}} And cancel common factors, never terms: x+2x+1\dfrac{x + 2}{x + 1} is not 21.\dfrac{2}{1}\mathclose{\text{.}}

Roots

For x≥0,x \ge 0\mathclose{\text{,}} the square root x\sqrt{x} is the non-negative number whose square is x.x\mathclose{\text{.}} So 9=3,\sqrt{9} = 3\mathclose{\text{,}} not ±3.\pm 3\mathclose{\text{.}} The equation x2=9x^2 = 9 has two solutions, 9=3\sqrt9 = 3 and −9=−3,-\sqrt9 = -3\mathclose{\text{,}} but the symbol 9\sqrt9 means only the first. The domain and the range of x\sqrt x are both [0,∞);[0, \infty)\mathclose{\text{;}} its graph is half of a parabola lying on its side (Figure 1.3).

The cube root x3\sqrt[3]{x} is the number whose cube is x.x\mathclose{\text{.}} Every real number has exactly one real cube root, so the domain is R:\R\mathclose{\text{:}} 83=2\sqrt[3]{8} = 2 and −83=−2.\sqrt[3]{-8} = -2\mathclose{\text{.}} In general the nnth root xn\sqrt[n]{x} is defined for every xx when nn is odd, and for x≥0x \ge 0 when nn is even. Roots are powers with fractional exponents: x1/n=xnx^{1/n} = \sqrt[n]{x} and xm/n=(xn)mx^{m/n} = \big(\sqrt[n]{x}\big)^m (with m/nm/n in lowest terms), so 82/3=22=4.8^{2/3} = 2^2 = 4\mathclose{\text{.}} For a negative x,x\mathclose{\text{,}} this series follows most calculus books and reads x1/3x^{1/3} as the real cube root; Python and SymPy do not, as Section 1.7 shows.

Watch out

x2\sqrt{x^2} is not always x.x\mathclose{\text{.}} For x=−3,x = -3\mathclose{\text{,}} (−3)2=9=3.\sqrt{(-3)^2} = \sqrt9 = 3\mathclose{\text{.}} The square root is never negative, so

x2=∣x∣for every real x,\sqrt{x^2} = \abs{x} \quad \text{for every real } x,

and x2=x\sqrt{x^2} = x only when x≥0.x \ge 0\mathclose{\text{.}} Nor do roots split over sums: 9+16=25=5,\sqrt{9 + 16} = \sqrt{25} = 5\mathclose{\text{,}} not 9+16=7.\sqrt9 + \sqrt{16} = 7\mathclose{\text{.}}

Exponential functions

In a power function such as x2x^2 the variable is the base. Put it in the exponent instead and you get an exponential function f(x)=ax,f(x) = a^x\mathclose{\text{,}} with a fixed base a>0.a > 0\mathclose{\text{.}} The laws of exponents hold for all bases a,b>0a, b > 0 and all real numbers xx and y:y\mathclose{\text{:}}

ax+y=axay,ax−y=axay,a0=1,(ax)y=axy,(ab)x=axbx,a−x=1ax.\begin{aligned} a^{x+y} &= a^x a^y, & a^{x-y} &= \frac{a^x}{a^y}, & a^0 &= 1, \\ (a^x)^y &= a^{xy}, & (ab)^x &= a^x b^x, & a^{-x} &= \frac{1}{a^x}. \end{aligned}

For whole-number exponents they follow from counting factors, as in 23⋅22=(2⋅2⋅2)(2⋅2)=25;2^3 \cdot 2^2 = (2 \cdot 2 \cdot 2)(2 \cdot 2) = 2^5\mathclose{\text{;}} fractional exponents are roots, a1/2=a;a^{1/2} = \sqrt a\mathclose{\text{;}} and for an irrational exponent such as 2=1.41421…,\sqrt2 = 1.41421\ldots\mathclose{\text{,}} a2a^{\sqrt2} is the number that a1.4,a1.41,a1.414,…a^{1.4}, a^{1.41}, a^{1.414}, \dots approach. So axa^x is defined, and positive, for every real x.x\mathclose{\text{.}}

If a>1,a > 1\mathclose{\text{,}} axa^x grows: 2x2^x doubles with every step of 1 in x.x\mathclose{\text{.}} If 0<a<1,0 < a < 1\mathclose{\text{,}} it decays: (12)x(\tfrac12)^x halves with every step. Every exponential passes through (0,1),(0, 1)\mathclose{\text{,}} because a0=1.a^0 = 1\mathclose{\text{.}} For a≠1a \ne 1 the domain is R\R and the range is (0,∞).(0, \infty)\mathclose{\text{.}}

The number e. One base is special: the number

e=2.718281828…,e = 2.718281828\ldots,

known as Euler’s number. Like π\pi it is irrational: its decimals never end and never repeat. The function ex,e^x\mathclose{\text{,}} read “e to the x”, is called the exponential function, because the formulas of calculus are simplest with base e;e\mathclose{\text{;}} Module 6 shows where ee comes from and why. For now, ee is a number between 2 and 3, e≈2.71828,e \approx 2.71828\mathclose{\text{,}} so the graph of exe^x lies between those of 2x2^x and 3x.3^x\mathclose{\text{.}}

xx2x2^xexe^x(12)x(\tfrac12)^x
−2-20.250.250.135340.1353444
−1-10.50.50.367880.3678822
00111111
11222.71832.71830.50.5
22447.38917.38910.250.25
338820.08620.0860.1250.125
Example 1.6A doubling model✓ Checked

Suppose a colony of bacteria starts with 1000 cells and doubles every 3 hours. (The numbers are made up, but real colonies grow like this while food and space last.) After tt hours it has

N(t)=1000⋅2t/3N(t) = 1000 \cdot 2^{t/3}

cells. Find N(0),N(0)\mathclose{\text{,}} N(3),N(3)\mathclose{\text{,}} N(12)N(12) and N(1),N(1)\mathclose{\text{,}} and show that N(t+3)=2N(t)N(t + 3) = 2N(t) for every t.t\mathclose{\text{.}}

N(0)=1000⋅20=1000,N(0) = 1000 \cdot 2^0 = 1000\mathclose{\text{,}} N(3)=1000⋅21=2000N(3) = 1000 \cdot 2^1 = 2000 and N(12)=1000⋅24=16,000.N(12) = 1000 \cdot 2^4 = 16{,}000\mathclose{\text{.}} For N(1)N(1) you need a calculator: N(1)=1000⋅21/3≈1259.9,N(1) = 1000 \cdot 2^{1/3} \approx 1259.9\mathclose{\text{,}} about 1260 cells.

By the first law of exponents,

N(t+3)=1000⋅2(t+3)/3=1000⋅2t/3+1=1000⋅2t/3⋅2=2N(t).\begin{aligned} N(t + 3) &= 1000 \cdot 2^{(t+3)/3} = 1000 \cdot 2^{t/3 + 1} \\ &= 1000 \cdot 2^{t/3} \cdot 2 = 2N(t). \end{aligned}

So the colony doubles every 3 hours, whenever you start the clock. That is the signature of exponential growth: equal steps in time multiply the quantity by equal factors.

Watch out

Two classic slips. First, x2x^2 and 2x2^x are different functions: in x2x^2 the variable is the base, in 2x2^x it is the exponent, and at x=10x = 10 they are 100 and 1024. Second, exponents do not split over sums: 2x+3=2x⋅23=8⋅2x,2^{x+3} = 2^x \cdot 2^3 = 8 \cdot 2^x\mathclose{\text{,}} not 2x+23.2^x + 2^3\mathclose{\text{.}}

Logarithms

The exponential function answers questions like “what is 25?2^5\mathclose{\text{?}}” The logarithm answers the reverse question: “what power of 2 gives 32?”

Definition 1.6Logarithm

Let a>0a > 0 with a≠1.a \ne 1\mathclose{\text{.}} For x>0,x > 0\mathclose{\text{,}} the logarithm of xx to base aa, written log⁡ax\log_a x and read “log to base a of x”, is the number yy with ay=x:a^y = x\mathclose{\text{:}}

log⁡ax=ymeansay=x.\log_a x = y \quad\text{means}\quad a^y = x.

The natural logarithm ln⁡x,\ln x\mathclose{\text{,}} read “the natural log of x”, is the logarithm to base e:e\mathclose{\text{:}} ln⁡x=y\ln x = y means ey=x.e^y = x\mathclose{\text{.}}

For example, log⁡232=5\log_2 32 = 5 because 25=32;2^5 = 32\mathclose{\text{;}} log⁡101000=3;\log_{10} 1000 = 3\mathclose{\text{;}} log⁡214=−2\log_2 \tfrac14 = -2 because 2−2=14;2^{-2} = \tfrac14\mathclose{\text{;}} ln⁡1=0\ln 1 = 0 because e0=1;e^0 = 1\mathclose{\text{;}} and ln⁡e=1.\ln e = 1\mathclose{\text{.}} Since aya^y is always positive, the logarithm of 0 or of a negative number is not defined: the domain of ln⁡\ln is (0,∞),(0, \infty)\mathclose{\text{,}} and its range is R.\R\mathclose{\text{.}}

The logarithm undoes the exponential, and the exponential undoes the logarithm:

eln⁡x=xfor x>0,ln⁡ ⁣(ey)=yfor every real y.\begin{aligned} e^{\ln x} &= x \quad \text{for } x > 0, \\ \ln\!\big(e^{y}\big) &= y \quad \text{for every real } y. \end{aligned}

In the language of Section 1.5, ln⁡\ln is the inverse function of ex,e^x\mathclose{\text{,}} and the graph of ln⁡x\ln x is the graph of exe^x reflected in the line y=xy = x (Figure 1.3).

Theorem 1.1Laws of logarithms

For all x>0,x > 0\mathclose{\text{,}} y>0y > 0 and every real number r:r\mathclose{\text{:}}

ln⁡(xy)=ln⁡x+ln⁡y,ln⁡xy=ln⁡x−ln⁡y,ln⁡(xr)=rln⁡x.\begin{aligned} \ln(xy) &= \ln x + \ln y, \\ \ln\frac{x}{y} &= \ln x - \ln y, \\ \ln\big(x^r\big) &= r\ln x. \end{aligned}

The same laws hold for log⁡a,\log_a\mathclose{\text{,}} for any base a>0a > 0 with a≠1.a \ne 1\mathclose{\text{.}}

Proof

Let p=ln⁡xp = \ln x and q=ln⁡y,q = \ln y\mathclose{\text{,}} so that ep=xe^p = x and eq=y.e^q = y\mathclose{\text{.}} By the laws of exponents, ep+q=epeq=xy.e^{p+q} = e^p e^q = xy\mathclose{\text{.}} So p+qp + q is the power of ee that gives xy,xy\mathclose{\text{,}} which is what ln⁡(xy)=p+q\ln(xy) = p + q says. In the same way, ep−q=ep/eq=x/ye^{p-q} = e^p/e^q = x/y gives the second law, and erp=(ep)r=xre^{rp} = (e^p)^r = x^r gives the third. The same argument works with any base aa in place of e.e\mathclose{\text{.}}

∎

Two consequences follow. To convert between bases, write y=log⁡ax,y = \log_a x\mathclose{\text{,}} so that ay=x;a^y = x\mathclose{\text{;}} take ln⁡\ln of both sides and use the third law: yln⁡a=ln⁡x.y \ln a = \ln x\mathclose{\text{.}} Since a≠1,a \ne 1\mathclose{\text{,}} ln⁡a≠0,\ln a \ne 0\mathclose{\text{,}} and

log⁡ax=ln⁡xln⁡a.\log_a x = \frac{\ln x}{\ln a}.

And to solve an equation with the unknown in an exponent, take logarithms of both sides (Example 1.7).

In computing, log⁡2n\log_2 n counts halvings. Binary search in a sorted list of nn items halves the part still to be searched at every step, so it takes about log⁡2n\log_2 n steps: only about 20 for a million items, since log⁡2106≈19.93.\log_2 10^6 \approx 19.93\mathclose{\text{.}}

Example 1.7Solving an exponential equation✓ Checked

When does the colony of Example 1.6 reach 10,000 cells?

Solve 1000⋅2t/3=10,000.1000 \cdot 2^{t/3} = 10{,}000\mathclose{\text{.}} Divide by 1000: 2t/3=10.2^{t/3} = 10\mathclose{\text{.}} Take the natural logarithm of both sides and use the third law:

t3ln⁡2=ln⁡10,sot=3ln⁡10ln⁡2≈9.966.\frac{t}{3}\ln 2 = \ln 10, \quad\text{so}\quad t = \frac{3\ln 10}{\ln 2} \approx 9.966.

The colony passes 10,000 cells after about 9.97 hours, a little under 10 hours. Check: 9.966/3=3.322,9.966/3 = 3.322\mathclose{\text{,}} and 23.322≈10.00.2^{3.322} \approx 10.00\mathclose{\text{.}}

Watch out

The laws of logarithms are about products, quotients and powers, not sums: ln⁡(x+y)\ln(x + y) is not ln⁡x+ln⁡y,\ln x + \ln y\mathclose{\text{,}} and ln⁡xln⁡y\dfrac{\ln x}{\ln y} is not ln⁡xy.\ln\dfrac{x}{y}\mathclose{\text{.}} The laws also need positive inputs: for every x≠0,x \ne 0\mathclose{\text{,}} ln⁡(x2)=2ln⁡∣x∣,\ln(x^2) = 2\ln\abs{x}\mathclose{\text{,}} which is not 2ln⁡x2\ln x when x<0,x < 0\mathclose{\text{,}} where ln⁡x\ln x is not even defined. Watch the notation too: some books and calculators write log⁡x\log x for log⁡10x,\log_{10} x\mathclose{\text{,}} while others, and Python, write log⁡x\log x for ln⁡x.\ln x\mathclose{\text{.}} This series always writes the base, except in ln⁡.\ln\mathclose{\text{.}}

Trigonometric functions

School trigonometry measures angles in degrees. Calculus measures them in radians.

Definition 1.7Radian

The unit circle is the circle of radius 1 centred at the origin. An angle at its centre that cuts off an arc of length θ\theta on the unit circle measures θ\theta radians. (The letter θ\theta is the Greek “theta”.) Angles are measured from the positive xx-axis, anticlockwise for positive angles and clockwise for negative ones.

The circumference of the unit circle is 2π,2\pi\mathclose{\text{,}} so a full turn is 2π2\pi radians: 360∘=2π360^\circ = 2\pi and 180∘=π.180^\circ = \pi\mathclose{\text{.}} To convert degrees to radians, multiply by π/180.\pi/180\mathclose{\text{.}} So 90∘=π/2,90^\circ = \pi/2\mathclose{\text{,}} 60∘=π/3,60^\circ = \pi/3\mathclose{\text{,}} 45∘=π/445^\circ = \pi/4 and 30∘=π/6,30^\circ = \pi/6\mathclose{\text{,}} and one radian is 180∘/π≈57.30∘.180^\circ/\pi \approx 57.30^\circ\mathclose{\text{.}}

Radians make calculus simplest: for a small angle θ\theta in radians, sin⁡θ\sin\theta is almost exactly θ\theta (sin⁡0.01≈0.0099998),\sin 0.01 \approx 0.0099998\mathclose{\text{),}} and Module 5 shows that the rate of change of sin⁡x\sin x is then cos⁡x,\cos x\mathclose{\text{,}} with no stray factor π/180.\pi/180\mathclose{\text{.}} From now on, angles are in radians unless a page says otherwise.

Definition 1.8Sine and cosine

Let θ\theta be any real number, and let PP be the point of the unit circle reached by turning from (1,0)(1, 0) through θ\theta radians. Then cos⁡θ,\cos\theta\mathclose{\text{,}} the cosine of θ,\theta\mathclose{\text{,}} is the xx-coordinate of P,P\mathclose{\text{,}} and sin⁡θ,\sin\theta\mathclose{\text{,}} the sine of θ,\theta\mathclose{\text{,}} is its yy-coordinate:

P=(cos⁡θ,sin⁡θ).P = (\cos\theta, \sin\theta).

The other four trigonometric functions are defined from these two, wherever the denominator is not 0:

tan⁡θ=sin⁡θcos⁡θ,cot⁡θ=cos⁡θsin⁡θ,sec⁡θ=1cos⁡θ,csc⁡θ=1sin⁡θ.\begin{aligned} \tan\theta &= \frac{\sin\theta}{\cos\theta}, & \cot\theta &= \frac{\cos\theta}{\sin\theta}, \\ \sec\theta &= \frac{1}{\cos\theta}, & \csc\theta &= \frac{1}{\sin\theta}. \end{aligned}

They are read “tangent”, “cotangent”, “secant” and “cosecant” (the first and third share their names with the lines of Section 1.1). For 0<θ<π/2,0 < \theta < \pi/2\mathclose{\text{,}} the origin, PP and the point (cos⁡θ,0)(\cos\theta, 0) below it form a right triangle with hypotenuse 1, so these definitions agree with the school ones, “opposite over hypotenuse” and “adjacent over hypotenuse”; but the unit-circle definition works for every angle.

Left: the point P at angle theta on the unit circle has coordinates (costheta, sintheta); the orange arc has length theta. Right: the graphs of sin x and cos x. The blue segment has height sintheta in both panels: as P goes round the circle, its height traces the sine curve.
Figure 1.4

Left: the point PP at angle θ\theta on the unit circle has coordinates (cos⁡θ,sin⁡θ);(\cos\theta, \sin\theta)\mathclose{\text{;}} the orange arc has length θ.\theta\mathclose{\text{.}} Right: the graphs of sin⁡x\sin x and cos⁡x.\cos x\mathclose{\text{.}} The blue segment has height sin⁡θ\sin\theta in both panels: as PP goes round the circle, its height traces the sine curve.

Everything about sine and cosine can be read from the circle:

  • Range. PP is on a circle of radius 1, so the domain of sin⁡\sin and of cos⁡\cos is R\R and their range is [−1,1].[-1, 1]\mathclose{\text{.}}
  • The Pythagorean identity. PP lies on the circle x2+y2=1,x^2 + y^2 = 1\mathclose{\text{,}} so for every θ\theta
    sin⁡2θ+cos⁡2θ=1,\sin^2\theta + \cos^2\theta = 1,
    where sin⁡2θ\sin^2\theta means (sin⁡θ)2.(\sin\theta)^2\mathclose{\text{.}}
  • Periodicity. Adding 2π2\pi to θ\theta takes PP once round the circle, so sin⁡(θ+2π)=sin⁡θ\sin(\theta + 2\pi) = \sin\theta and cos⁡(θ+2π)=cos⁡θ:\cos(\theta + 2\pi) = \cos\theta\mathclose{\text{:}} sine and cosine are periodic with period 2π2\pi (Figure 1.4). The tangent has period π\pi (the formulas for π+θ\pi + \theta below show why); it is undefined where cos⁡θ=0,\cos\theta = 0\mathclose{\text{,}} at θ=π/2+kπ\theta = \pi/2 + k\pi for every integer k.k\mathclose{\text{.}}
  • Symmetry. Turning through −θ-\theta gives the mirror image of PP in the xx-axis, so cos⁡(−θ)=cos⁡θ\cos(-\theta) = \cos\theta and sin⁡(−θ)=−sin⁡θ:\sin(-\theta) = -\sin\theta\mathclose{\text{:}} cosine is even and sine is odd.

The exact values at the standard angles come from two triangles of school geometry, each with hypotenuse 1. Cutting a square along a diagonal gives a right triangle with two angles of π/4;\pi/4\mathclose{\text{;}} its two shorter sides are equal, say s,s\mathclose{\text{,}} and Pythagoras’ theorem gives 2s2=1,2s^2 = 1\mathclose{\text{,}} so s=1/2=2/2.s = 1/\sqrt2 = \sqrt2/2\mathclose{\text{.}} Cutting an equilateral triangle with sides 1 in half gives a right triangle with angles π/6\pi/6 and π/3;\pi/3\mathclose{\text{;}} its shortest side, opposite π/6,\pi/6\mathclose{\text{,}} is 12,\tfrac12\mathclose{\text{,}} and Pythagoras’ theorem gives the third side, 1−14=3/2.\sqrt{1 - \tfrac14} = \sqrt3/2\mathclose{\text{.}} Opposite over hypotenuse and adjacent over hypotenuse then give the middle three rows of the table; the first and last rows are the points (1,0)(1, 0) and (0,1)(0, 1) of the unit circle:

θ\theta sin⁡θ\sin\theta cos⁡θ\cos\theta tan⁡θ\tan\theta
00 00 11 00
π/6\pi/6 1/21/2 3/2\sqrt3/2 1/31/\sqrt3
π/4\pi/4 2/2\sqrt2/2 2/2\sqrt2/2 11
π/3\pi/3 3/2\sqrt3/2 1/21/2 3\sqrt3
π/2\pi/2 11 00 undefined

For other angles, use the symmetry of the circle. The point at angle π−θ\pi - \theta is the mirror image in the yy-axis of the point at angle θ,\theta\mathclose{\text{,}} and the point at angle π+θ\pi + \theta is its reflection through the origin, so

sin⁡(π−θ)=sin⁡θ,cos⁡(π−θ)=−cos⁡θ,sin⁡(π+θ)=−sin⁡θ,cos⁡(π+θ)=−cos⁡θ.\begin{aligned} \sin(\pi - \theta) &= \sin\theta, & \cos(\pi - \theta) &= -\cos\theta, \\ \sin(\pi + \theta) &= -\sin\theta, & \cos(\pi + \theta) &= -\cos\theta. \end{aligned}
Example 1.8Exact values at 2π/32\pi/3✓ Checked

Find the exact values of sin⁡,\sin\mathclose{\text{,}} cos⁡\cos and tan⁡\tan at θ=2π/3,\theta = 2\pi/3\mathclose{\text{,}} and the point of the unit circle at that angle.

2π/32\pi/3 is 120∘,120^\circ\mathclose{\text{,}} and 2π/3=π−π/3.2\pi/3 = \pi - \pi/3\mathclose{\text{.}} By the mirror symmetry in the yy-axis,

sin⁡2π3=sin⁡π3=32,cos⁡2π3=−cos⁡π3=−12,\begin{aligned} \sin\frac{2\pi}{3} &= \sin\frac{\pi}{3} = \frac{\sqrt3}{2}, \\ \cos\frac{2\pi}{3} &= -\cos\frac{\pi}{3} = -\frac12, \end{aligned}

so

tan⁡2π3=3/2−1/2=−3.\tan\frac{2\pi}{3} = \frac{\sqrt3/2}{-1/2} = -\sqrt3.

The point is (−12,32):\big(-\tfrac12, \tfrac{\sqrt3}{2}\big)\mathclose{\text{:}} left of the yy-axis and above the xx-axis, as an angle of 120∘120^\circ should be. Check with the Pythagorean identity: (32)2+(−12)2=34+14=1.\big(\tfrac{\sqrt3}{2}\big)^2 + \big(-\tfrac12\big)^2 = \tfrac34 + \tfrac14 = 1\mathclose{\text{.}}

Good to know

Two identities from school trigonometry, the addition formulas, are used from Module 5 on:

sin⁡(x+y)=sin⁡xcos⁡y+cos⁡xsin⁡y,cos⁡(x+y)=cos⁡xcos⁡y−sin⁡xsin⁡y.\begin{aligned} \sin(x + y) &= \sin x\cos y + \cos x\sin y, \\ \cos(x + y) &= \cos x\cos y - \sin x\sin y. \end{aligned}
Watch out

Three common slips with trigonometric functions. A calculator in degree mode gives sin⁡30=0.5;\sin 30 = 0.5\mathclose{\text{;}} in radians, sin⁡30≈−0.988,\sin 30 \approx -0.988\mathclose{\text{,}} since 30 radians is almost five turns. sin⁡x2\sin x^2 means sin⁡(x2),\sin(x^2)\mathclose{\text{,}} while sin⁡2x\sin^2 x means (sin⁡x)2.(\sin x)^2\mathclose{\text{.}} And sin⁡(x+y)\sin(x + y) is not sin⁡x+sin⁡y:\sin x + \sin y\mathclose{\text{:}} use the addition formula.

5

New functions from old

Shifting and stretching graphs

Compare f(x)=x2f(x) = x^2 with g(x)=(x−2)2.g(x) = (x - 2)^2\mathclose{\text{.}} At x=5,x = 5\mathclose{\text{,}} gg gives 32=9,3^2 = 9\mathclose{\text{,}} the value that ff has at x=3;x = 3\mathclose{\text{;}} at x=2,x = 2\mathclose{\text{,}} gg gives 0, the value of ff at 0. In general g(x)=f(x−2):g(x) = f(x - 2)\mathclose{\text{:}} gg does at xx what ff did two units earlier. So the whole graph moves 2 units to the right.

Each simple change to a formula moves the graph in a simple way. For a constant c>0:c > 0\mathclose{\text{:}}

Formula The graph of y=f(x)y = f(x) is
f(x)+c,f(x) + c\mathclose{\text{,}} f(x)−cf(x) - c shifted up, down by cc
f(x−c),f(x - c)\mathclose{\text{,}} f(x+c)f(x + c) shifted right, left by cc
c f(x)c\,f(x) stretched vertically by the factor cc (squashed if c<1)c < 1\mathclose{\text{)}}
f(cx)f(cx) squashed horizontally by the factor cc (stretched if c<1)c < 1\mathclose{\text{)}}
−f(x)-f(x) reflected in the xx-axis
f(−x)f(-x) reflected in the yy-axis

Changes outside ff act the way they look. Changes inside ff act the opposite way, because the new function reaches each value of ff at a different x:x\mathclose{\text{:}} f(x−c)f(x - c) moves the graph right, and f(2x)f(2x) reaches the value that ff has at 6 already at x=3,x = 3\mathclose{\text{,}} so everything happens twice as early and the graph is squashed towards the yy-axis.

Try it

Choose a function, then move one slider at a time: the sliders give y=a f(b(x−c))+d,y = a\,f\big(b(x - c)\big) + d\mathclose{\text{,}} and the dashed curve is the original y=f(x).y = f(x)\mathclose{\text{.}} Predict each move before you make it. With f(x)=x2,f(x) = x^2\mathclose{\text{,}} set c=1,c = 1\mathclose{\text{,}} then d=2,d = 2\mathclose{\text{,}} and follow the bottom of the U; set a=−1a = -1 to flip the graph. Press Reset, choose sin⁡x\sin x and set b=2:b = 2\mathclose{\text{:}} two waves now fit where there was one. Then build the function of Example 1.9.

Example 1.9Building a graph from y=x2y = x^2✓ Checked

Describe how to obtain the graph of g(x)=−(x+2)2+4g(x) = -(x + 2)^2 + 4 from the graph of y=x2.y = x^2\mathclose{\text{.}} Find the highest point of the graph of g,g\mathclose{\text{,}} its zeros and the range of g.g\mathclose{\text{.}}

Build gg in three steps, following the bottom point (0,0)(0, 0) of the parabola:

  1. (x+2)2(x + 2)^2 is x2x^2 with x+2x + 2 in place of x:x\mathclose{\text{:}} shift left by 2. The point (0,0)(0, 0) moves to (−2,0).(-2, 0)\mathclose{\text{.}}
  2. −(x+2)2:-(x + 2)^2\mathclose{\text{:}} reflect in the xx-axis. The parabola now opens downwards, and (−2,0)(-2, 0) stays where it is.
  3. −(x+2)2+4:-(x + 2)^2 + 4\mathclose{\text{:}} shift up by 4. The point moves to (−2,4).(-2, 4)\mathclose{\text{.}}

So the graph is an upside-down parabola with its highest point at (−2,4).(-2, 4)\mathclose{\text{.}} For the zeros, −(x+2)2+4=0-(x + 2)^2 + 4 = 0 means (x+2)2=4,(x + 2)^2 = 4\mathclose{\text{,}} so x+2=2x + 2 = 2 or x+2=−2,x + 2 = -2\mathclose{\text{,}} that is, x=0x = 0 or x=−4.x = -4\mathclose{\text{.}} Since (x+2)2≥0,(x + 2)^2 \ge 0\mathclose{\text{,}} every value of gg is at most 4. Conversely, every number y≤4y \le 4 is a value: g(x)=yg(x) = y means (x+2)2=4−y,(x + 2)^2 = 4 - y\mathclose{\text{,}} which holds at x=−2+4−y.x = -2 + \sqrt{4 - y}\mathclose{\text{.}} So the range is (−∞,4].(-\infty, 4]\mathclose{\text{.}} In the explorer: f(x)=x2,f(x) = x^2\mathclose{\text{,}} a=−1,a = -1\mathclose{\text{,}} c=−2,c = -2\mathclose{\text{,}} d=4.d = 4\mathclose{\text{.}}

Watch out

f(x−3)f(x - 3) moves the graph 3 units to the right, not to the left: the minus sign inside ff works against intuition. Check with one point: the value f(0)f(0) is now reached at x=3.x = 3\mathclose{\text{.}}

Composition

To compute x2+1,\sqrt{x^2 + 1}\mathclose{\text{,}} you first square and add 1, then take the square root: the function is a chain of two simpler ones, g(x)=x2+1g(x) = x^2 + 1 followed by f(u)=u.f(u) = \sqrt u\mathclose{\text{.}}

Definition 1.9Composition

The composition f∘g,f \circ g\mathclose{\text{,}} read “f composed with g” or “f after g”, is the function

(f∘g)(x)=f(g(x)).(f \circ g)(x) = f\big(g(x)\big).

Its domain is the set of all xx in the domain of gg for which g(x)g(x) is in the domain of f.f\mathclose{\text{.}}

The function written next to xx acts first: in f∘g,f \circ g\mathclose{\text{,}} first g,g\mathclose{\text{,}} then f.f\mathclose{\text{.}} In a program, composition is a pipeline in which the output of one function becomes the input of the next; a neural network is a long composition of simple functions, its layers.

Example 1.10Composition in both orders✓ Checked

Let f(x)=xf(x) = \sqrt{x} and g(x)=x−3.g(x) = x - 3\mathclose{\text{.}} Find f∘gf \circ g and g∘fg \circ f with their domains, and evaluate both at x=7.x = 7\mathclose{\text{.}}

(f∘g)(x)=f(x−3)=x−3.(f \circ g)(x) = f(x - 3) = \sqrt{x - 3}\mathclose{\text{.}} Here gg accepts every x,x\mathclose{\text{,}} and ff needs its input x−3x - 3 to be at least 0, so the domain is [3,∞).[3, \infty)\mathclose{\text{.}}

(g∘f)(x)=g(x)=x−3.(g \circ f)(x) = g(\sqrt x) = \sqrt x - 3\mathclose{\text{.}} Here ff needs x≥0,x \ge 0\mathclose{\text{,}} and gg accepts any input, so the domain is [0,∞).[0, \infty)\mathclose{\text{.}}

At x=7:x = 7\mathclose{\text{:}} (f∘g)(7)=4=2,(f \circ g)(7) = \sqrt4 = 2\mathclose{\text{,}} while (g∘f)(7)=7−3≈−0.354.(g \circ f)(7) = \sqrt7 - 3 \approx -0.354\mathclose{\text{.}} The two orders give different functions, with different domains: in composition, order matters.

Seeing a complicated function as a composition is a skill that the chain rule of Module 5 depends on. For example, h(x)=(2x+1)5h(x) = (2x + 1)^5 is f(g(x))f\big(g(x)\big) with inner function g(x)=2x+1g(x) = 2x + 1 and outer function f(u)=u5;f(u) = u^5\mathclose{\text{;}} and e−x2e^{-x^2} is f(g(x))f\big(g(x)\big) with g(x)=−x2g(x) = -x^2 and f(u)=eu.f(u) = e^u\mathclose{\text{.}}

Watch out

The domain of a composition comes from its pieces, not from the simplified formula. With f(x)=x2f(x) = x^2 and g(x)=x,g(x) = \sqrt x\mathclose{\text{,}} (f∘g)(x)=(x)2=x,(f \circ g)(x) = (\sqrt x)^2 = x\mathclose{\text{,}} but only for x≥0:x \ge 0\mathclose{\text{:}} g(−4)g(-4) is not defined, so neither is f(g(−4)).f\big(g(-4)\big)\mathclose{\text{.}}

Inverse functions

The formula F=1.8C+32F = 1.8C + 32 turns degrees Celsius into degrees Fahrenheit, and C=(F−32)/1.8C = (F - 32)/1.8 turns them back: 100 °C becomes 212 °F, and 212 °F becomes 100 °C again. Each formula undoes the other. Not every function can be undone: x2x^2 sends both 2 and −2-2 to 4, so the output 4 does not tell you the input.

Definition 1.10One-to-one function

A function ff is one-to-one if different inputs always give different outputs: whenever x1≠x2,x_1 \ne x_2\mathclose{\text{,}} f(x1)≠f(x2).f(x_1) \ne f(x_2)\mathclose{\text{.}}

A horizontal line y=ky = k meets the graph of ff where f(x)=k,f(x) = k\mathclose{\text{,}} so ff is one-to-one exactly when no horizontal line meets its graph more than once: the horizontal line test. x3x^3 and exe^x pass it; x2x^2 and sin⁡x\sin x fail it.

Definition 1.11Inverse function

Let ff be a one-to-one function with domain DD and range R.R\mathclose{\text{.}} Its inverse function f−1,f^{-1}\mathclose{\text{,}} read “f inverse”, has domain RR and range D,D\mathclose{\text{,}} and is defined by

f−1(y)=xexactly whenf(x)=y.f^{-1}(y) = x \quad\text{exactly when}\quad f(x) = y.

In words, f−1f^{-1} sends each output of ff back to the input it came from. So the two undo each other:

f−1(f(x))=xfor every x in D,f(f−1(y))=yfor every y in R.\begin{aligned} f^{-1}\big(f(x)\big) &= x \quad \text{for every } x \text{ in } D, \\ f\big(f^{-1}(y)\big) &= y \quad \text{for every } y \text{ in } R. \end{aligned}

exe^x and ln⁡x\ln x are the pair you met in Section 1.4: ln⁡(ex)=x\ln(e^x) = x for every real x,x\mathclose{\text{,}} and eln⁡y=ye^{\ln y} = y for every y>0.y > 0\mathclose{\text{.}}

Watch out

f−1(x)f^{-1}(x) does not mean 1f(x):\dfrac{1}{f(x)}\mathclose{\text{:}} here the −1-1 is not an exponent but part of the name of the inverse. For f(x)=2x,f(x) = 2x\mathclose{\text{,}} f−1(x)=x/2,f^{-1}(x) = x/2\mathclose{\text{,}} while 1/f(x)=1/(2x).1/f(x) = 1/(2x)\mathclose{\text{.}} When you mean the reciprocal, write 1f(x)\dfrac{1}{f(x)} or (f(x))−1.\big(f(x)\big)^{-1}\mathclose{\text{.}}

To find a formula for f−1,f^{-1}\mathclose{\text{,}} write y=f(x)y = f(x) and solve for x.x\mathclose{\text{.}} If each yy in the range comes from exactly one x,x\mathclose{\text{,}} then ff is one-to-one and the solution is x=f−1(y).x = f^{-1}(y)\mathclose{\text{.}} At the end, rename yy as x,x\mathclose{\text{,}} so that xx is the input of f−1f^{-1} as usual.

Example 1.11Finding an inverse✓ Checked

Show that f(x)=x+1x−2,f(x) = \dfrac{x + 1}{x - 2}\mathclose{\text{,}} with x≠2,x \ne 2\mathclose{\text{,}} is one-to-one, and find its range and its inverse.

Write y=x+1x−2y = \dfrac{x + 1}{x - 2} and solve for x.x\mathclose{\text{.}} Multiply both sides by x−2,x - 2\mathclose{\text{,}} collect the terms with xx on the left, and factor:

y(x−2)=x+1yx−x=2y+1x(y−1)=2y+1.\begin{aligned} y(x - 2) &= x + 1 \\ yx - x &= 2y + 1 \\ x(y - 1) &= 2y + 1. \end{aligned}

If y=1,y = 1\mathclose{\text{,}} the last line says 0=3,0 = 3\mathclose{\text{,}} which is impossible: the value 1 is never reached. If y≠1,y \ne 1\mathclose{\text{,}} divide by y−1:y - 1\mathclose{\text{:}}

x=2y+1y−1.x = \frac{2y + 1}{y - 1}.

This xx is never 2 (that would need 2y+1=2y−2,2y + 1 = 2y - 2\mathclose{\text{,}} that is, 1=−2),1 = -2\mathclose{\text{),}} so it is in the domain. Each y≠1y \ne 1 therefore comes from exactly one x:x\mathclose{\text{:}} ff is one-to-one, its range is (−∞,1)∪(1,∞),(-\infty, 1) \cup (1, \infty)\mathclose{\text{,}} and, renaming yy as x,x\mathclose{\text{,}}

f−1(x)=2x+1x−1,x≠1.f^{-1}(x) = \frac{2x + 1}{x - 1}, \qquad x \ne 1.

Check one value: f(3)=4/1=4,f(3) = 4/1 = 4\mathclose{\text{,}} and f−1(4)=9/3=3.f^{-1}(4) = 9/3 = 3\mathclose{\text{.}}

The graph of an inverse comes free with the graph of f.f\mathclose{\text{.}}

Theorem 1.2The graph of an inverse

If ff is one-to-one, the graph of f−1f^{-1} is the reflection of the graph of ff in the line y=x.y = x\mathclose{\text{.}}

Proof

A point (p,q)(p, q) lies on the graph of ff exactly when f(p)=q,f(p) = q\mathclose{\text{,}} that is, exactly when f−1(q)=p,f^{-1}(q) = p\mathclose{\text{,}} that is, exactly when (q,p)(q, p) lies on the graph of f−1.f^{-1}\mathclose{\text{.}} So the graph of f−1f^{-1} consists of the points of the graph of ff with their coordinates swapped. Swapping the coordinates is reflection in the line y=x:y = x\mathclose{\text{:}} if p≠q,p \ne q\mathclose{\text{,}} the midpoint (p+q2,p+q2)\big(\tfrac{p+q}{2}, \tfrac{p+q}{2}\big) of (p,q)(p, q) and (q,p)(q, p) lies on the line, and the segment joining them has slope p−qq−p=−1,\tfrac{p - q}{q - p} = -1\mathclose{\text{,}} so it is perpendicular to the line, whose slope is 1. If p=q,p = q\mathclose{\text{,}} the point is on the line and is its own mirror image.

∎

A function that fails the horizontal line test can often be made one-to-one by restricting its domain: on [0,∞),[0, \infty)\mathclose{\text{,}} x2x^2 is one-to-one, and its inverse is x.\sqrt x\mathclose{\text{.}} Reflecting the right half of the parabola in y=xy = x gives the half parabola lying on its side.

6

Average rates of change

Back to the falling ball and its table in Section 1.3. Between t=1t = 1 and t=3t = 3 it falls s(3)−s(1)=44.1−4.9=39.2s(3) - s(1) = 44.1 - 4.9 = 39.2 metres in 2 seconds, an average speed of 39.2/2=19.639.2/2 = 19.6 metres per second (m/s). Between t=1t = 1 and t=2t = 2 it falls 19.6−4.9=14.719.6 - 4.9 = 14.7 metres in 1 second: 14.7 m/s. The ball is speeding up, so the average depends on the interval. What is its speed at the instant t=1,t = 1\mathclose{\text{,}} the number a speedometer on the ball would show?

Definition 1.12Average rate of change

The average rate of change of ff over the interval [a,b][a, b] is

f(b)−f(a)b−a=ΔyΔx.\frac{f(b) - f(a)}{b - a} = \frac{\Delta y}{\Delta x}.

Δ\Delta is the Greek capital delta, used for “change in”: Δx=b−a\Delta x = b - a is the change in the input, Δy=f(b)−f(a)\Delta y = f(b) - f(a) the change in the output, and Δy/Δx\Delta y/\Delta x is read “delta y over delta x”. Its units are output units per input unit: metres per second for the ball, degrees per minute for a cooling cup of tea.

Geometrically, Δy/Δx\Delta y/\Delta x is the slope of the secant line through the points (a,f(a))(a, f(a)) and (b,f(b))(b, f(b)) of the graph. For a linear function every secant is the line itself, so the average rate of change over every interval is the slope m.m\mathclose{\text{.}} For a curve it depends on the interval, as Figure 1.5 shows.

The falling ball, s(t) = 4.9t^2. The secant lines from (1, 4.9) to the points at t = 1 + h, for h = 2, 1 and 0.5, have slopes 19.6, 14.7 and 12.25: the average speeds over [1, 3], [1, 2] and [1, 1.5]. As h shrinks, the secants approach the dashed tangent line at t = 1, whose slope is 9.8.
Figure 1.5

The falling ball, s(t)=4.9t2.s(t) = 4.9t^2\mathclose{\text{.}} The secant lines from (1,4.9)(1, 4.9) to the points at t=1+h,t = 1 + h\mathclose{\text{,}} for h=2,h = 2\mathclose{\text{,}} 1 and 0.5, have slopes 19.6, 14.7 and 12.25: the average speeds over [1,3],[1, 3]\mathclose{\text{,}} [1,2][1, 2] and [1,1.5].[1, 1.5]\mathclose{\text{.}} As hh shrinks, the secants approach the dashed tangent line at t=1,t = 1\mathclose{\text{,}} whose slope is 9.8.

The difference quotient

To study rates over shorter and shorter intervals, fix the starting point aa and call the length of the interval h.h\mathclose{\text{.}}

Definition 1.13Difference quotient

For a function f,f\mathclose{\text{,}} a number aa and a number h≠0,h \ne 0\mathclose{\text{,}} with aa and a+ha + h in the domain of f,f\mathclose{\text{,}} the difference quotient is

f(a+h)−f(a)h.\frac{f(a + h) - f(a)}{h}.

It is the average rate of change of ff between aa and a+h:a + h\mathclose{\text{:}} over [a,a+h][a, a + h] if h>0,h > 0\mathclose{\text{,}} and over [a+h,a][a + h, a] if h<0.h < 0\mathclose{\text{.}}

Example 1.12The difference quotient of the falling ball✓ Checked

Simplify the difference quotient of s(t)=4.9t2s(t) = 4.9t^2 at t=1.t = 1\mathclose{\text{.}}

Substitute 1+h1 + h for t,t\mathclose{\text{,}} keeping the brackets, and expand:

s(1+h)=4.9(1+h)2=4.9(1+2h+h2)=4.9+9.8h+4.9h2.\begin{aligned} s(1 + h) &= 4.9(1 + h)^2 \\ &= 4.9(1 + 2h + h^2) \\ &= 4.9 + 9.8h + 4.9h^2. \end{aligned}

Subtract s(1)=4.9:s(1) = 4.9\mathclose{\text{:}} the constant terms cancel, and s(1+h)−s(1)=9.8h+4.9h2.s(1 + h) - s(1) = 9.8h + 4.9h^2\mathclose{\text{.}} Every remaining term contains h,h\mathclose{\text{,}} so dividing by hh (allowed, since h≠0)h \ne 0\mathclose{\text{)}} gives

s(1+h)−s(1)h=9.8h+4.9h2h=9.8+4.9h(h≠0).\begin{aligned} \frac{s(1 + h) - s(1)}{h} &= \frac{9.8h + 4.9h^2}{h} \\ &= 9.8 + 4.9h \qquad (h \ne 0). \end{aligned}

For h=2,h = 2\mathclose{\text{,}} 1 and 0.5 this gives 19.6, 14.7 and 12.25, the slopes in Figure 1.5.

Shrinking the interval

Now let hh shrink. The table shows the change in distance, s(1+h)−s(1),s(1 + h) - s(1)\mathclose{\text{,}} and the average speed over intervals that start at t=1t = 1 (h>0)h > 0\mathclose{\text{)}} or end there (h<0).h < 0\mathclose{\text{).}} For h<0h < 0 the change is negative, because s(1+h)s(1 + h) is the earlier position, and dividing it by the negative hh gives a positive speed:

hhs(1+h)−s(1)s(1+h) - s(1)s(1+h)−s(1)h\dfrac{s(1+h) - s(1)}{h}
1114.714.714.714.7
0.10.11.0291.02910.2910.29
0.010.010.098490.098499.8499.849
0.0010.0010.00980490.00980499.80499.8049
−0.001-0.001−0.0097951-0.00979519.79519.7951
−0.01-0.01−0.09751-0.097519.7519.751
−0.1-0.1−0.931-0.9319.319.31
−1-1−4.9-4.94.94.9

As hh shrinks towards 0, from either side, the average speeds settle down to 9.8 m/s. The formula 9.8+4.9h9.8 + 4.9h of Example 1.12 shows why: the term 4.9h4.9h shrinks to nothing. It is natural to call 9.8 m/s the speed of the ball at the instant t=1,t = 1\mathclose{\text{,}} its instantaneous speed. In Figure 1.5 it is the slope of the tangent line.

Key idea

The instantaneous rate of change is the number that the average rates of change approach as the interval shrinks. You cannot set h=0h = 0 in the difference quotient, which would become 0/0;0/0\mathclose{\text{;}} instead you watch what happens as hh gets close to 0. Module 2 makes “approach” precise: it is the idea of a limit. Module 4 calls the result the derivative.

Watch out

When you substitute a+ha + h into a formula, replace every xx and keep the brackets. For f(x)=x2,f(x) = x^2\mathclose{\text{,}} f(1+h)=(1+h)2=1+2h+h2.f(1 + h) = (1 + h)^2 = 1 + 2h + h^2\mathclose{\text{.}} It is not f(1)+h=1+h,f(1) + h = 1 + h\mathclose{\text{,}} and it is not f(1)+f(h)=1+h2.f(1) + f(h) = 1 + h^2\mathclose{\text{.}} Losing the middle term 2h2h is the most common error in difference quotients.

7

Setting up Python

This section is optional: you need Python only for the Compute it boxes. Three free packages turn the Python programming language into a mathematical workbench: SymPy does exact algebra and calculus with symbols, NumPy computes with arrays of numbers, and matplotlib draws graphs.

The outputs on these pages were produced with Python 3.11.18, SymPy 1.14.0, mpmath 1.3.0, NumPy 2.4.6 and matplotlib 3.11.2. At the time of writing (November 2026) the latest Python is 3.15.2; the current NumPy (2.5.5) needs Python 3.12 or later and the current matplotlib (3.11.2) needs 3.11 or later, and both offer ready-built packages for Python 3.12 to 3.15 on Windows, macOS and Linux. Newer versions may print some results differently, for example with terms in another order.

Install Python

  1. In a web browser, open python.org/downloads and click Download Python install manager. (The Python install manager is also in the Microsoft Store; the two versions are identical.)

  2. Double-click the downloaded file and select Install. This gives you the commands python, py and pymanager.

  3. Open PowerShell from the Start menu and type python. If no Python runtime is installed yet, the install manager installs the latest release automatically. When Python starts, it shows its prompt >>>; type exit() and press Enter to leave it.

    Terminal
    PS> python

When you first install a runtime, you will probably be asked whether to add a folder, %LocalAppData%\Python\bin, to your PATH. This is optional, because this series uses the py command, which works either way.

Many guides still describe the traditional full installer. It has been deprecated since Python 3.14 and will not be produced for Python 3.16 or later, so this page uses the install manager.

  1. In a web browser, open python.org/downloads and download the macOS installer package (.pkg) of the latest release. It is a universal2 build, for both Apple Silicon and Intel Macs.

  2. Double-click it. Click Continue (the Read Me), Continue and Agree (the licence), then Install. Installing needs an administrator account.

  3. To finish, double-click Install Certificates.command in the /Applications/Python 3.15/ window.

  4. Open Terminal and check the version:

    Terminal
    $ python3 --version

You start the new Python with python3 (or python3.15). macOS also has its own /usr/bin/python3, which belongs to Apple and is usually older: do not modify or delete it.

Python comes preinstalled on most Linux distributions. You need two extra parts, venv (virtual environments) and pip (the package installer). On Debian and Ubuntu:

Terminal
$ sudo apt update$ sudo apt install python3-venv python3-pip

On Fedora, sudo dnf install python3-pip python3-wheel; on Arch, sudo pacman -S python-pip. Then check the version:

Terminal
$ python3 --version

Python 3.12 or later lets pip install the current versions of all three packages; Python 3.11, which produced the outputs on these pages, works too.

Create a virtual environment

A virtual environment is a folder with its own set of Python packages, kept apart from the rest of your computer: packages that you install while it is active go into that folder, and deleting the folder removes them. Create one for this series, in the folder where you keep your work, and activate it:

Terminal
PS> py -m venv calculus_envPS> calculus_env\Scripts\Activate.ps1

If PowerShell refuses to run Activate.ps1, run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser once, then activate again. (In the older Command Prompt, the second command is calculus_env\Scripts\activate.)

Terminal
$ python3 -m venv calculus_env$ source calculus_env/bin/activate
Terminal
$ python3 -m venv calculus_env$ source calculus_env/bin/activate

deactivate leaves the environment. Each time you open a new terminal to work on the series, go to the same folder and activate the environment again with the second command.

Install SymPy, NumPy and matplotlib

With the environment active, check that pip, Python’s package installer, works, and then install the three packages:

Terminal
PS> py -m pip --versionPS> py -m pip install sympy numpy matplotlib
Terminal
$ python3 -m pip --version$ python3 -m pip install sympy numpy matplotlib
Terminal
$ python3 -m pip --version$ python3 -m pip install sympy numpy matplotlib

Installing SymPy also installs mpmath, which SymPy uses for numbers with many digits.

To run Python code, start Python in the activated environment, with py on Windows or python3 on macOS and Linux, and type the lines at the prompt >>>; or save them in a file such as first.py and run py first.py or python3 first.py. All the code of the series is in calculus-code.zip, one script per module.

If something went wrong
  • macOS: python3 --version shows an older version than the one you installed. That is Apple’s own Python. Use python3.15 in place of python3 to create the environment (python3.15 -m venv calculus_env); once the environment is active, python3 is the right one. Leave Apple’s Python alone.
  • Linux: python3 -m venv fails. On Debian and Ubuntu, install the missing parts with sudo apt install python3-venv python3-pip and try again.
  • ModuleNotFoundError: No module named 'sympy'. Python cannot find the packages, usually because the environment is not active in this terminal. Activate it and try again; if the error remains, install the packages again with the environment active.

A first session

The four boxes below revisit this module with Python; compare what you see with the outputs shown.

Compute itSymbols, substitution, factoring and expanding

SymPy works with symbols, names for unknown numbers, which you create with symbols. Then you can build expressions, substitute numbers into them with subs, and factor and expand them:

Python
import sympy as sp
x = sp.symbols('x')            # x is now a symbol, a name for a number
p = x**3 - x**2 - 6*x          # ** is a power; write * for every product
print(p.subs(x, 4))            # substitute 4 for x: p(4)
print(sp.factor(p))
print(sp.expand((x + 2)*(x - 3)))
Output
24
x*(x - 3)*(x + 2)
x**2 - x - 6

The polynomial is the one of Example 1.4. The three lines are its value p(4)=64−16−24=24,p(4) = 64 - 16 - 24 = 24\mathclose{\text{,}} its factored form, and the product (x+2)(x−3)(x + 2)(x - 3) expanded. Powers need **: in Python the symbol ^ means something else.

Pythonraises an error on purpose
print(x^2)
Error
TypeError: unsupported operand type(s) for ^: 'Symbol' and 'int'

Between whole numbers, ^ combines their binary digits, so 2^3 is 1, without complaint. Next, simplify looks for a simpler form of an expression; try it on the rational function of Example 1.5:

Python
r = (x**2 - 4)/(x**2 - x - 2)
print(sp.simplify(r))
print(r.subs(x, 2))
Output
(x + 2)/(x + 1)
nan

SymPy cancels the factor x−2x - 2 without mentioning that x≠2:x \ne 2\mathclose{\text{:}} the pitfall of Section 1.4 is yours to remember. Substituting 2 into rr itself gives nan, “not a number”, since it is 0/0.0/0\mathclose{\text{.}}

Compute itExact numbers and decimals

SymPy keeps numbers exact unless you ask for decimals. Write 4.9 as the fraction sp.Rational(49, 10) and let SymPy simplify the difference quotient of Example 1.12:

Python
import sympy as sp
t, h = sp.symbols('t h')
s = sp.Rational(49, 10)*t**2                 # 4.9 t^2, with 4.9 kept exact
q = (s.subs(t, 1 + h) - s.subs(t, 1))/h      # the difference quotient at t = 1
print(q)
print(sp.simplify(q))
Output
(49*(h + 1)**2/10 - 49/10)/h
49*h/10 + 49/5

49h10+495\tfrac{49h}{10} + \tfrac{49}{5} is 4.9h+9.8,4.9h + 9.8\mathclose{\text{,}} the answer of Example 1.12, with the terms in SymPy’s order. sp.N turns an exact number into a decimal, with 15 significant digits unless you ask for more:

Python
print(sp.sqrt(8), sp.N(sp.sqrt(8)))
print(sp.N(sp.E), sp.N(sp.pi, 30))
print(sp.N(3*sp.log(10)/sp.log(2), 4))       # Example 1.7; log is ln
Output
2*sqrt(2) 2.82842712474619
2.71828182845905 3.14159265358979323846264338328
9.966

SymPy keeps 8\sqrt8 exact, as 22.2\sqrt2\mathclose{\text{.}} In SymPy, as in Python’s math module, log is the natural logarithm ln⁡;\ln\mathclose{\text{;}} write sp.log(x, 10) for log⁡10x.\log_{10} x\mathclose{\text{.}}

Compute itPython’s own arithmetic: radians, rounding and domains

Python’s math module computes with floating-point numbers, the computer’s fast approximations to real numbers, which keep about 16 significant digits:

Python
import math
print(math.sin(math.pi/6))           # sin(pi/6) is exactly 1/2
print(math.sin(30))                  # 30 radians, not 30 degrees
print(math.sin(math.radians(30)))    # convert 30 degrees to radians first
print(math.log(math.e**2), math.log10(1000))
Output
0.49999999999999994
-0.9880316240928618
0.49999999999999994
2.0 3.0

Three lessons. Python’s trigonometric functions work in radians; math.radians converts degrees. Floating-point results can be off in the last digit, so sin⁡(π/6)\sin(\pi/6) comes out a hair below 0.5 (SymPy’s sp.sin(sp.pi/6) is exactly 1/2); Module 2 shows when such errors matter. And math.log is ln⁡.\ln\mathclose{\text{.}} Two more surprises:

Python
print((-8)**(1/3))
print(math.cbrt(-8))
Output
(1.0000000000000002+1.7320508075688772j)
-2.0

Python raises a negative number to a fractional power as a complex number (the j marks its imaginary part), not as the real cube root −2-2 that this series means by (−8)1/3;(-8)^{1/3}\mathclose{\text{;}} math.cbrt gives the real cube root. SymPy, too, takes the complex root unless you ask for the real one:

Python
import sympy as sp
print(sp.root(-8, 3), sp.real_root(-8, 3))
Output
2*(-1)**(1/3) -2

In 2*(-1)**(1/3), the factor (-1)**(1/3) stands for a complex number, not for −1.-1\mathclose{\text{.}} And outside the domain of a function, Python refuses:

Pythonraises an error on purpose
print(math.sqrt(-4))
Error
ValueError: math domain error

Python 3.11 calls this a “math domain error”; other versions may word the message differently.

Compute itNumbers and pictures: lambdify, NumPy and matplotlib

sp.lambdify turns a SymPy formula into a fast numerical function, which accepts a NumPy array, a list of numbers that arithmetic acts on all at once:

Python
import sympy as sp
import numpy as np
t = sp.symbols('t')
s = sp.lambdify(t, 4.9*t**2)       # the formula as a numerical function
ts = np.linspace(0, 3, 7)          # 7 equally spaced times from 0 to 3
print(ts)
print(s(ts))                       # s at all seven times at once
Output
[0.  0.5 1.  1.5 2.  2.5 3. ]
[ 0.     1.225  4.9   11.025 19.6   30.625 44.1  ]

The second line is the table of Section 1.3. Now the average speeds of Section 1.6:

Python
for h in [0.1, 0.01, 0.001]:
    print(h, (s(1 + h) - s(1))/h)
Output
0.1 10.290000000000008
0.01 9.848999999999997
0.001 9.804899999998895

The exact values are 10.29, 9.849 and 9.8049, so the computer’s answers are wrong in their last few digits. Module 2 explains why, and why the error grows if hh shrinks much further. Finally, a graph:

Python
import matplotlib.pyplot as plt
ts = np.linspace(0, 3, 200)
plt.plot(ts, s(ts))
plt.xlabel('t (seconds)')
plt.ylabel('distance fallen (metres)')
plt.show()

A window opens with the graph of s:s\mathclose{\text{:}} the curve of Figure 1.5, without its secant lines. Close the window to finish.

8

What you learned

  • Calculus studies how fast quantities change (the tangent problem, leading to derivatives) and how much builds up (the area problem, leading to integrals); both are answered with limits.
  • A function assigns to each input in its domain exactly one output; the range is the set of outputs. Intervals such as [0,2][0, 2] and (−∞,2)∪(2,∞)(-\infty, 2) \cup (2, \infty) describe domains and ranges.
  • The domain of a formula leaves out division by zero, even roots of negative numbers and logarithms of numbers that are not positive; a model may restrict it further.
  • The graph of ff is the set of points (x,f(x));(x, f(x))\mathclose{\text{;}} no vertical line meets it twice. Piecewise functions use different formulas on different parts of the domain, with filled and hollow dots at the boundaries.
  • The catalogue: linear functions (constant rate of change m),m\mathclose{\text{),}} powers and polynomials, rational functions, roots, exponentials axa^x and exe^x with e≈2.71828,e \approx 2.71828\mathclose{\text{,}} logarithms with ln⁡\ln the inverse of ex,e^x\mathclose{\text{,}} and the trigonometric functions, defined from the unit circle in radians.
  • For c>0,c > 0\mathclose{\text{,}} f(x−c)f(x - c) shifts a graph cc units right and f(x)+cf(x) + c shifts it cc units up; for c>1,c > 1\mathclose{\text{,}} c f(x)c\,f(x) stretches it vertically and f(cx)f(cx) squashes it horizontally. (f∘g)(x)=f(g(x))(f \circ g)(x) = f\big(g(x)\big) applies gg first. A one-to-one function has an inverse, whose graph is the mirror image in y=x.y = x\mathclose{\text{.}}
  • The average rate of change (f(b)−f(a))/(b−a)\big(f(b) - f(a)\big)/(b - a) is the slope of a secant line, and the difference quotient (f(a+h)−f(a))/h\big(f(a + h) - f(a)\big)/h is the average rate over an interval of length h.h\mathclose{\text{.}} As hh shrinks, it approaches the instantaneous rate: the idea behind limits (Module 2) and derivatives (Module 4).
  • SymPy (symbols, subs, expand, factor, simplify, N, lambdify), NumPy and matplotlib check and explore all of this; floating-point arithmetic is approximate in its last digits.
9

Exercises

Exercise 1.1★Domains in interval notation

Find the domain of each function, and write it in interval notation.

  • (a) f(x)=5−2xf(x) = \sqrt{5 - 2x}
  • (b) g(x)=1x2−9g(x) = \dfrac{1}{x^2 - 9}
  • (c) h(x)=ln⁡(x+4)xh(x) = \dfrac{\ln(x + 4)}{x}
Show solution✓ Checked

(a) The square root needs 5−2x≥0,5 - 2x \ge 0\mathclose{\text{,}} that is, 2x≤5,2x \le 5\mathclose{\text{,}} that is, x≤52.x \le \tfrac52\mathclose{\text{.}} The domain is (−∞,52],\big(-\infty, \tfrac52\big]\mathclose{\text{,}} with 52\tfrac52 included because 0=0.\sqrt0 = 0\mathclose{\text{.}}

(b) The denominator must not be 0. x2−9=0x^2 - 9 = 0 when x2=9,x^2 = 9\mathclose{\text{,}} at x=3x = 3 and at x=−3.x = -3\mathclose{\text{.}} The domain is (−∞,−3)∪(−3,3)∪(3,∞).(-\infty, -3) \cup (-3, 3) \cup (3, \infty)\mathclose{\text{.}} Forgetting x=−3x = -3 is the common slip: x2=9x^2 = 9 has two solutions.

(c) Two conditions. The logarithm needs x+4>0,x + 4 > 0\mathclose{\text{,}} that is, x>−4;x > -4\mathclose{\text{;}} the division needs x≠0.x \ne 0\mathclose{\text{.}} The domain is (−4,0)∪(0,∞).(-4, 0) \cup (0, \infty)\mathclose{\text{.}} The −4-4 is excluded, because ln⁡0\ln 0 is not defined.

Exercise 1.2★Reading a piecewise function

Let

f(x)={2x+1if x≤1,x2−1if x>1.f(x) = \begin{cases} 2x + 1 & \text{if } x \le 1, \\ x^2 - 1 & \text{if } x > 1. \end{cases}
  • (a) Find f(−2),f(-2)\mathclose{\text{,}} f(1),f(1)\mathclose{\text{,}} f(2)f(2) and f(3).f(3)\mathclose{\text{.}}
  • (b) Solve f(x)=3.f(x) = 3\mathclose{\text{.}}
  • (c) Describe the graph near x=1:x = 1\mathclose{\text{:}} where is there a filled dot, and where a hollow one?
Show solution✓ Checked

(a) Decide the piece first. −2≤1,-2 \le 1\mathclose{\text{,}} so f(−2)=2(−2)+1=−3.f(-2) = 2(-2) + 1 = -3\mathclose{\text{.}} 1≤1,1 \le 1\mathclose{\text{,}} so f(1)=2+1=3.f(1) = 2 + 1 = 3\mathclose{\text{.}} 2>1,2 > 1\mathclose{\text{,}} so f(2)=4−1=3.f(2) = 4 - 1 = 3\mathclose{\text{.}} 3>1,3 > 1\mathclose{\text{,}} so f(3)=9−1=8.f(3) = 9 - 1 = 8\mathclose{\text{.}}

(b) Solve on each piece, and keep only the solutions that lie in that piece. On the first piece, 2x+1=32x + 1 = 3 gives x=1,x = 1\mathclose{\text{,}} and 1≤1,1 \le 1\mathclose{\text{,}} so it counts. On the second, x2−1=3x^2 - 1 = 3 gives x=2x = 2 or x=−2,x = -2\mathclose{\text{,}} but only x=2x = 2 satisfies x>1x > 1 (indeed f(−2)=−3).f(-2) = -3\mathclose{\text{).}} The solutions are x=1x = 1 and x=2.x = 2\mathclose{\text{.}}

(c) The line y=2x+1y = 2x + 1 ends at (1,3),(1, 3)\mathclose{\text{,}} which is on the graph: a filled dot. To the right of x=1x = 1 the graph follows the parabola y=x2−1,y = x^2 - 1\mathclose{\text{,}} which heads for (1,0);(1, 0)\mathclose{\text{;}} that point is not on the graph: a hollow dot. The graph jumps down at x=1.x = 1\mathclose{\text{.}}

Exercise 1.3★Radians and exact values
  • (a) Convert 225∘225^\circ and −60∘-60^\circ to radians, and 5π/65\pi/6 to degrees.
  • (b) Find the exact values of sin⁡θ\sin\theta and cos⁡θ\cos\theta for θ=3π/4,\theta = 3\pi/4\mathclose{\text{,}} 7π/67\pi/6 and −π/3.-\pi/3\mathclose{\text{.}}
Show solution✓ Checked

(a) Multiply degrees by π/180:\pi/180\mathclose{\text{:}}

225⋅π180=5π4,−60⋅π180=−π3.\begin{aligned} 225 \cdot \frac{\pi}{180} &= \frac{5\pi}{4}, \\ -60 \cdot \frac{\pi}{180} &= -\frac{\pi}{3}. \end{aligned}

To go back, multiply by 180/π:180/\pi\mathclose{\text{:}}

5π6⋅180π=150∘.\frac{5\pi}{6} \cdot \frac{180}{\pi} = 150^\circ.

(b) Use the standard angles and the symmetries of the circle.

  • 3π/4=π−π/4,3\pi/4 = \pi - \pi/4\mathclose{\text{,}} the mirror image of π/4\pi/4 in the yy-axis:
    sin⁡3π4=sin⁡π4=22,cos⁡3π4=−cos⁡π4=−22.\begin{aligned} \sin\frac{3\pi}{4} &= \sin\frac{\pi}{4} = \frac{\sqrt2}{2}, \\ \cos\frac{3\pi}{4} &= -\cos\frac{\pi}{4} = -\frac{\sqrt2}{2}. \end{aligned}
  • 7π/6=π+π/6,7\pi/6 = \pi + \pi/6\mathclose{\text{,}} the reflection of π/6\pi/6 through the origin:
    sin⁡7π6=−sin⁡π6=−12,cos⁡7π6=−cos⁡π6=−32.\begin{aligned} \sin\frac{7\pi}{6} &= -\sin\frac{\pi}{6} = -\frac12, \\ \cos\frac{7\pi}{6} &= -\cos\frac{\pi}{6} = -\frac{\sqrt3}{2}. \end{aligned}
  • −π/3-\pi/3 is the mirror image of π/3\pi/3 in the xx-axis:
    sin⁡(−π3)=−sin⁡π3=−32,cos⁡(−π3)=cos⁡π3=12.\begin{aligned} \sin\Big(-\frac{\pi}{3}\Big) &= -\sin\frac{\pi}{3} \\ &= -\frac{\sqrt3}{2}, \\ \cos\Big(-\frac{\pi}{3}\Big) &= \cos\frac{\pi}{3} = \frac12. \end{aligned}
Exercise 1.4★Logarithms and exponentials

Without a calculator, find:

  • (a) log⁡381\log_3 81
  • (b) log⁡100.001\log_{10} 0.001
  • (c) ln⁡(e5)\ln\big(e^5\big)
  • (d) eln⁡7e^{\ln 7}
  • (e) ln⁡12−ln⁡3+ln⁡2,\ln 12 - \ln 3 + \ln 2\mathclose{\text{,}} written as a single logarithm.

Then (f) solve e2x=7,e^{2x} = 7\mathclose{\text{,}} giving the exact answer and its value to three decimal places.

Show solution✓ Checked

(a) 34=81,3^4 = 81\mathclose{\text{,}} so log⁡381=4.\log_3 81 = 4\mathclose{\text{.}}

(b) 0.001=10−3,0.001 = 10^{-3}\mathclose{\text{,}} so log⁡100.001=−3.\log_{10} 0.001 = -3\mathclose{\text{.}}

(c) ln⁡\ln undoes ex:e^x\mathclose{\text{:}} ln⁡(e5)=5.\ln\big(e^5\big) = 5\mathclose{\text{.}}

(d) exe^x undoes ln⁡,\ln\mathclose{\text{,}} for positive inputs: eln⁡7=7.e^{\ln 7} = 7\mathclose{\text{.}}

(e) By the laws of logarithms, ln⁡12−ln⁡3=ln⁡123=ln⁡4,\ln 12 - \ln 3 = \ln\dfrac{12}{3} = \ln 4\mathclose{\text{,}} and ln⁡4+ln⁡2=ln⁡8.\ln 4 + \ln 2 = \ln 8\mathclose{\text{.}} Since 8=23,8 = 2^3\mathclose{\text{,}} this is also 3ln⁡2.3\ln 2\mathclose{\text{.}}

(f) Take ln⁡\ln of both sides: ln⁡(e2x)=2x,\ln\big(e^{2x}\big) = 2x\mathclose{\text{,}} so 2x=ln⁡72x = \ln 7 and

x=ln⁡72≈0.973.x = \frac{\ln 7}{2} \approx 0.973.

Check: e2⋅0.973=e1.946≈7.00.e^{2 \cdot 0.973} = e^{1.946} \approx 7.00\mathclose{\text{.}}

Exercise 1.5★★Transforming the square root

Start from the graph of y=x.y = \sqrt x\mathclose{\text{.}}

  • (a) Write the formula of the graph obtained by shifting it 3 units to the left, then stretching it vertically by the factor 2, then shifting it down by 1.
  • (b) Find the domain and the range of the new function.
  • (c) Where does its graph cross the xx-axis?

Check your answers with the function explorer of Section 1.5.

Show solution✓ Checked

(a) Shifting left by 3 replaces xx by x+3:x + 3\mathclose{\text{:}} y=x+3.y = \sqrt{x + 3}\mathclose{\text{.}} Stretching vertically by 2 multiplies the outputs by 2: y=2x+3.y = 2\sqrt{x + 3}\mathclose{\text{.}} Shifting down by 1 subtracts 1:

y=2x+3−1.y = 2\sqrt{x + 3} - 1.

(b) The square root needs x+3≥0,x + 3 \ge 0\mathclose{\text{,}} so the domain is [−3,∞).[-3, \infty)\mathclose{\text{.}} As xx runs through [−3,∞),[-3, \infty)\mathclose{\text{,}} x+3x + 3 runs through [0,∞),[0, \infty)\mathclose{\text{,}} so x+3\sqrt{x + 3} takes every value in [0,∞);[0, \infty)\mathclose{\text{;}} doubling keeps [0,∞),[0, \infty)\mathclose{\text{,}} and subtracting 1 gives [−1,∞).[-1, \infty)\mathclose{\text{.}} The range is [−1,∞):[-1, \infty)\mathclose{\text{:}} the starting point (0,0)(0, 0) of the graph has moved to (−3,−1).(-3, -1)\mathclose{\text{.}}

(c) Solve 2x+3−1=0:2\sqrt{x + 3} - 1 = 0\mathclose{\text{:}} x+3=12,\sqrt{x + 3} = \tfrac12\mathclose{\text{,}} so x+3=14x + 3 = \tfrac14 (square both sides) and x=−114=−2.75.x = -\tfrac{11}{4} = -2.75\mathclose{\text{.}} Squaring can introduce false solutions, so check: 20.25−1=2⋅0.5−1=0.2\sqrt{0.25} - 1 = 2 \cdot 0.5 - 1 = 0\mathclose{\text{.}}

In the explorer: f(x)=x,f(x) = \sqrt x\mathclose{\text{,}} a=2,a = 2\mathclose{\text{,}} c=−3,c = -3\mathclose{\text{,}} d=−1.d = -1\mathclose{\text{.}}

Exercise 1.6★★Composition and domains

Let f(x)=1xf(x) = \dfrac{1}{x} and g(x)=x2−4.g(x) = x^2 - 4\mathclose{\text{.}} Find each composition and its domain:

  • (a) f∘gf \circ g
  • (b) g∘fg \circ f
  • (c) f∘ff \circ f
Show solution✓ Checked

(a) (f∘g)(x)=f(x2−4)=1x2−4.(f \circ g)(x) = f(x^2 - 4) = \dfrac{1}{x^2 - 4}\mathclose{\text{.}} gg accepts every x,x\mathclose{\text{,}} and ff needs its input x2−4x^2 - 4 to be non-zero, so x≠2x \ne 2 and x≠−2.x \ne -2\mathclose{\text{.}} The domain is (−∞,−2)∪(−2,2)∪(2,∞).(-\infty, -2) \cup (-2, 2) \cup (2, \infty)\mathclose{\text{.}}

(b) (g∘f)(x)=g(1x)=1x2−4.(g \circ f)(x) = g\Big(\dfrac1x\Big) = \dfrac{1}{x^2} - 4\mathclose{\text{.}} ff needs x≠0,x \ne 0\mathclose{\text{,}} and gg accepts any input, so the domain is (−∞,0)∪(0,∞).(-\infty, 0) \cup (0, \infty)\mathclose{\text{.}}

(c) (f∘f)(x)=f(1x)=11/x=x,(f \circ f)(x) = f\Big(\dfrac1x\Big) = \dfrac{1}{1/x} = x\mathclose{\text{,}} but only for x≠0:x \ne 0\mathclose{\text{:}} f(0)f(0) is not defined, so neither is f(f(0)).f\big(f(0)\big)\mathclose{\text{.}} The domain is (−∞,0)∪(0,∞),(-\infty, 0) \cup (0, \infty)\mathclose{\text{,}} not R.\R\mathclose{\text{.}} The common wrong answer, R,\R\mathclose{\text{,}} reads the domain off the simplified formula x;x\mathclose{\text{;}} the domain comes from the pieces. (On its domain, ff undoes itself: ff is its own inverse.)

Exercise 1.7★★An inverse with a logarithm

Let f(x)=ex−1+2.f(x) = e^{x - 1} + 2\mathclose{\text{.}}

  • (a) Find the domain and the range of f.f\mathclose{\text{.}}
  • (b) Show that ff is one-to-one, and find f−1(x).f^{-1}(x)\mathclose{\text{.}}
  • (c) State the domain and the range of f−1,f^{-1}\mathclose{\text{,}} and check that f(f−1(x))=x.f\big(f^{-1}(x)\big) = x\mathclose{\text{.}}
Show solution✓ Checked

(a) ex−1e^{x - 1} is defined for every x,x\mathclose{\text{,}} so the domain is R.\R\mathclose{\text{.}} As xx runs through R,\R\mathclose{\text{,}} so does x−1,x - 1\mathclose{\text{,}} and ex−1e^{x-1} takes every positive value (each v>0v > 0 is eue^u for u=ln⁡v)u = \ln v\mathclose{\text{)}} and no other. So ex−1+2e^{x - 1} + 2 takes every value greater than 2: the range is (2,∞).(2, \infty)\mathclose{\text{.}}

(b) Write y=ex−1+2y = e^{x - 1} + 2 and solve for x.x\mathclose{\text{.}} Subtract 2: y−2=ex−1.y - 2 = e^{x - 1}\mathclose{\text{.}} For yy in the range, y−2>0,y - 2 > 0\mathclose{\text{,}} so you may take ln⁡\ln of both sides: ln⁡(y−2)=x−1,\ln(y - 2) = x - 1\mathclose{\text{,}} and

x=1+ln⁡(y−2).x = 1 + \ln(y - 2).

Each yy in the range comes from exactly this one x,x\mathclose{\text{,}} so ff is one-to-one. Renaming yy as x:x\mathclose{\text{:}} f−1(x)=1+ln⁡(x−2).f^{-1}(x) = 1 + \ln(x - 2)\mathclose{\text{.}}

(c) The domain of f−1f^{-1} is the range of f,f\mathclose{\text{,}} (2,∞);(2, \infty)\mathclose{\text{;}} this is exactly where ln⁡(x−2)\ln(x - 2) is defined. The range of f−1f^{-1} is the domain of f,f\mathclose{\text{,}} R.\R\mathclose{\text{.}} Check, for x>2:x > 2\mathclose{\text{:}}

f(f−1(x))=e(1+ln⁡(x−2))−1+2=eln⁡(x−2)+2=(x−2)+2=x.\begin{aligned} f\big(f^{-1}(x)\big) &= e^{(1 + \ln(x - 2)) - 1} + 2 \\ &= e^{\ln(x - 2)} + 2 \\ &= (x - 2) + 2 = x. \end{aligned}
Exercise 1.8★★Average rates of a cube

Let f(x)=x3.f(x) = x^3\mathclose{\text{.}}

  • (a) Find the average rate of change of ff over [1,2],[1, 2]\mathclose{\text{,}} over [1,1.1][1, 1.1] and over [1,1.01].[1, 1.01]\mathclose{\text{.}}
  • (b) Simplify the difference quotient f(1+h)−f(1)h,\dfrac{f(1 + h) - f(1)}{h}\mathclose{\text{,}} for h≠0.h \ne 0\mathclose{\text{.}}
  • (c) What number do the average rates approach as hh shrinks?
Show solution✓ Checked

(a) Use f(b)−f(a)b−a:\dfrac{f(b) - f(a)}{b - a}\mathclose{\text{:}}

8−12−1=7,1.331−10.1=3.31,1.030301−10.01=3.0301.\begin{aligned} \frac{8 - 1}{2 - 1} &= 7, \\ \frac{1.331 - 1}{0.1} &= 3.31, \\ \frac{1.030301 - 1}{0.01} &= 3.0301. \end{aligned}

(b) Expand (1+h)3:(1 + h)^3\mathclose{\text{:}} first (1+h)2=1+2h+h2,(1 + h)^2 = 1 + 2h + h^2\mathclose{\text{,}} then multiply by 1+h1 + h and collect terms, to get (1+h)3=1+3h+3h2+h3.(1 + h)^3 = 1 + 3h + 3h^2 + h^3\mathclose{\text{.}} So

f(1+h)−f(1)h=3h+3h2+h3h=3+3h+h2(h≠0).\begin{aligned} \frac{f(1 + h) - f(1)}{h} &= \frac{3h + 3h^2 + h^3}{h} \\ &= 3 + 3h + h^2 \qquad (h \ne 0). \end{aligned}

This agrees with (a): h=1,h = 1\mathclose{\text{,}} 0.1 and 0.01 give 7, 3.31 and 3.0301.

(c) As hh shrinks, 3h3h and h2h^2 shrink to nothing, so the average rates approach 3. This is the slope of the curve y=x3y = x^3 at the point (1,1),(1, 1)\mathclose{\text{,}} its instantaneous rate of change there.

Exercise 1.9★★The difference quotient of 1/x

Let f(x)=1x,f(x) = \dfrac1x\mathclose{\text{,}} and let a≠0.a \ne 0\mathclose{\text{.}}

  • (a) Show that, for h≠0h \ne 0 with a+h≠0,a + h \ne 0\mathclose{\text{,}}
    f(a+h)−f(a)h=−1a(a+h).\frac{f(a + h) - f(a)}{h} = -\frac{1}{a(a + h)}.
  • (b) Evaluate it for a=2a = 2 with h=0.1h = 0.1 and with h=−0.1,h = -0.1\mathclose{\text{,}} to four decimal places.
  • (c) What does it approach as hh shrinks? Why is it negative?
Show solution✓ Checked

(a) Put the two fractions over the common denominator a(a+h):a(a + h)\mathclose{\text{:}}

f(a+h)−f(a)=1a+h−1a=a−(a+h)a(a+h)=−ha(a+h).\begin{aligned} f(a + h) - f(a) &= \frac{1}{a + h} - \frac1a \\ &= \frac{a - (a + h)}{a(a + h)} \\ &= \frac{-h}{a(a + h)}. \end{aligned}

Dividing by hh (allowed, since h≠0)h \ne 0\mathclose{\text{)}} gives −1a(a+h).-\dfrac{1}{a(a + h)}\mathclose{\text{.}}

(b) For a=2a = 2 and h=0.1,h = 0.1\mathclose{\text{,}}

−12⋅2.1=−14.2≈−0.2381,-\frac{1}{2 \cdot 2.1} = -\frac{1}{4.2} \approx -0.2381,

and for h=−0.1,h = -0.1\mathclose{\text{,}}

−12⋅1.9=−13.8≈−0.2632.-\frac{1}{2 \cdot 1.9} = -\frac{1}{3.8} \approx -0.2632.

(c) As hh shrinks, a+ha + h approaches a,a\mathclose{\text{,}} so the quotient approaches −1a2;-\dfrac{1}{a^2}\mathclose{\text{;}} for a=2a = 2 that is −14=−0.25,-\tfrac14 = -0.25\mathclose{\text{,}} between the two values of (b). The quotient is negative whenever aa and a+ha + h lie on the same side of 0, as they do once ∣h∣<∣a∣:\abs{h} < \abs{a}\mathclose{\text{:}} then a(a+h)>0.a(a + h) > 0\mathclose{\text{.}} The reason is that 1/x1/x decreases on each side of 0: when the input increases, the output decreases, so Δy\Delta y and Δx\Delta x have opposite signs. Across 0 this fails: for a=2a = 2 and h=−3,h = -3\mathclose{\text{,}} the quotient is −12⋅(−1)=12.-\dfrac{1}{2 \cdot (-1)} = \tfrac12\mathclose{\text{.}}

Exercise 1.10★★★Increasing functions are one-to-one

A function ff is strictly increasing if, for all x1x_1 and x2x_2 in its domain, x1<x2x_1 < x_2 implies f(x1)<f(x2).f(x_1) < f(x_2)\mathclose{\text{.}}

  • (a) Prove that a strictly increasing function is one-to-one.
  • (b) Prove that its inverse is strictly increasing too.
  • (c) Show that f(x)=x3+xf(x) = x^3 + x is strictly increasing on R,\R\mathclose{\text{,}} and so has an inverse function. (Hint: x23−x13=(x2−x1)(x22+x1x2+x12).)x_2^3 - x_1^3 = (x_2 - x_1)\big(x_2^2 + x_1 x_2 + x_1^2\big)\mathclose{\text{.)}}
Show solution✓ Checked

(a) Let x1≠x2x_1 \ne x_2 be in the domain, named so that x1<x2.x_1 < x_2\mathclose{\text{.}} Since ff is strictly increasing, f(x1)<f(x2);f(x_1) < f(x_2)\mathclose{\text{;}} in particular f(x1)≠f(x2).f(x_1) \ne f(x_2)\mathclose{\text{.}} Different inputs give different outputs, so ff is one-to-one.

(b) By (a), ff has an inverse. Let y1<y2y_1 < y_2 be in the range of f,f\mathclose{\text{,}} and let x1=f−1(y1)x_1 = f^{-1}(y_1) and x2=f−1(y2),x_2 = f^{-1}(y_2)\mathclose{\text{,}} so that f(x1)=y1f(x_1) = y_1 and f(x2)=y2.f(x_2) = y_2\mathclose{\text{.}} If x1=x2,x_1 = x_2\mathclose{\text{,}} then y1=y2;y_1 = y_2\mathclose{\text{;}} if x2<x1,x_2 < x_1\mathclose{\text{,}} then f(x2)<f(x1),f(x_2) < f(x_1)\mathclose{\text{,}} that is, y2<y1.y_2 < y_1\mathclose{\text{.}} Both contradict y1<y2,y_1 < y_2\mathclose{\text{,}} so x1<x2:x_1 < x_2\mathclose{\text{:}} f−1f^{-1} is strictly increasing.

(c) Let x1<x2.x_1 < x_2\mathclose{\text{.}} Using the hint,

f(x2)−f(x1)=(x23−x13)+(x2−x1)=(x2−x1)(x22+x1x2+x12+1).\begin{aligned} &f(x_2) - f(x_1) \\ &\quad= \big(x_2^3 - x_1^3\big) + (x_2 - x_1) \\ &\quad= (x_2 - x_1)\big(x_2^2 + x_1 x_2 + x_1^2 + 1\big). \end{aligned}

The first factor is positive. For the second, complete the square:

x22+x1x2+x12=(x2+x12)2+34x12≥0,x_2^2 + x_1 x_2 + x_1^2 = \Big(x_2 + \frac{x_1}{2}\Big)^2 + \frac34 x_1^2 \ge 0,

so the second factor is at least 1. A product of two positive numbers is positive, so f(x1)<f(x2):f(x_1) < f(x_2)\mathclose{\text{:}} ff is strictly increasing. By (a) it has an inverse function, which by (b) is strictly increasing too. A formula for f−1f^{-1} would mean solving the cubic equation x3+x=y,x^3 + x = y\mathclose{\text{,}} but the inverse exists all the same, and Theorem 1.2 gives its graph.

Exercise 1.11★★★Symmetric intervals for a quadratic

Let f(x)=px2+qx+r,f(x) = px^2 + qx + r\mathclose{\text{,}} with constants p,p\mathclose{\text{,}} qq and r.r\mathclose{\text{.}}

  • (a) Show that the average rate of change of ff over [a−h,a+h],[a - h, a + h]\mathclose{\text{,}} for h>0,h > 0\mathclose{\text{,}} is 2pa+q,2pa + q\mathclose{\text{,}} whatever the value of h.h\mathclose{\text{.}}
  • (b) What does (a) say about the secant lines through the points of the graph at a−ha - h and a+h,a + h\mathclose{\text{,}} and about the instantaneous rate of change of ff at a?a\mathclose{\text{?}}
  • (c) For the falling ball, s(t)=4.9t2,s(t) = 4.9t^2\mathclose{\text{,}} find the average speed over [0.5,1.5][0.5, 1.5] and over [0.9,1.1][0.9, 1.1] without computing any value of s.s\mathclose{\text{.}} Compare with Section 1.6.
Show solution✓ Checked

(a) The interval has length Δx=(a+h)−(a−h)=2h.\Delta x = (a + h) - (a - h) = 2h\mathclose{\text{.}} For the change in f,f\mathclose{\text{,}} group the terms:

f(a+h)−f(a−h)=p[(a+h)2−(a−h)2]+q[(a+h)−(a−h)]+(r−r).\begin{aligned} &f(a + h) - f(a - h) \\ &\quad= p\big[(a + h)^2 - (a - h)^2\big] \\ &\qquad + q\big[(a + h) - (a - h)\big] + (r - r). \end{aligned}

Expanding, (a+h)2−(a−h)2=(a2+2ah+h2)−(a2−2ah+h2)=4ah,(a + h)^2 - (a - h)^2 = (a^2 + 2ah + h^2) - (a^2 - 2ah + h^2) = 4ah\mathclose{\text{,}} and (a+h)−(a−h)=2h.(a + h) - (a - h) = 2h\mathclose{\text{.}} So f(a+h)−f(a−h)=4pah+2qh,f(a + h) - f(a - h) = 4pah + 2qh\mathclose{\text{,}} and

f(a+h)−f(a−h)2h=4pah+2qh2h=2pa+q.\begin{aligned} \frac{f(a + h) - f(a - h)}{2h} &= \frac{4pah + 2qh}{2h} \\ &= 2pa + q. \end{aligned}

The hh cancels completely: the answer is the same for every h>0.h > 0\mathclose{\text{.}}

(b) All these secant lines have the same slope, 2pa+q,2pa + q\mathclose{\text{,}} so they are parallel, however wide the interval. As hh shrinks, the average rate stays at 2pa+q,2pa + q\mathclose{\text{,}} so that is the number it approaches: the instantaneous rate of change of ff at aa is 2pa+q.2pa + q\mathclose{\text{.}} The difference quotient of Section 1.6 agrees: f(a+h)−f(a)=p(2ah+h2)+qh,f(a + h) - f(a) = p(2ah + h^2) + qh\mathclose{\text{,}} so the difference quotient is 2pa+q+ph,2pa + q + ph\mathclose{\text{,}} which also approaches 2pa+q2pa + q as hh shrinks.

(c) Here p=4.9p = 4.9 and q=r=0.q = r = 0\mathclose{\text{.}} Both intervals are centred on a=1a = 1 (with h=0.5h = 0.5 and h=0.1),h = 0.1\mathclose{\text{),}} so the average speed over each is 2⋅4.9⋅1=9.82 \cdot 4.9 \cdot 1 = 9.8 m/s: exactly the instantaneous speed found in Section 1.6, where intervals starting or ending at t=1t = 1 only approached 9.8. Module 4 uses centred intervals, the central difference, for other functions, where they are very accurate though not exact.

10

Check yourself

1
The domain of f(x)=x−3x−5f(x) = \dfrac{\sqrt{x - 3}}{x - 5} is
2
If f(x)=x2f(x) = x^2 and g(x)=x+1,g(x) = x + 1\mathclose{\text{,}} then (f∘g)(x)(f \circ g)(x) is
3
The graph of y=f(x+2)−1y = f(x + 2) - 1 is the graph of y=f(x)y = f(x) shifted
4
cos⁡2π3\cos\dfrac{2\pi}{3} equals
5
For x>0,x > 0\mathclose{\text{,}} ln⁡(x3)−ln⁡x\ln\big(x^3\big) - \ln x equals
6
If f(x)=3x−6,f(x) = 3x - 6\mathclose{\text{,}} then f−1(x)f^{-1}(x) is
7
The average rate of change of f(x)=x2f(x) = x^2 over [2,5][2, 5] is
8
For f(x)=x2f(x) = x^2 and h≠0,h \ne 0\mathclose{\text{,}} the difference quotient f(3+h)−f(3)h\dfrac{f(3 + h) - f(3)}{h} simplifies to
Finished this module?