minimize 
Representing the Rosenbrock problem as an NLF1 requires an user-supplied function to evaluate the problem and construction of an NLF1.
Step 1: Write a function that evaluates the Rosenbrock problem and gradient.
void rosen(int mode, int n, const ColumnVector& x, double& fx, ColumnVector& g, int& result) { // Rosenbrock's function double f1, f2, x1, x2; if (n != 2) return; x1 = x(1); x2 = x(2); f1 = (x2 - x1 * x1); f2 = 1. - x1; if (mode & NLPFunction) { fx = 100.* f1*f1 + f2*f2; } if (mode & NLPGradient) { g(1) = -400.*f1*x1 - 2.*f2; g(2) = 200.*f1; } result = NLPFunction & NLPGradient; }
Step 2: Create an NLF1 object.
NLF1 rosen_problem(n,rosen,init_rosen);
Next Section: Bound-constrained Minimization | Back to Solvers Page
Last revised July 13, 2006