
function [F,J]=f8(x, C, v, thita, Nss)

  r_l  = x(1,1);
  r_h  = x(2,1);
  c_sl = x(3,1);
  c_wl = x(4,1);  
  c_wh = x(5,1);
  H    = x(6,1);
  w    = x(7,1);
  alpha= x(8,1);
  
  F(1,1) = 1 - ((1-alpha)^(1+thita)+(alpha*H)^(1+thita))*r_l^(1-thita) - ((alpha*(1-H))^(1+thita))*r_h^(1-thita);                    %f1
  F(2,1) = r_h^((thita+v-thita*v)/v) - (thita/(thita-1))*(w/v)*(C^((1-v)/v))*((alpha*(1-H))^(thita*(v-1)/v));                        %f2
  F(3,1) = r_l^((thita+v-thita*v)/v) - (thita/(thita-1))*(w/v)*(C^((1-v)/v))*((H*alpha)^((thita+v)/v)+(1-alpha)^((thita+v)/v))/((H*alpha)^(1+thita)+(1-alpha)^(1+thita));          %f3
  % H equation is in the moment profit form
  F(4,1) = r_h*c_wh - (w)*(c_wh^(1/v))- r_l*c_wl + (w)*(c_wl^(1/v)) - ((1-alpha)/H/alpha)*(r_l*c_sl - (w)*(c_sl^(1/v)));             %f4 
  F(5,1) = c_sl - ((r_l/(1-alpha))^(-thita))*C;                                                                                      %f5
  F(6,1) = c_wl - ((r_l/alpha/H)^(-thita))*C;                                                                                        %f6
  F(7,1) = c_wh - ((r_h/(1-H)/alpha)^(-thita))*C;                                                                                    %f7
  F(8,1) = (alpha-1)*c_sl^((thita-1)/thita)+alpha*(H^2)*c_wl^((thita-1)/thita)+alpha*((1-H)^2)*c_wh^((thita-1)/thita) - (1-thita)*w*Nss*(C^(-1/thita))/(1+thita);
  
  if nargout > 1
      
    J(1,1) = ((thita - 1)*((H*alpha)^(thita + 1) + (1 - alpha)^(thita + 1)))/r_l^thita;
    J(2,1) = 0;
    J(3,1) = (r_l^((thita + v - thita*v)/v - 1)*(thita + v - thita*v))/v;
    J(4,1) = (c_sl*(alpha - 1))/(H*alpha) - c_wl;
    J(5,1) = -(C*thita)/((alpha - 1)*(-r_l/(alpha - 1))^(thita + 1));
    J(6,1) = (C*thita)/(H*alpha*(r_l/(H*alpha))^(thita + 1));
    J(7,1) = 0;
    J(8,1) = 0;
    J(1,2) = ((-alpha*(H - 1))^(thita + 1)*(thita - 1))/r_h^thita;
    J(2,2) = (r_h^((thita + v - thita*v)/v - 1)*(thita + v - thita*v))/v;
    J(3,2) = 0;
    J(4,2) = c_wh;
    J(5,2) = 0;
    J(6,2) = 0;
    J(7,2) = -(C*thita)/(alpha*(H - 1)*(-r_h/(alpha*(H - 1)))^(thita + 1));
    J(8,2) = 0;
    J(1,3) = 0;
    J(2,3) = 0;
    J(3,3) = 0;
    J(4,3) = ((r_l - (c_sl^(1/v - 1)*w)/v)*(alpha - 1))/(H*alpha);
    J(5,3) = 1;
    J(6,3) = 0;
    J(7,3) = 0;
    J(8,3) = (c_sl^((thita - 1)/thita - 1)*(alpha - 1)*(thita - 1))/thita;
    J(1,4) = 0;
    J(2,4) = 0;
    J(3,4) = 0;
    J(4,4) = (c_wl^(1/v - 1)*w)/v - r_l;
    J(5,4) = 0;
    J(6,4) = 1;
    J(7,4) = 0;
    J(8,4) = (H^2*alpha*c_wl^((thita - 1)/thita - 1)*(thita - 1))/thita;
    J(1,5) = 0;
    J(2,5) = 0;
    J(3,5) = 0;
    J(4,5) = r_h - (c_wh^(1/v - 1)*w)/v;
    J(5,5) = 0;
    J(6,5) = 0;
    J(7,5) = 1; 
    J(8,5) = (alpha*c_wh^((thita - 1)/thita - 1)*(H - 1)^2*(thita - 1))/thita;
    J(1,6) = alpha*r_h^(1 - thita)*(-alpha*(H - 1))^thita*(thita + 1) - alpha*r_l^(1 - thita)*(H*alpha)^thita*(thita + 1);
    J(2,6) = (alpha*thita^2*w*(-alpha*(H - 1))^((thita*(v - 1))/v - 1)*(v - 1))/(C^((v - 1)/v)*v^2*(thita - 1));
    J(3,6) =  (alpha*thita*w*(H*alpha)^thita*((H*alpha)^((thita + v)/v) + (1 - alpha)^((thita + v)/v))*(thita + 1))/(C^((v - 1)/v)*v*(thita - 1)*((H*alpha)^(thita + 1) + (1 - alpha)^(thita + 1))^2) - (alpha*thita*w*(H*alpha)^((thita + v)/v - 1)*(thita + v))/(C^((v - 1)/v)*v^2*(thita - 1)*((H*alpha)^(thita + 1) + (1 - alpha)^(thita + 1)));
    J(4,6) = -((c_sl*r_l - c_sl^(1/v)*w)*(alpha - 1))/(H^2*alpha);
    J(5,6) = 0;
    J(6,6) = -(C*r_l*thita)/(H^2*alpha*(r_l/(H*alpha))^(thita + 1));
    J(7,6) = (C*r_h*thita)/(alpha*(H - 1)^2*(-r_h/(alpha*(H - 1)))^(thita + 1));
    J(8,6) = alpha*c_wh^((thita - 1)/thita)*(2*H - 2) + 2*H*alpha*c_wl^((thita - 1)/thita);
    J(1,7) = 0;
    J(2,7) = -(thita*(-alpha*(H - 1))^((thita*(v - 1))/v))/(C^((v - 1)/v)*v*(thita - 1));
    J(3,7) = -(thita*((H*alpha)^((thita + v)/v) + (1 - alpha)^((thita + v)/v)))/(C^((v - 1)/v)*v*(thita - 1)*((H*alpha)^(thita + 1) + (1 - alpha)^(thita + 1)));
    J(4,7) = c_wl^(1/v) - c_wh^(1/v) - (c_sl^(1/v)*(alpha - 1))/(H*alpha);
    J(5,7) = 0;
    J(6,7) = 0;
    J(7,7) = 0;
    J(8,7) = (Nss*(thita - 1))/(C^(1/thita)*(thita + 1));
    J(1,8) = r_l^(1 - thita)*((1 - alpha)^thita*(thita + 1) - H*(H*alpha)^thita*(thita + 1)) + r_h^(1 - thita)*(-alpha*(H - 1))^thita*(H - 1)*(thita + 1);
    J(2,8) = (thita^2*w*(-alpha*(H - 1))^((thita*(v - 1))/v - 1)*(H - 1)*(v - 1))/(C^((v - 1)/v)*v^2*(thita - 1));
    J(3,8) = (thita*w*(((thita + v)*(1 - alpha)^((thita + v)/v - 1))/v - (H*(H*alpha)^((thita + v)/v - 1)*(thita + v))/v))/(C^((v - 1)/v)*v*(thita - 1)*((H*alpha)^(thita + 1) + (1 - alpha)^(thita + 1))) - (thita*w*((H*alpha)^((thita + v)/v) + (1 - alpha)^((thita + v)/v))*((1 - alpha)^thita*(thita + 1) - H*(H*alpha)^thita*(thita + 1)))/(C^((v - 1)/v)*v*(thita - 1)*((H*alpha)^(thita + 1) + (1 - alpha)^(thita + 1))^2);
    J(4,8) = (c_sl*r_l - c_sl^(1/v)*w)/(H*alpha) - ((c_sl*r_l - c_sl^(1/v)*w)*(alpha - 1))/(H*alpha^2);
    J(5,8) = (C*r_l*thita)/((alpha - 1)^2*(-r_l/(alpha - 1))^(thita + 1));
    J(6,8) = -(C*r_l*thita)/(H*alpha^2*(r_l/(H*alpha))^(thita + 1));
    J(7,8) = (C*r_h*thita)/(alpha^2*(H - 1)*(-r_h/(alpha*(H - 1)))^(thita + 1));
    J(8,8) = c_wh^((thita - 1)/thita)*(H - 1)^2 + c_sl^((thita - 1)/thita) + H^2*c_wl^((thita - 1)/thita);
  end
end

 
