Mercurial > octave
changeset 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 | 42456fc9bf6c |
children | ab139f0733b9 |
files | NEWS scripts/statistics/base/cov.m |
diffstat | 2 files changed, 16 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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.
--- 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