Question

In: Advanced Math

QUESTION: USING MATLAB, Carry out three iterations of the Gauss-Seidel method, starting from the initial vector...

QUESTION:

USING MATLAB, Carry out three iterations of the Gauss-Seidel method, starting from the initial vector Use the  ,  and  norm to calculate the residual error after each iteration, until all errors are below 0.0001.

[Use 5 decimal place accuracy in you calculations]

Solutions

Expert Solution

%Output:

% S = the solution( M x 1 matrix ; jacobi approximation)

% j = the number of iterations it took to

% converge to the user inputed value

% R = Residual Values

%establishes the variables needed

%B is an M x 1 matrix

%A is an M x M matrix

%P is the initial M x 1 matrix

%Z = remembering matrix

%Ask the user for each input statement required

Imax = input('What do you want the maximum iteration to be? ');

N = input('How many equations do you want? ');

C_n = input('What number do you want to converge to? ');

%Assigns the values inputed by the user into the matrices

for x=1:1:N

for y=1:1:N

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:N

strB = ('What do you desire the Solution matrix to be? ');

B = input(strB);

end

n = length(B);

X = zeros(n,1);

e = ones(n,1);

%%Check if the matrix A is diagonally dominant

for i = 1:n

j = 1:n;

j(i) = [];

C = abs(A(i,j));

Check(i,1) = 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\n\n',i)

end

end

iteration = 0;

while max(e) > C_n%check error

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,1) = (B(i,1) - sum(A(i,j) * Xtemp)) / A(i,i);

end

Xs = X;

e = sqrt((X - Z).^2);

end


Related Solutions

how can I change the Gauss-Seidel method to SOR method code in Matlab? The question has...
how can I change the Gauss-Seidel method to SOR method code in Matlab? The question has shows that In implementing SOR method in MATLAB, one should not calculate Tw and cw by formulas Tw = (D -wL)^(-1)[(1-w)D+wU)] and Cw = w(D-wL)^(-1)b , where w stands for omega and using MATLAB's built-in inv function, since this function requires O(n^3) flops and therefore the whole matter loses its point. I have tried for many times but I can't get the correct answers....
A) Use Jacobi or Gauss-Seidel iteration and perform three iterations by hand. B) Use Jacobi or...
A) Use Jacobi or Gauss-Seidel iteration and perform three iterations by hand. B) Use Jacobi or Gauss-Siedel iteration for ten iterations with a MAT-LAB function. * A= [5, -1,0;-1,5,-1;0,-1,5] , B=[9;4;-6]
A) Use Jacobi or Gauss-Seidel iteration and perform three iterations by hand. B) Use Jacobi or...
A) Use Jacobi or Gauss-Seidel iteration and perform three iterations by hand. B) Use Jacobi or Gauss-Siedel iteration for ten iterations with a MAT-LAB function. * A= [10 -2 1;-2 10 -2;-2 -5 10] , B=[9;12;18]
Problem 1: Carry out the first three iterations of the solution of the following set of...
Problem 1: Carry out the first three iterations of the solution of the following set of equations using the Gauss Seidel iterative method.Provide the solution using a program, you are free to use any language including MATLAB. 8x1+2x2+3x3 = 51 2x1+5x2+x3 = 23 -3x1+x2+6x3 = 20
how to write coding in matlab using gauss elimination method for equation 10a + 50b +...
how to write coding in matlab using gauss elimination method for equation 10a + 50b + 20c + 10d = 100 5a + 15b + 75c - 25d=200 25a -15c - 5d = 300 10a + 20b - 30c + 100d = 400
Determine the roots of the following simultaneous nonlinear equations using multiple-equation Newton Raphson method. Carry out...
Determine the roots of the following simultaneous nonlinear equations using multiple-equation Newton Raphson method. Carry out two iterations with initial guesses of x1(0) =0.6 and x2(0) =1.2. Calculate the approximate relative error εa in each iteration by using maximum magnitude norm (║x║∞). x1 + 1 - x22 = 0 x12 + x22 – 5 = 0
6) Solving for method Newton-Rapson starting from (1,1,1) in matlab (with algorithm) 1) sin(x) + y^2...
6) Solving for method Newton-Rapson starting from (1,1,1) in matlab (with algorithm) 1) sin(x) + y^2 + ln(z) – 7 = 0 2) 3x + 2^y – z^3 + 1 = 0 3) x + y + z – 5 = 0
Using the regime-theory method, design a channel to carry wastewater from a manufacturing plant. Assume a...
Using the regime-theory method, design a channel to carry wastewater from a manufacturing plant. Assume a design discharge of 950 ft3/s.950 ft3/s. The channel will have a sand bed and banks. Use a Manning’s roughness coefficient of 0.025. Assume: Water Temp = 60°F, slope = 0.25%
Using the regime-theory method, design a channel to carry wastewater from a manufacturing plant. Assume a...
Using the regime-theory method, design a channel to carry wastewater from a manufacturing plant. Assume a design discharge of 950 ft3/s.950 ft3/s. The channel will have a sand bed and banks. Use a Manning’s roughness coefficient of 0.025. Assume: Water Temp = 60°F, slope = 0.25%
QUESTION 2 If you set up your initial review of the literature using the Matrix Method,...
QUESTION 2 If you set up your initial review of the literature using the Matrix Method, you already have a start on the Matrix Indexing System. However, the indexing system differs from the Matrix Method. The Matrix Method is a strategy for acquiring, analyzing, and writing a synthesis of a review of the scientific literature. In contrast, the Matrix Indexing System provides a way of coping with all the information and documents that you use or create as a result...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT