Interpretation of The COV function in MATLAB
1. Variance and covariance matrix of Vectors
Cov (X) Returns the variance of vector X. Cov (X) is a numerical value. The formula for calculating the value is S (X ).
Cov (x, y) Returns the covariance matrix of X and Y. Cov (X, Y) is a 2*2 matrix, [S (x) C (x, y); C (Y, x) S (y);]
2. Matrix Covariance Matrix
Cov (X) Returns the covariance of X. Diag (COV (x) returns the variance of each column vector. SQRT (DIAG (COV (X) returns the standard deviation of each column. If X is M * n, The COV (x) size is N * n matrix. The (I, j) element of Cov (X) is equal to the variance between the column I vector of X and the column J vector, that is, C (XI, XJ ).
Cov (x, y) Returns the covariance between x and y. If X is M * n and Y is K * P
The size of X and Y must meet
M * n = K * P That is, the number of elements X and Y is the same. At this time,
Cov (x, y)
Equal to the values of Cov ([x (:) y (:)]) and
Cov (x (:), y (:)) The covariance matrix of the two vectors is calculated and the result is a 2*2 matrix. [S (x (:)) C (x (:), y (:)); C (Y (:), x (:)) S (Y (:));] can be seen, S (x) = C (x, x ).
3. Normalization In the above S (x), C (x, y) calculation, the normalized parameter is 1/(N-1), where N is the number of elements in the vector. The following call method uses the normalization parameter 1/N. Shows the corresponding formula.
Cov (x, 1) Returns the variance of vector X. The calculation method is cov (x), but the normalization parameter is 1/N.
Cov (X, Y, 1) Returns the covariance matrix of X and Y. The calculation method is cov (x, y), but the normalization parameter is 1/N.
4. PS:
For differentiated treatment,
Cov (X) is recorded as Cov (x, 0)
Cov (X, Y) is recorded as Cov (X, Y, 0)
Cov (X)
Also recorded
Cov (x
, 0)
Cov (x, y)
Again
Recorded as Cov (X, Y
, 0) If the normalization parameter is 1/(N-1), the parameter is automatically adjusted to 1/n when n = 1.
MATLAB covariance function Cov