Question: Write a Matlab function myInverse.m that computes the inverse matrix using Gauss-Jordan elimination. This means function [B, err]=my Inverse(A) [n, nc]=size(A) if (n~=nc) error('Square Matrices

 Write a Matlab function myInverse.m that computes the inverse matrix using

Write a Matlab function myInverse.m that computes the inverse matrix using Gauss-Jordan elimination. This means function [B, err]=my Inverse(A) [n, nc]=size(A) if (n~=nc) error('Square Matrices Only!'); end id = eye(n); C=[A, id]; % augment A with identity % (1) Do Gauss Elimination to upper triangular (all zeros below main diagonal) % (2) Do Gauss Elimination Get zeros above main diagonal. % (3) Make sure to scale so main diagonal is all one when your done % (4) Extract the inverse from the right of C (see code below) B = C(:, (n+1):2n); % extract right half of C % check err if (nargout > 1) err = max(max(abs(A*B - I)); end end Check your work with the following code: >> A = [1 2 3; 1 0 1; 2 0 5] >> B = myInverse(A) 0 1.6667 -0.3333 0.5000 0.1667 -0.3333 0 -0.6667 0.3333

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!