Class NewtonRootFinder


  • public class NewtonRootFinder
    extends RootFinder
    This class implements the Newton method for finding zeros of a function.
    Author:
    Matthias Thimm
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<java.util.List<Term>> jacobian
      The jacobian of the function.
      static int MAX_FIX_ITERATIONS
      The maximum number of fixing iterations.
      static double PRECISION
      The precision of the approximation.
    • Constructor Summary

      Constructors 
      Constructor Description
      NewtonRootFinder​(java.util.List<Term> functions, java.util.Map<Variable,​Term> startingPoint)
      Creates a new Newton root finder for the given starting point and the given (multi-dimensional) function
      NewtonRootFinder​(Term function, java.util.Map<Variable,​Term> startingPoint)
      Creates a new Newton root finder for the given starting point and the given function
    • Method Summary

      Modifier and Type Method Description
      private java.util.List<java.lang.Double> approximate​(java.util.List<java.util.List<java.lang.Double>> currentJacobianValue, java.util.List<java.lang.Double> currentVector, java.util.List<java.lang.Double> currentValue)
      Solves the linear equation currentJacobianValue * (X-currentVector) = - currentValue.
      private java.util.List<java.util.List<java.lang.Double>> evaluateMatrix​(java.util.List<java.util.List<Term>> functions, java.util.Map<Variable,​? extends Term> mapping)
      Evaluates each function in the given matrix with the given values for variables.
      private java.util.Map<Variable,​Term> midpoint​(java.util.Map<Variable,​Term> m1, java.util.Map<Variable,​Term> m2)
      Computes the midpoint of the two maps
      java.util.Map<Variable,​Term> randomRoot()
      Determines the values for the variables appearing in the function such the function evaluates to zero.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • jacobian

        private java.util.List<java.util.List<Term>> jacobian
        The jacobian of the function.
      • PRECISION

        public static final double PRECISION
        The precision of the approximation. The actual used precision depends on the number of variables.
        See Also:
        Constant Field Values
      • MAX_FIX_ITERATIONS

        public static final int MAX_FIX_ITERATIONS
        The maximum number of fixing iterations.
        See Also:
        Constant Field Values
    • Constructor Detail

      • NewtonRootFinder

        public NewtonRootFinder​(Term function,
                                java.util.Map<Variable,​Term> startingPoint)
        Creates a new Newton root finder for the given starting point and the given function
        Parameters:
        function - a function
        startingPoint - the starting point
      • NewtonRootFinder

        public NewtonRootFinder​(java.util.List<Term> functions,
                                java.util.Map<Variable,​Term> startingPoint)
        Creates a new Newton root finder for the given starting point and the given (multi-dimensional) function
        Parameters:
        functions - a list of functions
        startingPoint - the starting point
    • Method Detail

      • randomRoot

        public java.util.Map<Variable,​Term> randomRoot()
                                                      throws GeneralMathException
        Description copied from class: RootFinder
        Determines the values for the variables appearing in the function such the function evaluates to zero.
        Specified by:
        randomRoot in class RootFinder
        Returns:
        a map from variables to terms such that "function" evaluates to zero.
        Throws:
        GeneralMathException - if something went wrong.
      • midpoint

        private java.util.Map<Variable,​Term> midpoint​(java.util.Map<Variable,​Term> m1,
                                                            java.util.Map<Variable,​Term> m2)
        Computes the midpoint of the two maps
        Parameters:
        m1 - a map
        m2 - a map
        Returns:
        the midpoint of the two maps
      • approximate

        private java.util.List<java.lang.Double> approximate​(java.util.List<java.util.List<java.lang.Double>> currentJacobianValue,
                                                             java.util.List<java.lang.Double> currentVector,
                                                             java.util.List<java.lang.Double> currentValue)
                                                      throws GeneralMathException
        Solves the linear equation currentJacobianValue * (X-currentVector) = - currentValue.
        Parameters:
        currentJacobianValue - the current Jacobian value
        currentVector - the current vector
        currentValue - the current value
        Returns:
        the next guess for the approximation.
        Throws:
        GeneralMathException
      • evaluateMatrix

        private java.util.List<java.util.List<java.lang.Double>> evaluateMatrix​(java.util.List<java.util.List<Term>> functions,
                                                                                java.util.Map<Variable,​? extends Term> mapping)
        Evaluates each function in the given matrix with the given values for variables.
        Parameters:
        functions - a list of functions
        mapping - a map mapping variables to terms
        Returns:
        the matrix of values