%% this code solves the steady-state values of Rg and Rd
function [res]=Solve1(x,alpha,beta,thetg,thetd,t,omg,mu,ee,xi,eta_c,eta_l,delk,kappa)

%Rdss = x(1,1);     % return to dirty capitals
%Rgss = x(2,1);     % return to green capitals
Rdss=x;
xdss  = Rdss+delk;      % gross return on dirty capital with depreciation
Rbss  = 1/xi-1;        % bank loan rate
pss  = (ee-1)/ee;      % marginal cost
wss = alpha^(alpha/(1-alpha))*(1-alpha)*(pss-t*thetd)^(1/(1-alpha))*xdss^(alpha/(alpha-1));
xgss = (alpha-alpha*beta)*((alpha*beta)^beta*((1-alpha)/wss)^((1-alpha)/alpha)*(pss-t*thetg)^(1/alpha))^(1/(1-beta));
Rgss = xgss-delk;
ess   = Rdss/Rgss;  % cutoff
phiss = Rdss/(omg-Rdss+Rbss);  % leverage ratio
Lss   = 1;              % labor supply
Fss   = ess;            % probability of investing in dirty project with uniform distribution

%新增部分
Lgss = ((xgss*(1-Fss))/((1-beta)*xdss*Fss+xgss*(1-Fss)))*Lss;
Ldss = Lss-Lgss;

Kdss  = (xdss/(alpha*(pss-t*thetd)))^(1/(alpha-1))*Ldss;  % capital stock of dirty project
Kgss  = ((1-Fss)/Fss)*Kdss;                   % capital stock of green project            
Kss   = Kdss+Kgss;

Ydss  = (Kdss^alpha)*Ldss^(1-alpha);                        % output of dirty project
wss   = (1-alpha)*(pss-t*thetd)*Ydss/Ldss;    % real wage
Gss= ((alpha*beta)*((1-alpha)/wss)^((1-alpha)/alpha)*(pss-t*thetg)^(1/alpha))^(1/(1-beta))*Kgss;
Ygss = (Gss^beta*Kgss^(1-beta))^alpha*Lgss^(1-alpha);  

nss   = Kgss/((1-Fss)*(1+phiss));               % net worth of entrepreneurs
sss   = phiss*nss;                            % loan 

%Yss   = (kappa*Ygss^((ee-1)/ee)+(1-kappa)*Ydss^((ee-1)/ee))^(ee/(ee-1));   % all output
Yss = Ydss+Ygss;

Thetass = (1-Fss)*thetg+Fss*thetd;             % all emission

Igss  = Gss;                                  % real investment in green capital
Ikss  = delk*Kss;                             % real invsetment 
Css   = Yss-Igss-Ikss;                       % consumption
Lamdss = Css^(-eta_c);                        % Lagrangian multiplier
kai_l  = wss*Lamdss;

Eess  = (1+ess)/2;                            % E(e|e>e*)
ERss  = (1-Fss)*Rgss*Eess+Fss*Rdss;           % firms' gross return

%res(1,1) = Yss-Css-Igss-Ikss;
res = (1-mu)*(1+(1+phiss)*ERss-phiss*Rbss)-1;
