Commit 005e7a064e8180d29f7b1243b6fdabaf5ef9e36c

Authored by knodlseder
1 parent 1bd83a2f

remove eps increase abortion

Showing 1 changed file with 6 additions and 34 deletions
src/numerics/GDerivative.cpp
... ... @@ -182,7 +182,7 @@ GDerivative* GDerivative::clone(void) const
182 182 * iteratively decreases the step size until the error becomes less than
183 183 * a threshold defined with the eps() method (by default the threshold is
184 184 * set to 1e-6). If the initial step size is zero, the method takes
185   - * h=0.02*|x| as initial step size.
  185 + * \f$h={\tt m\_step\_frac} |x|\f$ as initial step size.
186 186 * The maximum number of iterations is controlled by the max_iter()
187 187 * method (by default, the maximum is set to 5).
188 188 ***************************************************************************/
... ... @@ -194,7 +194,9 @@ double GDerivative::value(const double& x, double step)
194 194 // Initialise result
195 195 double result = 0.0;
196 196  
197   - // Set initial step size
  197 + // Set initial step size. Use either the specified initial step size,
  198 + // or if the initial step size is 0, use a fixed fraction of the function
  199 + // value
198 200 double h = step;
199 201 if (h == 0.0) {
200 202 h = m_step_frac * std::abs(x);
... ... @@ -205,11 +207,8 @@ double GDerivative::value(const double& x, double step)
205 207 // Save initial step size
206 208 double h_initial = h;
207 209  
208   - // Initialise
209   - double err = DBL_MAX; // Tolenarce
210   - double last_result = 0.0; // Last result
211   - double last_err = DBL_MAX; // Last error
212   - double last_h = h; // Last step size
  210 + // Initialise tolerance
  211 + double err = DBL_MAX;
213 212  
214 213 // Loop over Ridder's method until we have an acceptable tolerance
215 214 m_iter = 0;
... ... @@ -233,33 +232,6 @@ double GDerivative::value(const double& x, double step)
233 232 if (err < m_eps)
234 233 break;
235 234  
236   - // Did last error increase? If yes then take last value and stop
237   - if (err > last_err) {
238   -
239   - // Recover last results
240   - result = last_result;
241   - err = last_err;
242   - h = last_h;
243   -
244   - // Optional dump warning
245   - if (!silent()) {
246   - std::cout << "WARNING: GDerivative::value(x=";
247   - std::cout << x;
248   - std::cout << "): initial step size ";
249   - std::cout << h_initial;
250   - std::cout << " possibly too small." << std::endl;
251   - }
252   -
253   - // Break
254   - break;
255   -
256   - } // endif: last error increased
257   -
258   - // Store last values
259   - last_result = result;
260   - last_err = err;
261   - last_h = h;
262   -
263 235 // Reduce the step size
264 236 h /= 5.0;
265 237  
... ...