% DEMONSTARCE POUZITI PROCEDURY linregr
% =====================================

echo on
format compact
disp('NECENTROVANY MODEL:');
% Matice planu:
D = [ones(16,1),kron((2:5).',ones(4,1)),kron(ones(4,1),(2:5).')]
[n,p]=size(D)
% Vektor pozorovani
x = [96.3;95.7;99.9;99.4;95.1;97.8;99.3;104.9;96.2;100.1;...
     103.2;104.3;97.8;102.2;104.7;108.8]
pause;
%---------------------------------------------------------------
[bE,rE,sE]=linregr(x,D)
pause;
%---------------------------------------------------------------
disp('CENTROVANY MODEL:');
Dm = [0,mean(D(:,2:3))];    % Prumer z poslednich dvou sloupcu
Dc = D - kron(Dm,ones(n,1)) % Matice planu pro centrovany model
% Parametricka funkce pro vypocet bE(1,:) v necentrovanem modelu
C = [1 0 0] - Dm
pause;
%---------------------------------------------------------------
[bcE,rcE,scE,PbE,CbE]=linregr(x,Dc,[],C)
% Porovnani vysledku
bE_CbE = max(abs(bE(1,:) - CbE))
bE_bcE = max(max(abs(bE(2:3,:) - bcE(2:3,:))))
rE_rcE = max(abs(rE-rcE))
sE_scE = max(abs(sE-scE))
pause;
%---------------------------------------------------------------
% Totez lze spocist neprimo s vyuzitim operatoru:
[R,E0,s1,PE0,CE0]=linregr([],Dc,[],C)
bc=R*x, disp('+-'); sE(1)*E0
C*bc, disp('+-'); sE(1)*CE0
echo off
