Python math.expm1() Method



The Python math.expm1() method is used to calculate the value of ex − 1, where e is the base of the natural logarithm (Euler's number) and x is the input parameter. It calculates the exponential of the input value minus 1.

Mathematically, the math.expm1() method is equivalent to ex − 1, where e is approximately equal to 2.71828.

For example, if x = 1, then math.expm1(1) returns e1 − 1, which simplifies to e − 1.

Syntax

Following is the basic syntax of the Python math.expm1() method −

math.expm1(x)

Parameters

This method accepts either an integer or a floating-point number as a parameter, representing the exponent to which e is raised.

Return Value

The method returns the value of e raised to the power of x, minus 1. The return value is a floating-point number.

Example 1

In the following example, we calculate e raised to the power of 1 minus 1, which means passing a positive integer exponent as a parameter to the base e −

import math
result = math.expm1(1)
print("The result obtained is:", result)  

Output

The output obtained is as follows −

The result obtained is: 1.718281828459045

Example 2

Here, we pass a negative integer exponent to the base e as a parameter. We calculate e raised to the power of -2 minus 1 −

import math
result = math.expm1(-2)
print("The result obtained is:", result)  

Output

Following is the output of the above code −

The result obtained is: -0.8646647167633873

Example 3

In this example, we are passing a fractional exponent as a parameter to the base e. We are calculating e raised to the power of 1.5 minus 1 −

import math
result = math.expm1(1.5)
print("The result obtained is:", result) 

Output

We get the output as shown below −

The result obtained is: 3.481689070338065

Example 4

Now, we use a variable "x" to store the exponent value. We then calculate e raised to the power of "x" minus 1, which is e2 - 1 −

import math
x = 2
result = math.expm1(x)
print("The result obtained is:", result)  

Output

The result produced is as shown below −

The result obtained is: 6.38905609893065
python_maths.htm
Advertisements
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy