简体   繁体   中英

[a b]=cholcov function returns a=[] and b=NaN for a symmetric positive definite matrix

I have this matrix:

S=   6.84370358358718e-006    -7.45833473076585e-007
    -7.45833473076565e-007     7.11723106043725e-006

It is symmetric:

S-S'=                     0    -2.00111533788828e-020
      2.00111533788828e-020                         0 

and is positive definite:

eig(S)= 6.22219831321029e-006    and     7.73873633081414e-006

When I use [ab]=cholcov(S) , it returns returns a=[] and b=NaN . It is written in MatLab help that [T,num] = cholcov(SIGMA) ... If SIGMA is not square and symmetric, num is NaN and T is empty.

Of course the chol(S) function decomposes this function without any error. I don't know the difference between chol and cholcov and it is not important, since I don't have any choices. The error comes from mvnrnd(zeros(1,2),S) function, when I try to generate some random numbers:

??? Error using ==> mvnrnd at 118
SIGMA must be a symmetric positive semi-definite matrix.

Can anyone tell me what's wrong here? thanks.

It is NEARLY symmetric. You yourself admit that it is NOT symmetric. Is being ALMOST pregnant the same thing as pregnant? You show that S~=S'. The fix is easy.

S = (S + S')/2;

You wrote:

S-S'=                     0    -2.00111533788828e-020
      2.00111533788828e-020                         0 

That says that S is not symmetric. It's ALMOST symmetric. But... not quite. If this is due to numerics, you might be able to fix this with:

symmetricS = mean(cat(3,S,S'),3);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM