use matlab to create a function that finds inverse of 2x2 matrix and returns result. Should...

Free

90.2K

Verified Solution

Question

Mechanical Engineering

use matlab to create a function that finds inverse of 2x2 matrixand returns result. Should be a error check to make sure matrix is2x2, and nonsingular.

Answer & Explanation Solved by verified expert
4.3 Ratings (775 Votes)

Matlab code:

______________________________________________________________________________

a = [4 7; 2 6];
det_a = (a(1,1)*a(2,2) - a(1,2)*a(2,1));
s = size(a);
if det_a == 0 || s(1,1) ~= 2 || s(1,2) ~= 2
fprintf('Determinant of the provided matrix is zero or either size of the matrix is not 2x2 hence inverse not possible')
else
a1 = [a(2,2) -a(1,2) ; -a(2,1) a(1,1)];
inv_a = (1/det_a)*a1
end

____________________________________________________________________________

Above code will use the direct method of finding inverse of an 2x2 matrix. If the matrix size is different than 2x2 or it is singular code will give an message that provided matrix is not correct.

Please provide the feedback.


Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students