Example usage for java.lang Math exp

List of usage examples for java.lang Math exp

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double exp(double a) 

Source Link

Document

Returns Euler's number e raised to the power of a double value.

Usage

From source file:br.ufrgs.enq.jcosmo.test.VLEdiagrams.java

@SuppressWarnings("deprecation")
public JPanel calcMethanolMethilAcetate() throws Exception {
    super.setTitle("P vs x1");
    double T = 25;

    COSMOSACDataBase db = COSMOSACDataBase.getInstance();

    COSMOSACCompound comps[] = new COSMOSACCompound[2];
    comps[0] = db.getComp("methanol");
    comps[1] = db.getComp("methyl-acetate");

    COSMOSAC cosmosac = new COSMOSAC();
    cosmosac.setComponents(comps);/*from www .  j  av a  2 s. c o  m*/

    cosmosac.setTemperature(T + 273.15);

    double[] x1 = new double[n];
    double[] x2 = new double[n];
    double[] gamma1 = new double[n];
    double[] gamma2 = new double[n];
    double[] z = new double[2];
    double[] lnGamma = new double[2];
    z[0] = 0.00;
    int j = 0;
    while (z[0] < 1.0001) {
        z[1] = 1 - z[0];
        x1[j] = z[0];
        x2[j] = z[1];
        cosmosac.setComposition(z);
        cosmosac.activityCoefficient(lnGamma);
        gamma1[j] = Math.exp(lnGamma[0]);
        gamma2[j] = Math.exp(lnGamma[1]);
        z[0] += 0.05;
        j++;
    }

    double[][] parAntoine = new double[3][3];
    parAntoine[0][0] = 16.5785;
    parAntoine[0][1] = 3638.27;
    parAntoine[0][2] = 239.500;
    parAntoine[1][0] = 14.2456;
    parAntoine[1][1] = 2662.78;
    parAntoine[1][2] = 219.690;

    double[] Psat = pSat(parAntoine, T);
    double[] P = calcPx(x1, x2, gamma1, gamma2, Psat);
    double[] y1 = calcY(x1, gamma1, Psat, P);

    XYPlot plot2;
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries liq = new XYSeries("liquid");
    XYSeries vap = new XYSeries("vapor");
    XYSeries raoult = new XYSeries("Raoult's Law");
    for (int i = 0; i < n; i++) {
        liq.add(x1[i], P[i]);
        vap.add(y1[i], P[i]);
    }
    raoult.add(0, Psat[1]);
    raoult.add(1, Psat[0]);
    dataset.addSeries(liq);
    dataset.addSeries(vap);
    dataset.addSeries(raoult);

    JFreeChart chart = ChartFactory.createXYLineChart(null, "Mole Fraction: x1, y1", "P/KPa", null,
            PlotOrientation.VERTICAL, true, true, false);
    plot2 = (XYPlot) chart.getPlot();
    plot2.getDomainAxis().setRange(new Range(0.0, 1.0));
    plot2.getRangeAxis().setRange(new Range(15.0, 30.0));

    plot2.setDataset(dataset);

    XYSplineRenderer r = new XYSplineRenderer();
    BasicStroke stroke = new BasicStroke(2f);
    r.setStroke(stroke);
    plot2.setRenderer(r);
    r.setBaseShapesVisible(false);

    ChartPanel chartPanel = new ChartPanel(chart);
    JPanel jp = new JPanel(new BorderLayout());
    jp.add(chartPanel, BorderLayout.CENTER);

    add(jp);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400, 500);

    return jp;
}

From source file:com.opengamma.analytics.financial.credit.creditdefaultswap.pricing.vanilla.isdanew.ISDACompliantCurve.java

/**
 * A curve in which the knots are measured (in fractions of a year) from a particular base-date but the curve is 'observed'
 * from a different base-date. As an example<br>
 * Today (the observation point) is 11-Jul-13, but the yield curve is snapped (bootstrapped from money market and swap rates)
 * on 10-Jul-13 - seen from today there is an offset of -1/365 (assuming a day count of ACT/365) that must be applied to use
 * the yield curve today.  <br>// w w w. j a  v a 2  s .c  o m
 * In general, a discount curve observed at time $t_1$ can be written as $P(t_1,T)$. Observed from time $t_2$ this is
 * $P(t_2,T) = \frac{P(t_1,T)}{P(t_1,t_2)}$
 * @param timesFromBaseDate times measured from the base date of the curve
 * @param r zero rates
 * @param offsetFromNewBaseDate if this curve is to be used from a new base-date, what is the offset from the curve base
 */
protected ISDACompliantCurve(final double[] timesFromBaseDate, final double[] r,
        final double offsetFromNewBaseDate) {
    ArgumentChecker.notEmpty(timesFromBaseDate, "t empty");
    ArgumentChecker.notEmpty(r, "r empty");
    _n = timesFromBaseDate.length;
    ArgumentChecker.isTrue(_n == r.length, "r and t different lengths");
    ArgumentChecker.isTrue(timesFromBaseDate[0] >= 0.0, "timesFromBaseDate must be >= 0");

    // TODO allow larger offsets
    ArgumentChecker.isTrue(timesFromBaseDate[0] + offsetFromNewBaseDate >= 0,
            "offsetFromNewBaseDate too negative");
    for (int i = 1; i < _n; i++) {
        ArgumentChecker.isTrue(timesFromBaseDate[i] > timesFromBaseDate[i - 1], "Times must be ascending");
    }

    _t = new double[_n];
    if (offsetFromNewBaseDate == 0.0) {
        System.arraycopy(timesFromBaseDate, 0, _t, 0, _n);
    } else {
        for (int i = 0; i < _n; i++) {
            _t[i] = timesFromBaseDate[i] + offsetFromNewBaseDate;
        }
    }

    _r = new double[_n];
    _rt = new double[_n];
    _df = new double[_n];
    final double r0 = r[0];
    if (offsetFromNewBaseDate == 0.0) {
        System.arraycopy(r, 0, _r, 0, _n);
    } else {
        _r[0] = r0;
        for (int i = 1; i < _n; i++) {
            _r[i] = r[i] + offsetFromNewBaseDate / _t[i] * (r0 - r[i]);
        }
    }

    _offsetTime = offsetFromNewBaseDate;
    _offsetRT = r0 * _offsetTime;

    for (int i = 0; i < _n; i++) {
        _rt[i] = r[i] * timesFromBaseDate[i]; // We make no check that rt is ascending (i.e. we allow negative forward rates)
        _df[i] = Math.exp(-_rt[i] - _offsetRT);
    }
}

From source file:dnimp.Statistics.java

private double erf(double z) {

    if (z == 0)/*  ww w .  java 2 s .c  om*/
        return 0.0;

    double t = 1.0 / (1.0 + 0.5 * Math.abs(z));

    // use Horner's method
    double ans = 1 - t * Math.exp(-z * z - 1.26551223
            + t * (1.00002368 + t * (0.37409196 + t * (0.09678418 + t * (-0.18628806 + t * (0.27886807
                    + t * (-1.13520398 + t * (1.48851587 + t * (-0.82215223 + t * (0.17087277))))))))));
    if (z >= 0)
        return ans;
    else
        return -ans;
}

From source file:ch.epfl.leb.sass.models.illuminations.internal.SquareUniformElectricField.java

/**
* Returns the x-component of the time-independent electric field at the position (x, y, z).
* 
* @param x The x-position within the sample.
* @param y The y-position within the sample.
* @param z The z-position within the sample.
* @return The x-component of the electric field at the position (x, y, z).
*//*ww w .j  a  va2s  . com*/
@Override
public Complex getEx(double x, double y, double z) {
    if (x < 0 || x > width)
        return new Complex(0);
    if (y < 0 || y > height)
        return new Complex(0);

    Complex arg = getArgument(x, y, z);
    double magnitude = orientation.getX() * Math.exp(-arg.getImaginary());
    return ComplexUtils.polar2Complex(magnitude, arg.getReal());
}

From source file:edu.snu.leader.discrete.simulator.SueurPersonalityDecisionCalculator.java

/**
 * Calculates the k value to modify the probabilities
 * /*from   w ww .j a  v  a  2 s .c  o  m*/
 * @param decision The decision for which the k value needs to be calculated
 * @return The k value
 */
private double kValue(Decision decision) {
    double k = 0;
    double x = 0;
    // if the decision is initiation then x = p
    if (decision.getDecisionType().equals(DecisionType.INITIATION)) {
        x = decision.getAgent().getPersonalityTrait().getPersonality();
    }
    // else x = 1 - p
    else {
        x = 1 - decision.getAgent().getPersonalityTrait().getPersonality();
    }
    // the formula
    k = 2 / (1 + (Math.exp(10 * (.5 - x))));
    return k;
}

From source file:StatFunctions.java

public static double qt(double p, double ndf, boolean lower_tail) {
    // Algorithm 396: Student's t-quantiles by
    // G.W. Hill CACM 13(10), 619-620, October 1970
    if (p <= 0 || p >= 1 || ndf < 1)
        throw new IllegalArgumentException("Invalid p or df in call to qt(double,double,boolean).");
    double eps = 1e-12;
    double M_PI_2 = 1.570796326794896619231321691640; // pi/2
    boolean neg;// www .java  2  s  .c  o m
    double P, q, prob, a, b, c, d, y, x;
    if ((lower_tail && p > 0.5) || (!lower_tail && p < 0.5)) {
        neg = false;
        P = 2 * (lower_tail ? (1 - p) : p);
    } else {
        neg = true;
        P = 2 * (lower_tail ? p : (1 - p));
    }

    if (Math.abs(ndf - 2) < eps) { /* df ~= 2 */
        q = Math.sqrt(2 / (P * (2 - P)) - 2);
    } else if (ndf < 1 + eps) { /* df ~= 1 */
        prob = P * M_PI_2;
        q = Math.cos(prob) / Math.sin(prob);
    } else { /*-- usual case;  including, e.g.,  df = 1.1 */
        a = 1 / (ndf - 0.5);
        b = 48 / (a * a);
        c = ((20700 * a / b - 98) * a - 16) * a + 96.36;
        d = ((94.5 / (b + c) - 3) / b + 1) * Math.sqrt(a * M_PI_2) * ndf;
        y = Math.pow(d * P, 2 / ndf);
        if (y > 0.05 + a) {
            /* Asymptotic inverse expansion about normal */
            x = qnorm(0.5 * P, false);
            y = x * x;
            if (ndf < 5)
                c += 0.3 * (ndf - 4.5) * (x + 0.6);
            c = (((0.05 * d * x - 5) * x - 7) * x - 2) * x + b + c;
            y = (((((0.4 * y + 6.3) * y + 36) * y + 94.5) / c - y - 3) / b + 1) * x;
            y = a * y * y;
            if (y > 0.002)/* FIXME: This cutoff is machine-precision dependent */
                y = Math.exp(y) - 1;
            else { /* Taylor of e^y -1 : */
                y = (0.5 * y + 1) * y;
            }
        } else {
            y = ((1 / (((ndf + 6) / (ndf * y) - 0.089 * d - 0.822) * (ndf + 2) * 3) + 0.5 / (ndf + 4)) * y - 1)
                    * (ndf + 1) / (ndf + 2) + 1 / y;
        }
        q = Math.sqrt(ndf * y);
    }
    if (neg)
        q = -q;
    return q;
}

From source file:com.itemanalysis.psychometrics.irt.model.IrmGPCM.java

/**
 * Computes the numerator of the item response model. This method is used internally for the computation
 * of the probability of an item response. It uses item parameter values passed in the iparam argument.
 * It does NOT use item parameter values stored in the object.
 *
 * @param theta person ability value//from   www . j a  v a 2  s.c  om
 * @param iparam item parameter array. The order is iparam[0] = discrimination, iparam[1] = step1 (fixed to zero),
 *               iparam[2] = step 2, iparam[3] = step 3, ..., iparam[m+1] = step m.
 * @param category response category.
 * @param D scaling constant that is either 1 or 1.7
 * @return numerator value of the item response model.
 */
private double numer(double theta, double[] iparam, int category, double D) {
    double Zk = 0;
    double a = iparam[0];
    for (int k = 0; k <= category; k++) {
        Zk += D * a * (theta - iparam[k + 1]);
    }
    return Math.exp(Zk);
}

From source file:lanchester.MultiArena4.java

public void step() {
    boolean aboveFloor = true;
    double currentCycle = 0.;
    int numFoes = forces.size();
    if (isMyTurn == null) {
        isMyTurn = new boolean[numFoes][numFoes];
        stanceArray = new int[numFoes][numFoes];
        currentFloor = new double[numFoes][numFoes];
        currentCeiling = new double[numFoes][numFoes];
        for (int i1 = 0; i1 < numFoes; i1++) {
            //                int ind1 = forceMap.get(forces.get(i1));
            for (int i2 = 0; i2 < numFoes; i2++) {
                //                    int ind2 = forceMap.get(forces.get(i2));
                isMyTurn[i1][i2] = true;
                if (i1 == i2) {
                    stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                    currentFloor[i1][i2] = 0.;
                    currentCeiling[i1][i2] = 1000000.;
                } else {
                    stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                    //                        setStances(i1,i2);
                    setFloor(i1, i2);//from   ww w . j av a2  s.  co  m
                    setCeiling(i1, i2);
                }
            }
        }
    }
    Array2DRowRealMatrix mat = getMat();
    EigenDecomposition eigen = new EigenDecomposition(mat);
    double det = eigen.getDeterminant();
    double[] eVals = eigen.getRealEigenvalues();
    if (eigen.hasComplexEigenvalues()) {
        System.out.println("Complex eigenvalues");
        for (int i1 = 0; i1 < forces.size(); i1++) {
            MultiForce f = forces.get(i1);
            System.out.println(f.getName() + " has " + f.getNumber() + " forces remaining");
        }
    }
    double[] initialNums = getInitialNumbers(forces);
    Array2DRowRealMatrix eVectors = (Array2DRowRealMatrix) eigen.getV();
    LUDecomposition lu = new LUDecomposition(eVectors);
    double det2 = lu.getDeterminant();
    double[] coeffs = new double[numFoes];
    for (int i1 = 0; i1 < numFoes; i1++) {
        Array2DRowRealMatrix tmpMat = (Array2DRowRealMatrix) eVectors.copy();
        tmpMat.setColumn(i1, initialNums);
        LUDecomposition tmpLU = new LUDecomposition(tmpMat);
        double tmpDet = tmpLU.getDeterminant();
        coeffs[i1] = tmpDet / det2;
    }
    aboveFloor = true;
    boolean belowCeiling = true;
    int cntr = 0;
    int numGone;
    do {
        timeStep = determineTimeStep();
        MultiTimeStep currentStep = new MultiTimeStep(numFoes);
        currentTime += timeStep;
        currentCycle += timeStep;
        currentStep.setTime(currentTime);
        numGone = 0;
        for (int i1 = 0; i1 < numFoes; i1++) {
            double updatedForce = 0.;
            //                if (forces.get(i1).getForceSize() > lb) {
            if (stillAlive[i1]) {
                for (int i2 = 0; i2 < numFoes; i2++) {
                    //                    updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * timeStep);
                    updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * currentCycle);

                    //                updatedForce+=coeffs[i2]*eVectors.getEntry(i2, i1)*Math.exp(eVals[i2]*timeStep);
                    //                updatedForce+=coeffs[i1]*eVectors.getEntry(i2, i1)*Math.exp(eVals[i1]*timeStep);
                }
                if (updatedForce < 1.) {
                    updatedForce = lb;
                    stillAlive[i1] = false;
                    numGone++;
                }
            } else {
                updatedForce = lb;
                numGone++;
            }
            forces.get(i1).updateForce(updatedForce);
            currentStep.setForceNumber(updatedForce, i1);
            //                for (int i2 = 0; i2 < numFoes; i1++) {
            //                    if (i1 != i2) {
            //
            //                    }
            //                }
        }
        history.add(currentStep);
        aboveFloor = checkAboveFloors();
        belowCeiling = checkBelowCeilings();
        cntr++;
    } while (aboveFloor && belowCeiling && cntr < 2000 && (numFoes - numGone) > 1);
    for (int i1 = 0; i1 < numFoes; i1++) {
        for (int i2 = 0; i2 < numFoes; i2++) {
            if (i1 == i2) {
                stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                currentFloor[i1][i2] = 0.;
            } else {
                //                    stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                setStances(i1, i2);
                setFloor(i1, i2);
                setCeiling(i1, i2);
            }
        }
    }

    //        eVectors.
    //        this.currentTime++;
    //                Truncator truncator = new Truncator();
    if (numFoes - numGone == 1) {
        loneSurvivor = true;
        //            System.out.println("time = " + time);
    }
}

From source file:com.alvermont.terraj.stargen.dole.DoleAccrete.java

/**
 * Get the density for a particular radius
 *
 * @param r The orbital radius to get the density for
 * @return The calculated density/*from   w ww  .  j  a  va2  s .co  m*/
 */
public double getDensity(double r) {
    return (A * Math.exp(-DoleConstants.ALPHA * Math.pow(r, DoleConstants.GAMMA)));
}

From source file:com.nextbreakpoint.nextfractal.mandelbrot.core.Expression.java

public static Number funcExp(MutableNumber out, Number x) {
    double d = Math.exp(x.r());
    return out.set(d * Math.cos(x.i()), d * Math.sin(x.i()));
}