Question
function x = gauss(A,b) %% Checks [m,n] = size (A); if m ~= n, error('The coefficient matrix A is not square'), end if ~iscolumn(b), error('The
function x = gauss(A,b)
%% Checks [m,n] = size (A); if m ~= n, error('The coefficient matrix A is not square'), end if ~iscolumn(b), error('The load vector b is not column'), end if m ~= length(b), error('Dimensions of A and b are incompatible for matrix operations'), end if det(A) == 0, error('The system is singular and no solution can be obtained'), end if cond(A) >= 1e4, warning('The system is ill-conditioned and results may be inaccurate'), end
Ab = [A b];
% Forward elimination for j = 1:n-1 if abs(Ab(j,j)) == 0, error('zero pivot encountered'), end if abs(Ab(j,j))
%% Backward substitution x = zeros(m,1); x(m) = Ab(m,n+1)/Ab(m,m); for i = m-1:-1:1 x(i) = (Ab(i,n+1)-Ab(i,i+1:n)*x(i+1:n))/Ab(i,i); end
function x = GaussPivot(A,b)
%% Checks [m,n] = size (A); if m ~= n, error('The coefficient matrix A is not square'), end if ~iscolumn(b), error('The load vector b is not column'), end if m ~= length(b), error('Dimensions of A and b are incompatible for matrix operations'), end if det(A) == 0, error('The system is singular and no solution can be obtained'), end if cond(A) >= 1e4, warning('The system is ill-conditioned and results may be inaccurate'), end
Ab = [A b];
% Forward elimination for j = 1:n-1 % Perform partial pivoting by determining the largest absolute value of % of the element along the j-th column from rows j to m. % Define: pvt = value of this largest pivot % kpvt = location of this pivot in the array [pvt, kpvt] = max(abs(Ab(j:m,j))); if pvt
% Backward substitution x = zeros(m,1); x(m) = Ab(m,n+1)/Ab(m,m); for i = m-1:-1:1 x(i) = (Ab(i,n+1)-Ab(i,i+1:n)*x(i+1:n))/Ab(i,i); end
Do This only in Matlab, thank you
Post-lab Problems: Problem 3: Gaussian elimination method with partial pivoting (Adapted from Gilat and Subramaniam 3/e, Problem 4.5) Solve the following system of linear equations by the Gaussian method with partial pivoting. x1 2x2 4x3 + 3x,-4 2x1 5x2 - 3x3 -X4-11 4x1 +2x2 +x3 -4x41 Solve by hand, and then scan and paste into the homework file. Highlight wherever partial pivoting is needed and explain how you perform the partial pivoting. a) b) Clearly explain your step-by-step procedure and draw correspondence to the MATLAB function GaussPivot up to at least the first time that a row exchange occurs. In other words, explain the execution of the MATLAB function file GaussPivot along with the step-by-step hand calculations Gaussian elimination with partial pivoting. Critical thinking: Idea is to find the largest absolute value along the j-th column from the j-th to the last rows, and move it to the pivot location (j,j) element before beginning the Gaussian elimination process along that colummStep 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