Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Plz I don't understand Matlab very well can someone help me with this question? Starting with this function function [f, rp, flag] = lufac2a(a) %
Plz I don't understand Matlab very well can someone help me with this question?
Starting with this function
function [f, rp, flag] = lufac2a(a)
% The purpose of this function is to apply Gaussian elimination with
% partial pivoting to the input matrix a . (This follows the LINPACK
% algorithm except uses elementary Gaussian transformations from Matrix
% Computations). This function returns:
%
% f - matrix containing the information about the L and U matrices in the
% factorization PA=LU
%
% rp - array containing information about the row interchanges used in the
% elimination process
%
% flag - error flag (set to 0 if a is invertible, and set to k>0 if a
% nonzero pivot could not be found for column k)
%
% The calling sequence is [f, rp, flag] = lufac2(a)
[m,n] = size(a);
if m ~= n
disp('The matrix must be a square matrix.')
return
end
f = a;
rp = zeros(n,1);
for j=1:n-1
[mx,p] = max(abs(f(j:n,j)));
if mx == 0
flag = j;
return
end
p = p + j - 1;
rp(j) = p;
if p~=j
temp = f(j,j:n);
f(j,j:n) = f(p,j:n);
f(p,j:n) = temp;
end
i=(j+1):n;
f(i,j) = f(i,j)/f(j,j);
f(i,i) = f(i,i) - f(i,j)*f(j,i);
end
if f(n,n)==0
flag = n;
else
flag = 0;
end
return
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