{"id":25383,"date":"2021-11-10T09:38:32","date_gmt":"2021-11-10T04:08:32","guid":{"rendered":"https:\/\/python-programs.com\/?p=25383"},"modified":"2021-11-10T09:38:32","modified_gmt":"2021-11-10T04:08:32","slug":"python-math-erf-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-math-erf-method-with-examples\/","title":{"rendered":"Python math.erf() Method with Examples"},"content":{"rendered":"
math.erf() Method in Python:<\/strong><\/p>\n The math.erf() method returns a number’s error function.<\/p>\n This method accepts values ranging from – inf to + inf and returns a value ranging from – 1 to + 1.<\/p>\n Syntax:<\/strong><\/p>\n Parameters<\/strong><\/p>\n x:<\/strong> This is Required. It is a number used to calculate the error function of<\/p>\n Return Value:<\/strong><\/p>\n Returns a float value that represents a number’s error function.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Similarly, try for other numbers.<\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n 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 …<\/p>\nmath.erf(x)<\/pre>\n
Given Number = 0.5<\/pre>\n
The given number's { 0.5 } error function = 0.5204998778130465<\/pre>\n
Given Number = -4.5<\/pre>\n
The given number's { -4.5 } error function = -0.9999999998033839<\/pre>\n
math.erf() Method with Examples in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Import math module using the import keyword\r\nimport math\r\n# Give the number as static input and store it in a variable.\r\ngvn_numb = 0.5\r\n# Pass the given number as an argument to the math.erf() function to get\r\n# the given number's error function.\r\n# Store it in another variable.\r\nrslt = math.erf(gvn_numb)\r\n# Print the error function of the given number.\r\nprint(\"The given number's {\", gvn_numb, \"} error function = \", rslt)\r\n<\/pre>\n
The given number's { 0.5 } error function = 0.5204998778130465<\/pre>\n
import math\r\ngvn_numb = -15.2\r\nrslt = math.erf(gvn_numb)\r\nprint(\"The given number's {\", gvn_numb, \"} error function = \", rslt)\r\n<\/pre>\n
The given number's { -15.2 } error function = -1.0<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Import math module using the import keyword\r\nimport math\r\n# Give the number as user input using the float(input()) function and store it in a variable.\r\ngvn_numb = float(input(\"Enter some random number = \"))\r\n# Pass the given number as an argument to the math.erf() function to get\r\n# the given number's error function.\r\n# Store it in another variable.\r\nrslt = math.erf(gvn_numb)\r\n# Print the error function of the given number.\r\nprint(\"The given number's {\", gvn_numb, \"} error function = \", rslt)\r\n<\/pre>\n
Enter some random number = -4.5\r\nThe given number's { -4.5 } error function = -0.9999999998033839<\/pre>\n","protected":false},"excerpt":{"rendered":"