Question
Problem 12.12
Pls show the m-file
Develop your own M-file function for the Gauss-Sei
0 0
Add a comment Improve this question Transcribed image text
Answer #1

function [x1 , ea,iterval] //if conditiorn -ĢaussseidelR (Arba omg, esvaïr max..it ) if nargin<2 errer(2 arguments); end //for 1:n1 = end x1=x1; %Transpose matrix for = 1:n1 end ER五五= 1:n! end While iterval max ït xoldval = x1;eal (1) = abs ( (x1 (2) -xoldval (2) ) /x1 () ) * 100; end end iterval = iterva1+1; %while loop if max (eal) <=e s val breakOutput: 0.8000 0.4000 -0.4000 0.8000 -0.4000 0 0.4000 0.8000 41 25 105 esvai 1.0000e-05 ans = 173.7500 245.0000 253.7500

copyable code:

% GaussSeidelR.m

function [x1,ea,iterval] = GaussSeidelR(A,b,omg,esval,max_it)

//if condition

if nargin<2

     error('2 arguments');

end

//check the max iteration

if nargin<5||isempty(max_it)

     max_it=50;

end

if nargin<4||isempty(esval)

     esval=0.00001;

end

if nargin<3||isempty(omg)

     omg=1;

end

[m1,n1] = size(A);

if m1~=n1, error('Matrix A '); end

C1 = A;

for i = 1:n1

     C1(i,i) = 0; %diagonal

     x1(i) = 0;

end

x1 = x1'; %Transpose matrix

for i = 1:n1

     C1(i,1:n1) = C1(i,1:n1)/A(i,i);

end

for i = 1:n1

     d1(i) = b(i)/A(i,i);

end

iterval = 0;

while iterval<=max_it

   

     xoldval = x1;

     for i = 1:n1

         x1(i) = d1(i)-C1(i,:)*x1;

         x1(i) = omg*x1(i) + (1-omg)*xoldval(i);

       

         if x1(i) ~= 0

             ea1(i) = abs((x1(i) - xoldval(i))/x1(i)) * 100;

         end

     end

     iterval = iterval+1;

  

     %while loop

       if max(ea1)<=esval

         break

       end

%     iterval

%     x1

%     ea

end

%main.m

A=[0.8 -0.4 0;-0.4 0.8 -0.4;0 -0.4 0.8]

b=[41;25;105]

esval=0.00001

GaussSeidelR(A,b,1,esval,50)

Add a comment
Know the answer?
Add Answer to:
Problem 12.12 Pls show the m-file Develop your own M-file function for the Gauss-Seidel method without...
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
  • Using MATLAB, develop an M-file to determine LU factorization of a square matrix with partial pivoting....

    Using MATLAB, develop an M-file to determine LU factorization of a square matrix with partial pivoting. That is, develop a function called mylu that is passed the square matrix [A] and returns the triangular matrices [L] and [U] and the permutation P. You are not to use MATLAB built-in function lu in your codes. Test your function by using it to solve a system of equations listed below in part 3. Confirm that your function is working properly by verifying...

  • Generate asuch that its Develop an M-file function that is passed tw8 sucr vll and returns θ.(c) ...

    I wonder how to solve a problem 3.21 generate asuch that its Develop an M-file function that is passed tw8 sucr vll and returns θ.(c) and the magnitude or(c), and generates three-dimensional plot of the three vectors (a), tb), and with their origins at zero. Use dashed lines for (a) and (b) and a solid line for (c). Test your function for the following vectors nunda n. The first cases to 2 dec- 一0.125. (a) a = [6 4 2];...

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