关于MATLAB中方差函数var()的问题

来源:百度知道 编辑:UC知道 时间:2024/06/24 10:54:17
已知var()函数有以下用法:
V=var(X)
V=var(X,1)
V=var(X,w)
V=var(X,flag,dim)
问题是关于后两种用法的,例如下面的程序
x=[-1 -1 1 2];
w=[1 2 3 4];
v4=var(x,w)
v5=var(x,1,w)

运行结果为:
v4=
1.5600
v5=
0 0 0 0

哪位高手能够把这两个结果是怎么得到的解释一下吗?最好能够给出演算过程

V = var(X,w) computes the variance using the weight vector w. The length of w must equal must equal the length of the dimension over which var operates, and its elements must be nonnegative. The elements of w must be positive. var normalizes w to sum of 1.

V = var(X,w,dim) takes the variance along the dimension dim of X. Pass in 0 for w to use the default normalization by N-1, or 1 to use N.

The variance is the square of the standard deviation (STD).