Mercurial > octave-nkf
annotate scripts/statistics/base/cor.m @ 12557:4715ce9f911d
cor.m: Increase tolerance of %!tests using random data to assure passage.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Thu, 31 Mar 2011 10:09:34 -0700 |
parents | 422a7a7e9b6e |
children | 6b2f14af2360 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1995-2011 Kurt Hornik |
3426 | 2 ## |
3922 | 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. | |
3426 | 9 ## |
3922 | 10 ## Octave is distributed in the hope that it will be useful, but |
3200 | 11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 13 ## General Public License for more details. |
14 ## | |
3200 | 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/>. | |
3200 | 18 |
3453 | 19 ## -*- texinfo -*- |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
20 ## @deftypefn {Function File} {} cor (@var{x}) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
21 ## @deftypefnx {Function File} {} cor (@var{x}, @var{y}) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
22 ## Compute matrix of correlation coefficients. |
3200 | 23 ## |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
24 ## This is an alias for @code{corrcoef}. |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
25 ## @seealso{corrcoef} |
3453 | 26 ## @end deftypefn |
3200 | 27 |
12555
422a7a7e9b6e
cor.m: fix operation with only single input (bug #32961)
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
28 function retval = cor (x, y = x) |
3200 | 29 |
30 if (nargin < 1 || nargin > 2) | |
6046 | 31 print_usage (); |
3200 | 32 endif |
33 | |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
34 retval = corrcoef (x, y); |
3200 | 35 |
36 endfunction | |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
37 |
12555
422a7a7e9b6e
cor.m: fix operation with only single input (bug #32961)
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
38 %!test |
422a7a7e9b6e
cor.m: fix operation with only single input (bug #32961)
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
39 %! x = rand (10, 2); |
12557
4715ce9f911d
cor.m: Increase tolerance of %!tests using random data to assure passage.
Rik <octave@nomad.inbox5.com>
parents:
12555
diff
changeset
|
40 %! assert (cor (x), corrcoef (x), 5*eps); |
12555
422a7a7e9b6e
cor.m: fix operation with only single input (bug #32961)
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
41 %! assert (cor (x(:,1), x(:,2)) == corrcoef (x(:,1), x(:,2))); |
422a7a7e9b6e
cor.m: fix operation with only single input (bug #32961)
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
42 |
422a7a7e9b6e
cor.m: fix operation with only single input (bug #32961)
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
43 %% Test input validation |
422a7a7e9b6e
cor.m: fix operation with only single input (bug #32961)
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
44 %!error corrcoef (); |
422a7a7e9b6e
cor.m: fix operation with only single input (bug #32961)
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
45 %!error corrcoef (1, 2, 3); |
422a7a7e9b6e
cor.m: fix operation with only single input (bug #32961)
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
46 |