The Sylvester’s criterion can be used to check whether a symmetric matrix is positive definite
A quadratic form
( symmetric matrix) is positive definite if the leading principal minors of are positive. Leading principal minors are the determinants of the top-left square submatrices of a given matrix Image credit: Princeton lecture
Code
Sagemath
def is_positive_definite(A):
"""Apply Sylvester's Criterion to check if a matrix is positive definite.
Inputs:
- A: A symmetric matrix
Output:
- True if the matrix is positive definite, False otherwise
"""
# Ensure matrix is symmetric
if A.is_symmetric():
print(f"Matrix is not symmetric")
return False
n = A.nrows()
# Loop through submatrices
for k in range(1, n+1):
# Extract the top-left k x k submatrix
submatrix = A[:k, :k]
determinant = submatrix.det()
# If any determinant is non-positive, the matrix is not positive definite
if determinant <= 0:
print(f"Submatrix {k}x{k}: \n{submatrix}\nDeterminant: {determinant}")
return False
return True
A = Matrix(QQ, [
[4, 12, -16],
[12, 37, -43],
[-16, -43, 98]
])
is_positive_definite()