function raschet(nach,sv,n)
f=zr(nach,sv,n);
%Ocenka mat.ogidaniay
mat=0;
for i=1:1:n
    mat = mat + f(i);
end
mat=mat/n
%Ocenka dispersii
disp=0;
for i=1:1:n
    disp=disp + (f(i)-mat)^2;
end
disp=disp/(n-1)
%Vichislenie korrel
korel=[];
for j=1:1:n-1
    kor =0;
    for i=1:1:n-j
         kor=kor + (f(i)-mat)*(f(i+j)-mat);
    end
    korel(j)=kor/(n-j);
end
%Vichislenie koef korrel
for j=1:1:n-1
    coef(j)= korel(j)/disp;
end
%doveritelniy interval
t=1.96;
sigma=sqrt(disp/n);
e=sigma*t;
I1=mat-e
I2=mat+e
% Zavisimost korrel ot koef korrel   
%figure(1);
j=1:1:20;
plot(j,coef(j),'--*')
%zavisimost zacheiay cledyushego ot predudyshego
figure(2);
hold on;
j=1:1:n-1;
plot(f(j),f(j+1),'*')
%hist
x0=0;
m=35;
ma=max(f);
mi=min(f);
dx=(ma-mi)/m;
x1=dx;
for i=1:40
    chek(i)=0;
    for j=1:n
        if (f(j)>=x0 ) & (f(j)<x1)
            chek(i)=chek(i) + 1;
        end
    end
    chek(i)=chek(i) / n/ dx;
    x0=x1;
    x1=dx*(i+1);
end;
for i=1:40
    shag(i)=i*dx;
end;
figure(3);
bar(shag-dx/2,chek);
x = [0 shag];
hold;
plot(x,exp(-x/sv)/sv,'r');


%hi2
for i=0:19
        alpha(i+1) = -sv*log(1 - i/20);
    end;
    alpha(21)=10^3;
    
    pj=0.05;
    Nj = zeros(1,20);
    for j=1:20
        for i=1:n
        if (f(i)<alpha(j+1)) & (f(i)>alpha(j))
           Nj(j)=Nj(j)+1;
        end;
        end;
    end;
    
    Hi = 0;
    Z = zeros(1,20);
    for i=1:20
        Z(i) = (Nj(i) - n*pj)^2/(n*pj);
        Hi = Hi + Z(i);
        
    end;
   abs(Hi)
    %disp(Nj);
    %disp(alpha);
%    disp(Hi);

