Hilbert matrix come on

n=100;
for i=1:n
for j=1:n
A(i,j)=1/(i+j-1);
end
end
[L,U,P]=lu(A),xex=ones(n,1),
b=A*xex,R=L*U-P*A,y=L\P*b;
x=U\y ,r=max(abs(R))
for k=1:n; er(k)=norm(xex-x,2)/norm(xex,2) ; end
semilogy((1:n),er,'r--',(1:n),r,'g--'),
there is a problem with er when i draw the curve i find it stable (red)

2 件のコメント

David Goodmanson
David Goodmanson 2021 年 1 月 14 日
Hi Karim
You can save some lines of code with the hilb function.
The big problem here is that you are always operating on the same size matrix, so of course er does not change. You need the matrix to change size for each iteration of the for loop.
Walter Roberson
Walter Roberson 2021 年 1 月 14 日
for k=1:n; er(k)=norm(xex-x,2)/norm(xex,2) ; end
is always doing the same calculation so it always has the same result.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

タグ

質問済み:

2021 年 1 月 13 日

コメント済み:

2021 年 1 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by