math.erf() Method in Python:
The math.erf() method returns a number’s error function.
This method accepts values ranging from – inf to + inf and returns a value ranging from – 1 to + 1.
Syntax:
math.erf(x)
Parameters
x: This is Required. It is a number used to calculate the error function of
Return Value:
Returns a float value that represents a number’s error function.
Examples:
Example1:
Input:
Given Number = 0.5
Output:
The given number's { 0.5 } error function = 0.5204998778130465
Example2:
Input:
Given Number = -4.5
Output:
The given number's { -4.5 } error function = -0.9999999998033839
math.erf() Method with Examples in Python
Method #1: Using Built-in Functions (Static Input)
Approach:
- Import math module using the import keyword.
- Give the number(angle) as static input and store it in a variable.
- Pass the given as an argument to the math.erf() function to get the given number’s error function.
- Store it in another variable.
- Print the error function of the given number.
- The Exit of the Program.
Below is the implementation:
# Import math module using the import keyword import math # Give the number as static input and store it in a variable. gvn_numb = 0.5 # Pass the given number as an argument to the math.erf() function to get # the given number's error function. # Store it in another variable. rslt = math.erf(gvn_numb) # Print the error function of the given number. print("The given number's {", gvn_numb, "} error function = ", rslt)
Output:
The given number's { 0.5 } error function = 0.5204998778130465
Similarly, try for other numbers.
import math gvn_numb = -15.2 rslt = math.erf(gvn_numb) print("The given number's {", gvn_numb, "} error function = ", rslt)
Output:
The given number's { -15.2 } error function = -1.0
Method #2: Using Built-in Functions (User Input)
Approach:
- Import math module using the import keyword.
- Give the number as user input using the float(input()) function and store it in a variable.
- Pass the given number as an argument to the math.erf() function to get the given number’s error function.
- Store it in another variable.
- Print the error function of the given number.
- The Exit of the Program.
Below is the implementation:
# Import math module using the import keyword import math # Give the number as user input using the float(input()) function and store it in a variable. gvn_numb = float(input("Enter some random number = ")) # Pass the given number as an argument to the math.erf() function to get # the given number's error function. # Store it in another variable. rslt = math.erf(gvn_numb) # Print the error function of the given number. print("The given number's {", gvn_numb, "} error function = ", rslt)
Output:
Enter some random number = -4.5 The given number's { -4.5 } error function = -0.9999999998033839