AbstractPolynomialSolver.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.apache.commons.math4.legacy.analysis.solvers;

  18. import org.apache.commons.math4.legacy.analysis.polynomials.PolynomialFunction;

  19. /**
  20.  * Base class for solvers.
  21.  *
  22.  * @since 3.0
  23.  */
  24. public abstract class AbstractPolynomialSolver
  25.     extends BaseAbstractUnivariateSolver<PolynomialFunction>
  26.     implements PolynomialSolver {
  27.     /** Function. */
  28.     private PolynomialFunction polynomialFunction;

  29.     /**
  30.      * Construct a solver with given absolute accuracy.
  31.      *
  32.      * @param absoluteAccuracy Maximum absolute error.
  33.      */
  34.     protected AbstractPolynomialSolver(final double absoluteAccuracy) {
  35.         super(absoluteAccuracy);
  36.     }
  37.     /**
  38.      * Construct a solver with given accuracies.
  39.      *
  40.      * @param relativeAccuracy Maximum relative error.
  41.      * @param absoluteAccuracy Maximum absolute error.
  42.      */
  43.     protected AbstractPolynomialSolver(final double relativeAccuracy,
  44.                                        final double absoluteAccuracy) {
  45.         super(relativeAccuracy, absoluteAccuracy);
  46.     }
  47.     /**
  48.      * Construct a solver with given accuracies.
  49.      *
  50.      * @param relativeAccuracy Maximum relative error.
  51.      * @param absoluteAccuracy Maximum absolute error.
  52.      * @param functionValueAccuracy Maximum function value error.
  53.      */
  54.     protected AbstractPolynomialSolver(final double relativeAccuracy,
  55.                                        final double absoluteAccuracy,
  56.                                        final double functionValueAccuracy) {
  57.         super(relativeAccuracy, absoluteAccuracy, functionValueAccuracy);
  58.     }

  59.     /**
  60.      * {@inheritDoc}
  61.      */
  62.     @Override
  63.     protected void setup(int maxEval, PolynomialFunction f,
  64.                              double min, double max, double startValue) {
  65.         super.setup(maxEval, f, min, max, startValue);
  66.         polynomialFunction = f;
  67.     }

  68.     /**
  69.      * @return the coefficients of the polynomial function.
  70.      */
  71.     protected double[] getCoefficients() {
  72.         return polynomialFunction.getCoefficients();
  73.     }
  74. }