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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11436
diff changeset
1 ## Copyright (C) 1995-2011 Kurt Hornik
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3200
diff changeset
2 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3456
diff changeset
3 ## This file is part of Octave.
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3456
diff changeset
4 ##
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3456
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3456
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6754
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6754
diff changeset
8 ## your option) any later version.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3200
diff changeset
9 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3456
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3200
diff changeset
13 ## General Public License for more details.
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3200
diff changeset
14 ##
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6754
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6754
diff changeset
17 ## <http://www.gnu.org/licenses/>.
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
18
3453
71d2e09c15a2 [project @ 2000-01-18 08:32:09 by jwe]
jwe
parents: 3426
diff changeset
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
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
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
71d2e09c15a2 [project @ 2000-01-18 08:32:09 by jwe]
jwe
parents: 3426
diff changeset
26 ## @end deftypefn
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
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
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
29
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
30 if (nargin < 1 || nargin > 2)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5428
diff changeset
31 print_usage ();
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
32 endif
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
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
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
35
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
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