백터 A=[a_1,a_2,a_3,....a_N)에 대한 분산(V)과 표준편차(\sigma )는 아래와 같이 구한다.

 

     V(A)=\frac{\sum_{k=1}^{N} a_{k}^{2} }{N} -(\frac{\sum_{k=1}^{N} a_{k}}{N})^2

      \sigma(A)=\sqrt{V(A)}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%   calculate variance and standard deviation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [variance, S_deviation] = variance(indata)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%  indata : input data

%  var    : variance

%  dev    : standard deviation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% calculate average value

mvalue = sum(indata)/length(indata);

% calculate square average

sqmean = sum(indata.^2)/length(indata);

% calculate variance vale

variance = sqmean - mvalue.^2;

% caculate standard deviation 

S_deviation = sqrt(variance);


>> A=[2,5,7,8,2,4,6,7,2,5,6,2]

A =

     2     5     7     8     2     4     6     7     2     5     6     2

>> [a,b] = variance(A)

a =

    4.5556

b =

    2.1344

 

 

이 글은 스프링노트에서 작성되었습니다.

'Programing language > Matlab' 카테고리의 다른 글

randint  (0) 2011.04.14
nargin  (0) 2011.04.14
AWGN채널  (0) 2011.02.10
randn  (0) 2011.02.09


Posted by bayron