HomeLinuxPython Math Exp

Python Math Exp


Python’s “Math” module is a robust software that lets you carry out mathematical operations and calculations within the code. It supplies a variety of capabilities, constants, and strategies that may make it easier to remedy advanced issues and make your code extra environment friendly. These capabilities embody addition, subtraction, multiplication, and division, in addition to exponents, roots, modulo, and absolute worth.

On this information, we’ll discover the Python “math.exp()” operate of the “math” module, and discover ways to use them within the code. The next are the contents of this weblog:

What’s Python “math.exp()” Operate?

The Python “math.exp()” operate returns the exponential worth of a given quantity. It calculates the worth of “e” raised to the facility of the quantity handed as its(operate) argument. As an example, in case you cross “2” as an argument, it is going to return “e^2”.

Syntax

 
Within the above syntax, the “math.exp()” operate takes one parameter “x”. The calculation is finished such that “e” is raised to the facility of “x” i.e., “e^x”. This argument is usually a constructive, damaging, or zero worth.

Nevertheless, in case you cross an invalid argument, equivalent to a string or a non-numeric worth, it is going to elevate a “TypeError”.

Instance 1: Utilizing “math.exp()” With a Constructive Worth

Let’s overview the next instance utilizing the “math.exp()” operate with a constructive worth:

import math
print(math.exp(55))

 
Within the above code, the “math.exp()” operate takes the worth “55” as an argument and calculates the exponential worth of “e^55”.

Output


The above output calculates the exponent worth of the handed constructive quantity.

Instance 2: Utilizing “math.exp()” With a Unfavorable Worth

Now, let’s see an instance of utilizing the “math.exp()” operate with a damaging worth:

import math
print(math.exp(55))

 
Within the above code, the “math.exp()” operate takes the worth “-55” as an argument and calculates the exponential worth of “e^-55”.

Output


The above output returns the calculation of the exponent worth of the handed damaging quantity.

Instance 3: Utilizing “math.exp()” With a Zero Worth

Lastly, let’s see an instance of utilizing the mentioned operate with a “zero” worth:

import math
print(math.exp(0))

 
Within the above code, we handed “0” as an argument to the “math.exp()” operate, which calculates the exponential worth of “e^0”.

Output


The output reveals the exponent worth results of the handed zero worth as “1”.

Conclusion

In Python, the “math.exp()” operate of the “math” module is used to calculate the exponent energy of the numeric values equivalent to “int” and “float”. This operate retrieves the “e” worth raised by “x“(handed as argument). It returns the exponent energy when the worth is an integer or a float quantity. In the event you cross different values, equivalent to string, listing, and many others., the “math.exp()” operate returns a “Sort error” as an alternative. This weblog mentioned the utilization and implementation of the “math.exp()” operate in Python.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments