This document discusses and provides code examples for implementing the Gauss-Seidel and Jacobi methods for solving systems of linear equations in MATLAB. The Gauss-Seidel method iteratively updates values by using the most recent estimates, while the Jacobi method updates values using only the previous estimates. Both methods iterate until the change between iterations is less than a threshold.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
30 views
Statistics Gauss-Siedel Examples
This document discusses and provides code examples for implementing the Gauss-Seidel and Jacobi methods for solving systems of linear equations in MATLAB. The Gauss-Seidel method iteratively updates values by using the most recent estimates, while the Jacobi method updates values using only the previous estimates. Both methods iterate until the change between iterations is less than a threshold.
%b = [-2 45 80]' function x=GaussSeidelMethod(A,b) D = diag( A ).^-1; diag( diag( A ) ); A1 = A - diag( diag( A ) ); x = [0, 0, 0]'; for i = 1:50 xold = x; for j = 1:3 x(j) = D(j)*(b(j) - A1(j, :)*x); end if (norm( x - xold ) /norm(x))< 0.001 break; end end
%A = [4 -1 -1;6 8 0;-5 0 12];
%b = [-2 45 80]'; function x=JacobiMethod(A,b) D = diag( A ).^-1; A1 = A - diag( diag( A ) ); x = [0, 0, 0]'; for i=1:50 xn = D.*(b - A1*x);