Movatterモバイル変換


[0]ホーム

URL:


Python Tutorial

Python math.expm1() Method



The Pythonmath.expm1() method is used to calculate the value of ex − 1, wheree is the base of the natural logarithm (Euler's number) andx 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 Pythonmath.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 mathresult = 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 mathresult = 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 mathresult = 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 mathx = 2result = 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
Print Page
Advertisements

[8]ページ先頭

©2009-2025 Movatter.jp