matlab怎么算方差和标准差,matlab用var函数算出的方差和标准差求解释~

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2021/03/16 19:00:30

matlab用var函数算出的方差和标准差求解释~

在matlab里面关于var函数的一段程序及结果:

>> %ex1104.m 计算x的方差和标准差

clear all

x=[-1 -1 1 2]; %输入向量x

w=[1 2 3 4]; %权向量w

%用各种命令形式计算方差

v1=var(x)

v2=var(x,0)

v3=var(x,1)

v4=var(x,w)

v5=var(x,1,1)

%用各种命令形式计算向量标准差

s1=std(x)

s2=std(x,1)

s3=std(x,w)

v1 =

2.2500

v2 =

2.2500

v3 =

1.6875

v4 =

1.5600

v5 =

0 0 0 0

s1 =

1.5000

s2 =

1.2990

s3 =

1.2490

还有和我自己人工算出来的方差也不同啊,这个方差和标准差的计算法则和原理是什么呀?

这个你具体打开help,分别搜var和std函数就行了,help里边说的很明白很详细,一看就懂.

我这里稍微做一下解释:

v1=var(x)

V = var(X) returns the variance of X for vectors.

v2=var(x,0)

var(X,0) is equivalent to var(X).

v3=var(x,1)

V = var(X,1) normalizes by N and produces the second moment of the sample about its mean.

v4=var(x,w)

V = var(X,w) computes the variance using the weight vector w.

v5=var(x,1,1)

V = var(X,w,dim) takes the variance along the dimension dim of X.

s1=std(x)

s = std(X),where X is a vector,returns the standard deviation using (1) above.

(std可以使用不同的式子求,求出来不等价,看具体情况选择,这里的(1)是help里边的一个公式)

s2=std(x,1)

s = std(X,flag) for flag = 0,is the same as std(X).For flag = 1,std(X,1) returns the standard deviation using (2) above,producing the second moment of the set of values about their mean.

s3=std(x,w)

s = std(X,flag,dim) computes the standard deviations along the dimension of X specified by scalar dim.Set flag to 0 to normalize Y by n-1; set flag to 1 to normalize by n.

这里只是大体粘贴了一下,公式在help里边也有,你还是自己help一下哈~

你可能感兴趣的:(matlab怎么算方差和标准差)