Question

Please answer in Matlab, thank you!

Gauss-Seidel method Exercise: 1. Find the roots of following simultaneous equations using the Gauss-Seidel method. 10x+2y-2z-

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

Ans)

%====================MATLAB CODE=============

%====question1====

A=[10 2 -2;4 2 -1;2 -3 10];

b=[18;-10;5];

sol=Gauss_seidel(A,b)

%====question2====

A=[4 -1 -1;-2 6 1;-1 1 7];

b=[3;9;-6];

sol=Gauss_seidel(A,b)

%====question3====

A=[4 1 -1;2 7 1;1 -3 12];

b=[3;19;31];

sol=Gauss_seidel(A,b)

%====question4====

A=[25 5 1;64 8 1;144 12 1];

b=[106.8;177.2;279.2];

sol=Gauss_seidel(A,b)

function X=Gauss_seidel(A,b)

n = length(b);

X = zeros(n,1);

Error_eval = ones(n,1);

%% Start the Iterations

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

end

Xsolution(:,iteration) = X;

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

end

end

%========================================

Add a comment
Know the answer?
Add Answer to:
Please answer in Matlab, thank you! Gauss-Seidel method Exercise: 1. Find the roots of following simultaneous...
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