function graph

max_elements = 1000;
a = 630360016;
m = 2147483647;
s = 0.8;

%379615, 263239
array_temp_1(1)= 379615;

summ_for_math_awaiting = 0;
summ_for_dispersion = 0;

%Генерация массива
for i = 1: max_elements
    array_temp_1(i+1) = mod ( a * array_temp_1(i), m );
    array(i) = -s * log( 1 - array_temp_1(i+1) / m);
    summ_for_math_awaiting = summ_for_math_awaiting + array(i);
end;

%Математическое ожидание
math_awaiting = summ_for_math_awaiting / max_elements

for i = 1: max_elements
    summ_for_dispersion = summ_for_dispersion + (array(i) - math_awaiting)^2;        
end;

%Дисперсия
dispersion = summ_for_dispersion / (max_elements - 1)

%Доверительный интервал
Dd=sqrt(dispersion/max_elements);
t=1.96;
e=Dd*t;
In(1)=math_awaiting-e;
In(2)=math_awaiting+e;
disp('Доверительный интервал: ');
In

%Корреляция
for j=1:max_elements-1
    summ_for_correlation=0;
    for i=1:max_elements-j
        summ_for_correlation=summ_for_correlation+(array(i)-math_awaiting)*(array(i+j)-math_awaiting);
    end;
    k(j)=summ_for_correlation/(max_elements-j);
    %Ro - Кореляц.ф-я
    Ro(j)=k(j)/dispersion;
end;

plot(1:20, Ro(1:20), '*');

figure(2);
hold on;
for i = 1:max_elements - 1
   plot(array(i), array(i+1), 'b:*');
end;

%Гистограмма

dx=0.1;
for i=1:50
   column(i)=i*dx;
end;

x0=0;
x1=dx;
for i=1:50
    temp(i)=0;
    for j=1:max_elements
        if (array(j)>=x0 && array(j)<x1)
            temp(i)=temp(i) + 1;
        end
    end
    temp(i)=temp(i) / max_elements / dx;
    x0=x1;
    x1=dx*(i+1);
end

for i=1:50
        column(i)=i*dx;
    end;
figure(3);
bar(column-dx/2, temp);
hold on;
x = [0 column];
betta=0.8;
plot(x,exp(-x/betta)/betta);

%Хи - квадрат

for i=0:19
    alpha(i+1) = -betta*log(1 - i/20);
end;
alpha(21)=10^3;
   
pj=0.05;
Nj = zeros(1,20);
for j=1:20
    for i=1:1000
    if (array(i)<alpha(j+1) && array(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) - max_elements*pj)^2/(max_elements*pj);
    Hi = Hi + Z(i);
end;
Hi



















