In: Computer Science
Answer:-
Formula
We have to write script file to find out cofactor of matrix.
Script file:-
%-----------------------------------------------------------------------------------------------------------------------------
function cof=cof(a)
%% Check Input Argument
%----------------------
if isempty(a)
error(message('cof:EmptyMatrix'));
end
%% Algorithm
%-----------
[r, c] = size(a); %determine size of input
m = ones(r,c); %preallocate r x c cofactor matrix
a_temp=a; %create temporary matrix equal to input
for i = 1:r
for k = 1:c
a_temp([i],:)=[]; %remove ith row
a_temp(:,[k])=[]; %remove kth row
m(i,k) = ((-1)^(i+k))*det(a_temp); %compute cofactor element
a_temp=a; %reset elements of temporary matrix to input
elements
end
end
cof=m; %return cofactor matrix as output variable
end
%----------------------------------------------------------------------------------------------------------------------------
Paste above file in Editor section of matlab
(save it as name 'cof')
Then in command window type these command.(TYPE YOUR MATRIX AND INVERSE FORMULA given below)
Step 1.) a=[1 2 5 4 8;7 5 8 9 6;4 1 4 5 2;7 8 5 6 3;7 8 5 2 1]
Step 2.) inverse=cof(a)'/det(a)
cof(a) command help us to find out cofactor of 'a' matrix.
det(a) command help us to find out Determent of 'a' matrix
cof(a)' Transpose of cofactor matrix
INVERSE formula using cofactor = cof(a)'/det(a)
output:-
Editor Section
Command Window section :-
Full-screen shot of a working screen :-
If you need any help in understanding, Please comment your query.
I tried my best for this question, I hope you upvote my answer.
Thank You