In: Economics
Part 1: (Due March 21, 2018 by 8 am) 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. Interchange the first row with the row with the maximum first-column-entry. (To achieve this, create a sub-function that interchanges two specified rows for any matrix.) Submit a single m-file with a subfunction that switches rows. Complete project: Reduce the matrix into row-echelon form, using Gaussian elimination with partial pivoting (generalize the steps in Part 1 as they apply to all columns, so that the largest absolute of the values on the active column is used as the pivot.) Program to make all values below the pivot zero. Bring the system into a reduced row echelon form. Obtain x as a column matrix. Submit a single m-file with two subfunctions which switch rows and do row reduction. Label your program lastname_firstinit_ME3430_Project2.m. Use comments on the side of each line to explain the purpose of that line. NOTES ? Some built in functions to use: error, size, abs, max 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.) ? Test your function with various square and rectangular matrices. ? Include comments. ? Suppress all displaying of intermediate results other than the error messages that your program generates, such as “Error: the matrix is not square”, and “Error: No unique solution exists”.
Please find the program for the same.
Here I am getting assigning the values of a by myself, you can get it from the user .
Please find the code below
a=[2 1 -1 2 5
4 5 -3 6 9
4 2 -2 9 8
4 11 -4 8 2];
%Gauss elimination method [m,n)=size(a);
[m,n]=size(a); % to get the size of a, i.e, getting the
coordinates
for j=1:m-1 % the outer loop to iterate over the rows in a
for z=j+1:m % the inner loop to iterate over the columns in a
if a(j,j)==0
t=a(j,:);a(j,:)=a(z,:); % getting the data in temp variable
a(z,:)=t; % copying back to a
end
end
for i=j+1:m
a(i,:)=a(i,:)-a(j,:)*(a(i,j)/a(j,j));
end
end
x=zeros(1,m);
for s=m:-1:1
c=0;
for k=2:m
c=c+a(s,k)*x(k);
end
x(s)=(a(s,n)-c)/a(s,s); % stroing the result in output
variable
end
disp('Gauss elimination method:');
a % prtinting a
x' % printing output
Sample output
a = 2 1 -1 2 5 0 3 -1 2 -1 0 0 1 -2 -5 0 0 0 5 -2 ans = 1.00000 -2.00000 -5.80000 -0.40000