Toggle Menu Icon

Java Matrix Calculator

Download

Change Log:

Compile and Run Matrix Calculator

No special classes or libraries are used with this application. The complete source resides in the one file above. After downloading, the following should work in any JDK 1.2 compatible compiler:

$ javac MatrixCalculator.java
$ java MatrixCalculator

Matrix Calculator Tips/Help

All Matrices must be symmetric (n x n)Enter Matrix Elements Row by Row separated by spaces. Ex. (3x3)

1 2 3
4 5 6
7 8 9

Results will be placed in the C matrix.

The calculation of the determinant, by definition, is based upon a factorial number of calculations with respect to the size of the matrix. ie. a 3x3 matrix would have 6 calculations (3!) to make, whereas a 20x20 matrix would have 2.43 x 10^18 calculations (20!). So instead of brute forcing the calculations, I first do some operations on the matrix, which converts it to a upper triangular matrix, and then calculate the determinant by multiplying down the diagonal, since everything below is 0, this will give the determinant.

Floating Points and Accuracies - For some reason computers aren’t as accurate as I think they are, probably my calculation techniques. The accuracy of the numbers are probably only to 3 maybe 2 decimal places. If you keep applying operations to matrices and then use the resultant matrix a couple of times, the decimals get out of whack.

Calculating an inverse and then multiplying the matrix by it, is a good example of this.

Test Some Mathematical Theories

Mathematics and Linear Algebra

Calculating the Determinant The calculation of the determinant, by definition, is based upon a factorial number of calculations with respect to the size of the matrix. ie. a 3x3 matrix would have 6 calculations (3!), whereas a 20x20 matrix would have 2.43 x 10^18 calculations (20!).

So instead of brute forcing the calculations, I first do some operations on the matrix which converts it to a upper triangular matrix, and then calculate the determinant by multiplying down the diagonal, since everything below is 0, this will give the determinant.

Read about the Linear Algebra Math behind the calculators for more information and mathematical explanations on the definitions and calculation techniques.