0

I have a matrix A which is 390 by 390 and contains numbers such as:

141270,991258825 -92423,2972762164 -92423,2972762164 60465,8168198016 139998,877391881 -91591,0460330842 30573,0969789307 -20001,7456206658 ...

If I try chol(A), Matlab fails and says that the matrix must be positive definite. Ok I saw in the API that [R,p] = chol(A) also works for negative definite matrices. I tried this, but R then becomes a 1x1 matrix. But I expect a 390x390 matrix.

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
farahm
  • 1,326
  • 6
  • 32
  • 70

1 Answers1

2

The help file is slightly unclear here, but it doesn't mean that you can just use a non-positive definite matrix and get the same result by changing the way you call the function:

[R,p] = chol(A) for positive definite A, produces an upper triangular matrix R from the diagonal and upper triangle of matrix A, satisfying the equation R'*R=A and p is zero. If A is not positive definite, then p is a positive integer and MATLABĀ® does not generate an error. When A is full, R is an upper triangular matrix of order q=p-1 such that R'*R=A(1:q,1:q).

If your matrix is not positive definite, p > 0, therefore the size of your result R will depend on p. In fact, I think this particular syntax is simply designed to allow you to use chol as a way of checking if A is positive definite, rather than just giving an error if it is not. The help file even says:

NoteĀ Using chol is preferable to using eig for determining positive definiteness.

Example - take pascal(5) and set the last element to something negative:

A =

     1     1     1     1     1
     1     2     3     4     5
     1     3     6    10    15
     1     4    10    20    35
     1     5    15    35    -3

[R,p] = chol(A) returns

R =

     1     1     1     1
     0     1     2     3
     0     0     1     3
     0     0     0     1


p =

     5

Sure enough, R'*R' == A(1:4,1:4)

By setting element X(2,2) to be negative, on the other hand, gives p of 2 and therefore a single value in R which will be sqrt(A(1,1). Setting A(1,1) to be negative returns p = 1 and an empty R.

nkjt
  • 7,825
  • 9
  • 22
  • 28