Function to check is a matrix is definite negative or not. This function check if the given matrix A is definite negative checking its eigenvalues. Prototype: bool = definiteNegative(A) Input: The A matrix to check. Output: It returns 1 (TRUE) if A is definite negative. It returns 0 (FALSE) if A is NOT definite negative. Author: Esposito Gianluca (N.Matr.056/100858) Revision Claudio Fantacci, Alessandro Martini.
0001 %Function to check is a matrix is definite negative or not. 0002 % 0003 %This function check if the given matrix A is definite negative checking its eigenvalues. 0004 % 0005 %Prototype: bool = definiteNegative(A) 0006 % 0007 %Input: The A matrix to check. 0008 % 0009 %Output: It returns 1 (TRUE) if A is definite negative. 0010 % It returns 0 (FALSE) if A is NOT definite negative. 0011 % 0012 %Author: Esposito Gianluca (N.Matr.056/100858) 0013 %Revision Claudio Fantacci, Alessandro Martini. 0014 0015 function bool = definiteNegative( A ) 0016 0017 bool = -1; 0018 [row,col] = size(A); 0019 0020 % Is A a square matrix? 0021 if (row ~= col) 0022 fprintf('Impossibile proseguire: matrice non quadrata\n'); 0023 return; 0024 end 0025 0026 % Checking the eigenvalues of matrix A we can say if A is definite positive 0027 % or not 0028 eigenvalues = eig(A); 0029 for i = 1:length(eigenvalues) 0030 if eigenvalues(i) > 0 0031 bool = 0; 0032 return; 0033 end 0034 end 0035 bool = 1;