%Matej Petruzalek, DU2

clear all; close all;
%data set 1
filename1 = 'upf_ukol2_data1.txt';
data1 = table2array(readtable(filename1));
pom= sort(data1);
data1 = pom(1:9900);

% figure; histfit(data1, 100, 'exponential'), hold on,xlim([0,20]);

[N,edges] = histcounts(data1,100);
figure
histogram(data1,100,'Normalization','pdf'); hold on;
xlim([0,20]);
mymean1 = mean(data1);
myvar1 = var(data1);
mystd1 = std(data1);
lambda1 = 1/mymean1;
fx = lambda1*exp(-lambda1*edges);
plot(edges,fx,'r','linewidth', 2); hold on;
p1 = 2+1/mymean1;
fm = (p1-1)./(edges+1).^p1;
plot(edges,fm,'g','linewidth', 2)
xlabel('data1'); ylabel('relativni cetnost'); 
legend(gca,{'Data1','Exponencialni r.','Mocninne r.'})



%data set 2
filename2 = 'upf_ukol2_data2.txt';
data2 = table2array(readtable(filename2));
% figure; histfit(data2, 100, 'exponential'), hold on,xlim([0,20]);


[N,edges] = histcounts(data2,100);
figure
histogram(data2,100,'Normalization','pdf'); hold on;
xlim([0,20]);
mymean2 = mean(data2);
myvar2 = var(data1);
mystd2 = std(data2);
lambda2 = 1/mymean2;
fx = lambda2*exp(-lambda2*edges);
plot(edges,fx,'r','linewidth', 2); hold on;
p = 2+(1/mymean2);
fm = (p-1)./((edges+1).^p);
plot(edges,fm,'g','linewidth', 2)
xlabel('data1'); ylabel('relativni cetnost'); 
legend(gca,{'Data2','Exponencialni r.','Mocninne r.'})

pom = [ mymean1 myvar1  mystd1; mymean2 myvar2  mystd2 ]







