cmath.exp() Method in Python:
The cmath.exp() method takes a complex number as an argument and returns the exponential value. If the number is x, it returns e**x, where e is the natural logarithm base.
Syntax:
cmath.exp(x)
Parameters
x: This is Required. A number whose exponential value is to be determined.
Return Value:
Returns a complex value that represents a complex number’s exponential.
Examples:
Example1:
Input:
Given Complex Number = 3+4j
Output:
The given complex number's (3+4j) exponential value = (-13.128783081462158-15.200784463067954j)
Example2:
Input:
Given realpart = 5 Given imaginary part = 2
Output:
The given complex number's (5+2j) exponential value = (-61.761666662504986+134.9517036790434j)
Note: The above input format is for dynamic input.
cmath.exp() 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.exp() method that returns the given complex number’s exponential value.
- Store it in another variable.
- Print the exponential 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.exp() method that # returns the the given complex number's exponential value. # Store it in another variable. rslt = cmath.exp(complexnumb) # Print the exponential value of the given complex number. print("The given complex number's", complexnumb, "exponential value = ") print(rslt)
Output:
The given complex number's (3+4j) exponential value = (-13.128783081462158-15.200784463067954j)
Similarly, try for the other examples
import cmath complexnumb = -1-2j rslt = cmath.exp(complexnumb) print("The given complex number's", complexnumb, "exponential value = ") print(rslt)
Output:
The given complex number's (-1-2j) exponential value = (-0.1530918656742263-0.33451182923926226j)
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.exp() method that returns the given complex number’s exponential value.
- Store it in another variable.
- Print the exponential 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.exp() method that # returns the the given complex number's exponential value. # Store it in another variable. rslt = cmath.exp(complexnumb) # Print the exponential value of the given complex number. print("The given complex number's", complexnumb, "exponential value = ") print(rslt)
Output:
Enter real part and complex part of the complex number = 5 2 The given complex number's (5+2j) exponential value = (-61.761666662504986+134.9517036790434j)