%uloha 1
load list_of_stars.dat
x = list_of_stars(:,1);     %hodnoty poradia = x-ova os
y = list_of_stars(:,2);     %hodnoty jasnosti = y-ova os
X = [ones(size(x),1),log10(x)];     %matica derivacii modelovej funkcie podla parametrov
W = eye(size(x,1));     %jednotkova diagonalna matica reprezentujuca vahy
V = X'*W*X;
U = X'*W*y;
b = inv(V)*U
z = b(1)+b(2)*log10(x);     %fit
plot(x,y,'*',x,z,'r')
xlabel('poradie')
ylabel('hviezdna velkost [mag]')
legend('data','fit','Location','SouthEast')

%uloha 2
[HJD,M4,M0,M1,M2,M3,E4,E0,E1,E2,E3,G,F] = textread('V2509_Sgr.dat','%f %f %f %f %f %f %f %f %f %f %f %s %f');
fi = HJD/1.087 - floor(HJD/1.087);  %fazova funkcia
fi = [fi-1;fi;fi+1];    %opakovanie fazoveho intervalu
E2 = [E2;E2;E2];
M2 = [M2;M2;M2];
figure
plot(fi,M2,'*')
axis ij
xlabel('phase')
ylabel('intensity [mag]')