[Rd] Unexplained difference between results of dppsv and dpotri LAPACK routines

Pierrick Bruneau pbruneau at gmail.com
Sat Dec 20 22:06:57 CET 2014


Dear R contributors,

Considering the following sample C code, that illustrates two possible
uses of a Cholesky decomp for inverting a matrix, equally valid at
least in theory:

SEXP test() {

int d = 2;
int info = 0;
double mat[4] = {2.5, 0.4, 0.4, 1.7};
double id[4] = {1.0, 0.0, 0.0, 1.0};
double lmat[3];
F77_CALL(dpotrf)("L", &d, mat, &d, &info);
lmat[0] = mat[0];
lmat[1] = mat[1];
lmat[2] = mat[3];
F77_CALL(dppsv)("L", &d, &d, lmat, id, &d, &info);
// id now contains L^(-T)
F77_CALL(dpotri)("L", &d, mat, &d, &info);
// mat contains mat^(-1)

Rprintf("%f\n", id[0] * id[0]);
// owing to that id is lower triangular
Rprintf("%f\n", mat[0]);

return(R_NilValue);

}

I expected both printed values to be identical, or almost so. But
issuing .Call("test") prints:
0.426571
0.415648

Difference is thus many degrees of magnitude above numerical
precision. What am I missing that explains it?

Thanks by advance for the kind answers,
Pierrick



More information about the R-devel mailing list