Answered step by step
Verified Expert Solution
Link Copied!

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? image text in transcribed
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
Write a Matab fiunction lusolre2a that solves a system Aib by nsing the output from the Your function shoutd lave inputs: f matri omlufac2a(pt array returned by lufac2a; and b= right-hand-side rector for your system. The only output should be the solution vector Guidelines: e column access for the matrix entries 2) do uot passed into your function ther matrices in your function-get your data directly from the matrix 3) do aot use any Mattab comands designed for solring systems. (For exaple, you cannot use triu() y to do the backward substitution with the upper triangular portionof f (triu(f) and right-hand-side y-) Au operation such as re"y, where x & y are vectors and c is a scalar, is acceptable. Tura in: a priat-out of your function 2) The results of using the giren lufac2a and your husolre2a to solte three random systeus each of order0 and 15 (a rand(5).b rand(S.I): create a random Sx5 matris and random 5x1 rector). You do not haye to print out tde matrix or tuput rector.and rou do not harve to priut out the solution Print out solution (you can use the Matlab diary command) I you call your solutioaprint out louK-a b.inf) to check: if your computed solution is accurate Write a Matab fiunction lusolre2a that solves a system Aib by nsing the output from the Your function shoutd lave inputs: f matri omlufac2a(pt array returned by lufac2a; and b= right-hand-side rector for your system. The only output should be the solution vector Guidelines: e column access for the matrix entries 2) do uot passed into your function ther matrices in your function-get your data directly from the matrix 3) do aot use any Mattab comands designed for solring systems. (For exaple, you cannot use triu() y to do the backward substitution with the upper triangular portionof f (triu(f) and right-hand-side y-) Au operation such as re"y, where x & y are vectors and c is a scalar, is acceptable. Tura in: a priat-out of your function 2) The results of using the giren lufac2a and your husolre2a to solte three random systeus each of order0 and 15 (a rand(5).b rand(S.I): create a random Sx5 matris and random 5x1 rector). You do not haye to print out tde matrix or tuput rector.and rou do not harve to priut out the solution Print out solution (you can use the Matlab diary command) I you call your solutioaprint out louK-a b.inf) to check: if your computed solution is accurate

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

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

Understand why customers are loyal to a particular service firm.

Answered: 1 week ago