2
$\begingroup$

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?

$\endgroup$
1
  • 1
    $\begingroup$ Try SparseArray[T] $\endgroup$ Commented Mar 26, 2016 at 19:19

1 Answer 1

5
$\begingroup$

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!

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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