日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

在matlab中求协方差,matlab里面的求协方差函数

發布時間:2024/7/23 56 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在matlab中求协方差,matlab里面的求协方差函数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一:matlab里面關于方差和協方差的幾點需要注意的

求均值的函數:mean

求方差的函數:var

標準差:

方差:

求協方差的函數:cov

1 如果a,b是向量,則:

cov(a,b)相當于是[D(a),cov(a,b);cov(b,a),D(b)],其中D(a)和D(b)分別代表了a,b的方差。cov(a,b)和cov(b,a)分別代表了兩者之間的協方差

舉例:

>> a=[1.1 2.2 3 4.5 0.8]

a =

1.1000 2.2000 3.0000 4.5000 0.8000

>> b=[1.3 2.4 2.1 5 3.3]

b =

1.3000 2.4000 2.1000 5.0000 3.3000

>> cov(a,b)

ans =

2.2570 1.3595

1.3595 1.9970

其中,對角線的值是兩個向量的方差,斜對角線的是兩個向量之間的協方差

2 如果a,b是矩陣,則:

cov(a,b)相當于是cov(a(:),b(:)),舉例說明:

>> a=randn(4);

>> a

a =

-0.4326 -1.1465 0.3273 -0.5883

-1.6656 1.1909 0.1746 2.1832

0.1253 1.1892 -0.1867 -0.1364

0.2877 -0.0376 0.7258 0.1139

>> b=randn(4);

>> b

b =

1.0668 0.2944 -0.6918 -1.4410

0.0593 -1.3362 0.8580 0.5711

-0.0956 0.7143 1.2540 -0.3999

-0.8323 1.6236 -1.5937 0.6900

>> cov(a,b)

ans =

0.8513 -0.0860

-0.0860 1.0129

/

>> a(:)

ans =

-0.4326

-1.6656

0.1253

0.2877

-1.1465

1.1909

1.1892

-0.0376

0.3273

0.1746

-0.1867

0.7258

-0.5883

2.1832

-0.1364

0.1139

>> b(:)

ans =

1.0668

0.0593

-0.0956

-0.8323

0.2944

-1.3362

0.7143

1.6236

-0.6918

0.8580

1.2540

-1.5937

-1.4410

0.5711

-0.3999

0.6900

>> cov(a(:),b(:))

ans =

0.8513 -0.0860

-0.0860 1.0129

另外,matlab里面關于cov函數的說明解釋的很詳細:

cov(x), if x is a vector, returns the variance of x. For matrix input X, where each row is an observation, and each column is a variable, cov(X) is the covariance matrix. diag(cov(X)) is a vector of variances for each column, and sqrt(diag(cov(X))) is a vector of standard deviations. cov(X,Y), where X and Y are matrices with the same number of elements, is equivalent to cov([X(:) Y(:)]).

cov(x) or cov(x,y) normalizes by N – 1, if N > 1, where N is the number of observations. This makes cov(X) the best unbiased estimate of the covariance matrix if the observations are from a normal distribution. For N = 1, cov normalizes by N.

cov(x,1) or cov(x,y,1) normalizes by N and produces the second moment matrix of the observations about their mean. cov(X,Y,0) is the same as cov(X,Y) and cov(X,0) is the same as cov(X).

參考:

http://www.voidcn.com/article/p-qzfcdcih-bv.html

總結

以上是生活随笔為你收集整理的在matlab中求协方差,matlab里面的求协方差函数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。