Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In MATLAB Please Code Provided: Problem 1: Iterative algorithm for the Jacobi and Gauss-Seidel methods applied to systems of linear and nonlinear equations (Modify the

In MATLAB Please

image text in transcribed

Code Provided:

image text in transcribed

Problem 1: Iterative algorithm for the Jacobi and Gauss-Seidel methods applied to systems of linear and nonlinear equations (Modify the code from Pre-lab exercise 1) (1) Consider the following system of linear equations by the Jacobi iterative method 7x1 + 4x2 3x3 = 44 X1 + 5x2 + 2x3 = 22 -2x1 + x2 + 5x3 -2 (2) (3) a) Modify your codes from the pre-lab to perform the iterations until the relative approximate error is smaller than a maximum tolerance (maxtol) or the number of iterations has exceeded a maximum allowable number of iterations (maxitr). Define the error using the 2-norm. b) Test your codes with zero initial vector and maxtol=1e-4, maxitr=30. c) Modify the Gauss-Seidel code from Pre-lab exercise 1 and apply to the following system of equations Ax = b to observe convergence or divergence of the systems of equations. Note that these equations are the same but arranged in different order. Apply the iteration 10 times. [10 A=1 0 5 7 -6 -21 4 12] b= [10 A=0 1 5 -6 7 -21 12 4 b = 4 % 8x(1) + 2x(2) + 3x(3) = 51 % 2x(1) + 5x(2) + X(3) = 23 % - 3x(1) + x(2) + 6x(3) = 20 % n = 5; % Number of iterations X0 = zeros(1,3); % Initial guess vector (user-input) X = XO; % Initial guess vector %% Jacobi method fprintf(' Results from Jacobi method: ') for i=1:n xold = x; X(1) = (51-2*xold(2)-3* xold(3))/8; X(2) = (23-2*xold(1)-xold(3))/5; x(3) = (20+3* xold(1)-xold(2))/6; er(i)=norm(x-xold, 2)orm(x, 2); fprintf('i = %d, \txi = %3.49, \tx2 = %3.49, \tx3 = %3.4g ',i,x) end %% Gauss-Seidel method X = XO; fprintf(' Results from Gauss-Seidel method: ') for i=1:n xold = x; x(1) = (51-2*x(2)-3*x(3))/8; x(2) = (23-2**(1)-X(3))/5; x(3) = (20+3*x(1)-x(2))/6; er(i)=norm(x-xold, 2)orm(x, 2); fprintf('i = %d, \txi = %3.49, \tx2 = %3.4g, \tx3 = %3.4g ',i,x) end fprintf(' ')

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions

Question

3. The group answers the questions.

Answered: 1 week ago