I am a data scientist working on time series forecasting (using R and Python 3) at the London Ambulance Service NHS Trust. I earned my PhD in cognitive neuroscience at the University of Glasgow working with fmri data and neural networks. I favour linux machines, and working in the terminal with Vim as my editor of choice.
Now that we have the method of elimination, we can get a lot of information
about a matrix easily. The pivots of a matrix are the first non-zero numbers
sitting in each row of U after elimination. Here we return those pivots along
with the columns in which they were found:
Demo
We create two matrices, call the pivots method and print the results:
Outputs:
Rank
The rank of a matrix tells us a huge amount, and is simply the number of
pivots:
Demo
We create two matrices, call the rank method and print the results:
Outputs:
Singularity
The matrix is singular if during elimination row exchanges can't avoid a
zero in a pivot position. Our elimination method already returns a variable
indicating singularity, and so this next method just provides a cleaner way of
accessing that variable:
Demo
We create two matrices, call the is_singular method and print the results:
Outputs:
Determinant
The determinant of a matrix is simply the product of the pivots, with a
negative sign if there were an odd number of row exchanges. Here we don't use
the pivot method we wrote, as we also need the number of row exchanges:
Demo
We create two matrices, call the determinant method and print the results:
Outputs:
Is matrix positive definite?
If all the pivots of a matrix are strictly greater than zero, then the
matrix is positive definite. If they are greater than or equal to zero, then
the matrix is positive semi-definite. Similary, strictly less than zero means
the matrix is negative definite and if there are also some zeros then the
matrix is negative semi-definite.
Code implementation
We also create a method that returns the base-10 integer representation of a
base-2 (i.e. binary) number. The binary number is constructed from the
TRUE/FALSE answers to 3 queries: whether the matrix contains any negative, zero
(i.e less pivots than columns), or positive pivots. The answers to these 3
queries uniquely determine what kind of 'definiteness' (if any) we can call the
matrix. Thus the method returns a number (between 0 and 7: since $2^3 = 8$
possibilities) which can be used as a unique identifier of the
'definiteness':
Demo
We use the same matrices as in the
Pivots section above
, and call the pivots method and check if they positive definite: