Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the functions myElimBelow and myElimAbove which are called by the funct

ID: 2266622 • Letter: C

Question

Complete the functions myElimBelow and myElimAbove which are called by the function myInv (given). myInv takes a square, invertible matrix and returns its inverse ure The procedure for calculating the inverse is as follows 1. Augment the matrix A (the example above is shown here) with an identity matrix of the same size 5.774 17.1187 4.6171 31.70991 0 0 0 74.313270.6046 9.7132 95.0222 0 1 0 0 9.22273.1833 82.3458 3.44460 01 0 5.5478 27.6923 69.4829 43.87440 0 0 1 2. Perform the Forward sweep on this augmented matrix. This will be accomplished my myElimBelow. 75.774 71187 4.6171 31.70991 0 53.8160 5.1850 63.92360.98071 0 0 0 80.5029-6.2251 -0.621 0.1055 0 0 6.1084-0.13460.3236-0.7981 1 3. Perform a modified forward sweep again, this time eliminating everything above the diagonal. This will be accomplished by myE1imAbove. 5.7740 0 1.5905 0.2929 47941.9000 0.4764 4.4010 8.3398-10.5306 0 80.50290-0.7582 -0.2243 0.1867 1.0191 0 53.8160 0 0 6.1084-0.1346-0.3236-0.7981 Divide each row of the augmented matrix by the corresponding diagonal element A(ii) 4. 1 00 0 0.0210 0.0039 0.0195-0.0251 01 0 0 0.0089 0.0818 0.1550-0.1957 0010|-0.0094-0.0028 0.0023 0.0127 0 0 0 -0.0220-0.0530-0.1307 0.1637 5. The augmented portion (columns n+1 through 2"n) is the inverse of A.

Explanation / Answer

function matInv=myInv(mat)

n=size(mat);
Unitmat=eye(n);
matAug=[mat Unitmat];

matBelowAug=myElimBelow(matAug,n);
matAboveAug=myElimAbove(matBelowAug,n);
for i=1:n
matAboveAug(i,:)=matAboveAug(i,:)/matAboveAug(i,i);
end
matInv=matAboveAug(:,n+1:2*n);
%%
function matAugElimBelow=myElimBelow(mat,n)
matnew=mat(:,1:n);
identmat=mat(:,n+1:2*n);

for j=1:1:n-1
for i=n:-1:j+1
mij=matnew(i,j)/matnew(j,j);
for k=1:1:n
matnew(i,k)=matnew(i,k)-mij*matnew(j,k);
identmat(i,k)=identmat(i,k)-mij*identmat(j,k);
end
end
end
% matElimBelow=matnew;
matAugElimBelow=[matnew identmat];
%%
function matAugElimAbove=myElimAbove(mat,n)
matnew=mat(:,1:n);
identmat=mat(:,n+1:2*n);

for j=n:-1:2
for i=1:1:j-1;
mij=matnew(i,j)/matnew(j,j);
for k=1:1:n
matnew(i,k)=matnew(i,k)-mij*matnew(j,k);
identmat(i,k)=identmat(i,k)-mij*identmat(j,k);
end
end
end
matAugElimAbove=[matnew identmat]