function [gfnew,gn] = goalgra(V,neqcstr,evalstr1,evalstr2,WEIGHT,GOAL,x,P1,P2,P3,P4,P5,P6);
%GOALGRA Utility function to translate gradient in goal-attainment problem.
%	Intermediate function used to translate goal attainment
%	problem into constrained optimization problem.
%	Used by ATTGOAL and CONSTR. See also, GOALFUN.

%	Copyright (c) 1990 by the MathWorks, Inc.
%	Andy Grace 7-9-90.

nx=length(V)-1;
x(:)=V(1:nx);
lambda=V(nx+1);
gg=[];
eval(evalstr2)
ncstr=length(WEIGHT);
GL = -ones(1,ncstr+neqcstr);
for i=1:ncstr
  if WEIGHT(i)~=0
    gf(:,i)=gf(:,i)/WEIGHT(i);
    if i<=neqcstr,gf(:,i+ncstr)=-gf(:,i); end 
  else
    GL(1,i)=0;
  end
end
gfnew=[zeros(nx,1);1];
gn=[gf;GL];
gs=size(gg);
if gs(1)>0, gn=[gn,[gg;zeros(1,gs(2))]]; end
