%Function file: fff.m 
%called to solve Dixit & Pindyck Ch.7 nonlinear system
function f=fff(vars,Q,Beta1,Beta2,delt,C,r,II,E)
A1=vars(1);
ph = vars(2);
B2 = vars(3);
pl = vars(4);
f=zeros(4,1);
f(1) = -Q*A1*ph^Beta1 + B2*Q*ph^Beta2 + Q*ph/delt -Q*C/r - II;
f(2)= -Beta1*A1*Q*ph^(Beta1-1) + B2*Q*Beta2*ph^(Beta2-1) + Q/delt;
f(3)= -A1*Q*pl^Beta1 + B2*Q*pl^Beta2 + Q*pl/delt -Q*C/r + E;
f(4) = -Beta1*A1*Q*pl^(Beta1-1) + B2*Q*Beta2*pl^(Beta2-1) + Q/delt;
