Question
Gaussian Elimination with Partial Pivoting Objective: Create a MATLAB function that finds the unique solution to Ax=b equation using Gaussian elimination with partial pivoting where
Gaussian Elimination with Partial Pivoting Objective:
Create a MATLAB function that finds the unique solution to Ax=b equation using Gaussian elimination with partial pivoting where A is a square matrix and b is a column vector of the same height. The function will take A and b as inputs and give x as the output.
Part 1: Start by writing a function (with comments) to achieve these:
Determine if the matrix A is square.
Augment A and b
Find the maximum absolute value in the first column and the row number that this belongs to using a for?loop.
Interchange the first row with the row with the maximum first?column?entry. Submit a single m?file with a subfunction that switches rows.
Modify what you have from part 1 to achieve these:
Reduce the matrix into row?echelon form, using Gaussian elimination with partial pivoting (you will modify what you had in Part 1 to generalize the steps as they apply to all columns, so that the largest absolute of the values on the active column is used as the pivot.) Make all values below the pivots zero.
Then reduce the system to a reduced row echelon form. Obtain x as a column matrix.Submit a single m?file with two subfunctions: one to switch any given two rows, the other one to add a multiple of a row onto another. Notes ?Some built in functions to use: error, size, abs, and the usual for, while, if structures. Ask before you use other built?in functions.
?Use for?loops instead of MATLAB vectorization. (Do not use the ":" operator to access matrix locations.)
This is what I have now but I need help
function A_new = Project2(A,b)
[m n] = size(A);
# determines if the matrix is square
if m~=n, error('Error: the matrix is not square'),end
nb = n + 1; % intialize nb with number of column plus one
# create an augmented matrix by adding b to A
A1 = [A b];
for column=1:n;
max_value = A(column,column);
max_value_location = column;
for row = column+1:n;
if abs(max_value) < abs(A(row,column));
max_value = A(row,column)
max_value_location =row
endif
end
A= flip(A,column,max_value_location);
end
function A= flip(A, row_a_number, row_b_number);
row_a = A(row_a_number,:);
A(row_a_number,:) = A(row_b_number,:);
A(row_b_number,:) = row_a;
end
A_new=A
end
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started