HELP with creating matrix for Jacobi and Gauss-Seidel method problem!!

4 ビュー (過去 30 日間)
equinox
equinox 2016 年 11 月 13 日
コメント済み: Dang Khoa 2018 年 8 月 13 日
How can i create this matrix in matlab?
aij= [2i when j=i and i=1,2,...,80
0.5i when {j=i+2 and i=1,2,...,78 AND j=i-2 and i=3,4,...,80
0.25i when {j=i+4 and i=1,2,...,76 AND j=i-4 and i=5,6,...,80
0 otherwise]
and those of b are bi = π, for each i = 1,2,...,80.
I will need to use Jacobi and Gauss-seidel method to solve the linear system Ax = b to within 10−5 in the l∞ norm with the given matrix entries above. I am just stuck with how to create the matrix. I have spent so long reading the book and other sites but still have no idea where to even begin with the entries of this matrix so any help is appreciated!
  1 件のコメント
Dang Khoa
Dang Khoa 2018 年 8 月 13 日
After that, how can you create the matrix ? can you give me a code

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

回答 (1 件)

Daniel kiracofe
Daniel kiracofe 2016 年 11 月 13 日
the brute force approach would be something like this.
for i = 1:80
for j = 1:80
if (i==j)
a(i,j) = 2*i;
elseif ( other conditions)
a(i,j) = whatever
etc.
end
end
There are quicker ways to do it, but this will be easiest to understand. for 80x80 matrix, speed will not be an issue.
  2 件のコメント
equinox
equinox 2016 年 11 月 15 日
Thank you for the help! i was able to construct the matrix using this approach. However now i am a little confused on using the Jacobi and Gauss-seidel methods to solve the linear system Ax=b. Any tips or suggestions?
Torsten
Torsten 2016 年 11 月 15 日
Use "tril", "diag" and "triu" to build the appropriate iterations matrices L, D and U and solve the linear systems
L*x_new = b-U*x_old for Gauss-Seidel
and
D*x_new = b-(L+U)*x_old for Jacobi
using "backslash (\)".
Best wishes
Torsten.

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

カテゴリ

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