A Java implementation of matrix arithmetic and determinant calculation using LU decomposition, including a specialised, memory-efficient representation for tri-diagonal matrices. The project also includes a Monte Carlo study investigating how the variance of a random matrix's determinant scales with matrix size.
Matrix classes
- An abstract
Matrixbase class defining shared structure and operations (addition, scalar and matrix-matrix multiplication, random matrix generation) GeneralMatrix— a dense m×n matrix, storing all entries explicitlyTriMatrix— a specialised n×n tri-diagonal matrix representation, storing only the three non-zero diagonals rather than a full n×n array, since tri-diagonal matrices are otherwise almost entirely zero
Determinant calculation via LU decomposition
Rather than computing determinants by cofactor expansion (which requires O(n!) operations and
becomes intractable quickly), both matrix classes calculate determinants via LU decomposition —
factorising a matrix into lower- and upper-triangular components in O(n³) time. TriMatrix uses a
custom-derived, closed-form LU decomposition that exploits the sparse tri-diagonal structure directly,
rather than falling back to the general dense algorithm.
Monte Carlo variance study For matrix sizes n = 2 to 50, thousands of random matrices (entries ~ U(0,1)) were generated for both the general and tri-diagonal case, and the variance of their determinants estimated empirically (20,000 samples per size for general matrices, 200,000 for tri-diagonal). The results were plotted to investigate how determinant variance scales with matrix dimension for each matrix type.
It's a concrete example of how exploiting a matrix's structure (sparsity, in this case) can turn an expensive O(n) full-array algorithm into a much cheaper closed-form one — a recurring theme in numerical linear algebra. The Monte Carlo variance study also ties the implementation back to a genuine statistical question: how does the "spread" of a random matrix's determinant behave as dimension grows, and does that behaviour differ between dense and structured matrices?
Java, LU decomposition, Monte Carlo simulation, MATLAB (for plotting)
Matrix.java— abstract base class for matrix operationsGeneralMatrix.java— dense matrix implementation with LU decompositionTriMatrix.java— tri-diagonal matrix implementation with a custom LU decompositionProject3.java— Monte Carlo simulation estimating determinant variance by matrix sizeVarGraph.pdf— plots of log-variance vs. matrix size for both matrix types