function v = vfn(z,p);

theta = p(1);
gamma = p(2);
delta = p(3);
pi    = p(4);

k  = z(1);
lam= z(2);
g  = z(3);
tau= z(4);
phi= z(5);
K  = z(7);
N  = z(8);
i  = z(9);
n  = z(10);

Y  = lam*K^theta*N^(1-theta);
r  = theta*Y/K;
w  = (1-theta)*Y/N;
T  = tau*r*K+phi*w*N-delta*tau*K-g;
c  = r*k+w*n-tau*(r-delta)*k-phi*w*n-i+T;
v  = log(c+pi*g)+gamma*log(1-n);
%v = -((c+pi*g)^(1/(1+gamma))*(1-n)^(gamma/(1+gamma)))^(-0.24)/0.24;

