%-------------------------------------------------
%   This module calculates several exit variables
%-------------------------------------------------

Gy = sum(L.*yl_prof);
Gc = sum(L.*c_prof);

py = L.*yl_prof/Gy;
pc = L.*c_prof/Gc;

mu_y = sum(ages.*py);
mu_c = sum(ages.*pc);

sig2y = sum(ages.*ages.*py)-mu_y^2;
sig2c = sum(ages.*ages.*pc)-mu_c^2;

gy_average = Gy/sum(L);
gc_average = Gc/sum(L);

growth_star = (sig2y==sig2c)*(mu_y - mu_c)/(sig2y - sig2c + (sig2y==sig2c));

mu_life = sum(ages.*L)/sum(L);    
mu_lifeGrowth = sum(ages.*exp(-rho_max*ages).*L)/sum(exp(-rho_max*ages).*L);

Beta0 = KoverY + (mu_y - mu_c)*(1-(lambda+delta)*KoverY);
Beta1 = -KoverY*(mu_y - mu_c)-(sig2y-sig2c)*(1-(lambda+delta)*KoverY);
Beta2 = KoverY*(sig2y-sig2c);

Beta = [Beta2 Beta1 Beta0];
koreni = roots(Beta);
if size(koreni,1)~=1 | size(koreni,2)~= 2
    koreni=[0 0];
end

