GRADIENT Statement

GRADIENT variables ;

The GRADIENT statement defines the gradient vector which contains the first-order derivatives of the objective function $ f$ with respect to $ x_1,\ldots ,x_ n$. For more information, see the section Derivatives. To specify the values of nonzero derivatives, the variables specified in the GRADIENT statement must be defined on the left-hand side of algebraic expressions in programming statements. For example, consider the Rosenbrock function:

proc nlp tech=congra;
   min y;
   decvar x1 x2;
   gradient g1 g2;
   
   y1 = 10 * (x2 - x1 * x1);
   y2 = 1 - x1;
   
   y  = .5 * (y1 * y1 + y2 * y2);
   
   g1 = -200 * x1 * (x2 - x1 * x1) - (1 - x1); 
   g2 = 100 * (x2 - x1 * x1);
run;