Please solve the following in MATLAB Please add the comments

Please solve the following in MATLAB. Please add the comments in each line and provide the coding window and the command window. Try to make the codes as universal as possible. x1 - 2x3 + x4 = 7 x2 - 7x3 - 2x4 = 12 x1 + x2 + x3 + x4 = 5 x1 - 10x4 = 10 Write a function file that solves the above system of linear equations using the Gauss-Seidel method. Determine what your inputs and outputs should be.

Solution

Program:

a = input(\'What do you want the maximum iteration to be? \');
a1 = input(\'How many equations do you want? \');
%Assigns the values inputed by the user into the matrices
for x=1:1:a1
for y=1:1:a1
strA = [\'What do you desire your numbers in the matrix to be? \' num2str(x) \'Row: \' num2str(y) \'Column: \'];
A = input(strA);
end
end
for l=1:1:a1
strB = (\'What do you desire the Solution matrix to be? \');
C = input(strB);
end

GS(A,C)

Function Program:

function GS(A,C)

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

 Please solve the following in MATLAB. Please add the comments in each line and provide the coding window and the command window. Try to make the codes as unive
 Please solve the following in MATLAB. Please add the comments in each line and provide the coding window and the command window. Try to make the codes as unive

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site