124 double result =
eval(p);
125 size_t size = p.size();
126 derivative.gradient.resize(size);
127 derivative.hessian.resize(size,size);
128 derivative.hessian.clear();
130 derivative.gradient(0) = 2*( p(0) - 1 ) - 400 * ( p(1) -
sqr( p(0) ) ) * p(0);
131 derivative.gradient(size-1) = 200 * ( p(size - 1) -
sqr( p( size - 2 ) ) ) ;
133 derivative.hessian(0,0) = 2 - 400* (p(1) - 3*
sqr(p(0))) ;
134 derivative.hessian(0,1) = -400 * p(0) ;
136 derivative.hessian(size-1,size-1) = 200;
137 derivative.hessian(size-1,size-2) = -400 * p( size - 2 );
139 for(
size_t i=1; i != size-1; ++i){
140 derivative.gradient( i ) = 2 * ( p(i) - 1 ) - 400 * (p(i+1) -
sqr( p(i) ) ) * p( i )+200 * ( p( i )-
sqr( p(i-1) ) );
142 derivative.hessian(i,i) = 202 - 400 * ( p(i+1) - 3 *
sqr(p(i)));
143 derivative.hessian(i,i+1) = - 400 * ( p(i) );
144 derivative.hessian(i,i-1) = - 400 * ( p(i-1) );