Angles, the Unit Circle and Trigonometric Graphs: Quick… | StemPy Lab
Python Programming
Angles, the Unit Circle and Trigonometric Graphs: Quick Revision
A brief note on Angles, the Unit Circle and Trigonometric Graphs: degrees and radians, the unit circle, the graphs of sine, cosine and tangent, and checking identities with numpy. With a worked example, practice, a program and questions.
A brief note on Angles, the Unit Circle and Trigonometric Graphs. Read it before a test. Try each question at the end before you open its answer.
Angles and the unit circle
360∘=2π rad. Degrees to radians: multiply by 180π, or call math.radians. Python's sin, cos and tan take radians.
The point at angle θ on the unit circle is (cosθ,sinθ). Quadrant I has both positive, II has only the sine positive, III has neither, IV has only the cosine positive.
Compare floats with math.isclose(a, b, abs_tol=...). math.sin(math.pi) is about 10−16, not 0.
Graphs
np.linspace(0, 2 * np.pi, n) makes the angles. np.sin works on the whole array.
y=Asin(B(x−C)): amplitude A, period B2π, shifted right by C. cosx=sin(x+2π).
The tangent repeats every π and has asymptotes. Replace the huge values with np.nan before plotting.
Identities
One counterexample proves an identity false. Many passes make it very likely true.
np.allclose(left, right) tests whole arrays. np.max(np.abs(left - right)) is the worst miss, about 10−16 for a true identity.
Use random angles from rng.uniform(0, 2 * np.pi, n), and skip the angles where cosa=0 for the tangent.
A worked example
What does this print?
Radians.150×180π=2.618.
Sine.150∘ is in quadrant II, where the sine is positive. sin150∘=sin30∘=0.5, printed as 0.5.
Tolerance. The cosine of 2π is about 6×10−17, which is close to 0 within 10−9: True.
It prints 2.618, 0.5 and True.
Practice with new numbers
A program to try
The program checks sin2a+cos2a=1 on four angles and compares each total with 1 using a tolerance.
Mistakes to avoid
Degrees given to a function that wants radians. Convert with math.radians or np.radians.
Typing 3.14 for π. Use math.pi.
Comparing floats with ==. Use isclose or allclose.
A tangent plot with steep joining lines. Hide the huge values with np.nan.
Taking a pass as a proof. Many passing angles do not prove an identity.
Check yourself
Convert 90∘ to radians.
What is the period of y=sin(4x)?
In which quadrant are both the cosine and the sine negative?
What does np.argmax(bad) give when bad marks the angles that fail?