How to fix in Gauss formula

2 ビュー (過去 30 日間)
Emilia
Emilia 2020 年 12 月 15 日
コメント済み: Jon 2020 年 12 月 16 日
Hello,
I have here two formulas of Jacobi and Gauss.
I wrote code in the method Jacobi and it worked for me, but in Gauss there is a problem it came out to me a matrix instead of a vector.
I have a problem with B and c in Gauss, If I did right.
Thanks for the helpers
%Jacobi
L = tril(A,-1);
U = triu(A,1);
D = diag(A);
B = -1./D.*(L+U);
c = (1./D).*b;
x_new = B*x+c;
%Gauss
L = tril(A,-1);
U = triu(A,1);
D = diag(A);
B = -1./(L+D).*U;
c = (1./(L+D)).*b;
x_new = B*x+c;

採用された回答

Jon
Jon 2020 年 12 月 15 日
It looks like in your calculation of c in both the Jacobi and Gauss you should do a Matrix -vector multiply not an element by element so replace yours with
c = (1./D)*b;
and
c = (1./(L+D))*b;
Maybe there are some other issues too.
Also as a comment you compute the same terms multiple times which isn't too efficient, e.g. 1./(L+D) gets computed twice in your Gauss calculation.
  7 件のコメント
Emilia
Emilia 2020 年 12 月 16 日
Excellent it works for me. Thank you :)
Jon
Jon 2020 年 12 月 16 日
Glad to hear it!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by