Class IPRootFinder

    • Field Detail

      • f

        protected FunctionIfc f
        Function for which the zero should be found.
      • myInterval

        protected Interval myInterval
        The interval for the search
      • myInitialPt

        protected double myInitialPt
        The initial point for the search
      • myMaxIterations

        protected int myMaxIterations
        The maximum number of iterations permitted to find the root The default is 100
      • numIterations

        protected static int numIterations
        Used in the static methods for finding intervals
      • searchFactor

        protected static double searchFactor
        used in the static methods for finding intervals
    • Constructor Detail

      • IPRootFinder

        public IPRootFinder​(FunctionIfc func,
                            Interval interval)
        Defines a function and an interval for searching for a root
        Parameters:
        func - must not be null, must have a root in the interval
        interval -
      • IPRootFinder

        public IPRootFinder​(FunctionIfc func,
                            double xLower,
                            double xUpper)
        Defines a function and an interval for searching for a root
        Parameters:
        func - must not be null, must have a root in the interval
        xLower - must be less than xUpper
        xUpper - must be greater than xLower
    • Method Detail

      • getRoot

        public double getRoot()
        Returns the last evaluated value that was considered for the root of the function
      • getFunctionAtRoot

        public double getFunctionAtRoot()
        Returns the value of the function at the last considered possible root of the function
        Returns:
      • relativePrecision

        public double relativePrecision​(double epsilon)
        Parameters:
        epsilon - double
        Returns:
        double
      • relativePrecision

        public double relativePrecision​(double epsilon,
                                        double x)
        Parameters:
        epsilon - double
        x - double
        Returns:
        double
      • getMaxIterations

        public int getMaxIterations()
        Returns:
        the maximum number of iterations
      • setMaxIterations

        public void setMaxIterations​(int maxIterations)
        Parameters:
        maxIterations - the maximum number of iterations
      • hasIterations

        public boolean hasIterations()
        Returns true if the number of iterations is < max iterations
        Returns:
      • hasRoot

        public final boolean hasRoot​(Interval interval)
        Returns true if the supplied interval contains a root
        Parameters:
        interval -
        Returns:
      • hasRoot

        public boolean hasRoot​(double xLower,
                               double xUpper)
        Returns true if the supplied interval contains a root
        Parameters:
        xLower -
        xUpper -
        Returns:
      • hasRoot

        public static boolean hasRoot​(FunctionIfc func,
                                      double xLower,
                                      double xUpper)
        Returns true if the supplied interval contains a root
        Parameters:
        func -
        xLower -
        xUpper -
        Returns:
      • findInterval

        public static boolean findInterval​(FunctionIfc func,
                                           Interval interval)
        Using the supplied function and the initial interval provided, try to find a bracketing interval by expanding the interval outward
        Parameters:
        func -
        interval -
        Returns:
      • findInterval

        public static java.util.List<Interval> findInterval​(FunctionIfc func,
                                                            Interval interval,
                                                            int n,
                                                            int nmax)
        Given a function and a starting interval, subdivide the interval into n subintervals and attempt to find nmax bracketing intervals that contain roots
        Parameters:
        func -
        interval -
        n -
        nmax -
        Returns:
        The list of bracketing intervals
      • setInterval

        public final void setInterval​(Interval interval)
        Sets the search interval for the search
        Parameters:
        interval -
      • setInterval

        public void setInterval​(double xLower,
                                double xUpper)
        Sets the bracketing interval within which the root should be found. Throws IllegalArgumentExceptons if the lower limit is > upper limit and if the function does not cross the axis within the provided interval.
        Parameters:
        xLower -
        xUpper -
      • getInitialPoint

        public double getInitialPoint()
        Returns the initial point used for the search
        Returns:
      • setInitialPoint

        public void setInitialPoint​(double initialPt)
        Sets the initial starting point for the search. The starting point must be in the interval defined for the search or an IllegalArgumentException will be thrown.
        Parameters:
        initialPt -
      • recommendInitialPoint

        public double recommendInitialPoint()
        Enumerates equally spaced points in the interval and returns the point that has the function value closest to zero
        Returns:
      • recommendInitialPoint

        public double recommendInitialPoint​(int nmax)
        Enumerates nmax equally spaced points in the interval and returns the point that has the function value closest to zero
        Parameters:
        nmax -
        Returns:
      • contains

        public final boolean contains​(double x)
        Checks to see if the the supplied point is within the search interval
        Parameters:
        x -
        Returns:
      • getLowerLimit

        public final double getLowerLimit()
        The lower limit for the search interval
        Returns:
      • getUpperLimit

        public final double getUpperLimit()
        The upper limit for the search interval
        Returns:
      • setInterval

        public final void setInterval​(FunctionIfc func,
                                      Interval interval)
        Sets the bracketing interval within which the root should be found. Throws IllegalArgumentExceptons if the lower limit is > upper limit and if the function does not cross the axis within the provided interval.
        Parameters:
        func -
        interval -
      • setInterval

        public final void setInterval​(FunctionIfc func,
                                      double xLower,
                                      double xUpper)
        Sets the bracketing interval within which the root should be found. Throws IllegalArgumentExceptons if the lower limit is > upper limit and if the function does not cross the axis within the provided interval.
        Parameters:
        func - Sets the function to be evaluated, must not be null
        xLower -
        xUpper -
      • toString

        public java.lang.String toString()
        Returns a String representation of the finder
        Overrides:
        toString in class IterativeProcess<RootFinderStep>
        Returns:
        A String with basic results
      • setFunction

        protected void setFunction​(FunctionIfc func)
        Parameters:
        func - OneVariableFunction
      • setRoot

        protected void setRoot​(double x)
      • hasConverged

        public abstract boolean hasConverged()
        Check to see if the result has been attained.
        Returns:
        boolean