I would like to find the inverse of a matrix.
I know this involves first LU factorisation then the inversion step but I cannot find the required function by searching apple’s docs of 10.7!
This seems like a useful post Symmetric Matrix Inversion in C using CBLAS/LAPACK, pointing out that the sgetrf_ and sgetri_ functions should be used. However searching these terms I find nothing in Xcode docs.
Does anybody have boiler plate code for this matrix operation?
Apple does not document the LAPACK code at all, I guess because they just implement the standard interface from netlib.org. It’s a shame that you cannot search the these function names from the built-in Xcode docs, however the solution is fairly straight forward: just specify the function name in the URL e.g. for
dgetrf_()go to, http://www.netlib.org/clapack/what/double/dgetrf.c.To invert a matrix two LAPACK function are need:
dgetrf_(), which performs LU factorisation, anddgetri_()which takes the output of the previous function and does the actual inversion.I created a standard Application Project using Xcode, added the Accelerate Framework, create two C files: matinv.h, matinv.c and edited the main.m file to remove Cocoa things:
Now the header file,
and then source file,