All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.commons.math3.dfp.BracketingNthOrderBrentSolverDFP Maven / Gradle / Ivy

Go to download

The Apache Commons Math project is a library of lightweight, self-contained mathematics and statistics components addressing the most common practical problems not immediately available in the Java programming language or commons-lang.

There is a newer version: 3.6.1
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.math3.dfp;


import org.apache.commons.math3.analysis.RealFieldUnivariateFunction;
import org.apache.commons.math3.analysis.solvers.AllowedSolution;
import org.apache.commons.math3.analysis.solvers.FieldBracketingNthOrderBrentSolver;
import org.apache.commons.math3.exception.NoBracketingException;
import org.apache.commons.math3.exception.NullArgumentException;
import org.apache.commons.math3.exception.NumberIsTooSmallException;
import org.apache.commons.math3.util.MathUtils;

/**
 * This class implements a modification of the  Brent algorithm.
 * 

* The changes with respect to the original Brent algorithm are: *

    *
  • the returned value is chosen in the current interval according * to user specified {@link AllowedSolution},
  • *
  • the maximal order for the invert polynomial root search is * user-specified instead of being invert quadratic only
  • *
*

* The given interval must bracket the root. * @deprecated as of 3.6 replaced with {@link FieldBracketingNthOrderBrentSolver} */ @Deprecated public class BracketingNthOrderBrentSolverDFP extends FieldBracketingNthOrderBrentSolver { /** * Construct a solver. * * @param relativeAccuracy Relative accuracy. * @param absoluteAccuracy Absolute accuracy. * @param functionValueAccuracy Function value accuracy. * @param maximalOrder maximal order. * @exception NumberIsTooSmallException if maximal order is lower than 2 */ public BracketingNthOrderBrentSolverDFP(final Dfp relativeAccuracy, final Dfp absoluteAccuracy, final Dfp functionValueAccuracy, final int maximalOrder) throws NumberIsTooSmallException { super(relativeAccuracy, absoluteAccuracy, functionValueAccuracy, maximalOrder); } /** * Get the absolute accuracy. * @return absolute accuracy */ @Override public Dfp getAbsoluteAccuracy() { return super.getAbsoluteAccuracy(); } /** * Get the relative accuracy. * @return relative accuracy */ @Override public Dfp getRelativeAccuracy() { return super.getRelativeAccuracy(); } /** * Get the function accuracy. * @return function accuracy */ @Override public Dfp getFunctionValueAccuracy() { return super.getFunctionValueAccuracy(); } /** * Solve for a zero in the given interval. * A solver may require that the interval brackets a single zero root. * Solvers that do require bracketing should be able to handle the case * where one of the endpoints is itself a root. * * @param maxEval Maximum number of evaluations. * @param f Function to solve. * @param min Lower bound for the interval. * @param max Upper bound for the interval. * @param allowedSolution The kind of solutions that the root-finding algorithm may * accept as solutions. * @return a value where the function is zero. * @exception NullArgumentException if f is null. * @exception NoBracketingException if root cannot be bracketed */ public Dfp solve(final int maxEval, final UnivariateDfpFunction f, final Dfp min, final Dfp max, final AllowedSolution allowedSolution) throws NullArgumentException, NoBracketingException { return solve(maxEval, f, min, max, min.add(max).divide(2), allowedSolution); } /** * Solve for a zero in the given interval, start at {@code startValue}. * A solver may require that the interval brackets a single zero root. * Solvers that do require bracketing should be able to handle the case * where one of the endpoints is itself a root. * * @param maxEval Maximum number of evaluations. * @param f Function to solve. * @param min Lower bound for the interval. * @param max Upper bound for the interval. * @param startValue Start value to use. * @param allowedSolution The kind of solutions that the root-finding algorithm may * accept as solutions. * @return a value where the function is zero. * @exception NullArgumentException if f is null. * @exception NoBracketingException if root cannot be bracketed */ public Dfp solve(final int maxEval, final UnivariateDfpFunction f, final Dfp min, final Dfp max, final Dfp startValue, final AllowedSolution allowedSolution) throws NullArgumentException, NoBracketingException { // checks MathUtils.checkNotNull(f); // wrap the function RealFieldUnivariateFunction fieldF = new RealFieldUnivariateFunction() { /** {@inheritDoc} */ public Dfp value(final Dfp x) { return f.value(x); } }; // delegate to general field solver return solve(maxEval, fieldF, min, max, startValue, allowedSolution); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy