Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Machine Problem 1 Develop your own M-file function for the Gauss- Seidel method without relaxation based on the figure given below, but change the

image text in transcribed

Machine Problem 1 Develop your own M-file function for the Gauss- Seidel method without relaxation based on the figure given below, but change the first line so that it returns the approximate error and the number of iterations: function [x,ea,iter] = GaussSeidel(A,b,es, maxit) Test your program by solving the following linear system: 3x1 0.12 0.1172 0.2x3 = 7.85 0.3x3 = -19.3 0.31 0.22 + 10x3 = 71.4 Note that the solution is x1-3, x2 -2.5, and x3-7. Use initial estimates of x240 and x3-0. function x = Gauss Seidel (A,b,es, maxit) % GaussSeidel: Gauss Seidel method % x = GaussSeidel (A,b): Gauss Seidel without relaxation % input: % A coefficient matrix % b = right hand side vector % es = stop criterion (default = 0.00001%) % maxit max iterations (default = 50) % output: % x = solution vector if nargin <2, error('at least 2 input arguments required'), end if nargin <4|isempty (maxit), maxit-50; end if nargin <3|isempty(es), es=0.00001; end [m,n] = size(A); if m=n, error('Matrix A must be square'); end C = A; for i=1:n C(1,1) = 0; x(1) = 0; end x = x'; for i=1:n C(1,1:n) C(1,1:n)/A(i,i); end for i=1:n d(i) b(1)/A(1,1); end iter = 0; while (1) xold = x; for i = 1:n x(i) = d(i)-C(i,:)*x; if x(1)=0 = - ea(1) abs((x(1) xold(1))/x(i)) end end iter = iter+1; 100; if max(ea) = maxit, break, end end MATLAB M-file to implement Gauss-Seidel.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Auditing A Practical Approach

Authors: Robyn Moroney

1st Canadian Edition

978-1118472972, 1118472977, 978-1742165943

Students also viewed these Programming questions