Example usage for java.lang Math PI

List of usage examples for java.lang Math PI

Introduction

In this page you can find the example usage for java.lang Math PI.

Prototype

double PI

To view the source code for java.lang Math PI.

Click Source Link

Document

The double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.

Usage

From source file:com.opengamma.strata.math.impl.minimization.SumToOneTest.java

@Test
public void transformTest() {
    for (int n = 2; n < 13; n++) {
        double[] from = new double[n - 1];
        for (int j = 0; j < n - 1; j++) {
            from[j] = RANDOM.nextDouble() * Math.PI / 2;
        }//from  ww  w.  j  a v a 2s  .  c om
        SumToOne trans = new SumToOne(n);
        DoubleArray to = trans.transform(DoubleArray.copyOf(from));
        assertEquals(n, to.size());
        double sum = 0;
        for (int i = 0; i < n; i++) {
            sum += to.get(i);
        }
        assertEquals("vector length " + n, 1.0, sum, 1e-9);
    }
}

From source file:com.itemanalysis.psychometrics.mixture.MvNormalComponentDistribution.java

/**
 *
 * @param x a matrix of dimension 1 x k, where k is the number of variables
 * @return//from   w w w.  j  av  a2  s.c o  m
 */
public double density(RealMatrix x) throws SingularMatrixException {
    double prob = 0.0;
    RealMatrix xTran = x.transpose();
    int d = xTran.getRowDimension();
    double det = new LUDecomposition(sigma).getDeterminant();
    double nconst = 1.0 / Math.sqrt(det * Math.pow(2.0 * Math.PI, d));
    RealMatrix Sinv = new LUDecomposition(sigma).getSolver().getInverse();
    RealMatrix delta = xTran.subtract(mu);
    RealMatrix dist = (delta.transpose().multiply(Sinv).multiply(delta));
    prob = nconst * Math.exp(-0.5 * dist.getEntry(0, 0));
    return prob;
}

From source file:org.neo4j.bench.chart.JFreeStackedBarChart.java

public JFreeChart render(String title, CategoryPlot plot, AbstractRenderer renderer) {
    plot.getDomainAxis()//from w ww.  j a va 2 s.  c  o m
            .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4.0));
    return new JFreeChart(title, plot);
}

From source file:etomica.math.SpecialFunctions.java

/**
 * Returns the ln(gamma), the natural logarithm of the gamma function.
 * Lanczos approximation, with precision ~15 digits
 * coefficients from GSL (GNU Scientific Library) with g=7
 */// w w  w.j  a va 2  s  .  c  om
public static double lnGamma(double x) {
    if (x < 0) {
        throw new IllegalArgumentException("x must not be negative");
    }
    if (x == 0) {
        return 0;
    }
    if (x < 0.5) {
        return Math.log(Math.PI / (Math.sin(Math.PI * x))) - lnGamma(1 - x);
    }
    double tmp = x + 7 - 0.5;
    double ser = 0.99999999999980993;
    for (int i = 7; i > -1; i--) {
        ser += lnGammaCoeff[i] / (x + i);
    }
    double y = lnsqrt2Pi + (x - 0.5) * Math.log(tmp) - tmp + Math.log(ser);
    return y;
}

From source file:com.insightml.math.distributions.GaussianDistribution.java

public GaussianDistribution(final double[] values, final boolean biasedVariance) {
    final int n = values.length;
    double sum = 0;
    double sumSquared = 0;
    for (final double value : values) {
        sum += value;//from  w  w w  .j  av  a 2s  .c  o  m
        sumSquared += value * value;
    }

    mean = sum / values.length;
    if (biasedVariance) {
        sigmaSquare = sumSquared / n - mean * mean;
    } else {
        sigmaSquare = sumSquared / (n - 1) - n * mean * mean / (n - 1);
    }
    stddev = Math.sqrt(sigmaSquare);

    factor = 1. / Math.sqrt(2 * Math.PI * sigmaSquare);
}

From source file:mase.mason.world.DistanceSensorArcs.java

public void setArcs(int numArcs) {
    double[] start = new double[numArcs];
    double[] end = new double[numArcs];
    double arcAngle = (Math.PI * 2) / numArcs;
    start[0] = -arcAngle / 2; // first arc aligned with front
    end[0] = arcAngle / 2;//from   w ww  . ja  v a  2 s .  c om
    for (int i = 1; i < numArcs; i++) {
        start[i] = end[i - 1];
        end[i] = start[i] + arcAngle;
        if (end[i] > Math.PI) {
            end[i] -= Math.PI * 2;
        }
    }
    this.setArcs(start, end);
}

From source file:com.opengamma.analytics.math.statistics.estimation.StudentTDistributionMaximumLikelihoodEstimator.java

@Override
public ProbabilityDistribution<Double> evaluate(final double[] x) {
    Validate.notNull(x, "x");
    ArgumentChecker.notEmpty(x, "x");
    final double[] standardized = getStandardizedData(x);
    final Function1D<Double, Double> f = new Function1D<Double, Double>() {

        @SuppressWarnings("synthetic-access")
        @Override// w  ww. j  av a  2 s  .  com
        public Double evaluate(final Double nu) {
            double sum = 0;
            for (final double t : standardized) {
                sum += Math.log(_gamma.evaluate((nu + 1) / 2.) * Math.pow(1 + t * t / (nu - 2), -(nu + 1) / 2.)
                        / Math.sqrt(Math.PI * (nu - 2)) / _gamma.evaluate(nu / 2.));
            }
            return -sum;
        }

    };
    return new StudentTDistribution(_minimizer.minimize(f, 0.0, 3., 10.));
}

From source file:fsm.series.Series_SS.java

@Override
public double[] getIntegralValues(int m, int n) {

    double[] I = new double[5];
    double pi = Math.PI;
    double pi2 = pi * pi;
    double pi4 = pi * pi * pi * pi;

    double m2 = m * m;
    double m4 = m * m * m * m;

    double n2 = n * n;

    if (m == n) {
        I[0] = a / 2;//from   w  ww.j  a va2 s. c  o  m
        I[1] = -m2 * pi2 / a / 2.0;
        I[2] = -n2 * pi2 / a / 2.0;
        I[3] = pi4 * m4 / 2.0 / (a * a * a);
        I[4] = pi2 * m2 / 2.0 / a;
    } else {
        I[0] = 0;
        I[1] = 0;
        I[2] = 0;
        I[3] = 0;
        I[4] = 0;

    }

    return I;
}

From source file:electrical_parameters.Admittance.java

public Admittance(RealMatrix Dik, RealMatrix Dik_mirror, double[] hx2,
        ArrayList<elpam_input_conductor> cnd_list, double krok, // m
        int n_zv, // -
        int fv, int gw) {
    this.r_cnd = new double[cnd_list.size()];
    if (cnd_list.get(0).isBundle()) {
        double rho = krok / (2 * Math.sin(Math.PI / n_zv));
        for (int i = 0; i < cnd_list.size(); i++) {
            this.r_cnd[i] = Math.pow(n_zv * (cnd_list.get(i).getD() / 2) * Math.pow(rho, n_zv - 1),
                    (double) 1 / n_zv);
        }/*ww w  .  j  a v  a2s  . co m*/
    } else {
        for (int i = 0; i < cnd_list.size(); i++) {
            this.r_cnd[i] = cnd_list.get(i).getD() / 2;
        }
    }
    this.fv = fv;
    this.gw = gw;
    this.f = constants.getFrequency();

    this.Dik = Dik;
    this.Dik_mirror = Dik_mirror;
    this.hx2 = hx2;

    this.P = new Array2DRowRealMatrix(fv + gw, fv + gw);
    this.P_red = new Array2DRowRealMatrix(fv, fv);
    this.C = new Array2DRowRealMatrix(fv, fv);
    this.B = new Array2DRowRealMatrix(fv, fv);
    this.Y = new ComplexMatrix(fv, fv);

    this.C_symm = new Array2DRowRealMatrix(fv, fv);
    this.B_symm = new Array2DRowRealMatrix(fv, fv);
    this.Y_symm = new ComplexMatrix(fv, fv);

    this.omega = (double) 2 * Math.PI * this.f;
    this.cnst = (double) 1 / (8.854187e-9 * 1 * 2 * Math.PI);
}

From source file:org.eclipse.swt.examples.graphics.StarPolyTab.java

@Override
public void paint(GC gc, int width, int height) {
    int centerX = width / 2;
    int centerY = height / 2;
    int pos = 0;/* w  ww. j ava 2 s  . c o  m*/
    for (int i = 0; i < POINTS; ++i) {
        double r = Math.PI * 2 * pos / POINTS;
        radial[i * 2] = (int) ((1 + Math.cos(r)) * centerX);
        radial[i * 2 + 1] = (int) ((1 + Math.sin(r)) * centerY);
        pos = (pos + POINTS / 2) % POINTS;
    }
    gc.setFillRule(fillRuleCb.getSelectionIndex() != 0 ? SWT.FILL_WINDING : SWT.FILL_EVEN_ODD);
    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_YELLOW));
    gc.fillPolygon(radial);
    gc.drawPolygon(radial);
}