This is for Linear Algebra Please explain your work as you w
This is for Linear Algebra. Please, explain your work as you work through it
This extra. credit is pass or fail, worth 2.5 quiz points. With the following matrix perform three Iteration beyond the initial guess using the Jacobi Method and then Gauss-Seidel. Part of this assignment is to learn a method on your own. Also use the initial guess of all zero\'s, meaning x = 0, y = 0 and so on.Solution
the solution require a lot of calculations , better you try it with some programming stuff,
here is a MATLAB code for Jacobi Method follow this :
Function used in MATLAB is :
function X=jacobi(A,B,P,delta, max1)
N = length(B);
for k=1:max1
for j=1:N
X(j)=(B(j)-A(j,[1:j-1,j+1:N])*P([1:j-1,j+1:N]))/A(j,j);
end
err=abs(norm(X\'-P));
relerr=err/(norm(X)+eps);
P=X\';
if (err<delta)|(relerr<delta)
break
end
end
X=X\';
where ,
- A is an N x N nonsingular matrix
- B is an N x 1 matrix
- P is an N x 1 matrix; the initial guess
- delta is the tolerance for P
- max1 is the maximum number of iterations
now call the function as ,
A = [-1 4 -1 0, 0 -1 4 -1, -1 0 -1 4, 4 -1 0 -1];
B = [-2 4 6 12];
P = [0 0 0 0];
delta = 0;
max1 = 10;
X=jacobi(A,B,P,delta, max1)
this gives your desired result.
Similarly for Gauss Seidel method use followinf codes :
Function of the MATLAB code is
function gauss_seidel(A, b, N)
n = size(A,1);
%splitting matrix A into the three matrices L, U and D
D = diag(diag(A));
L = tril(-A,-1);
U = triu(-A,1);
%transition matrix and constant vector used for iterations
Tg = inv(D-L)*U;
cg = inv(D-L)*b;
tol = 1e-05;
k = 1;
x = zeros(n,1); %starting vector
while k <= N
x(:,k+1) = Tg*x(:,k) + cg;
if norm(x(:,k+1)-x(:,k)) < tol
disp(\'The procedure was successful\')
disp(\'Condition ||x^(k+1) - x^(k)|| < tol was met after k iterations\')
disp(k); disp(\'x = \');disp(x(:,k+1));
break
end
k = k+1;
end
if norm(x(:,k+1)- x(:,k)) > tol || k > N
disp(\'Maximum number of iterations reached without satisfying condition:\')
disp(\'||x^(k+1) - x^(k)|| < tol\'); disp(tol);
disp(\'Please, examine the sequence of iterates\')
disp(\'In case you observe convergence, then increase the maximum number of iterations\')
disp(\'In case of divergence, the matrix may not be diagonally dominant\')
disp(x\');
end
where
Gauss_seidel(A, b, N) solve iteratively a system of linear equations
whereby A is the coefficient matrix, and b is the right-hand side column vector.
N is the maximum number of iterations.
The method implemented is the Gauss-Seidel iterative.
The starting vector is the null vector, but can be adjusted to one\'s needs.
The iterative form is based on the Gauss-Seidel transition/iteration matrix
Tg = inv(D-L)*U and the constant vector cg = inv(D-L)*b.
The output is the solution vector x.
now call the function and get your result.