Package org.apache.commons.math

Examples of org.apache.commons.math.ConvergenceException


                double scaleFactor = 1d;
                double lastScaleFactor = 1d;
                final int maxPower = 5;
                final double scale = FastMath.max(a,b);
                if (scale <= 0) {  // Can't scale
                    throw new ConvergenceException(
                            LocalizedFormats.CONTINUED_FRACTION_INFINITY_DIVERGENCE,
                             x);
                }
                infinite = true;
                for (int i = 0; i < maxPower; i++) {
                    lastScaleFactor = scaleFactor;
                    scaleFactor *= scale;
                    if (a != 0.0 && a > b) {
                        p2 = p1 / lastScaleFactor + (b / scaleFactor * p0);
                        q2 = q1 / lastScaleFactor + (b / scaleFactor * q0);
                    } else if (b != 0) {
                        p2 = (a / scaleFactor * p1) + p0 / lastScaleFactor;
                        q2 = (a / scaleFactor * q1) + q0 / lastScaleFactor;
                    }
                    infinite = Double.isInfinite(p2) || Double.isInfinite(q2);
                    if (!infinite) {
                        break;
                    }
                }
            }

            if (infinite) {
               // Scaling failed
               throw new ConvergenceException(
                 LocalizedFormats.CONTINUED_FRACTION_INFINITY_DIVERGENCE,
                  x);
            }

            double r = p2 / q2;

            if (Double.isNaN(r)) {
                throw new ConvergenceException(
                  LocalizedFormats.CONTINUED_FRACTION_NAN_DIVERGENCE,
                  x);
            }
            relativeError = FastMath.abs(r / c - 1.0);

View Full Code Here


            numIterations++ ;
        } while ((fa * fb > 0.0) && (numIterations < maximumIterations) &&
                ((a > lowerBound) || (b < upperBound)));

        if (fa * fb > 0.0 ) {
            throw new ConvergenceException(
                      LocalizedFormats.FAILED_BRACKETING,
                      numIterations, maximumIterations, initial,
                      lowerBound, upperBound, a, b, fa, fb);
        }

View Full Code Here

                return result;
            }
        }

        // should never happen
        throw new ConvergenceException();
    }
View Full Code Here

public class ConvergenceExceptionTest extends TestCase {
    /**
     *
     */
    public void testConstructor(){
        ConvergenceException ex = new ConvergenceException();
        assertNull(ex.getCause());
        assertNull(ex.getMessage());
    }
View Full Code Here

    /**
     *
     */
    public void testConstructorMessage(){
        String msg = "message";
        ConvergenceException ex = new ConvergenceException(msg);
        assertNull(ex.getCause());
        assertEquals(msg, ex.getMessage());
    }
View Full Code Here

     */
    public void testConstructorMessageCause(){
        String outMsg = "outer message";
        String inMsg = "inner message";
        Exception cause = new Exception(inMsg);
        ConvergenceException ex = new ConvergenceException(outMsg, cause);
        assertEquals(outMsg, ex.getMessage());
        assertEquals(cause, ex.getCause());
    }
View Full Code Here

     *
     */
    public void testConstructorCause(){
        String inMsg = "inner message";
        Exception cause = new Exception(inMsg);
        ConvergenceException ex = new ConvergenceException(cause);
        assertEquals(cause, ex.getCause());
    }
View Full Code Here

           
            x0 = x1;
            ++i;
        }
       
        throw new ConvergenceException
            ("Maximum number of iterations exceeded " + i);
    }
View Full Code Here

            numIterations++ ;
        } while ((fa * fb > 0.0) && (numIterations < maximumIterations) &&
                ((a > lowerBound) || (b < upperBound)));
  
        if (fa * fb >= 0.0 ) {
            throw new ConvergenceException
            ("Number of iterations= " + numIterations +
              " maximum iterations= "  + maximumIterations +
              " initial= " + initial + " lowerBound=" + lowerBound +
              " upperBound=" + upperBound + " final a value=" + a +
              " final b value=" + b + " f(a)=" + fa + " f(b)=" + fb);
View Full Code Here

                delta = x1 - x0;
                oldDelta = delta;
            }
            i++;
        }
        throw new ConvergenceException("Maximum number of iterations exceeded.");
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.math.ConvergenceException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.