diff scripts/statistics/base/cov.m @ 22226:9a0e30e24b9b

Calculate cov as Matlab does, not as its conjugate (bug #48315). * NEWS: Announce change. * cov.m: Remove "conj" from calculation of output. Update compatibility note to explain what Matlab actually does.
author Lachlan Andrew <lachlanbis@gmail.com>
date Thu, 30 Jun 2016 18:30:26 +1000
parents 516bb87ea72e
children 9fc91bb2aec3
line wrap: on
line diff
--- a/scripts/statistics/base/cov.m	Mon Aug 08 15:21:03 2016 -0700
+++ b/scripts/statistics/base/cov.m	Thu Jun 30 18:30:26 2016 +1000
@@ -56,11 +56,13 @@
 ##   normalize with @math{N}, this provides the second moment around the mean
 ## @end table
 ##
-## Compatibility Note:: Octave always computes the covariance matrix.
-## For two inputs, however, @sc{matlab} will calculate
-## @code{cov (@var{x}(:), @var{y}(:))} whenever the number of elements in
-## @var{x} and @var{y} are equal.  This will result in a scalar rather than
-## a matrix output.  Code relying on this odd definition will need to be
+## Compatibility Note:: Octave always treats rows of @var{x} and @var{y}
+## as multivariate random variables.
+## For two inputs, however, @sc{matlab} treats @var{x} and @var{y} as two
+## univariate distributions regardless of their shapes, and will calculate
+## @code{cov ([@var{x}(:), @var{y}(:)])} whenever the number of elements in
+## @var{x} and @var{y} are equal.  This will result in a 2x2 matrix.
+## Code relying on @sc{Matlab}'s definition will need to be
 ## changed when running in Octave.
 ## @seealso{corr}
 ## @end deftypefn
@@ -108,7 +110,7 @@
 
   if (nargin == 1 || isscalar (y))
     x = center (x, 1);
-    c = conj (x' * x / (n - 1 + opt));
+    c = x' * x / (n - 1 + opt);
   else
     if (isrow (y))
       y = y.';
@@ -118,7 +120,7 @@
     endif
     x = center (x, 1);
     y = center (y, 1);
-    c = conj (x' * y / (n - 1 + opt));
+    c = x' * y / (n - 1 + opt);
   endif
 
 endfunction