Chapter 11: ufunc Trigonometric

1. What are trigonometric ufuncs in NumPy?

NumPy provides six main trigonometric functions as universal functions (ufuncs):

Function Computes Input unit Output range Most common use case
np.sin sine radians [-1, 1] oscillations, waves
np.cos cosine radians [-1, 1] phase shifts, projections
np.tan tangent radians (-∞, +∞) slopes, angles
np.arcsin inverse sine (asin) radians [-π/2, π/2] find angle from sine
np.arccos inverse cosine (acos) radians [0, π] find angle from cosine
np.arctan inverse tangent (atan) radians (-π/2, π/2) find angle from tangent

There are also two-argument versions:

  • np.arctan2(y, x) → angle of point (x,y) in correct quadrant (−π, π]

And hyperbolic versions (less common but important):

  • np.sinh, np.cosh, np.tanh, np.arcsinh, etc.

2. The single most important rule you must remember

All trigonometric functions in NumPy expect input in radians — not degrees.

This is the #1 source of confusion for beginners.

Python

Conversion helpers (memorize or bookmark these):

Python

3. Basic usage examples – all six functions

Python

Inverse functions

Python

Very important: arctan2 (two-argument version)

Python

4. Realistic visualizations – the best way to build intuition

Python

5. Very common realistic patterns you will use

Pattern 1 – Convert degrees to radians and compute

Python

Pattern 2 – Generate sine/cosine waves (signal processing)

Python

Pattern 3 – Find angles from ratios (arctan2 is critical)

Python

Pattern 4 – Phase shift and superposition

Python

Summary – Trigonometric ufuncs Quick Reference

Function Input unit Output range Most common mistake
np.sin radians [-1, 1] giving degrees
np.cos radians [-1, 1] same
np.tan radians (-∞, +∞) discontinuities at π/2
np.arcsin [-1,1] [-π/2, π/2] domain error outside [-1,1]
np.arccos [-1,1] [0, π] domain error
np.arctan any (-π/2, π/2) loses quadrant info
np.arctan2 (y,x) (-π, π] always use this for angles

Final teacher advice (very important)

Golden rule #1 All trigonometric functions expect radians — never pass degrees directly. Always convert with np.deg2rad() or np.pi / 180.

Golden rule #2 Use np.arctan2(y, x) instead of np.arctan(y/x) whenever you need the correct angle in the full circle (−180° to 180°).

Golden rule #3 Tan has discontinuities — be careful when plotting or using np.tan near odd multiples of π/2.

Golden rule #4 For signal/wave work always use radians — the 2π period is natural in radians.

Would you like to continue with any of these topics?

  • Trigonometric identities and how NumPy handles them
  • Phase, amplitude, frequency in signal generation
  • Realistic mini-project: simulate sound wave or pendulum motion
  • Common floating-point pitfalls with trig functions
  • Hyperbolic trig functions (sinh, cosh, tanh)

Just tell me what you want to focus on next! 😊

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *