numpy - Matrix Inversion in CBLAS/LAPACK vs Python -


the matrix trying invert is:

    [ 1  0  1] = [ 2  0  1]     [-1  1  1]  

the true inverse is:

       [-1  1  0] a^-1 = [-3  2  1]        [ 2 -1  0] 

using python's numpy.linalg.inv, correct answer. 1 of routines matrix inverse uses dgetri_, is:

void compute_matrix_inverse_dbl( double* matrix,                                  int order,                                  double * inverse ) {      int n, lwork;     int success;     int *pivot;     double* workspace;      //===allocate space===//     pivot = malloc(order * order * order * sizeof(*pivot));     workspace = malloc(order * order * sizeof(*workspace));      //===run setup===//     n = order;     copy_array_dbl(matrix, order*order, inverse);     lwork = order*order;      //===factor matrix===//     dgetrf_(&n,&n,inverse,&n,pivot,&success);      //===compute inverse===//     dgetri_(&n, inverse, &n, pivot, workspace, &lwork, &success);      //===clean up===//     free(workspace);     free(pivot);      return;   } 

using routine, get:

       [-1   1 +-e1 ] a^-1 = [-3   2   1  ]        [ 2  -1 +-e2 ] 

where e1 , e2 , small numbers on order of machine precision 1e-16. perhaps dgetri_ not best use. however, when invert using qr decomposition via zgeqrf_ , zungqr_, similar answer. when use dgesvd_ inverse using svd, similar answer well.

python seems use routine called _umath_linalg.inv. have few questions:

  • what routine do?
  • what cblas/lapack routine can use invert matrix , result cblas/lapack (such e1 , e2 replaced proper zeros)?


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -