Home > Python > Introduction to Python

Ch. 1.8 Module math and cmath

Chapters Index
Program 1

Module math and cmath

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Program 2

Module math and cmath

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Program 3

Module math and cmath

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Program 4

Module math and cmath

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Program 5

Module math and cmath

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Program 6

Module math and cmath

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Program 7

Module math and cmath

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Program 8

Module math and cmath

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Program 9

Module math and cmath

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Program 10

Module math and cmath

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Program 11

Module math and cmath

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Program 12

Module math and cmath

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Program 13

Module math and cmath

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Program 14

Module math and cmath

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Program 15

Module math and cmath

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Program 16

Module math and cmath

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Program 17

Module math and cmath

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Theoretical Principles & Computational Physics Guide

Modules math and cmath: Standard Mathematical & Complex Libraries

Dr. Alorika Chatterjee & Dr. Anirban Shaw Science & Physics Learners Python 3 / NumPy / SciPy

1. Core Principles & Theoretical Framework

C-Optimized Math: The math module delivers fast, IEEE-compliant transcendental and trigonometric functions.
Complex Arithmetic: The cmath module provides analytic functions for complex variables, essential for quantum and wave mechanics.
Polar Coordinates: Seamless conversion between rectangular ($x + iy$) and polar ($r e^{i\theta}$) representations.

2. Mathematical Formulation & Algorithmic Pipeline

Euler's formula and polar decomposition:

$$ z = x + iy = r e^{i\theta}, \quad r = |z| = \sqrt{x^2 + y^2}, \quad \theta = \operatorname{atan2}(y, x) $$

3. Numerical Mechanics & Implementation Logic

  • Import Distinction: Use math for real quantities to detect unphysical negative roots early; use cmath when complex numbers are physically expected.
  • Phase Angles: Use math.atan2(y, x) rather than atan(y/x) to avoid division-by-zero and preserve quadrant sign.
  • Trig Argument Units: Remember that trigonometric functions in standard Python operate strictly in radians.

4. Relevant Computational Practice Exercises

Exercise 1
Calculate the complex impedance $Z = R + i(\omega L - 1/(\omega C))$ of an RLC circuit and determine the resonance frequency.
Exercise 2
Numerically evaluate Euler's identity $e^{i\pi} + 1 = 0$ using <code>cmath.exp(1j * cmath.pi)</code> to machine precision.
Exercise 3
Compute the phase shift and transmission coefficient for a plane wave incident on a dielectric boundary.
Standard Literature & References:
  • David J. Griffiths, "Introduction to Electrodynamics", Cambridge University Press (2017).