function z=solve_calibration(par_vec,kai,bbc,bbe,ddk,ddg,aa,ddb,bip,big,bg,bor,teta,car,xi,pi,n,csige,a,csig,etab,etad)
% function outvalue=solve_calibration(par_vec,betta,delta,hiring_cost_share,x,alfa,N,xi,U,varphi)
% Solves equations (22),(48)-(52) of Gali (2010) for the labor disutility chi, unemployment
% weight parameter psi, G and C, given the hiring_cost_share-target
%
% Copyright (C) 2016 Johannes Pfeifer
%
% This is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% It is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% For a copy of the GNU General Public License,
% see <http://www.gnu.org/licenses/>.
b=par_vec(1);
psi=par_vec(2);
q=par_vec(3);
ce=par_vec(4);
lae=par_vec(5);
cc=par_vec(6);
d=par_vec(7);
jb=par_vec(8);
kb=par_vec(9);
ke=par_vec(10);
ip=par_vec(11);
y=par_vec(12);
ye=par_vec(13);
w=par_vec(14);
kg=par_vec(15);
ig=par_vec(16);
g=par_vec(17);
lac=par_vec(18);
rk=par_vec(19);
or=par_vec(20);
lv=par_vec(21);
gae=par_vec(22);
jr=par_vec(23);
mkd=par_vec(24);
mkb=par_vec(25);
rd=par_vec(26);
rrs=par_vec(27);
rrb=par_vec(28);
rb=par_vec(29);


z(1)=b-log((exp(lv)*exp(pi)*exp(q)*exp(ke)*(1-ddk))/(1+exp(rb)));
z(2)=lae - log(exp(ce)^-csige);
z(3)=ce-log(exp(ye)/exp(xi)+exp(b)+(1-ddk)*exp(ke)*exp(q)-exp(w)*exp(n)-exp(ke)*exp(q)-(1+exp(rb))*exp(b)/exp(pi));
z(4)=cc-log(exp(y)-exp(ce)-exp(g)-exp(ig)-exp(ip));
z(5)=q-log(1/(1 - kai /2 * (exp(psi)-1) ^ 2 - kai*(exp(psi)- 1) * exp(psi) + bbc * kai * (exp(psi) -1) * exp(psi))) ;
z(6)=d-log(exp(b)-exp(kb));
z(7)= jb-log(exp(b)*exp(rb)-exp(rd)*exp(d));
z(8)= kb-log(((exp(rb)-exp(rd))*exp(b))/(exp(pi)-1+ddb-exp(rd)));
z(9)= w-log((1-aa)*exp(ye)/(exp(n)*exp(xi)));
z(10)= ig-log(big*exp(ye));
z(11)= kg-log(exp(ig)/ddg);
z(12)= ip-log(bip*exp(ye));
z(13)= or-log(bor*exp(y));
z(14)= ke-log((exp(ye)/(exp(a)*(exp(n)^(1-aa))*(exp(kg)^teta)))^(1/aa));
z(15)= psi-log(-(((2/kai)*(1-ddk*exp(ke)/exp(ip)))^(1/2))+1);
z(16)= rk-log((aa)*exp(ye)/(exp(ke)*exp(xi)));
z(17)= g-log(bg*exp(ye));
z(18)= lac - log(exp(cc)^-csig);
z(19)= jr - log(exp(y)*(1 - (1/exp(xi))));
z(20)=lv-log((exp(q)-bbe*(exp(q)*(1-ddk)+exp(rk)))/(exp(pi)*exp(q)*(1-ddk)*((1-bbe*(1+exp(rb))/exp(pi))/(1+exp(rb)))));
z(21)=gae-log((exp(lae)-exp(lae)*bbe*(1+exp(rb))/exp(pi))/(1+exp(rb)));
z(22)=car-exp(b)/exp(kb);
z(23)=y-ye;
z(24)=mkd-log(etad/(etad-1));
z(25)=mkb-log(etab/(etab-1));
z(26)=rd- log(exp(pi)/bbc - 1);
z(27)=rrs - log(exp(rd) /exp(mkd));
z(28)=rrb- rrs;
z(29)=rb-log(exp(rrb)*exp(mkb));

end