Erf Error Function Java
Contents |
Execution: java ErrorFunction z * * Implements the Gauss error function. * * erf(z) = 2 / sqrt(pi) * integral(exp(-t*t), t = 0..z) * * * % java ErrorFunction 1.0 * erf(1.0) = 0.8427007877600067 // actual = 0.84270079294971486934 * Phi(1.0) = 0.8413447386043253 // actual
Erf Error Function Ti-89
= 0.8413447460 * * * % java ErrorFunction -1.0 * erf(-1.0) = -0.8427007877600068 excel error function erf * Phi(-1.0) = 0.15865526139567465 * * % java ErrorFunction 3.0 * erf(3.0) = 0.9999779095015785 // actual = 0.99997790950300141456 *
Erf Q Function
Phi(3.0) = 0.9986501019267444 * * % java ErrorFunction 30 * erf(30.0) = 1.0 * Phi(30.0) = 1.0 * * % java ErrorFunction -30 * erf(-30.0) = -1.0 * Phi(-30.0) = 0.0 erf normal distribution * * % java ErrorFunction 1E-20 * erf(1.0E-20) = -3.0000000483809686E-8 // true anser 1.13E-20 * Phi(1.0E-20) = 0.49999998499999976 * * ******************************************************************************/ public class ErrorFunction { // fractional error in math formula less than 1.2 * 10 ^ -7. // although subject to catastrophic cancellation when z in very close to 0 // from Chebyshev fitting formula for erf(z) from Numerical Recipes, 6.2 erf erfc public static double erf(double z) { 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; } // fractional error less than x.xx * 10 ^ -4. // Algorithm 26.2.17 in Abromowitz and Stegun, Handbook of Mathematical. public static double erf2(double z) { double t = 1.0 / (1.0 + 0.47047 * Math.abs(z)); double poly = t * (0.3480242 + t * (-0.0958798 + t * (0.7478556))); double ans = 1.0 - poly * Math.exp(-z*z); if (z >= 0) return ans; else return -ans; } // cumulative normal distribution // See Gaussia.java for a better way to compute Phi(z) public static double Phi(double z) { return 0.5 * (1.0 + erf(z / (Math.sqrt(2.0)))); } /*************************************************************************** * Test client ***************************************************************************/ public
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more
Mathematica Erf
about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges wiki erf Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each
Gaussian Erf
other. Join them; it only takes a minute: Sign up Use of Erfc function: commons.apache.org library up vote 0 down vote favorite My problem is simple: I would like to use the error function Erfc(double) in Java with http://introcs.cs.princeton.edu/21function/ErrorFunction.java.html Eclipse but I do not want to implement it (because it is complicated). So, I have found this: http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/special/Erf.html That does exactly what I want. The problem is that I can not use it. As it is not from "docs.oracle.com", I can not just import it. But unfortunately, I can not include the library and use it neither because what I download from : http://commons.apache.org/proper/commons-math/download_math.cgi is not a .jar Does someone know how to "install - use" it? http://stackoverflow.com/questions/16221406/use-of-erfc-function-commons-apache-org-library I use Ubuntu 12.04 on a Intel® Core™ i7-3610QM CPU @ 2.30GHz × 8 and my IDE is ecplipse. java eclipse apache import static-libraries share|improve this question edited Apr 25 '13 at 17:50 Luiggi Mendoza 64.5k761133 asked Apr 25 '13 at 17:49 Beetlejuice 205 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote accepted Ok, this was a stupid question! So I have found the answer by myself. I just needed to download the binary files and add it as a .jar. Then it works as a classical library. To use it, I must import org.apache.commons.math3.*; share|improve this answer answered Apr 27 '13 at 13:32 Beetlejuice 205 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged java eclipse apache import static-libraries or ask your own question. asked 3 years ago viewed 984 times active 3 years ago Linked 1 How to calculate area under a normal distribution in Java? Related 684Access restriction on class due to restriction on required library rt.jar?746Failed to load the JNI shared Library (J
Frequently Used Methods erf ( ) Java Code Examples for org.apache.commons.math.special.Erf The following are top voted examples for showing how to use org.apache.commons.math.special.Erf. These examples http://www.programcreek.com/java-api-examples/index.php?api=org.apache.commons.math.special.Erf are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples. + Save this class to your library Example 1 Project: beast2 File: NormalDistributionImpl.java View source code 6 votes /** * For this distribution, X, this method returns P(X < x
). * * @param error function x the value at which the CDF is evaluated. * @return CDF evaluted at x
. * @throws MathException if the algorithm fails to converge; unless * x is more than 20 standard deviations from the mean, in which case the * convergence exception is caught and 0 or 1 is returned. */ public double cumulativeProbability(double x) throws MathException { try { erf error function return 0.5 * (1.0 + Erf.erf((x - mean) / (standardDeviation * Math.sqrt(2.0)))); } catch (MaxIterationsExceededException ex) { if (x < (mean - 20 * standardDeviation)) { // JDK 1.5 blows at 38 return 0.0d; } else if (x > (mean + 20 * standardDeviation)) { return 1.0d; } else { throw ex; } } } Example 2 Project: freehep-ncolor-pdf File: Gaussian.java View source code 6 votes public double evaluateAnalyticalNormalization(Dependent dep) throws RuntimeException { double[] xMax = x.range().upperBounds(); double[] xMin = x.range().lowerBounds(); if ( xMax == null && xMin == null ) return rootPiOverTwo*sigma; if ( xMax.length != 1 || xMin.length != 1 ) throw new IllegalArgumentException("Normalization over multiple ranges is not supported for Function Gaussian."); double den = r2*sigma; double ue = Double.NaN, le= Double.NaN; try { if ( Double.isInfinite(xMax[0]) ) ue = 1; else ue = Erf.erf((xMax[0]-mean)/den); if ( Double.isInfinite(xMin[0]) ) le = -1; else le = Erf.erf((xMin[0]-mean)/den); } catch ( org.apache.commons.math.MathException me) { throw new RuntimeException("Problems evaluating erf ",me); } return rootPiOverTwo*sigma*(ue-le); } Example 3 Project: javajoy File: NormalDistributionImpl.java View source code 6 votes /** * For this distrib