iterative method for matrix inversion

조회 수: 4 (최근 30일)
sherief hashima
sherief hashima 2018년 1월 22일
편집: Jan 2018년 1월 23일
hi all iam trying to apply some iterative method to have matrix inverse the method steps are
the iterations i do is not working
AA= [ 2 4 -3 1 0 5 -7 8;
3 2 10 -4 -1 -6 4 1;
9 7 3 2 0 0 -4 2;
6 4 0 -1 -1 3 10 5;
5 2 -3 -7 -5 4 8 -8];
bb= [38;-20;39;-16;-30];
z0=[ 2 0 -1 2 0 0 -3 1]';
z(:,1)=z0;
tol=1.e-3;
error=2*tol;
if abs(bb-AA*z0)<error xxsol=z0;
else
while (error>tol)
k=1;
for i=1:m
zk=z(:,k);
numerator= (bb(i)-(AA(i,:)*zk))*S(:,i);
denumerator=norm(AA(i,:),1);
secondterm= numerator/denumerator;
% x= zk+ secondterm;
x(:,i)=zk+ secondterm;
error=abs(bb-A*x(:,i));
if error<tol xxsol=x(:,i);
else
u=sum (x(:,i));
z(:,i+1)= 1/m * u;
error=abs(bb-AA*z(:,i+1));
end
k=k+1;
end
end
end
can any body check what is wrong thanks
  댓글 수: 1
Jan
Jan 2018년 1월 23일
It seems like you have a reason to assume, that something is going wrong. So why don't you share the important information with the readers?

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2018년 1월 23일
편집: Jan 2018년 1월 23일
Start with applying an auto-indentation: Ctrl-A Ctrl-I. This improves the readability.
k = 1
for i = 1:m
zk = z(:,k);
...
k = k + 1;
end
could be simplified to:
for k = 1:m
zk = z(:,k);
...
end
This looks fancy:
numerator= (bb(i)-(AA(i,:)*zk))*S(:,i);
denumerator=norm(AA(i,:),1);
secondterm= numerator/denumerator;
Do you mean "denominator"? Anyway, prefer simpler code:
t = (bb(i) - AA(i,:) * zk) * S(:,i) / norm(AA(i,:), 1);
If "error<tol" is reached, shouldn't the loop be left by using a break? Currently the loop is not stop in the case of success.
"error" is an important Matlab function. Do not shadow it by using the name for a variable.
In if abs(bb-AA*z0)<error, are you aware, that bb-AA*z0 is a vector? In the text of the question you find clearly, that the norm of (bb-AA*z0) is wanted. If the argument of an if command is an array, this is applied internally
if all(arg(:)) && ~isempty(arg)

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by