Use GaussSeidel Method to solve the following set of linear
Use Gauss-Seidel Method to solve the following set of linear system of equations. Show your solutions of x_1, x_2, x_3, and x_4 for first four iterations (excluding the initial trial values of x_i) of the solution. Provide solution in tabular besides answers through calculations. Assume x_1= x_2= x_3= x_4 = 0 as a trial (initial) solution. 12 x_1 + 3 x_2 - 4 x_3 + x_4 = 10 4 x_1 + 9 x_2 + 2 x_3 - 2 x_4 = 20 2 x_1 - 3 x_2 +10 x_3 + x_4 = 30 -3 x_1 + 2 x_2 - 3 x_3 + 12 x_4 = 40
Solution
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This code finds the solution to a system of simultaneous linear equation % using Gauss_Seidel Method. % Written By: Mohammad Y. Saadeh, on 06/14/2010, University of Nevada Las % Vegas %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%A%%%%%%%%%%%%%%%%%%%%%%%%% clear;clc format compact %% Read or Input any square Matrix A = [12 3 -4 1; 4 9 2 -2; 2 -3 10 1; -3 2 -3 12];% coefficients matrix C = [10;20;30 ;40];% constants vector n = length(C); X = zeros(n,1); Error_eval = ones(n,1); %% Check if the matrix A is diagonally dominant for i = 1:n j = 1:n; j(i) = []; B = abs(A(i,j)); Check(i) = abs(A(i,i)) - sum(B); % Is the diagonal value greater than the remaining row values combined? if Check(i) < 0 fprintf(\'The matrix is not strictly diagonally dominant at row %2i\ \ \',i) end end %% Start the Iterative method iteration = 0; while max(Error_eval) > 0.001 iteration = iteration + 1; Z = X; % save current values to calculate error later for i = 1:n j = 1:n; % define an array of the coefficients\' elements j(i) = []; % eliminate the unknow\'s coefficient from the remaining coefficients Xtemp = X; % copy the unknows to a new variable Xtemp(i) = []; % eliminate the unknown under question from the set of values X(i) = (C(i) - sum(A(i,j) * Xtemp)) / A(i,i); end Xsolution(:,iteration) = X; Error_eval = sqrt((X - Z).^2); end %% Display Results GaussSeidelTable = [1:iteration;Xsolution]\' MaTrIx = [A X C]