function realization=generate_realization(apriori,H0,H_tilde,C,regulator_parameters,system)

H=add_Hc_tilde0(H0,apriori,regulator_parameters); % nehlidam pozitivni definitnost !
realization=0;
system.S=zeros(1,3);
for o=1:regulator_parameters.horizont_simulace
    [u system]=control(system,H(:,1),interpol(H,H_tilde,C,regulator_parameters.H_tilde_on));
    system.x=H(:,1)+sqrt(diag(H(:,2:5))).*randn(4,1); %realizace systemu
    
    [system.x system.pozorovani]=get_next(system,system.x,u,randn(6,1));
    H=kalman_filter(H,u,system);
        
    realization=realization+u'*system.gamma*u+(system.x-system.x_opt)'*system.ksi*(system.x-system.x_opt);
end
end