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

Using MATLAB. develop an M-file to determine matrix inverse based on the LU fact

ID: 3575908 • Letter: U

Question

Using MATLAB. develop an M-file to determine matrix inverse based on the LU factorization method above. That is. develop a function called myinv that is passed the square matrix (A) and utilizing codes of part 1 above to return the inversed matrix. You are not to use MATLAB built-in function inv or left-division in your codes. Test your function by using it to solve a system of equations listed below in part 3. Confirm that your function is working properly by verifying that [A](A)^-1 = [1] and by using the MATLAB built-in function inv.

Explanation / Answer

%matlab code matrix inversion

function b = myinv(matrix)
% dimensions of matrix
[row,column] = size(matrix);

% inverse matrix result
inverseMatrix = eye(row);

%perform matrix inversion
for j = 1 : row
for i = j : row
if matrix(i,j) ~= 0
for k = 1 : row
temp = matrix(j,k); matrix(j,k) = matrix(i,k); matrix(i,k) = temp;
temp = inverseMatrix(j,k); inverseMatrix(j,k) = inverseMatrix(i,k); inverseMatrix(i,k) = temp;
end
t = 1/matrix(j,j);
for k = 1 : row
matrix(j,k) = t * matrix(j,k);
inverseMatrix(j,k) = t * inverseMatrix(j,k);
end
for iterator = 1 : row
if iterator ~= j
t = -matrix(iterator,j);
for k = 1 : row
matrix(iterator,k) = matrix(iterator,k) + t * matrix(j,k);
inverseMatrix(iterator,k) = inverseMatrix(iterator,k) + t * inverseMatrix(j,k);
end
end
end
end
break
end
% if zeroes row is found
if matrix(i,j) == 0
disp('Warning: Singular Matrix')
b = 'error';
return
end
end


% Input matrix
matrix = [3 5 -1 -4; 1 4 -.7 -3; 0 -2 0 ; -2 6 0 .3];

% Call the function to find its inverse
b = myinv(matrix)

% Compare with matrix result generated by predefined funtion
c = inv(matrix)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote