Numerical solution For Ax=b

조회 수: 3 (최근 30일)
Harel Harel Shattenstein
Harel Harel Shattenstein 2018년 7월 4일
편집: Matt J 2018년 7월 5일
What I manage is:
function y=fun(A,x,n)
w=[];
for i=1:length(A)
w(end+1)=A(i,i);
end
D=diagonal(w);
v=[];
for i=1:length(D)
if D(i,i)==0
v(end+1)=0;a
else
v(end+1)=D(i,i);
end
D_inv=diagonal(v);
R=A-D;
end
x=D_inv(b-R*zeros(length(n),1));
for i=2:n
x=D_inv(b-Rx);
end
y=x;
end
Is it correct?
  댓글 수: 1
Anton Semechko
Anton Semechko 2018년 7월 5일
No, your code is incorrect. You forgot to use '*' signs when doing matrix multiplication. Here is how I would do it:
function x=JacobiSolve(A,b,n)
D=diag(A);
D_inv=diag(1./D);
R=A-diag(D);
b=b(:);
x=zeros(size(b));
for i=1:n, x=D_inv*(b-R*x); end

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Nonlinear Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by