write a Matlab function file to solve system Ax=b by using the output of the function...

50.1K

Verified Solution

Question

Advance Math

write a Matlab function file to solve system Ax=b byusing the output of the function lufac2a your function should haveinputs f=matrix return from lufac2a, piv=array return by lufac2aand b=right hand side of your system.the only output for yoursystem should be x


guideline


1.use the column access for the matrixentries


2. do not create any other matrix in your function-getyour data directly from the matrix passed into yourfunction


3.do not use Matlab command designed for solvingsystem


function file LUFAC2A GIVEN BELOW


function [f, rp, flag] = lufac2a(a)


% The purpose of this function is to apply Gaussianelimination with


% partial pivoting to the input matrix a . (Thisfollows the LINPACK


% algorithm except uses elementary Gaussiantransformations from Matrix


% Computations). This function returns:


%


% f - matrix containing the information about the Land U matrices in the


% factorization PA=LU


%


% rp - array containing information about the rowinterchanges used in the


% elimination process


%


% flag - error flag (set to 0 if a is invertible, andset to k>0 if a


% nonzero pivot could not be found for columnk)


%


% 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


Answer & Explanation Solved by verified expert
4.0 Ratings (402 Votes)
a inputEnter Input matrix a n mn sizea if m n dispThe matrix must be a square matrix return end f a rp zerosn1 for j1n1 mxp    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students