|
"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
|