Pre-Calculus Exercises
Time to practise across the whole course: triangles, radians, the unit circle, trig equations, functions and inverses, sequences and series, the binomial expansion, polar and complex form, and limits. Each exercise has a starter program that runs but does not do the job yet. Replace the TODO parts, press ▶ Run, and compare your result with the expected output. The output block under each starter shows what the unfinished starter prints.
Tip: Sketch first. A quick drawing of the triangle, the angle on the unit circle or the first few terms of a series usually tells you the answer's size and sign before any code runs.
| # | Exercise | Practises |
|---|---|---|
| 1 | The third side | laws of sines and cosines |
| 2 | How far does the wheel roll? | angles and radians |
| 3 | Exact values | the unit circle |
| 4 | Every solution | trig equations, inverse trig |
| 5 | Undo a function | composition and inverses |
| 6 | Two series | arithmetic and geometric progressions |
| 7 | How many terms? | infinite series |
| 8 | Binomial coefficients | the binomial expansion |
| 9 | Polar form | polar coordinates, complex numbers |
| 10 | A hole in the graph | introduction to limits |
Exercise 1: The third side
A triangle has sides and with the angle between them. Use the law of cosines to find , then find angle with the law of sines.
import math
a, b, C = 7, 9, math.radians(60)
c = 0.0 # TODO: law of cosines
A = 0.0 # TODO: asin(a * sin(C) / c), in degrees
print(f"c = {c:.4f}, A = {A:.2f} deg")c = 0.0000, A = 0.00 deg
Expected output when solved:
c = 8.1854, A = 47.78 degHint: , so .
Show solution
import math
a, b, C = 7, 9, math.radians(60)
c = math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(C))
A = math.degrees(math.asin(a * math.sin(C) / c))
print(f"c = {c:.4f}, A = {A:.2f} deg")c = 8.1854, A = 47.78 deg
. Using the law of sines for is safe here because , so is not the largest angle and cannot be obtuse.
Exercise 2: How far does the wheel roll?
A robot wheel of radius 0.35 m turns through 150°. How far does the robot roll? Arc length is with in radians.
import math
r, degrees = 0.35, 150
theta = 0.0 # TODO: convert to radians
s = r * theta
print(f"theta = {theta:.4f} rad, distance = {s:.4f} m")theta = 0.0000 rad, distance = 0.0000 m
Expected output when solved:
theta = 2.6180 rad, distance = 0.9163 mHint: .
Show solution
import math
r, degrees = 0.35, 150
theta = math.radians(degrees)
s = r * theta
print(f"theta = {theta:.4f} rad, distance = {s:.4f} m")theta = 2.6180 rad, distance = 0.9163 m
Exercise 3: Exact values
Fill in the exact values of and at and as SymPy expressions, then let the program compare them with SymPy's own values.
import sympy as sp
angles = [5 * sp.pi / 6, 7 * sp.pi / 4]
by_hand = { # TODO: replace the zeros, e.g. sp.sqrt(3) / 2
"sin(5pi/6)": 0, "cos(5pi/6)": 0,
"sin(7pi/4)": 0, "cos(7pi/4)": 0,
}
true = [sp.sin(angles[0]), sp.cos(angles[0]), sp.sin(angles[1]), sp.cos(angles[1])]
for (name, mine), exact in zip(by_hand.items(), true):
print(f"{name}: {exact} {'ok' if sp.simplify(mine - exact) == 0 else 'wrong'}")sin(5pi/6): 1/2 wrong
cos(5pi/6): -sqrt(3)/2 wrong
sin(7pi/4): -sqrt(2)/2 wrong
cos(7pi/4): sqrt(2)/2 wrong
Expected output when solved: every line ends in ok.
Hint: is 150°, in quadrant II with reference angle 30°; is 315°, in quadrant IV with reference angle 45°.
Show solution
import sympy as sp
angles = [5 * sp.pi / 6, 7 * sp.pi / 4]
by_hand = {
"sin(5pi/6)": sp.Rational(1, 2), "cos(5pi/6)": -sp.sqrt(3) / 2,
"sin(7pi/4)": -sp.sqrt(2) / 2, "cos(7pi/4)": sp.sqrt(2) / 2,
}
true = [sp.sin(angles[0]), sp.cos(angles[0]), sp.sin(angles[1]), sp.cos(angles[1])]
for (name, mine), exact in zip(by_hand.items(), true):
print(f"{name}: {exact} {'ok' if sp.simplify(mine - exact) == 0 else 'wrong'}")sin(5pi/6): 1/2 ok
cos(5pi/6): -sqrt(3)/2 ok
sin(7pi/4): -sqrt(2)/2 ok
cos(7pi/4): sqrt(2)/2 ok
In quadrant II sine is positive and cosine negative; in quadrant IV it is the other way round.
Exercise 4: Every solution
Solve for . math.asin returns only one angle; add the second one that has the same sine.
import math
base = math.asin(1 / 2)
solutions = [base] # TODO: add the other solution in [0, 2π)
print([round(x, 4) for x in solutions])
print([round(2 * math.sin(x) - 1, 12) for x in solutions])[0.5236]
[0.0]
Expected output when solved:
[0.5236, 2.618]
[0.0, 0.0]Hint: .
Show solution
import math
base = math.asin(1 / 2)
solutions = [base, math.pi - base]
print([round(x, 4) for x in solutions])
print([round(2 * math.sin(x) - 1, 12) for x in solutions])[0.5236, 2.618]
[0.0, 0.0]
The solutions are and (30° and 150°). Adding to either gives all solutions on the whole real line.
Exercise 5: Undo a function
For and , compute and , then write the inverse and check that for a few .
f = lambda x: 3 * x - 2
g = lambda x: x ** 2
f_inv = lambda y: y # TODO: the inverse of f
print("f(g(2)) =", f(g(2)), " g(f(2)) =", g(f(2)))
print([f_inv(f(x)) for x in [-1, 0, 2.5, 10]])f(g(2)) = 10 g(f(2)) = 16
[-5, -2, 5.5, 28]
Expected output when solved:
f(g(2)) = 10 g(f(2)) = 16
[-1.0, 0.0, 2.5, 10.0]Hint: Solve for .
Show solution
f = lambda x: 3 * x - 2
g = lambda x: x ** 2
f_inv = lambda y: (y + 2) / 3
print("f(g(2)) =", f(g(2)), " g(f(2)) =", g(f(2)))
print([f_inv(f(x)) for x in [-1, 0, 2.5, 10]])f(g(2)) = 10 g(f(2)) = 16
[-1.0, 0.0, 2.5, 10.0]
but : composition is not commutative. The inverse undoes in reverse order: add 2, then divide by 3.
Exercise 6: Two series
Use the closed-form formulas, not loops, for (a) up to 30 terms and (b) up to 10 terms. The program checks them against sum.
n = 30
arith = 0 # TODO: n/2 · (2a + (n − 1)d) with a = 5, d = 3
m = 10
geom = 0 # TODO: a(rᵐ − 1)/(r − 1) with a = 3, r = 2
print(arith, sum(5 + 3 * k for k in range(n)))
print(geom, sum(3 * 2**k for k in range(m)))0 1455
0 3069
Expected output when solved:
1455 1455
3069 3069Hint: Use integer division
//in the arithmetic formula so the result stays anint.
Show solution
n = 30
arith = n * (2 * 5 + (n - 1) * 3) // 2
m = 10
geom = 3 * (2**m - 1) // (2 - 1)
print(arith, sum(5 + 3 * k for k in range(n)))
print(geom, sum(3 * 2**k for k in range(m)))1455 1455
3069 3069
(a) . (b) .
Exercise 7: How many terms?
The geometric series converges to . Find the first for which the partial sum ( terms) is within 0.001 of 3, by a loop and by a formula.
import math
limit, total, n = 3, 0.0, 0
# TODO: add terms (2/3)**n until limit - total < 0.001, counting n
n_formula = 0 # TODO: smallest n with 3·(2/3)**n < 0.001
print("loop:", n, f"S = {total:.5f}", " formula:", n_formula)loop: 0 S = 0.00000 formula: 0
Expected output when solved:
loop: 20 S = 2.99910 formula: 20Hint: The remainder after terms is . Solve with logarithms (and remember that flips the inequality).
Show solution
import math
limit, total, n = 3, 0.0, 0
while limit - total >= 0.001:
total += (2 / 3) ** n
n += 1
n_formula = math.floor(math.log(0.001 / 3) / math.log(2 / 3)) + 1
print("loop:", n, f"S = {total:.5f}", " formula:", n_formula)loop: 20 S = 2.99910 formula: 20
, so . Convergence tests for series that are not geometric come later in tests for convergence.
Exercise 8: Binomial coefficients
Build the coefficients of from the binomial theorem: the term with is . Compare with SymPy.
import math
import sympy as sp
coeffs = [0] * 6 # TODO: coeffs[k] = comb(5, k) * 2**k * (-1)**(5 - k)
print("mine :", coeffs)
x = sp.symbols("x")
print("SymPy:", sp.Poly(sp.expand((2 * x - 1) ** 5), x).all_coeffs()[::-1])mine : [0, 0, 0, 0, 0, 0]
SymPy: [-1, 10, -40, 80, -80, 32]
Expected output when solved: both lines show [-1, 10, -40, 80, -80, 32] (from the constant term up to ).
Hint:
math.comb(5, k)gives 1, 5, 10, 10, 5, 1.
Show solution
import math
import sympy as sp
coeffs = [math.comb(5, k) * 2**k * (-1) ** (5 - k) for k in range(6)]
print("mine :", coeffs)
x = sp.symbols("x")
print("SymPy:", sp.Poly(sp.expand((2 * x - 1) ** 5), x).all_coeffs()[::-1])mine : [-1, 10, -40, 80, -80, 32]
SymPy: [-1, 10, -40, 80, -80, 32]
So . The coefficients add up to 1, which is .
Exercise 9: Polar form
Convert the point to polar form , then multiply the complex numbers and . Multiplying in polar form means: multiply the lengths, add the angles.
import cmath, math
x, y = -1, math.sqrt(3)
r, theta = 0.0, 0.0 # TODO: r = hypot, theta = atan2 in degrees
print(f"r = {r:.4f}, theta = {theta:.2f} deg")
z1 = cmath.rect(2, math.radians(30))
z2 = cmath.rect(3, math.radians(45))
length, angle = 0.0, 0.0 # TODO: polar form of z1 * z2 (use cmath.polar)
print(f"product: {length:.4f} at {angle:.2f} deg")r = 0.0000, theta = 0.00 deg
product: 0.0000 at 0.00 deg
Expected output when solved:
r = 2.0000, theta = 120.00 deg
product: 6.0000 at 75.00 degHint:
cmath.polar(z)returns with in radians.
Show solution
import cmath, math
x, y = -1, math.sqrt(3)
r, theta = math.hypot(x, y), math.degrees(math.atan2(y, x))
print(f"r = {r:.4f}, theta = {theta:.2f} deg")
z1 = cmath.rect(2, math.radians(30))
z2 = cmath.rect(3, math.radians(45))
length, angle = cmath.polar(z1 * z2)
angle = math.degrees(angle)
print(f"product: {length:.4f} at {angle:.2f} deg")r = 2.0000, theta = 120.00 deg
product: 6.0000 at 75.00 deg
; the point is in quadrant II with , so . The product has length and angle .
Exercise 10: A hole in the graph
is undefined at . Estimate as from both sides with a table, then get the exact limit from SymPy.
import sympy as sp
f = lambda x: (x * x - 9) / (x - 3)
for h in [0.1, 0.01, 0.001]:
left, right = 0.0, 0.0 # TODO: f(3 - h) and f(3 + h)
print(f"h = {h:<6} left {left:.4f} right {right:.4f}")
x = sp.symbols("x")
print("SymPy limit:", None) # TODO: sp.limit(...)h = 0.1 left 0.0000 right 0.0000
h = 0.01 left 0.0000 right 0.0000
h = 0.001 left 0.0000 right 0.0000
SymPy limit: None
Expected output when solved:
h = 0.1 left 5.9000 right 6.1000
h = 0.01 left 5.9900 right 6.0100
h = 0.001 left 5.9990 right 6.0010
SymPy limit: 6Hint: , so for the function equals .
Show solution
import sympy as sp
f = lambda x: (x * x - 9) / (x - 3)
for h in [0.1, 0.01, 0.001]:
left, right = f(3 - h), f(3 + h)
print(f"h = {h:<6} left {left:.4f} right {right:.4f}")
x = sp.symbols("x")
print("SymPy limit:", sp.limit((x**2 - 9) / (x - 3), x, 3))h = 0.1 left 5.9000 right 6.1000
h = 0.01 left 5.9900 right 6.0100
h = 0.001 left 5.9990 right 6.0010
SymPy limit: 6
Both sides approach 6, the value of at . The graph is the line with a single point missing. More on this in limits and continuity, and the full theory in limits.
Test yourself
math.asin(0.5) returns . Which other angle in has sine 0.5?
What is the sum of the infinite geometric series ?
- 8
- 7.5
- It diverges
- 6
Multiplying two complex numbers in polar form…
- adds the lengths and multiplies the angles
- multiplies both the lengths and the angles
- multiplies the lengths and adds the angles
- adds both