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.polynomials.PolynomialFunction; 021 022 /** 023 * Base class for solvers. 024 * 025 * @since 3.0 026 * @version $Id: AbstractPolynomialSolver.java 1364387 2012-07-22 18:14:11Z tn $ 027 */ 028 public abstract class AbstractPolynomialSolver 029 extends BaseAbstractUnivariateSolver<PolynomialFunction> 030 implements PolynomialSolver { 031 /** Function. */ 032 private PolynomialFunction polynomialFunction; 033 034 /** 035 * Construct a solver with given absolute accuracy. 036 * 037 * @param absoluteAccuracy Maximum absolute error. 038 */ 039 protected AbstractPolynomialSolver(final double absoluteAccuracy) { 040 super(absoluteAccuracy); 041 } 042 /** 043 * Construct a solver with given accuracies. 044 * 045 * @param relativeAccuracy Maximum relative error. 046 * @param absoluteAccuracy Maximum absolute error. 047 */ 048 protected AbstractPolynomialSolver(final double relativeAccuracy, 049 final double absoluteAccuracy) { 050 super(relativeAccuracy, absoluteAccuracy); 051 } 052 /** 053 * Construct a solver with given accuracies. 054 * 055 * @param relativeAccuracy Maximum relative error. 056 * @param absoluteAccuracy Maximum absolute error. 057 * @param functionValueAccuracy Maximum function value error. 058 */ 059 protected AbstractPolynomialSolver(final double relativeAccuracy, 060 final double absoluteAccuracy, 061 final double functionValueAccuracy) { 062 super(relativeAccuracy, absoluteAccuracy, functionValueAccuracy); 063 } 064 065 /** 066 * {@inheritDoc} 067 */ 068 @Override 069 protected void setup(int maxEval, PolynomialFunction f, 070 double min, double max, double startValue) { 071 super.setup(maxEval, f, min, max, startValue); 072 polynomialFunction = f; 073 } 074 075 /** 076 * @return the coefficients of the polynomial function. 077 */ 078 protected double[] getCoefficients() { 079 return polynomialFunction.getCoefficients(); 080 } 081 }