docs/one_dim_spring.cc
//-> advance the system via Newton's method
> advance the system via Newton's method
> advance the system via Newton ' s method
void advance() {
  double xstar = x;
  double prev_x = xstar;
  Ep = Ek = 0;
  Ev->Val(&Ep, &xstar);
  Et->Val(&Ek, &xstar);
  E = Ep + Ek;
  for (size_t iter = 0; iter < MAXITER; ++iter) {
    double value = 0; {
      Ev->Val(&value, &xstar);
      Et->Val(&value, &xstar);
    }
    double grad = 0; {
      Ev->Gra(&grad, &xstar);
      Et->Gra(&grad, &xstar);
      grad *= -1;
    }
    double hess = 0; {
      Ev->Hes(&hess, &xstar);
      Et->Hes(&hess, &xstar);
    }
    double dx = grad/hess;
    if ( fabs(dx) <= EPSILON*prev_x ) {
      break;
    }
    prev_x = xstar;
    xstar += dx;
    {
    }
  }
  x = xstar;
}
void advance ( ) { double xstar = x ; double prev_x = xstar ; Ep = Ek = 0 ; Ev -> Val ( & Ep , & xstar ) ; Et -> Val ( & Ek , & xstar ) ; E = Ep + Ek ; for ( size_t iter = 0 ; iter < MAXITER ; ++ iter ) { double value = 0 ; { Ev -> Val ( & value , & xstar ) ; Et -> Val ( & value , & xstar ) ; } double grad = 0 ; { Ev -> Gra ( & grad , & xstar ) ; Et -> Gra ( & grad , & xstar ) ; grad *= -1 ; } double hess = 0 ; { Ev -> Hes ( & hess , & xstar ) ; Et -> Hes ( & hess , & xstar ) ; } double dx = grad / hess ; if ( fabs ( dx ) <= EPSILON * prev_x ) { break ; } prev_x = xstar ; xstar += dx ; { } } x = xstar ; }
> advance the system via Newton's method
> advance the system via Newton ' s method
//-> evaluate objective value //-> evaluate objective gradient //-> evaluate objective hessian //-> determine search direction, corresponds to solving Hx = g // cout << "\t@CONVERGED\n"; //-> maybe line search is needed for robustness // line search, just omit here.