Question: Create a function that will compute the determinant D of a by using cofactors of a the entries of the matrix C: function D =determine(a,
Create a function that will compute the determinant D of a by using cofactors of a the entries of the matrix C:
function D=determine(a, C) //Function C has an output matrix as a nxn matrix whose entries are // the cofactors calculated by the formulas C(I,j) = (-1) (i+j) det Aij
//Function C has already been coded (See the bottom of this question)
The function calculates the cofactor expansion across each row of a they form entries of a vector D1; and it calculates the cofactor expansion down each column of a they form entries of the vector D2.
Then, it should take the first entry of the vector D1, that is D1(1), as a reference and consider the absolute value of the difference between each entry of vectors D1, D2 and D1(1). If each value is less than 10^( 7) , it assigns D = D1(1); otherwise, the function returns an empty matrix D = [ ] and a message There is a problem with my code!
Hint: You could use for loop and while loop within your code (the command break stops executing the while loop, if needed).
FUNCTION C:
function c = cofactor(a)
[m,n] = size(a);
for i=1:n
for j=1:n
temp = a;
temp(i,:) = [ ];
temp(:,j) = [ ];
c(i,j) = power(-1,i+j)*det(temp);
end
end
end
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
