Jacobi Iteration into Gauss-Seidel for Linear Algebra course
이전 댓글 표시
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
2011년 10월 21일
0 개 추천
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
2011년 10월 21일
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).
카테고리
도움말 센터 및 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!