Home > source > definitePositive.m

definitePositive

PURPOSE ^

Function to check is a matrix is definite positive or not.

SYNOPSIS ^

function bool = definitePositive( A )

DESCRIPTION ^

Function to check is a matrix is definite positive or not.

This function check if the given matrix A is definite positive checking its eigenvalues.

Prototype: bool = definitePositive(A)

Input:     The A matrix to check.

Output:    It returns 1 (TRUE) if A is definite positive.
           It returns 0 (FALSE) if A is NOT definite positive.

Author: Esposito Gianluca (N.Matr.056/100858)
Revision Claudio Fantacci, Alessandro Martini.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %Function to check is a matrix is definite positive or not.
0002 %
0003 %This function check if the given matrix A is definite positive checking its eigenvalues.
0004 %
0005 %Prototype: bool = definitePositive(A)
0006 %
0007 %Input:     The A matrix to check.
0008 %
0009 %Output:    It returns 1 (TRUE) if A is definite positive.
0010 %           It returns 0 (FALSE) if A is NOT definite positive.
0011 %
0012 %Author: Esposito Gianluca (N.Matr.056/100858)
0013 %Revision Claudio Fantacci, Alessandro Martini.
0014 
0015 function bool = definitePositive( 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;

Generated on Thu 24-Sep-2009 17:17:32 by m2html © 2005