Jacobi Iteration into Gauss-Seidel for Linear Algebra course
6 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (1 件)
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 件のコメント
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 Exchange で Numerical Integration and Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!