问题
I'd like to seek some help with the DPOTRS function from LAPACK when being called from within C. Yes, I am aware that the matrix I am trying to work with is positive definite (with Eigenvalues 3, 1 in fact!)
Right now my function doesn't work correctly. 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 manually imported 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 the wrong result! The correct result would be 1.000,-0.500
However, I recieve 0.469,-0.188
But on top of that, info returns 0, as if it went well!
And that, ladies and gentlemen, boggles my mind.
Thanks in advance!
回答1:
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.
*
The input matrix to DPOTRS
must be an already Cholesky factorized matrix in LAPACK upper or lower triangular format. You have skipped a step. Factorize your A
with DPOTRF
first, then use it to solve for one or more right hand sides with DPOTRS
.
来源:https://stackoverflow.com/questions/9454328/calling-dpotrs-from-lapack-within-c-on-gnu-linux