Jacobi Iteration into Gauss-Seidel for Linear Algebra course
Afficher commentaires plus anciens
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
Réponses (1)
Matt Tearle
le 21 Oct 2011
0 votes
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 commentaires
Sullman
le 21 Oct 2011
Matt Tearle
le 25 Oct 2011
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).
Catégories
En savoir plus sur Numerical Integration and Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!