7017
|
1 ## Copyright (C) 2003, 2004, 2005, 2006, 2007 Gabriele Pannocchia |
4610
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
4610
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
4610
|
18 |
|
19 ## -*- texinfo -*- |
4855
|
20 ## @deftypefn {Function File} {} isdefinite (@var{x}, @var{tol}) |
4610
|
21 ## Return 1 if @var{x} is symmetric positive definite within the |
|
22 ## tolerance specified by @var{tol} or 0 if @var{x} is symmetric |
|
23 ## positive semidefinite. Otherwise, return -1. If @var{tol} |
5642
|
24 ## is omitted, use a tolerance equal to 100 times the machine precision. |
|
25 ## @seealso{issymmetric} |
4610
|
26 ## @end deftypefn |
|
27 |
|
28 ## Author: Gabriele Pannocchia <g.pannocchia@ing.unipi.it> |
|
29 ## Created: November 2003 |
|
30 ## Adapted-By: jwe |
|
31 |
|
32 function retval = isdefinite (x, tol) |
|
33 |
|
34 if (nargin == 1 || nargin == 2) |
|
35 if (nargin == 1) |
|
36 tol = 100*eps; |
|
37 endif |
|
38 sym = issymmetric (x, tol); |
|
39 if (sym > 0) |
|
40 ## Matrix is symmetric, check eigenvalues. |
|
41 mineig = min (eig (x)); |
|
42 if (mineig > tol) |
|
43 retval = 1; |
|
44 elseif (mineig > -tol) |
|
45 retval = 0; |
|
46 else |
|
47 retval = -1; |
7151
|
48 endif |
4610
|
49 else |
|
50 error ("isdefinite: matrix x must be symmetric"); |
|
51 endif |
|
52 else |
6046
|
53 print_usage (); |
4610
|
54 endif |
|
55 |
|
56 endfunction |