MATLAB HELP Write a function that can take any size square m

MATLAB HELP

Write a function that can take any size square matrix and return it\'s determinant. DO NOT USE BUILT IN FUNCTION det().
MATLAB HELP

Write a function that can take any size square matrix and return it\'s determinant. DO NOT USE BUILT IN FUNCTION det().

Write a function that can take any size square matrix and return it\'s determinant. DO NOT USE BUILT IN FUNCTION det().

Solution

function D = Det_algo (A)
if size(A,1)~=size(A,2)
message=\'matrix not square; no proper determinant\';
else
if max(size(A))==2
D = (A(1,1)*A(2,2))-(A(1,2)*A(2,1));
else
for i=1:size(A,1)
D_temp=A;
D_temp(1,:)=[ ];
D_temp(:,i)=[ ];
o=A(1,i);
o=((-1)^(i+1));
o=Det_algo(D_temp);
o=(A(1,i)*((-1)^(i+1))*Det_algo(D_temp));
if i==1
D=(A(1,i)*((-1)^(i+1))*Det_algo(D_temp));
else
D=D+(A(1,i)*((-1)^(i+1))*Det_algo(D_temp));
end
end
end
end

 MATLAB HELP Write a function that can take any size square matrix and return it\'s determinant. DO NOT USE BUILT IN FUNCTION det(). MATLAB HELP Write a functio

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site