help-octave
[Top][All Lists]

## Re: covariance matrix

 From: Michael Creel Subject: Re: covariance matrix Date: Tue, 20 Feb 2007 09:54:57 +0100 User-agent: Thunderbird 1.5.0.9 (X11/20070103)

```

John W. Eaton wrote:
```
```On 19-Feb-2007, baptiste AuguiĆ© wrote:

```
| I was trying to use a Matlab code (SCEM-UA, Monte Carlo | optimization), and I ended up correcting for all the | incompatibilities I could understand: | | - filenames and function names do not seem to be case sensitive in | Matlab, whereas Octave would not find a filename with random Upper/ | lower case | | - more concerning is this one: I have two vectors X and Y of same | length, and using cov(X,Y) returns a scalar (same thing with cov | (X',Y'))! The program - and myself after reading the documentation, | expects a covariance matrix. Is that a bug? | I changed this line to cov(X(:),Y(:)), which seems to work, but I | would like to know whether this is normal?
```
The Matlab documentation says that if cov is given two matrix
arguments with the same number of elements, it computes

cov ([X(:), Y(:)])

(not quite what you have above).  This expression will always compute
a 2x2 matrix.  Octave's cov function does this if X and Y are
matrices:

If each row of X and Y is an observation and each column is a
variable, the (I, J)-th entry of `cov (X, Y)' is the covariance
between the I-th variable in X and the J-th variable in Y.

and this will compute an NxN matrix with N == columns(X) == columns(Y).

I don't know why we have the difference.  Has Matlab always behaved
this way?  If so, then I'm surprised that you are the first to
notice.  Hmm.  Should we change Octave to be compatible?  What will
this break?  Should we try to preserve the old behavior?  If so, how?

Hmm.  It seems corrcoeff also has similar problems.

Will someone who understands what should be happening here please fix
cov and corrcoef and submit a patch?

Thanks,

jwe

_______________________________________________
Help-octave mailing list
```
```Michael