Returns the probability density function of a double with mean 0 variance 1. - Java java.lang

Java examples for java.lang:Math Function

Description

Returns the probability density function of a double with mean 0 variance 1.

Demo Code

/*/* www.  ja  v  a2s. c om*/
 * ------------------------------------------------------------------------=
 * Copyright (C) 1997 - 1998 by Visual Numerics, Inc. All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software is freely
 * granted by Visual Numerics, Inc., provided that the copyright notice
 * above and the following warranty disclaimer are preserved in human
 * readable form.
 *
 * Because this software is licenses free of charge, it is provided
 * "AS IS", with NO WARRANTY.  TO THE EXTENT PERMITTED BY LAW, VNI
 * DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO ITS PERFORMANCE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 * VNI WILL NOT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING OUT OF THE USE
 * OF OR INABILITY TO USE THIS SOFTWARE, INCLUDING BUT NOT LIMITED TO DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, PUNITIVE, AND EXEMPLARY DAMAGES, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 
 *
 * ------------------------------------------------------------------------=
 */
//package com.java2s;

public class Main {
    /**
     * Returns the probability density function of a double with mean 0 variance
     * 1.
     * 
     * @param x
     *            A double value.
     * @return Returns the probability density function of a double with mean 0
     *         variance 1.
     */
    static public double pdf(double x) {
        double ans;
        ans = Math.exp(-(x * x) / 2.) / Math.sqrt(2 * Math.PI);

        return ans;
    }

    /**
     * Returns the probability density function of a double.
     * 
     * @param x
     *            A double value.
     * @param mean
     *            The mean of the gaussian distribution.
     * @param variance
     *            The variance of the gaussian distribution.
     * @return Returns the probability density function of a double.
     */
    static public double pdf(double x, double mean, double variance) {
        double ans;
        ans = Math.exp(-(x - mean) * (x - mean) / (2. * variance))
                / Math.sqrt(2 * Math.PI * variance);

        return ans;
    }
}

Related Tutorials