commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilles <gil...@harfang.homelinux.org>
Subject Re: svn commit: r1488914 - in /commons/proper/math/trunk: ./ src/changes/ src/main/java/org/apache/commons/math3/analysis/integration/ src/test/java/org/apache/commons/math3/analysis/integration/
Date Mon, 03 Jun 2013 10:19:05 GMT
Hello.

On Mon, 03 Jun 2013 09:04:40 -0000, luc@apache.org wrote:
> Author: luc
> Date: Mon Jun  3 09:04:40 2013
> New Revision: 1488914
>
> URL: http://svn.apache.org/r1488914
> Log:
> Added midpoint integration method.
>
> Patch contributed by Oleksandr Kornieiev.
>
> JIRA: MATH-967

> [...]

> +    private double stage(final int n)
> +        throws TooManyEvaluationsException {
> +
> +        final double max = getMax();
> +        final double min = getMin();
> +
> +        if (n == 0) {
> +            final double midPoint = 0.5 * (max - min);
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Is this correct?

> +            s = (max - min) * computeObjectiveValue(midPoint);
> +            return s;
> +        } else {
> +            final long np = 1L << (n - 1);           // number of
> new points in this stage
> +            double sum = 0;
> +            // spacing between adjacent new points
> +            final double spacing = (max - min) / np;
> +            double x = min + 0.5 * spacing;    // the first new 
> point
> +            for (long i = 0; i < np; i++) {
> +                sum += computeObjectiveValue(x);
> +                x += spacing;
> +            }
> +            // add the new sum to previously calculated result
> +            s = 0.5 * (s + sum * spacing);
> +            return s;
> +        }
> +    }
> +
> +    /** {@inheritDoc} */
> +    protected double doIntegrate()
> +        throws MathIllegalArgumentException,
> TooManyEvaluationsException, MaxCountExceededException {
> +
> +        double oldt = stage(0);
> +        iterations.incrementCount();
> +        while (true) {
> +            final int i = iterations.getCount();
> +            final double t = stage(i);
> +            if (i >= getMinimalIterationCount()) {
> +                final double delta = FastMath.abs(t - oldt);
> +                final double rLimit =
> +                        getRelativeAccuracy() * (FastMath.abs(oldt)
> + FastMath.abs(t)) * 0.5;
> +                if ((delta <= rLimit) || (delta <= 
> getAbsoluteAccuracy())) {
> +                    return t;
> +                }
> +            }
> +            oldt = t;
> +            iterations.incrementCount();
> +        }
> +
> +    }
> +
> +}
>
> [...]


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message