Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MATLAB CODE: function x = Gauss(A,b) % create the augmented matrix Ab = [A,b]; % dtermine the size of the augmented matrix [R,C] = size(Ab);

MATLAB CODE:

image text in transcribed

function x = Gauss(A,b) % create the augmented matrix Ab = [A,b]; % dtermine the size of the augmented matrix [R,C] = size(Ab);

% iterate columns for i=1:R-1 % pivoting if(abs(Ab(i,i)) ~= max(abs(Ab(i:R,i)))) for j = i+1:R if(abs(Ab(j,i)) == max(abs(Ab(i:R,i)))) % swap rows of matrix A and vector b

% --------------------------------------- break; end end end % Gaussian elimination for k = i+1:R Ab(k,i:C) = Ab(k,i:C) - Ab(k,i)/Ab(i,i)*Ab(i,i:C); end end

% take the the upper triangular matrix and vector out from Ab U = Ab(1:R,1:R); b = Ab(:, R+1);

% Use the back substitution to solve the remaining equations x = backSub(U, b); nd

You are given a function file called Gauss.m, which runs Gaussian elimination with pivoting to solve a linear system Ax = b. You are not required to write the whole function body. However, this function lost a block of code for a part of the pivoting steps. a. You need to complete that part from line 16 to line 19 so that the function can swap rows of matrix A and vector b, and the integrated code can perform Gaussian elimination with pivoting for most invertible n x n matrices A and n x 1 vectors b. b. Test the function Gauss () for solving the following three problems and report the solution x for each problem, i. A is a 3 x 3 identity matrix, b is a 3x 1 matrix with all entries equal to 1. [2 1 0 0 1 2 1 0 0 1 2 1 0 0 1 2 ii. A= b = 9 3 2 1 iii. A is a random 5x 5 nonsingular matrix, b is a random 5 x 1 vector. Hint: The function Gauss () has to include the function backSub () you created in Problem 1. If you have trouble with your back substitution function in Problem 1, you can use the built-in solver in Matlab to solve the upper triangular system after completing Gaussian elimination. At the bottom of Gauss.m, you can see a line x = backSub (U, b). If you want to use the built-in solver, you can remove that line and add a new command x = U | b. You are given a function file called Gauss.m, which runs Gaussian elimination with pivoting to solve a linear system Ax = b. You are not required to write the whole function body. However, this function lost a block of code for a part of the pivoting steps. a. You need to complete that part from line 16 to line 19 so that the function can swap rows of matrix A and vector b, and the integrated code can perform Gaussian elimination with pivoting for most invertible n x n matrices A and n x 1 vectors b. b. Test the function Gauss () for solving the following three problems and report the solution x for each problem, i. A is a 3 x 3 identity matrix, b is a 3x 1 matrix with all entries equal to 1. [2 1 0 0 1 2 1 0 0 1 2 1 0 0 1 2 ii. A= b = 9 3 2 1 iii. A is a random 5x 5 nonsingular matrix, b is a random 5 x 1 vector. Hint: The function Gauss () has to include the function backSub () you created in Problem 1. If you have trouble with your back substitution function in Problem 1, you can use the built-in solver in Matlab to solve the upper triangular system after completing Gaussian elimination. At the bottom of Gauss.m, you can see a line x = backSub (U, b). If you want to use the built-in solver, you can remove that line and add a new command x = U | b

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

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

LO5 Describe job analysis and the stages in the process.

Answered: 1 week ago