Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

unexpected ?potrf subroutine failure

Yuna_D_
Beginner
307 Views

AHi,

I need to generate a gaussian correlated noise based on a covariance matrix with fortran. I am using spotrf subroutine to do the cholesky decomposition. However, the decomposition is always failed at a specific row of input matrix. As the reference indicates, it means the leading minors of that row is not positive definite. But previous work with the same data in matlab chol function shows that the matrix is positive definite.

This problem is killing me now. Can anyone help me get out of the swap ? Or just if there is a better way to generate correlated noise without getting involved in the covariance matrix.The code for generate the covariance matrix and cholesky decomposition is listed below. Thanks a lot!!

-------------------------------------------------------------------------------------------

Program DensityRealization

Implicit None

Real::lc

Integer::std,cases,Layer_Num,i,j,CholFlag

Real,Allocatable,Dimension(:,:)::c,sigma,rhostd

Real,Allocatable,Dimension(:)::z,Rnd

REAL,Parameter::p3=38.2273

 

Layer_Num=13827

std=20

cases=500

Allocate(z(Layer_Num),c(Layer_Num,Layer_Num),sigma(Layer_Num,Layer_Num),rhostd(Layer_Num,1),Rnd(cases*Layer_Num))

 

DO i=1,10000

    z(i)=(i-1)*0.01

 END DO 

 DO i=10001,11799

    z(i)=100+(i-10000-1)*0.5

 END DO

 DO i=11800,Layer_Num

    z(i)=1000+(i-11799-1)

 END DO

! coveriance matrix

Do i=1,Layer_Num

  Do j=1,i

     c(i,j)=abs(z(i)-z(j))

     c(j,i)=c(i,j)

  End DO

End DO

 

 

c=-c/lc

c=exp(c)

rhostd(:,1)=std*exp(-z/p3)

sigma=matmul(rhostd,TRANSPOSE(rhostd))

sigma=sigma*c

!cholesky decomposition

CALL SPOTRF('U',Layer_Num,sigma,Layer_Num,CholFlag)

print*,CholFlag

End

0 Kudos
2 Replies
mecej4
Honored Contributor III
307 Views

Please post the actual code. You cannot use the integer variable "Layer_Num" to dimension arrays, so your code gets rejected by the compiler. It is of little use to discuss the running behavior of code that cannot even be compiled.

It would be better if you attached the source file or pasted the code using the {code} button.

0 Kudos
Yuna_D_
Beginner
307 Views

Sorry, I have modified the code. It should work now. Initially, it is just a subroutine in a big project, I extract the related code so it looks like this. Sorry for the trouble.

0 Kudos
Reply