Home > Python > Matrix Operation

Ch. 4.3 Matrix Multiplication

Chapters Index
Program 1

Matrix Multiplication

Python 3.11 Ready

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

Matrix Multiplication: Inner Product Contraction & Operator Composition

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

1. Core Principles & Theoretical Framework

Successive Transformations: Models sequential rotations, Lorentz boosts, and quantum operator applications $\hat{A}\hat{B}|\psi\rangle$.
Dimension Rule: Multiplying an $m \times p$ matrix by a $p \times n$ matrix produces an $m \times n$ matrix. Inner dimensions must match.
Non-Commutative: In general, $\mathbf{A}\mathbf{B} \neq \mathbf{B}\mathbf{A}$, mirroring the non-commutativity of quantum observables $[\hat{x}, \hat{p}] = i\hbar$.

2. Mathematical Formulation & Algorithmic Pipeline

Matrix multiplication inner product contraction:

$$ C_{ij} = \sum_{k=1}^p A_{ik} B_{kj}, \quad \text{Complexity: } \mathcal{O}(m \cdot p \cdot n) \to \mathcal{O}(N^3) \text{ for square matrices} $$

3. Numerical Mechanics & Implementation Logic

  • Dimension Validation: Verify that columns of $\mathbf{A}$ equal rows of $\mathbf{B}$ (len(A[0]) == len(B)).
  • Three-Loop Nest: Iterate outer row $i$, inner column $j$, and contraction index $k$.
  • Accumulation: Initialize sum $C_{ij} = 0.0$ before executing the $k$-loop sum.

4. Relevant Computational Practice Exercises

Exercise 1
Multiply a $3 \times 3$ coordinate rotation matrix by a 3D position vector and verify that the vector magnitude $|\mathbf{r}|$ is invariant.
Exercise 2
Demonstrate matrix non-commutativity by computing $\mathbf{A}\mathbf{B} - \mathbf{B}\mathbf{A}$ for the Pauli spin matrices $\sigma_x$ and $\sigma_y$.
Exercise 3
Implement matrix exponentiation $\mathbf{A}^k = \mathbf{A} \cdot \mathbf{A} \cdots \mathbf{A}$ for a $2 \times 2$ matrix.
Standard Literature & References:
  • Mark Newman, "Computational Physics", University of Michigan (2013).
  • Gilbert Strang, "Introduction to Linear Algebra", Wellesley-Cambridge Press (2016).