001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.commons.math3.analysis.solvers; 019 020 import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction; 021 import org.apache.commons.math3.analysis.UnivariateFunction; 022 import org.apache.commons.math3.exception.TooManyEvaluationsException; 023 024 /** 025 * Provide a default implementation for several functions useful to generic 026 * solvers. 027 * 028 * @since 3.0 029 * @version $Id: AbstractDifferentiableUnivariateSolver.java 1379560 2012-08-31 19:40:30Z erans $ 030 * @deprecated as of 3.1, replaced by {@link AbstractUnivariateDifferentiableSolver} 031 */ 032 @Deprecated 033 public abstract class AbstractDifferentiableUnivariateSolver 034 extends BaseAbstractUnivariateSolver<DifferentiableUnivariateFunction> 035 implements DifferentiableUnivariateSolver { 036 /** Derivative of the function to solve. */ 037 private UnivariateFunction functionDerivative; 038 039 /** 040 * Construct a solver with given absolute accuracy. 041 * 042 * @param absoluteAccuracy Maximum absolute error. 043 */ 044 protected AbstractDifferentiableUnivariateSolver(final double absoluteAccuracy) { 045 super(absoluteAccuracy); 046 } 047 048 /** 049 * Construct a solver with given accuracies. 050 * 051 * @param relativeAccuracy Maximum relative error. 052 * @param absoluteAccuracy Maximum absolute error. 053 * @param functionValueAccuracy Maximum function value error. 054 */ 055 protected AbstractDifferentiableUnivariateSolver(final double relativeAccuracy, 056 final double absoluteAccuracy, 057 final double functionValueAccuracy) { 058 super(relativeAccuracy, absoluteAccuracy, functionValueAccuracy); 059 } 060 061 /** 062 * Compute the objective function value. 063 * 064 * @param point Point at which the objective function must be evaluated. 065 * @return the objective function value at specified point. 066 * @throws org.apache.commons.math3.exception.TooManyEvaluationsException 067 * if the maximal number of evaluations is exceeded. 068 */ 069 protected double computeDerivativeObjectiveValue(double point) 070 throws TooManyEvaluationsException { 071 incrementEvaluationCount(); 072 return functionDerivative.value(point); 073 } 074 075 /** 076 * {@inheritDoc} 077 */ 078 @Override 079 protected void setup(int maxEval, DifferentiableUnivariateFunction f, 080 double min, double max, double startValue) { 081 super.setup(maxEval, f, min, max, startValue); 082 functionDerivative = f.derivative(); 083 } 084 }