I am generating an n x n matrix where n is specified by DIM:

DIM = 10;
T = Table[Join[Table[0, {j, 1, i - 1}], {1, -2, 1},Table[0, {j, i + 3,DIM}]], {i, 1, DIM - 2}];
T = Join[{Table[If[i == 1, 1, 0], {i, 1, DIM}]},T, {Table[If[i == DIM, 1, 0], {i, 1, DIM}]}];

T // MatrixForm

The resulting matrix is square, and block diagonal. I then need to take the inverse of this matrix:

Tinv = Inverse[T];
Tinv // MatrixForm

This works fine as expected. However, I need to increase the dimensions of the matrix to be 2880 x 2880. When I go to invert this new matrix, my computer locks up. Is there an algorithm or efficient method for computing the inverse of such a simple matrix?

  • 1
    $\begingroup$ Try SparseArray[T] $\endgroup$ – Algohi Mar 26 '16 at 19:19

Thank you Algohi! I looked up how to invert a SparseArray and found some code which I implemented:

s = SparseArray[T];
f = LinearSolve[s];
aInv = f[SparseArray[{Band[{1, 1}] -> 1.}, {DIM, DIM}, 0.]];

It inverts the 2880 X 2880 matrix within a few seconds!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.