Sie sind auf Seite 1von 1

function [det] = determinant(A,n) format compact format long %Initializes the determinant variable det=0; %For loop to move

from column to column left to right for i=1:n %Creates a matrix B that is the minor of matrix A B=A; B(1,:)=[]; B(:,i)=[]; %Creates a variable to determine the cofactor signs sign=(-1)^(i+1); %Displays the sign, cofactor and matrix for ease of code %development if size(B,1)==4 sign_adjusted_cofactor=sign*A(1,i),B, end %Uses the 1x1 matrix rule to end the recursion if size(B,1) == 1 det=det*B; %Runs the next iteration of the recursion if the size of the matrix %is greater than 1x1 else det=det*(sign*A(1,i))*determinant(B,n-1); end end

Das könnte Ihnen auch gefallen