Example usage for org.apache.commons.math3.dfp Dfp divide

List of usage examples for org.apache.commons.math3.dfp Dfp divide

Introduction

In this page you can find the example usage for org.apache.commons.math3.dfp Dfp divide.

Prototype

public Dfp divide(int divisor) 

Source Link

Document

Divide by a single digit less than radix.

Usage

From source file:org.orekit.forces.gravity.AssociatedLegendreFunction.java

private Dfp[] getLegendrePolynomial(int n, DfpField dfpField) {

    // get (or create) the list of polynomials for the specified field
    List<Dfp[]> list = LEGENDRE_POLYNOMIALS.get(dfpField.getRadixDigits());
    if (list == null) {
        list = new ArrayList<Dfp[]>();
        list.add(new Dfp[] { dfpField.getOne() // P0(X) = 1
        });/*from   ww w . ja  v a 2  s  .  c o  m*/
        list.add(new Dfp[] { dfpField.getZero(), dfpField.getOne() // P1(X) = 0 + 1 * X
        });
    }

    while (list.size() <= n) {

        // build polynomial Pk+1 using recursion formula
        // (k+1) P<sub>k+1</sub>(X) = (2k+1) X P<sub>k</sub>(X) - k P<sub>k-1</sub>(X)
        int k = list.size() - 1;
        Dfp kDfp = dfpField.newDfp(k);
        Dfp kP1Dfp = kDfp.add(dfpField.getOne());
        Dfp ckDfp = kP1Dfp.add(kDfp).divide(kP1Dfp);
        Dfp[] pk = list.get(k);
        Dfp ckM1Dfp = kDfp.divide(kP1Dfp).negate();
        Dfp[] pkM1 = list.get(k - 1);

        Dfp[] pkP1 = new Dfp[k + 2];
        pkP1[0] = ckM1Dfp.multiply(pkM1[0]);
        for (int i = 0; i < k; ++i) {
            if ((k - i) % 2 == 1) {
                pkP1[i + 1] = dfpField.getZero();
            } else {
                pkP1[i + 1] = ckDfp.multiply(pk[i]).add(ckM1Dfp.multiply(pkM1[i + 1]));
            }
        }
        pkP1[k + 1] = ckDfp.multiply(pk[k]);

        list.add(pkP1);

    }

    // retrieve degree n polynomial
    return list.get(n);

}

From source file:org.orekit.forces.gravity.AssociatedLegendreFunction.java

public AssociatedLegendreFunction(boolean normalized, int n, int m, DfpField dfpField) {

    this.m = m;/* ww w  . j a v a 2 s .co  m*/

    // store mth derivative of the degree n Legendre polynomial
    polynomial = differentiateLegendrePolynomial(getLegendrePolynomial(n, dfpField), m, dfpField);

    if (normalized) {
        // compute normalization coefficient
        Dfp c = dfpField.newDfp(((m == 0) ? 1.0 : 2.0) * (2 * n + 1));
        for (int k = 0; k < m; ++k) {
            c = c.divide(dfpField.newDfp((n + 1 + k) * (n - k)));
        }
        this.normalization = c.sqrt();
    } else {
        this.normalization = dfpField.getOne();
    }

}

From source file:org.orekit.forces.gravity.ReferenceFieldModel.java

public Dfp nonCentralPart(final AbsoluteDate date, final Vector3D position) throws OrekitException {

    int degree = provider.getMaxDegree();
    int order = provider.getMaxOrder();
    //use coefficients without caring if they are the correct type
    final RawSphericalHarmonics harmonics = raw(provider).onDate(date);

    Dfp x = dfpField.newDfp(position.getX());
    Dfp y = dfpField.newDfp(position.getY());
    Dfp z = dfpField.newDfp(position.getZ());

    Dfp rho2 = x.multiply(x).add(y.multiply(y));
    Dfp rho = rho2.sqrt();/*from  w w w  .j  a va 2s  .  c  o m*/
    Dfp r2 = rho2.add(z.multiply(z));
    Dfp r = r2.sqrt();
    Dfp aOr = dfpField.newDfp(provider.getAe()).divide(r);
    Dfp lambda = position.getX() > 0 ? dfpField.getTwo().multiply(DfpMath.atan(y.divide(rho.add(x))))
            : dfpField.getPi().subtract(dfpField.getTwo().multiply(DfpMath.atan(y.divide(rho.subtract(x)))));
    Dfp cosTheta = z.divide(r);

    Dfp value = dfpField.getZero();
    Dfp aOrN = aOr;
    for (int n = 2; n <= degree; ++n) {
        Dfp sum = dfpField.getZero();
        for (int m = 0; m <= FastMath.min(n, order); ++m) {
            double cnm = harmonics.getRawCnm(n, m);
            double snm = harmonics.getRawSnm(n, m);
            Dfp mLambda = lambda.multiply(m);
            Dfp c = DfpMath.cos(mLambda).multiply(dfpField.newDfp(cnm));
            Dfp s = DfpMath.sin(mLambda).multiply(dfpField.newDfp(snm));
            Dfp pnm = alf[n][m].value(cosTheta);
            sum = sum.add(pnm.multiply(c.add(s)));
        }
        aOrN = aOrN.multiply(aOr);
        value = value.add(aOrN.multiply(sum));
    }

    return value.multiply(dfpField.newDfp(provider.getMu())).divide(r);

}

From source file:org.rhwlab.BHCnotused.Cluster.java

public Cluster(Cluster lef, Cluster rig) {
    data = lef.data.mergeWith(rig.data);
    Dfp G = field.newDfp(Gamma.logGamma(data.getN())).exp();
    d = alpha.multiply(G.add(lef.d.multiply(rig.d)));
    pi = alpha.multiply(G.divide(d));

    this.left = lef;
    this.right = rig;
    dpm = this.DPMLikelihood();
    posterior();/*  w w w . j a v  a2 s  .co m*/

    int iodrti = 0;
}

From source file:org.rhwlab.BHCnotused.GaussianGIWPrior.java

public void init() {
    int n = data.size();
    int d = m.getDimension();
    Dfp rP = r.add(n);//  ww w  .j  av a  2 s .  c o m
    //        System.out.printf("rP=%s\n",rP.toString());
    double nuP = nu + n;
    //        System.out.printf("nuP=%e\n", nuP);
    FieldMatrix C = new Array2DRowFieldMatrix(field, d, d);
    for (int row = 0; row < C.getRowDimension(); ++row) {
        for (int col = 0; col < C.getColumnDimension(); ++col) {
            C.setEntry(row, col, field.getZero());
        }
    }
    FieldVector X = new ArrayFieldVector(field, d); // a vector of zeros

    for (FieldVector v : data) {
        X = X.add(v);
        FieldMatrix v2 = v.outerProduct(v);
        C = C.add(v2);
    }
    FieldVector mP = (m.mapMultiply(r).add(X)).mapDivide(r.add(n));
    FieldMatrix Sp = C.add(S);

    FieldMatrix rmmP = mP.outerProduct(mP).scalarMultiply(rP);
    Sp = Sp.add(rmm).subtract(rmmP);

    FieldLUDecomposition ed = new FieldLUDecomposition(Sp);
    Dfp det = (Dfp) ed.getDeterminant();

    Dfp detSp = det.pow(field.newDfp(nuP / 2.0));

    Dfp gamma = field.getOne();

    Dfp gammaP = field.getOne();

    for (int i = 1; i <= d; ++i) {
        gamma = gamma.multiply(Gamma.gamma((nu + 1 - i) / 2.0));
        gammaP = gammaP.multiply(Gamma.gamma((nuP + 1 - i) / 2.0));
    }

    Dfp t1 = field.getPi().pow(-n * d / 2.0);
    Dfp t2 = r.divide(rP).pow(d / 2.0);
    Dfp t3 = detS.divide(detSp);

    Dfp t4 = gammaP.divide(gamma);
    Dfp t34 = t3.multiply(t4);
    /*        
            System.out.printf("detSp=%s\n", detSp.toString());
            System.out.printf("det=%s\n", det.toString());
            System.out.printf("gamma=%s\n", gamma.toString());
            System.out.printf("gammaP=%s\n", gammaP.toString());        
            System.out.printf("t1=%s\n", t1.toString());  
            System.out.printf("t2=%s\n", t2.toString());
            System.out.printf("t3=%s\n", t3.toString());
            System.out.printf("t4=%s\n", t4.toString());
    */
    likelihood = t2.multiply(t34).multiply(t1);
    double realLike = likelihood.getReal();
    //       System.out.printf("Likelihood=%e\n", realLike);
    int uhfd = 0;
}