Question

Using MatLab!!!!
1.b1. Program the Gauss-Seidel method and test it on these examples: ( 3x + y +z = 5 a. { x + 3y - 2 = 3 ( 3x + ” – 5z = -1 | 3x

0 0
Add a comment Improve this question Transcribed image text
Answer #1

% Solving Ax=b using Gauss Siedel Method
A=[3 1 1; 3 1 -5;1 3 -1];
b=[5;-1;3];
Ab=[A b];
% Rearranging to get diagonaly dominant matrix
As=[Ab(1,:);Ab(3,:);Ab(2,:)];
% Initializing
n=3;
x=zeros(n,1);
error=zeros(n,1);
% G-S Iterations
for iter =1:10
for k=1:n
xold=x(k);
num=As(k,end)-As(k,1:k-1)*x(1:k-1)-As(k,k+1:n)*x(k+1:n);
x(k)=num/As(k,k);
error(k)=abs(x(k)-xold);
end
disp(['Iter' ,num2str(iter),' Error= ',num2str(max(error))]);
disp(x)
end

Before running the below code please define Matrix A and vector b in command window. As shown below

>>A=[3,1,1;3,1,-5;1,3,-1];
>> b=[5;-1;3];

% Gauss elimination method with out pivoting;
function x = Gauss(A, b)


[n, n] = size(A);   
[n, k] = size(b);
x = zeros(n,k);   
for i = 1:n-1
m = -A(i+1:n,i)/A(i,i); % multipliers
A(i+1:n,:) = A(i+1:n,:) + m*A(i,:);
b(i+1:n,:) = b(i+1:n,:) + m*b(i,:);
end;

% Use back substitution to find unknowns
x(n,:) = b(n,:)/A(n,n);
for i = n-1:-1:1
x(i,:) = (b(i,:) - A(i,i+1:n)*x(i+1:n,:))/A(i,i);
end

As we can see after running these code we are not getting the solution without pivoting. So pivoting is necessary to get the solution.

Add a comment
Know the answer?
Add Answer to:
Using MatLab!!!! 1.b 1. Program the Gauss-Seidel method and test it on these examples: ( 3x...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT