Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Find element aii of Invert Matrix

Subject: Find element aii of Invert Matrix

From: Jean-Sebastien Lacroix

Date: 16 Nov, 2010 18:59:05

Message: 1 of 5

Hi,

I’m looking for a Matlab efficient function that finds the diagonal elements of the inverse of a matrix.

In other words, for a system Ax = b, i’m looking for aii elements of A-1. One way would be to do:
    
[N,N] = size(A);

    [L,U]=lu(A);

    for i = 1:N
        b = zeros(N,1);
        b(i,1) = 1;
    
        x = U\(L\b);
        Diagonal(:,i) = x;
   end

The problem is that I’m evaluating every element of the matrix.

Does anyone tried to do this?

Thanks

Subject: Find element aii of Invert Matrix

From: Wayne King

Date: 16 Nov, 2010 19:24:07

Message: 2 of 5

"Jean-Sebastien Lacroix" <j_s_lacroix@hotmail.com> wrote in message <ibuk9p$2lm$1@fred.mathworks.com>...
> Hi,
>
> I’m looking for a Matlab efficient function that finds the diagonal elements of the inverse of a matrix.
>
> In other words, for a system Ax = b, i’m looking for aii elements of A-1. One way would be to do:
>
> [N,N] = size(A);
>
> [L,U]=lu(A);
>
> for i = 1:N
> b = zeros(N,1);
> b(i,1) = 1;
>
> x = U\(L\b);
> Diagonal(:,i) = x;
> end
>
> The problem is that I’m evaluating every element of the matrix.
>
> Does anyone tried to do this?
>
> Thanks

Why not use diag()?

A = [1 1; 1 -1];
diag(inv(A))

Or did I misunderstand something in your post?

Wayne

Subject: Find element aii of Invert Matrix

From: Brian Borchers

Date: 16 Nov, 2010 20:07:29

Message: 3 of 5

On Nov 16, 10:59 am, "Jean-Sebastien Lacroix"
<j_s_lacr...@hotmail.com> wrote:
> I’m looking for a Matlab efficient function that finds the diagonal elements of the inverse of a matrix.

If your matrix is reasonably small, you can simply compute the inverse
and then use diag.

If your matrix is extremely large but sparse, and if the inverse would
be dense, then you have a much harder problem. There has been some
interesting work on stochastic algorithms for estimating the diagonal
of a matrix using only matrix vector multiplications (in your case
these would be inv(A)*x multiplications or solutions to a system of
equations involving A) that might be relevant.

Subject: Find element aii of Invert Matrix

From: Jean-Sebastien Lacroix

Date: 16 Nov, 2010 20:31:04

Message: 4 of 5

The matrix has the following characteristic:
Square: 100 000 x 100 000
Symmetric with complexe values
Non Hermittian, Non Positive Definite, Non Diagonnally dominant

The problem is not finding the diagonal of the inverse, but to find the best algorithm to do it. I'm looking for a faster method than doing the LU factorization to then perform N gaussian elimination. ( see initial matlab code).

It seems there must be a way to find diagonal element without computing every other elements aij.

Thanks

Subject: Find element aii of Invert Matrix

From: Matt J

Date: 16 Nov, 2010 20:59:04

Message: 5 of 5

"Jean-Sebastien Lacroix" <j_s_lacroix@hotmail.com> wrote in message <ibupm8$l7j$1@fred.mathworks.com>...
>
> It seems there must be a way to find diagonal element without computing every other elements aij.
===

The only way that I can think of is Cramer's rule, as in theo code below, but I don't think it's efficient,


%simulated data
N=4;
A=rand(N);
theResult=nan(1,N);



tic;
D=det(A);
K=A;
for ii=1:N
   K(:,ii)=0;
   K(ii,ii)=1;
  theResult(ii)=det(K)/D;
   K(:,ii)=A(:,ii);
end

toc;

>>theResult, diag(inv(A)).',


theResult =

  -15.2997 -1.8442 -14.6497 -0.4008


ans =

  -15.2997 -1.8442 -14.6497 -0.4008

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us