# HG changeset patch # User Lachlan Andrew # Date 1467275426 -36000 # Node ID 9a0e30e24b9bc943a92e33adbafe0c123e2d6b2a # Parent 42456fc9bf6c0217fe855d64fc25b98fac86c32b 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. diff -r 42456fc9bf6c -r 9a0e30e24b9b NEWS --- a/NEWS Mon Aug 08 15:21:03 2016 -0700 +++ b/NEWS Thu Jun 30 18:30:26 2016 +1000 @@ -1,8 +1,6 @@ Summary of important user-visible changes for version 4.2: --------------------------------------------------------- - ** condest now works with a normest1 compatible syntax. - ** The parser has been extended to accept, but ignore, underscore characters in numbers. This facilitates writing more legible code by using '_' as a thousands separator or to group nibbles into bytes @@ -30,7 +28,7 @@ to the old command "hold all" and was made for Matlab compatibility. Existing code *may* produce differently colored plots if it did not specify the color for a plot and relied on each new plot having the - the default first color in the "ColorOrder" property. + default first color in the "ColorOrder" property. ** When starting, Octave now looks in the function path for a file startup.m and executes any commands found there. This change was @@ -64,6 +62,12 @@ compatible with Matlab releases newer than 2011. In addition, Octave no longer supports matrix inputs for A or B. + ** The cov function now returns the complex conjugate of the result + from previous versions of Octave. This change was made for + compatibility with Matlab. + + ** condest now works with a normest1 compatible syntax. + ** The griddata function no longer plots the interpolated mesh if no output argument is requested, instead the vector or array of interpolated values is always returned for Matlab compatibility. diff -r 42456fc9bf6c -r 9a0e30e24b9b scripts/statistics/base/cov.m --- 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