4

I have two matrices A and B.

B is just a matrix with only one of the diagonal elements non zero. All the non diagonal elements are zero as well. I have to calculate $A^{-1}B$. My $A^{-1}B$ matrix is sparse. In matlab I can do A\B. But is there any trick to further speed this up?

I have a bunch of B matrices in which only one of the diagonal elements are non zero and the non diagonal elements are zero. I cannot store the $A^{-1}$. Is there any way to speed this up?

user34790
  • 2,020
  • 7
  • 30
  • 37
  • Let n be the number of rows or columns of A and B. In the worst case, A^-1 has n^2 nonzero entries. For each B, A^-1*B has n nonzero entries. Do you mean that you can store all the A^-1*B results but not A^-1? How many B matrices do you have? What is a typical value for n in your problem? – Luis Mendo Dec 26 '13 at 00:08
  • have you considered spinv (sparse matrix invert? http://www.mathworks.com/help/matlab/math/sparse-matrix-operations.html?searchHighlight=sparse+inverse – EngrStudent Dec 27 '13 at 19:50

2 Answers2

0

If the $(i,i)^{th}$ element of an otherwise zero matrix $B$ is equal to one, and you post-multiply some matrix $A^{-1}$ by this matrix, you are, in effect, extracting the $i^{th}$ column from $A^{-1}$ and setting all the other elements equal to zero. Since you need the full $i^{th}$ column of $A^{-1}$, you'll still have to invert $A$, but you don't need to actually do the post-multiplication; just create a zero matrix and replace the $i^{th}$ column with that of $A^{-1}$.

jbowman
  • 193
  • 6
-1

Your problem can be simplified very much. Given that we want to store solution in a new matrix (C say), and

a) A is an NxN matrix

b) you know B only the main diagonal has elements in it (with itself being an NxN matrix)

c) you want A*B

C = zeros(size(A));
new_B = diag(B)';
[A_rows, A_cols] = size(A);
for i=1:A_rows
    C(i,:) = A(i,:).*new_B;
end
woosah
  • 843
  • 11
  • 22
  • I have to downvote your answer. It seems you are computing A*B. The OP asks to compute A^-1*B – Luis Mendo Dec 25 '13 at 23:58
  • 1
    @LuisMendo My bad. Tricky question after reading it fully. I can't seem to beat MATLABs built-in A\b. Still interesting if one finds just a solution for some size – woosah Dec 26 '13 at 01:08