简体   繁体   中英

Need an example code for getting the inverse of a square matrix using gsl LU decomposition

Could someone kindly show me an example c++ code on how to call gsl function gsl_linalg_LU_decomp() and related to obtain the inverse of a matrix? Very much appreciate it!

I am assuming you do not need the actual inverse, but you need to solve a problem of the type Ax=b. If so, then there is a pretty good example here . If you are using STL containers for your data, eg std::vector , then you need to pass a pointer to the first data entry like

std::vector<double> vec(length,val);
gsl_needs_ptr_to_double(&vec[0]);

If you do need the actual inverse of A, then follow the example I linked to obtain the LU decomposition and then call the function gsl_linalg_LU_invert . The gsl library is a GNU project and is generally well documented online, so I suggest you just take some time to read through it a bit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM