Jacobi Iteration into Gauss-Seidel for Linear Algebra course

6 ビュー (過去 30 日間)
Sullman
Sullman 2011 年 10 月 21 日
Hello I have been try to write a program for a gauss-Seidel iteration on matlab but am having trouble... I have figured out how to write a Jacobi iteration program but have no idea how to convert it into Gauss-Seidel. I believe i need a new xvalue, xnew? Can anybody please help me out

回答 (1 件)

Matt Tearle
Matt Tearle 2011 年 10 月 21 日
Your loop in j is effectively 1:(i-1) then (i+1):n. The difference between GS and Jacobi is whether you use x or xold in that first loop.
Also note that your line x(i) = sum/a(i,i) doesn't depend on j, so it doesn't need to be in the loop (over j).
(Also don't use sum as a variable name. But that has no bearing on the GS-vs-Jacobi issue.)
  2 件のコメント
Sullman
Sullman 2011 年 10 月 21 日
i have xold=x
should i change that and have a new x
Matt Tearle
Matt Tearle 2011 年 10 月 25 日
Your code has disappeared, so it's hard to say for sure, but probably not. x should be the new x you're calculating; I'm assuming "xold = x" occurs at the beginning of the iteration. Then your Jacobi program updates x based entirely on xold. That means you're always using the previous iteration's values of x (xold). The only difference between Jacobi and GS is that GS uses the current iteration's values of x that have been computed so far. As I said, for the ith element, the x values that have been updated so far are j = 1:(i-1). So for that loop, update x(i) based on x(j). From then on (j = (i+1):n) update x(i) based on xold(j).

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

カテゴリ

Help Center および File ExchangeNumerical Integration and Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by