Movatterモバイル変換


[0]ホーム

URL:


Python Tutorial

Python cmath.log() Function



The Pythoncmath.log() function provides a way to perform logarithm operation on complex numbers. This method returns the logarithm of a complex number with respect to base.

If there is a single argument passed then it calculates the natural logarithm with basee. In case of multiple arguments, this method returns the logarithm of the initial argument with the base of the final argument.

If the specified argument is zero or negative then this returns ValueError, and if it is not a number then this returns TypeError.

Syntax

Following is the syntax of the Pythoncmath.log() method −

cmath.log(a, base = None)

Parameters

This method accepts following parameters −

  • a:This specifies the value to calculate the logarithm, a is the component of the base.

  • base:This parameter specifies the base. It is not mandatory to mention, this is optional.

Return Value

This function returns the logarithm of the complex number.

Example 1

Following is the basic example of the Pythoncmath.log() function. Here we are trying to calculate the simple logarithm with base 10.

import cmathx=cmath.log(5, 10)print(x)

Output

The output of the above code is as follows −

(0.6989700043360187+0j)

Example 2

In this example, we are calculating logarithm of the given complex number usingcmath.log().

import cmathy=2+3jx=cmath.log(y)print(x)

Output

The output obtained is as follows −

(1.2824746787307684+0.982793723247329j)
python_modules.htm
Print Page
Advertisements

[8]ページ先頭

©2009-2025 Movatter.jp