AppDividend
Latest Code Tutorials

Python erfc() Function | Math.erfc() in Python Example

0

Python erfc() is an inbuilt method that is defined under the math module, which is used to find the complementary error function at x if x is the parameter passed. For instance, if x is passed as a parameter in erf function (erf(x)) it returns the complementary error function. We can use the math module by importing it. The syntax for it would be import math; after importing, we use to call this function using the static object.

Python erfc()

Python math.erfc() function returns the complementary error function at x. The error function is also known as gauss error function, and the function throws an error if any non-number is passed as a parameter. It is defined as 1.0 – erf(x). It is used for a large value of x if we subtract from 1, then that would cause loss of significance.  

Syntax

math.erfc(var)

Here var is the variable of which complementary error function we have to find.

Parameters

It takes one parameter var, which takes values of numeric datatype and throws type error if the argument is of any other data type is passed.

Return Value

It returns the error function value of the number in the float datatype.

See the following code.

import math

var = 0.6
print(math.erfc(var))

Example programs on erfc() method in Python

Example 1: Write a program to show the working of the erfc() method in Python.

import math

a1 = 0.3
b1 = 0.9
c1 = 0.7
d1 = 0.2

print("Value for parameter ", a1, " is ", math.erfc(a1))
print("Value for parameter ", b1, " is ", math.erfc(b1))
print("Value for parameter ", c1, " is ", math.erfc(c1))
print("Value for parameter ", d1, " is ", math.erfc(d1))

Output

Value for parameter  0.3  is  0.6713732405408726
Value for parameter  0.9  is  0.20309178757716786
Value for parameter  0.7  is  0.32219880616258156
Value for parameter  0.2  is  0.7772974107895215

In this example, we have seen that by passing a vaild parameter, which is different for different examples, we get the desired erfc() method solution, which is the complementary error function value.

Example 2: Write a program to pass a value out of range from the erfc() function and display the output.

import math

x = 'b'
print(math.erfc(x))

Output

TypeError: must be real number, not str

In this example, we’ve seen that by passing a parameter which is not of number type, the function throws an error.

See also

Python erf()

Python radians()

Python tanh()

Python sinh()

Python tan()

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.