当前位置: 首页>>代码示例>>Java>>正文


Java MathUtils.max方法代码示例

本文整理汇总了Java中org.apache.commons.math3.util.MathUtils.max方法的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.max方法的具体用法?Java MathUtils.max怎么用?Java MathUtils.max使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.util.MathUtils的用法示例。


在下文中一共展示了MathUtils.max方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: end

import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/**
 * End visiting the Nordsieck vector.
 * <p>The correction is used to control stepsize. So its amplitude is
 * considered to be an error, which must be normalized according to
 * error control settings. If the normalized value is greater than 1,
 * the correction was too large and the step must be rejected.</p>
 * @return the normalized correction, if greater than 1, the step
 * must be rejected
 */
public T end() {

    T error = getField().getZero();
    for (int i = 0; i < after.length; ++i) {
        after[i] = after[i].add(previous[i].add(scaled[i]));
        if (i < mainSetDimension) {
            final T yScale = MathUtils.max(previous[i].abs(), after[i].abs());
            final T tol = (vecAbsoluteTolerance == null) ?
                          yScale.multiply(scalRelativeTolerance).add(scalAbsoluteTolerance) :
                          yScale.multiply(vecRelativeTolerance[i]).add(vecAbsoluteTolerance[i]);
            final T ratio  = after[i].subtract(before[i]).divide(tol); // (corrected-predicted)/tol
            error = error.add(ratio.multiply(ratio));
        }
    }

    return error.divide(mainSetDimension).sqrt();

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:28,代码来源:AdamsMoultonFieldIntegrator.java

示例2: estimateError

import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
protected T estimateError(final T[][] yDotK, final T[] y0, final T[] y1, final T h) {

    T error = getField().getZero();

    for (int j = 0; j < mainSetDimension; ++j) {
        final T errSum =     yDotK[0][j].multiply(e1).
                         add(yDotK[2][j].multiply(e3)).
                         add(yDotK[3][j].multiply(e4)).
                         add(yDotK[4][j].multiply(e5)).
                         add(yDotK[5][j].multiply(e6)).
                         add(yDotK[6][j].multiply(e7));

        final T yScale = MathUtils.max(y0[j].abs(), y1[j].abs());
        final T tol    = (vecAbsoluteTolerance == null) ?
                         yScale.multiply(scalRelativeTolerance).add(scalAbsoluteTolerance) :
                         yScale.multiply(vecRelativeTolerance[j]).add(vecAbsoluteTolerance[j]);
        final T ratio  = h.multiply(errSum).divide(tol);
        error = error.add(ratio.multiply(ratio));

    }

    return error.divide(mainSetDimension).sqrt();

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:27,代码来源:DormandPrince54FieldIntegrator.java

示例3: estimateError

import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
protected T estimateError(final T[][] yDotK, final T[] y0, final T[] y1, final T h) {

    T error = getField().getZero();

    for (int j = 0; j < mainSetDimension; ++j) {
        T errSum = yDotK[0][j].multiply(e[0]);
        for (int l = 1; l < e.length; ++l) {
            errSum = errSum.add(yDotK[l][j].multiply(e[l]));
        }

        final T yScale = MathUtils.max(y0[j].abs(), y1[j].abs());
        final T tol    = (vecAbsoluteTolerance == null) ?
                         yScale.multiply(scalRelativeTolerance).add(scalAbsoluteTolerance) :
                         yScale.multiply(vecRelativeTolerance[j]).add(vecAbsoluteTolerance[j]);
        final T ratio  = h.multiply(errSum).divide(tol);
        error = error.add(ratio.multiply(ratio));

    }

    return error.divide(mainSetDimension).sqrt();

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:25,代码来源:HighamHall54FieldIntegrator.java

示例4: initializeStep

import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/** Initialize the integration step.
 * @param forward forward integration indicator
 * @param order order of the method
 * @param scale scaling vector for the state vector (can be shorter than state vector)
 * @param state0 state at integration start time
 * @param mapper mapper for all the equations
 * @return first integration step
 * @exception MaxCountExceededException if the number of functions evaluations is exceeded
 * @exception DimensionMismatchException if arrays dimensions do not match equations settings
 */
public T initializeStep(final boolean forward, final int order, final T[] scale,
                        final FieldODEStateAndDerivative<T> state0,
                        final FieldEquationsMapper<T> mapper)
    throws MaxCountExceededException, DimensionMismatchException {

    if (initialStep.getReal() > 0) {
        // use the user provided value
        return forward ? initialStep : initialStep.negate();
    }

    // very rough first guess : h = 0.01 * ||y/scale|| / ||y'/scale||
    // this guess will be used to perform an Euler step
    final T[] y0    = mapper.mapState(state0);
    final T[] yDot0 = mapper.mapDerivative(state0);
    T yOnScale2    = getField().getZero();
    T yDotOnScale2 = getField().getZero();
    for (int j = 0; j < scale.length; ++j) {
        final T ratio    = y0[j].divide(scale[j]);
        yOnScale2        = yOnScale2.add(ratio.multiply(ratio));
        final T ratioDot = yDot0[j].divide(scale[j]);
        yDotOnScale2     = yDotOnScale2.add(ratioDot.multiply(ratioDot));
    }

    T h = (yOnScale2.getReal() < 1.0e-10 || yDotOnScale2.getReal() < 1.0e-10) ?
          getField().getZero().add(1.0e-6) :
          yOnScale2.divide(yDotOnScale2).sqrt().multiply(0.01);
    if (! forward) {
        h = h.negate();
    }

    // perform an Euler step using the preceding rough guess
    final T[] y1 = MathArrays.buildArray(getField(), y0.length);
    for (int j = 0; j < y0.length; ++j) {
        y1[j] = y0[j].add(yDot0[j].multiply(h));
    }
    final T[] yDot1 = computeDerivatives(state0.getTime().add(h), y1);

    // estimate the second derivative of the solution
    T yDDotOnScale = getField().getZero();
    for (int j = 0; j < scale.length; ++j) {
        final T ratioDotDot = yDot1[j].subtract(yDot0[j]).divide(scale[j]);
        yDDotOnScale = yDDotOnScale.add(ratioDotDot.multiply(ratioDotDot));
    }
    yDDotOnScale = yDDotOnScale.sqrt().divide(h);

    // step size is computed such that
    // h^order * max (||y'/tol||, ||y''/tol||) = 0.01
    final T maxInv2 = MathUtils.max(yDotOnScale2.sqrt(), yDDotOnScale);
    final T h1 = maxInv2.getReal() < 1.0e-15 ?
                 MathUtils.max(getField().getZero().add(1.0e-6), h.abs().multiply(0.001)) :
                 maxInv2.multiply(100).reciprocal().pow(1.0 / order);
    h = MathUtils.min(h.abs().multiply(100), h1);
    h = MathUtils.max(h, state0.getTime().abs().multiply(1.0e-12));  // avoids cancellation when computing t1 - t0
    h = MathUtils.max(minStep, MathUtils.min(maxStep, h));
    if (! forward) {
        h = h.negate();
    }

    return h;

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:72,代码来源:AdaptiveStepsizeFieldIntegrator.java

示例5: estimateError

import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
protected T estimateError(final T[][] yDotK, final T[] y0, final T[] y1, final T h) {
    T error1 = h.getField().getZero();
    T error2 = h.getField().getZero();

    for (int j = 0; j < mainSetDimension; ++j) {
        final T errSum1 =      yDotK[ 0][j].multiply(e1_01).
                           add(yDotK[ 5][j].multiply(e1_06)).
                           add(yDotK[ 6][j].multiply(e1_07)).
                           add(yDotK[ 7][j].multiply(e1_08)).
                           add(yDotK[ 8][j].multiply(e1_09)).
                           add(yDotK[ 9][j].multiply(e1_10)).
                           add(yDotK[10][j].multiply(e1_11)).
                           add(yDotK[11][j].multiply(e1_12));
        final T errSum2 =      yDotK[ 0][j].multiply(e2_01).
                           add(yDotK[ 5][j].multiply(e2_06)).
                           add(yDotK[ 6][j].multiply(e2_07)).
                           add(yDotK[ 7][j].multiply(e2_08)).
                           add(yDotK[ 8][j].multiply(e2_09)).
                           add(yDotK[ 9][j].multiply(e2_10)).
                           add(yDotK[10][j].multiply(e2_11)).
                           add(yDotK[11][j].multiply(e2_12));

        final T yScale = MathUtils.max(y0[j].abs(), y1[j].abs());
        final T tol = vecAbsoluteTolerance == null ?
                      yScale.multiply(scalRelativeTolerance).add(scalAbsoluteTolerance) :
                      yScale.multiply(vecRelativeTolerance[j]).add(vecAbsoluteTolerance[j]);
        final T ratio1  = errSum1.divide(tol);
        error1        = error1.add(ratio1.multiply(ratio1));
        final T ratio2  = errSum2.divide(tol);
        error2        = error2.add(ratio2.multiply(ratio2));
    }

    T den = error1.add(error2.multiply(0.01));
    if (den.getReal() <= 0.0) {
        den = h.getField().getOne();
    }

    return h.abs().multiply(error1).divide(den.multiply(mainSetDimension).sqrt());

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:43,代码来源:DormandPrince853FieldIntegrator.java


注:本文中的org.apache.commons.math3.util.MathUtils.max方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。