
function [F] = F_QYH(x,R)
global BETA SIGMA PHI CHI GAMMA GAMMA_STAR THETA EPSILON ALPHA DELTA;
global XI_P;
global BF_GDP;

% Define endogenous variables, 
% We want to solve these unknowns
% characterized by fminsearch
Q  = x(1);
YH = x(2);

% Define the equations to compute the steady state
% The model should be as simplified as possible in order to obtain a
% precise solution faster

%R = 1;        %  to experiment beforehand

Ystar  = 1;
Rstar  = 1/BETA;
pi     = BETA*R;
piH    = pi;
%q      = 1;
rk     = 1/BETA - (1-DELTA);
%dE     = pi;
%r      = R/pi;

%Q      = find_QYH();
%YH     = find_QYH();

pH     = ((1-GAMMA*Q^(1-THETA))/(1-GAMMA))^(1/(1-THETA));
mc     = pH - pH*(XI_P/(1-EPSILON))*(1-BETA)*piH*(piH-1);
K_YH   = ALPHA*(mc/rk);
K      = K_YH*YH;
I      = DELTA*K;
N      = K_YH^(-ALPHA/(1-ALPHA))*YH;
N_YH   = N/YH;
w      = (1-ALPHA)*N_YH^(-1)*mc;
lambda = CHI*N^PHI/w;
C      = lambda^(-1/SIGMA);
GDP    = pH*YH;
bF     = BF_GDP*GDP;


% All the equations should have the form Ax=0
F= [
GDP*(1-XI_P/2*(piH-1)^2)-C-I-Q*(1-Rstar)*bF;
YH-(1-GAMMA)*pH^(-THETA)*(C+I)-GAMMA_STAR*(Q/pH)^THETA*Ystar-XI_P/2*(piH-1)^2*YH;
];

F = F'*F;

end


