<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/166759</link>
    <title>MATLAB Central Newsreader - calculating the inverse efficiently (not for solving equations :-) )</title>
    <description>Feed for thread: calculating the inverse efficiently (not for solving equations :-) )</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 01 Apr 2008 19:19:02 -0400</pubDate>
      <title>calculating the inverse efficiently (not for solving equations :-) )</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/166759#424037</link>
      <author>M E</author>
      <description>Hi,&lt;br&gt;
&lt;br&gt;
well most of you probably think &quot;Oh no, not another one&lt;br&gt;
trying to solve a system of linear equations using the&lt;br&gt;
matrix inverse&quot;, but luckily for those guys I don't need it&lt;br&gt;
for that :-)&lt;br&gt;
&lt;br&gt;
So my problem is that after some calculations I got stuck&lt;br&gt;
with an equation of the following kind:&lt;br&gt;
&lt;br&gt;
(A*B^-1*C)*x=y&lt;br&gt;
&lt;br&gt;
As the matrix B is multiplied with A and C there's no way&lt;br&gt;
(or at least I don't know of any) to get around the problem&lt;br&gt;
of knowing the full inverse of B.&lt;br&gt;
&lt;br&gt;
Some important properties for B are, that it's symmetric and&lt;br&gt;
sparse. Yes, I know having the inverse will destroy the&lt;br&gt;
sparisty :-)&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
So far the possibilities for calculating the inverse of B, I&lt;br&gt;
have come up with are:&lt;br&gt;
*LU decomposition: tends to fail because B is rather large&lt;br&gt;
and therefore my computer runs out of memory&lt;br&gt;
*Cholesky decomposition: not much more efficient than the LU&lt;br&gt;
decomposition (n^3/3 compared to 2n^3/3)&lt;br&gt;
&lt;br&gt;
I also thought of using eigenvalues, but that wouldn't help&lt;br&gt;
much since you need the inverse of the matrix with the&lt;br&gt;
eigenvectors.&lt;br&gt;
&lt;br&gt;
I hope that I could give anyone enough insight into my&lt;br&gt;
problem...&lt;br&gt;
&lt;br&gt;
Does anyone know another efficient way for calculating the&lt;br&gt;
inverse for sparse symmetric matrices, or maybe to simplify&lt;br&gt;
or transform the upper equation to make it less costly?&lt;br&gt;
&lt;br&gt;
Thanks in advance!!&lt;br&gt;
&lt;br&gt;
Albert Buehrli</description>
    </item>
    <item>
      <pubDate>Tue, 01 Apr 2008 20:02:06 -0400</pubDate>
      <title>Re: calculating the inverse efficiently (not for solving equations :-) )</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/166759#424050</link>
      <author>Roger Stafford</author>
      <description>&quot;M E&quot; &amp;lt;gitsnedbutzi@hotmail.com&amp;gt; wrote in message &amp;lt;fsu1r6$ib3&lt;br&gt;
$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; ........&lt;br&gt;
&amp;gt; I also thought of using eigenvalues, but that wouldn't help&lt;br&gt;
&amp;gt; much since you need the inverse of the matrix with the&lt;br&gt;
&amp;gt; eigenvectors.&lt;br&gt;
&amp;gt; ........&lt;br&gt;
&amp;gt; Albert Buehrli&lt;br&gt;
---------&lt;br&gt;
&amp;nbsp;&amp;nbsp;If B is symmetric, real, and non-singular, you CAN use eigenvectors to find its &lt;br&gt;
inverse.  Just take the reciprocals of its eigenvalues:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;[v,d] = eig(B);&lt;br&gt;
&amp;nbsp;Binv = v*diag(1./diag(d))*v';&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;However, I am not claiming this is necessarily the most efficient way to solve &lt;br&gt;
your problem.&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
    <item>
      <pubDate>Tue, 01 Apr 2008 20:38:02 -0400</pubDate>
      <title>Re: calculating the inverse efficiently (not for solving equations :-) )</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/166759#424054</link>
      <author>M E</author>
      <description>&quot;Roger Stafford&quot; &amp;lt;ellieandrogerxyzzy@mindspring.com.invalid&amp;gt;&lt;br&gt;
wrote in message &amp;lt;fsu4bu$l24$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt;   If B is symmetric, real, and non-singular, you CAN use&lt;br&gt;
eigenvectors to find its &lt;br&gt;
&amp;gt; inverse.  Just take the reciprocals of its eigenvalues:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;  [v,d] = eig(B);&lt;br&gt;
&amp;gt;  Binv = v*diag(1./diag(d))*v';&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   However, I am not claiming this is necessarily the most&lt;br&gt;
efficient way to solve &lt;br&gt;
&amp;gt; your problem.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Roger Stafford&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Indeed, yes you're right. Forgot that for symmetric matrices&lt;br&gt;
you don't need the inverse of V, but only the transpose.&lt;br&gt;
&lt;br&gt;
Maybe still not the most efficient way, but at least I'm one&lt;br&gt;
step closer to an efficient solution.&lt;br&gt;
&lt;br&gt;
Thanks!!</description>
    </item>
    <item>
      <pubDate>Tue, 01 Apr 2008 20:43:03 -0400</pubDate>
      <title>Re: calculating the inverse efficiently (not for solving equations :-) )</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/166759#424056</link>
      <author>M E</author>
      <description>&amp;gt; Indeed, yes you're right. Forgot that for symmetric matrices&lt;br&gt;
&amp;gt; you don't need the inverse of V, but only the transpose.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Maybe still not the most efficient way, but at least I'm one&lt;br&gt;
&amp;gt; step closer to an efficient solution.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks!!&lt;br&gt;
&lt;br&gt;
Btw. has anyone experience with how long it takes to&lt;br&gt;
calculate all eigenvalues of the large sparse matrix? Is&lt;br&gt;
this fast?</description>
    </item>
    <item>
      <pubDate>Tue, 01 Apr 2008 22:54:03 -0400</pubDate>
      <title>Re: calculating the inverse efficiently (not for solving equations :-) )</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/166759#424079</link>
      <author>John D'Errico</author>
      <description>&quot;M E&quot; &amp;lt;gitsnedbutzi@hotmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;fsu6on$qaa$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Indeed, yes you're right. Forgot that for symmetric matrices&lt;br&gt;
&amp;gt; &amp;gt; you don't need the inverse of V, but only the transpose.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Maybe still not the most efficient way, but at least I'm one&lt;br&gt;
&amp;gt; &amp;gt; step closer to an efficient solution.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Thanks!!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Btw. has anyone experience with how long it takes to&lt;br&gt;
&amp;gt; calculate all eigenvalues of the large sparse matrix? Is&lt;br&gt;
&amp;gt; this fast?&lt;br&gt;
&lt;br&gt;
No, I don't think this is the right way to go.&lt;br&gt;
&lt;br&gt;
You don't want to use eig to do this if your&lt;br&gt;
matrix is large and sparse, as the eigenvector&lt;br&gt;
set will NOT be sparse, and you need them&lt;br&gt;
too.&lt;br&gt;
&lt;br&gt;
Best is probably to use chol, perhaps with a&lt;br&gt;
permutation to minimize the fill-in. I think&lt;br&gt;
that the current best method is amd if I&lt;br&gt;
remember right. A quick test shows that for&lt;br&gt;
some matrices, the difference can be&lt;br&gt;
significant.&lt;br&gt;
&lt;br&gt;
n = 1000;&lt;br&gt;
A = sprand(n,n,.001);&lt;br&gt;
A = (A + A') + 3*speye(n,n);&lt;br&gt;
&lt;br&gt;
timeit(@() chol(A))&lt;br&gt;
ans =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.56226&lt;br&gt;
&lt;br&gt;
p = amd(A);&lt;br&gt;
timeit(@() chol(A(p,p)))&lt;br&gt;
ans =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.0038918&lt;br&gt;
&lt;br&gt;
timeit(@() amd(A))&lt;br&gt;
ans =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.0014697&lt;br&gt;
&lt;br&gt;
R = chol(A);&lt;br&gt;
nnz(R)&lt;br&gt;
ans =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;31133&lt;br&gt;
&lt;br&gt;
r(:,p) = chol(A(p,p));&lt;br&gt;
nnz(r)&lt;br&gt;
ans =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3940&lt;br&gt;
&lt;br&gt;
Most of the time, the difference will not be&lt;br&gt;
that dramatic. You will still need to undo the&lt;br&gt;
permutation. This should work:&lt;br&gt;
&lt;br&gt;
R(:,p) = chol(A(p,p));&lt;br&gt;
&lt;br&gt;
HTH,&lt;br&gt;
John</description>
    </item>
    <item>
      <pubDate>Wed, 02 Apr 2008 00:43:01 -0400</pubDate>
      <title>Re: calculating the inverse efficiently (not for solving equations :-) )</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/166759#424095</link>
      <author>Tim Davis</author>
      <description>&quot;M E&quot; &amp;lt;gitsnedbutzi@hotmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;fsu1r6$ib3$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; well most of you probably think &quot;Oh no, not another one&lt;br&gt;
&amp;gt; trying to solve a system of linear equations using the&lt;br&gt;
&amp;gt; matrix inverse&quot;, but luckily for those guys I don't need it&lt;br&gt;
&amp;gt; for that :-)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; So my problem is that after some calculations I got stuck&lt;br&gt;
&amp;gt; with an equation of the following kind:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; (A*B^-1*C)*x=y&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; As the matrix B is multiplied with A and C there's no way&lt;br&gt;
&amp;gt; (or at least I don't know of any) to get around the problem&lt;br&gt;
&amp;gt; of knowing the full inverse of B.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Some important properties for B are, that it's symmetric and&lt;br&gt;
&amp;gt; sparse. Yes, I know having the inverse will destroy the&lt;br&gt;
&amp;gt; sparisty :-)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; So far the possibilities for calculating the inverse of B, I&lt;br&gt;
&amp;gt; have come up with are:&lt;br&gt;
&amp;gt; *LU decomposition: tends to fail because B is rather large&lt;br&gt;
&amp;gt; and therefore my computer runs out of memory&lt;br&gt;
&amp;gt; *Cholesky decomposition: not much more efficient than the LU&lt;br&gt;
&amp;gt; decomposition (n^3/3 compared to 2n^3/3)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I also thought of using eigenvalues, but that wouldn't help&lt;br&gt;
&amp;gt; much since you need the inverse of the matrix with the&lt;br&gt;
&amp;gt; eigenvectors.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I hope that I could give anyone enough insight into my&lt;br&gt;
&amp;gt; problem...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Does anyone know another efficient way for calculating the&lt;br&gt;
&amp;gt; inverse for sparse symmetric matrices, or maybe to simplify&lt;br&gt;
&amp;gt; or transform the upper equation to make it less costly?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks in advance!!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Albert Buehrli&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
If you ever find yourself multiplying by the inverse, then&lt;br&gt;
you know one thing for certain.  You know, for sure, that&lt;br&gt;
you don't know what you're doing.  One needs never, ever,&lt;br&gt;
ever multiply by the inverse.  Multiplying by the inverse is&lt;br&gt;
mathematically equivalent to solving a system of linear&lt;br&gt;
equations, but it is an awful computational replacement for&lt;br&gt;
the latter.&lt;br&gt;
&lt;br&gt;
You really *are* solving a system of equations, either B*z=C&lt;br&gt;
for z, or you are solving A=w*B for w.  Both are systems of&lt;br&gt;
linear equations.&lt;br&gt;
&lt;br&gt;
Instead of inv(B)*C, you should use B\C instead.  Or,&lt;br&gt;
replace A*inv(B) by A/B.&lt;br&gt;
&lt;br&gt;
You gave as the equation:&lt;br&gt;
&lt;br&gt;
(A*B^-1*C)*x=y&lt;br&gt;
&lt;br&gt;
does this mean you know A, B, C, and x, and you want to&lt;br&gt;
compute y?  Or are you solving for x?  If it's the latter,&lt;br&gt;
then what you are should do is this:&lt;br&gt;
&lt;br&gt;
x = ((A/B)*C)\y&lt;br&gt;
&lt;br&gt;
or&lt;br&gt;
&lt;br&gt;
x = (A*(B\C))\y&lt;br&gt;
&lt;br&gt;
If you have x and want to compute y, then do&lt;br&gt;
&lt;br&gt;
y = ((A/B)*C)*x&lt;br&gt;
&lt;br&gt;
or&lt;br&gt;
&lt;br&gt;
y = (A*(B\C))*x</description>
    </item>
    <item>
      <pubDate>Wed, 02 Apr 2008 01:50:03 -0400</pubDate>
      <title>Re: calculating the inverse efficiently (not for solving equations :-) )</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/166759#424109</link>
      <author>Roger Stafford</author>
      <description>&quot;Tim Davis&quot; &amp;lt;davis@cise.ufl.edu&amp;gt; wrote in message &amp;lt;fsukql$df3&lt;br&gt;
$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; If you ever find yourself multiplying by the inverse, then&lt;br&gt;
&amp;gt; you know one thing for certain.  You know, for sure, that&lt;br&gt;
&amp;gt; you don't know what you're doing.  One needs never, ever,&lt;br&gt;
&amp;gt; ever multiply by the inverse.  Multiplying by the inverse is&lt;br&gt;
&amp;gt; mathematically equivalent to solving a system of linear&lt;br&gt;
&amp;gt; equations, but it is an awful computational replacement for&lt;br&gt;
&amp;gt; the latter.&lt;br&gt;
&amp;gt; ...........&lt;br&gt;
---------&lt;br&gt;
&amp;nbsp;&amp;nbsp;Tim, it is best not to make claims that can be misunderstood, as in: &quot;If you &lt;br&gt;
ever find yourself multiplying by the inverse, then you know one thing for &lt;br&gt;
certain.  You know, for sure, that you don't know what you're doing.  One &lt;br&gt;
needs never, ever, ever multiply by the inverse.&quot;  There is a Murphy's Law-like &lt;br&gt;
principle that states that someone, sometime, somewhere is surely going to &lt;br&gt;
come up with an example for which multiplying by the inverse of a square &lt;br&gt;
matrix is the very, very best way of carrying out a given task.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;How about this one for starters.  We are given a non-singular 3 x 3 square &lt;br&gt;
matrix M that transforms 3 x 1 vectors, x, to 3 x 1 vectors, y, in 3D space.  &lt;br&gt;
We are also given a point cloud of 1,000,000 different points of y-values and &lt;br&gt;
are to determine the x-point cloud they came from by way of multiplication &lt;br&gt;
by M.  I claim the very best way to do this is to determine, once and for all, by &lt;br&gt;
whatever means are necessary, fair or foul, the explicit, full inverse of M, and &lt;br&gt;
then, having accomplished that despicable operation, to then proceed with &lt;br&gt;
the 1,000,000 matrix multiplications of it by y-points necessary to determine &lt;br&gt;
all the x-points.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;At this juncture, I can envision you claiming, &quot;Foul, foul, that isn't what I &lt;br&gt;
meant in my statement!&quot;  But that is exactly the point of my comment here.  &lt;br&gt;
Your extreme statement could easily be interpreted in just such a manner.  It &lt;br&gt;
is always best to carefully quantify such statements so as not to allow of such &lt;br&gt;
misinterpretations.&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
    <item>
      <pubDate>Wed, 02 Apr 2008 08:28:02 -0400</pubDate>
      <title>Re: calculating the inverse efficiently (not for solving equations :-) )</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/166759#424148</link>
      <author>M E</author>
      <description>@John:&lt;br&gt;
&lt;br&gt;
Thanks for your hints on using amd. I'll have to try that &lt;br&gt;
one.&lt;br&gt;
&lt;br&gt;
@Tim:&lt;br&gt;
&lt;br&gt;
Unfortunately, the mldivide also runs out of memory, so I &lt;br&gt;
can't use that one.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Since memory seems to be the main issue, I also thought of &lt;br&gt;
using blockwise inversion. There I would only have to &lt;br&gt;
compute the inverse of A and (D-C*A^-1*B), where I could &lt;br&gt;
reduce the size from n to n/2.&lt;br&gt;
&lt;br&gt;
For those who don't know it:&lt;br&gt;
[A, B; C, D]^-1 = [A^-1+ A^-1*B*(D-C*A^-1*B)^-1*C*A^-&lt;br&gt;
1, ...; ..., ...]&lt;br&gt;
&lt;br&gt;
Has anyone any experience on using blockwise inversion?&lt;br&gt;
&lt;br&gt;
Thx in advance</description>
    </item>
  </channel>
</rss>

