function [ztrata u y b P]=ce(regulator_parameters,system,apriori)

horizont=regulator_parameters.horizont;

y=zeros(horizont);
b=zeros(horizont);
P=zeros(horizont);
u=zeros(horizont);
ztrata=0;

y(1)=apriori(1);
b(1)=apriori(2);
P(1)=apriori(3);

for i=1:horizont-1
    u(i)=(system.yr(i)-y(i))/b(i);
    [y(i+1) b(i+1) P(i+1)]=get_next([y(i) b(i) P(i)],u(i),system);
    ztrata=ztrata+(y(i+1)-system.yr(i+1))^2;
end

end

