I have an algorithm that allocates a complex double matrix "A" with a pre-defined size N x N. The elements are initially zero. I also allocated matrix of size N x N to store the inverse, "A_inv". During the algorithm, elements of "A" get filled. At each iteration i, I end up with a submatrix of size i x i. So it looks something like this for the second iteration, where N=4:
| x00 x01 0.0 0.0 |
| x10 x11 0.0 0.0 |
| 0.0 0.0 0.0 0.0 |
| 0.0 0.0 0.0 0.0 |
where the x's indicate some non-zero value. Now I wish to invert the non-zero part of the matrix (a 2x2 matrix in this example). So far I have been doing this in the following way:
- copy the non-zero elements of "A" to a 2x2 gsl matrix
- use gsl LU decomposition to invert the 2x2 gsl matrix
- copy the 2x2 inverted matrix into A_inv
The problem with this approach is that I have to copy over a matrix twice in each iteration. Once to a smaller n x n gsl matrix and once to copy the resulting inverted nxn gsl matrix to A_inv.
I was wondering if anyone knows of a more direct way. Is there a way to use some gsl function to only invert part of a matrix and ignore any zero elements? Say something like this:
A = NxN matrix
A_inv = invert_submatrix(A,n,n)
where n < N.
Here invert_submatrix()
would only consider the n x n part of A. Furthermore, the original matrix "A" must not be altered by this inversion.
Maybe that last demand makes it necessary to copy over the matrix anyway, in which case it would be no more efficient than what I do now. That said, gsl algorithms tend to be a lot more efficient than anything I usually come up with. So thoughts on this are still very welcome.