cmath.log10() Method in Python:
The cmath.log10() method returns the complex number’s base-10 logarithm.
There is one continuous branch cut from 0 to – ∞ along the negative real axis.
Syntax:
cmath.log10(x)
Parameters
x: This is Required. Specifies the value for which the base-10 logarithm will be computed.
- If the value is 0 or a negative number, a ValueError is returned.
- If the value is not a number, a TypeError is returned.
Return Value:
Returns a complex value that represents a number’s base-10 logarithm.
Examples:
Example1:
Input:
Given Complex Number = 3+4j
Output:
The given complex number's (3+4j) base-10 logarithm value = (0.6989700043360187+0.4027191962733731j)
Example2:
Input:
Given realpart = 5 Given imaginary part = 2
Output:
The given complex number's (5+2j) base-10 logarithm value = (0.7311989989494779+0.16525181990889787j)
Note: The above input format is for dynamic input.
cmath.log10() Method with Examples in Python
Method #1: Using Built-in Functions (Static Input)
Approach:
- Import cmath module(for complex number operations) using the import keyword.
- Give the complex number as static input and store it in a variable.
- Pass the given complex number as an argument to the cmath.log10() method that returns the given complex number’s base-10 logarithm value.
- Store it in another variable.
- Print the base-10 logarithm value of the given complex number.
- The Exit of the Program.
Below is the implementation:
# Import cmath module(for complex number operations) using the import keyword.
import cmath
# Give the complex number as static input and store it in a variable.
complexnumb = 3+4j
# Pass the given complex number as an argument to the cmath.log10() method that
# returns the the given complex number's base-10 logarithm value.
# Store it in another variable.
rslt = cmath.log10(complexnumb)
# Print the base-10 logarithm value of the given complex number.
print("The given complex number's", complexnumb,
"base-10 logarithm value = ")
print(rslt)
Output:
The given complex number's (3+4j) base-10 logarithm value = (0.6989700043360187+0.4027191962733731j)
Similarly, try for the other examples
import cmath
complexnumb = -6-2j
rslt = cmath.log10(complexnumb)
print("The given complex number's", complexnumb,
"base-10 logarithm value = ")
print(rslt)
Output:
The given complex number's (-6-2j) base-10 logarithm value = (0.8010299956639811-1.2246418635180674j)
Method #2: Using Built-in Functions (User Input)
Approach:
- Import cmath module(for complex number operations) using the import keyword.
- Give the real part and imaginary part of the complex number as user input using map(), int(), split().
- Store it in two variables.
- Using a complex() function convert those two variables into a complex number and store them in a variable.
- Pass the given complex number as an argument to the cmath.log10() method that returns the given complex number’s base-10 logarithm value.
- Store it in another variable.
- Print the base-10 logarithm value of the given complex number.
- The Exit of the Program.
Below is the implementation:
# Import cmath module(for complex number operations) using the import keyword.
import cmath
# Give the real part and imaginary part of the complex number as user input
# using map(), int(), split().
# Store it in two variables.
realnumb, imaginarynumb = map(int, input(
'Enter real part and complex part of the complex number = ').split())
# Using a complex() function convert those two variables into a complex number.
complexnumb = complex(realnumb, imaginarynumb)
# Pass the given complex number as an argument to the cmath.log10() method that
# returns the the given complex number's base-10 logarithm value.
# Store it in another variable.
rslt = cmath.log10(complexnumb)
# Print the base-10 logarithm value of the given complex number.
print("The given complex number's", complexnumb,
"base-10 logarithm value = ")
print(rslt)
Output:
Enter real part and complex part of the complex number = 5 2 The given complex number's (5+2j) base-10 logarithm value = (0.7311989989494779+0.16525181990889787j)