Skip to content

Repository files navigation

Matrix Determinants via LU Decomposition

Overview

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.

What this project does

Matrix classes

  • An abstract Matrix base class defining shared structure and operations (addition, scalar and matrix-matrix multiplication, random matrix generation)
  • GeneralMatrix — a dense m×n matrix, storing all entries explicitly
  • TriMatrix — 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.

Why this is interesting

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?

Tools

Java, LU decomposition, Monte Carlo simulation, MATLAB (for plotting)

Files

  • Matrix.java — abstract base class for matrix operations
  • GeneralMatrix.java — dense matrix implementation with LU decomposition
  • TriMatrix.java — tri-diagonal matrix implementation with a custom LU decomposition
  • Project3.java — Monte Carlo simulation estimating determinant variance by matrix size
  • VarGraph.pdf — plots of log-variance vs. matrix size for both matrix types

About

Java matrix library with LU-decomposition-based determinant calculation, plus a Monte Carlo study of determinant variance by matrix size.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages