Python Error Function
Contents |
2/sqrt(pi)*integral(exp(-t**2), t=0..z). Parameters:x python import math : ndarray Input array. Returns:res : ndarray The values of
Math Domain Error
the error function at the given points x. See also erfc, erfinv, erfcinv Notes The cumulative of the unit normal distribution
Python Math Operators
is given by Phi(z) = 1/2[1 + erf(z/sqrt(2))]. References [R200]http://en.wikipedia.org/wiki/Error_function [R201]Milton Abramowitz and Irene A. Stegun, eds. Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables. New York: Dover, 1972. http://www.math.sfu.ca/~cbm/aands/page_297.htm [R202]Steven G. Johnson, Faddeeva W function implementation. http://ab-initio.mit.edu/Faddeeva Previous topic scipy.special.multigammaln Next topic scipy.special.erfc © Copyright 2008-2009, The Scipy community. Last updated on May 11, 2014. Created using Sphinx 1.2.2.
module is always available. It provides access to the mathematical functions defined by the C standard. These functions cannot be used with complex numbers; use the functions of the same name from numpy error function the cmath module if you require support for complex numbers. The
Python Float To Int
distinction between functions which support complex numbers and those which don't is made since most users do not want python squared to learn quite as much mathematics as required to understand complex numbers. Receiving an exception instead of a complex result allows earlier detection of the unexpected complex number used as a https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.special.erf.html parameter, so that the programmer can determine how and why it was generated in the first place. The following functions are provided by this module. Except when explicitly noted otherwise, all return values are floats. 9.2.1. Number-theoretic and representation functions¶ math.ceil(x)¶ Return the ceiling of x as a float, the smallest integer value greater than or equal to x. math.copysign(x, y)¶ Return https://docs.python.org/2/library/math.html x with the sign of y. On a platform that supports signed zeros, copysign(1.0, -0.0) returns -1.0. New in version 2.6. math.fabs(x)¶ Return the absolute value of x. math.factorial(x)¶ Return x factorial. Raises ValueError if x is not integral or is negative. New in version 2.6. math.floor(x)¶ Return the floor of x as a float, the largest integer value less than or equal to x. math.fmod(x, y)¶ Return fmod(x, y), as defined by the platform C library. Note that the Python expression x % y may not return the same result. The intent of the C standard is that fmod(x, y) be exactly (mathematically; to infinite precision) equal to x - n*y for some integer n such that the result has the same sign as x and magnitude less than abs(y). Python's x % y returns a result with the sign of y instead, and may not be exactly computable for float arguments. For example, fmod(-1e-100, 1e100) is -1e-100, but the result of Pytho
module is always available. It provides access to the mathematical functions defined by the C standard. These functions cannot be used with complex numbers; use the functions of the same name https://docs.python.org/3/library/math.html from the cmath module if you require support for complex numbers. http://www.johndcook.com/blog/python_erf/ The distinction between functions which support complex numbers and those which don't is made since most users do not want to learn quite as much mathematics as required to understand complex numbers. Receiving an exception instead of a complex result allows earlier detection of the unexpected complex number used error function as a parameter, so that the programmer can determine how and why it was generated in the first place. The following functions are provided by this module. Except when explicitly noted otherwise, all return values are floats. 9.2.1. Number-theoretic and representation functions¶ math.ceil(x)¶ Return the ceiling of x, the smallest integer greater than or equal to x. If x is not a python error function float, delegates to x.__ceil__(), which should return an Integral value. math.copysign(x, y)¶ Return a float with the magnitude (absolute value) of x but the sign of y. On platforms that support signed zeros, copysign(1.0, -0.0) returns -1.0. math.fabs(x)¶ Return the absolute value of x. math.factorial(x)¶ Return x factorial. Raises ValueError if x is not integral or is negative. math.floor(x)¶ Return the floor of x, the largest integer less than or equal to x. If x is not a float, delegates to x.__floor__(), which should return an Integral value. math.fmod(x, y)¶ Return fmod(x, y), as defined by the platform C library. Note that the Python expression x % y may not return the same result. The intent of the C standard is that fmod(x, y) be exactly (mathematically; to infinite precision) equal to x - n*y for some integer n such that the result has the same sign as x and magnitude less than abs(y). Python's x % y returns a result with the
following code first appeared on my blog post Stand-alone error function erf. See that post for documentation. See also Relating erf and Φ.import math def erf(x): # constants a1 = 0.254829592 a2 = -0.284496736 a3 = 1.421413741 a4 = -1.453152027 a5 = 1.061405429 p = 0.3275911 # Save the sign of x sign = 1 if x < 0: sign = -1 x = abs(x) # A&S formula 7.1.26 t = 1.0/(1.0 + p*x) y = 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*math.exp(-x*x) return sign*y A&S refers to Handbook of Mathematical Functions by Abramowitz and Stegun.This code is in the public domain. Do whatever you want to with it, no strings attached.Other versions: C++, C#More Stand-alone numerical code Search for: Subscribe to my newsletter John D. Cook© All rights reserved. Search for: