2
$\begingroup$

I think its already been asked , but still i can't figure out a way to do it computationally,

I had to check for positive definiteness of a matrix $A$ of order $n$ by $n$.I know that for any vector $x$ of order $1$ by $n$ , $x^{t}Ax > 0$,

But the problem is i want to implement it while coding a C++ program for Cholesky method in which i need both 1)Symmetric matrix and 2)Positive definite matrix.

How do i approach this situation,if i go for the definition then it can be computationally inefficient as i have to check for each vector $x$.

Any other method which i can use for Positive - definiteness. ?

Any help is great!

  • 2
    I saw that it can be checked by taking the determinant of sub-square matrices and checking if they all are positive, but that too is little computationally difficult as we have to take each sub square matrix and then again determinant of those!2017-02-16
  • 0
    Also i could not find a tag related to c++ , eventhough a tag of matlab is there.2017-02-16

2 Answers 2

4

A matrix $A$ is positive definite if and only if the symmetric matrix $M = A + A^T$ is positive definite. You should be able to find a program that attempts a Cholesky decomposition on $M$. If it succeeds, then $A$ is positive semidefinite. If it succeeds and the resulting lower-triangular matrix has only non-zero elements on the diagonal (or a non-square lower-triangular matrix), then $A$ is positive definite. If the Cholesky decomposition fails, then $A$ is not positive semidefinite (and of course, not positive definite).


About $A + A^T$: note that for any $x$, we have $$ 2(x^TAx) = x^T(Ax) + (Ax)^Tx = x^TAx + x^TA^Tx = x^T(A + A^T)x $$ clearly, $x^TAx$ will be positive (or non-negative) if and only if $x^T(A + A^T)x$ is positive (or non-negative).

  • 0
    Oh nice..Can you give some reference to this..2017-02-16
  • 0
    @BAYMAX sorry, don't really have a good reference off the top of my head. My guess is that Trefethen and Bau might have something relevant in there, though2017-02-16
  • 0
    it was nice short answer though!2017-02-16
  • 0
    @BAYMAX did you mean a reference for $A$ is positive definite if and only if $A + A^T$ is positive definite? Because that's a quick proof.2017-02-16
  • 0
    Actually i needed both, How to get the first one?2017-02-16
  • 1
    See my edit. Don't have a reference for the Cholesky stuff, though.2017-02-16
0

There are symmetric positive definite matrices $M$ for which Cholesky's algorithm will fail due to the limitations of floating point arithmetic.

A specific example is given here. Let $u \ll 1$ denote the unit round off error and consider the matrix $$ M = \begin{bmatrix} 1 + 2u & 1 \\ 1 & 1 - u \end{bmatrix}.$$ This matrix is exactly representable. It is clear that $M$ is symmetric positive definite, for $$ \text{Tr}(M) = 2 + u > 0$$ and $$ \text{det}(M) = u - 2u^2 > 0.$$

Now let $\text{fl}(x)$ denote the floating point representation of the real number $x$. Since $$1+2u = (1 + u)^2 - u^2$$ we have $$ 1 < \sqrt{1 + 2 u} < 1 + u < 1 + 2u. $$ It follows that $\text{fl}(\sqrt{1+2u}) = 1$ as there are no floating point numbers in the open interval between $1$ and $1+2u$ and we must pick the option which has the smallest error. After processing the first column of $M$ and performing the linear update of the lower right corner, we are left with $$ M^{(1)} = \begin{bmatrix} 1 & 1 \\ 1 & - u \end{bmatrix}.$$ The algorithm will now fail because the final pivot is strictly negative.

In general, if Cholesky's algorithm runs to completion, then it produces the exact factorization of a matrix $\hat{M} = \hat{L}\hat{L}^T $ which is close to $M$. This may very well be enough for your purposes, especially if you can establish that the smallest eigenvalue of $\hat{M}$ is not too small.