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
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

i have xold=x
should i change that and have a new x
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에 대해 자세히 알아보기

태그

질문:

2011년 10월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by