Call DPOTRS from LAPACK to C on GNU / Linux

I would like to get some help in the DPOTRS function from LAPACK when called from C. Yes, I know that the matrix I'm trying to work with is positive definite (with Eigenvalues ​​3, 1 really!)

Now my function is not working properly. It returns an incorrect result.

double A[] = {2.0, 1.0, 1.0, 2.0};
double b[] = {1.5, 0.0};
printf("%5.3f %5.3f\n", b[0], b[1]);
info = dpotrs('U',2,1,A,2,b,2);
printf("%d\n", info);
printf("%5.3f %5.3f\n", b[0], b[1]);

This is the code. dpotrs is imported manually using this code:

static long dpotrs(char UPLO, long N, long NRHS, double* A, long LDA, double* B, long LDB)
{
    extern void dpotrs_(char* UPLOp, long* Np, long* NRHSp, double* A, long* LDAp, double* B, long* LDBp, long* infop);
    long info;
    dpotrs_(&UPLO, &N, &NRHS, A, &LDA, B, &LDB, &info);
    return info;
}

It returns an incorrect result! Correct result: 1.000, -0.500

However, I get 0.469, -0.188

But also, the information returns 0, as if everything went well!

And that, ladies and gentlemen, illuminates my mind.

Thanks in advance!

0
source share
1 answer

I think you need to read some documentation:

*
*  Purpose
*  =======
*
*  DPOTRS solves a system of linear equations A*X = B with a symmetric
*  positive definite matrix A using the Cholesky factorization
*  A = U**T*U or A = L*L**T computed by DPOTRF.
*

DPOTRS LAPACK. . A DPOTRF , DPOTRS.

+1

All Articles