Author name: Vikram Chiluka

Python cmath.phase() Method with Examples

cmath.phase() Method in Python:

The phase of a complex number is returned by the cmath.phase() method.

The magnitude and angle of a complex number can be expressed. Phase is the angle formed by a vector (representing a complex number) and the positive x-axis.

Note: It should be noted that the output is always between -π and π.

Syntax:

cmath.phase(x)

Parameters

x: This is Required. The number used to determine the phase of

Return Value:

Returns a float value that represents a complex number’s phase.

Examples:

Example1:

Input:

Given Complex Number = 3+4j

Output:

The given complex number's (3+4j) phase value = 
0.9272952180016122

Example2:

Input:

Given realpart = 5
Given imaginary part = 2

Output:

The given complex number's (5+2j) phase value = 
0.3805063771123649

Note: The above input format is for dynamic input.

cmath.phase() 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.phase() method that returns the given complex number’s phase value.
  • Store it in another variable.
  • Print the phase 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.phase() method that
# returns the the given complex number's phase value.
# Store it in another variable.
rslt = cmath.phase(complexnumb)
# Print the phase value of the given complex number.
print("The given complex number's", complexnumb,
      "phase value = ")
print(rslt)

Output:

The given complex number's (3+4j) phase value = 
0.9272952180016122

Similarly, try for the other examples

import cmath
complexnumb = -2-1j
rslt = cmath.phase(complexnumb)
print("The given complex number's", complexnumb,
      "phase value = ")
print(rslt)

Output:

The given complex number's (-2-1j) phase value = 
-2.677945044588987

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.phase() method that returns the given complex number’s phase value.
  • Store it in another variable.
  • Print the phase 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.phase() method that
# returns the the given complex number's phase value.
# Store it in another variable.
rslt = cmath.phase(complexnumb)
# Print the phase value of the given complex number.
print("The given complex number's", complexnumb,
      "phase value = ")
print(rslt)

Output:

Enter real part and complex part of the complex number = 5 2
The given complex number's (5+2j) phase value = 
0.3805063771123649

Python cmath.phase() Method with Examples Read More »

Python cmath.isnan() Method with Examples

cmath.isnan() Method in Python:

The cmath.isnan() method determines whether a value is a nan (Not a Number).

This method gives the following Boolean value: True if the value is nan, False otherwise.

Syntax:

cmath.isnan(x)

Parameters

x: This is Required. The value used to test for NaN

Return Value:

Returns a bool value that is True if any part of a complex number (real or imaginary) is NaN, otherwise False.

Examples:

Example1:

Input:

Given Complex Number = 3+4j

Output:

The result after applying isnan() method to the given complex number (3+4j)  = 
False

Example2:

Input:

Given realpart = 5
Given imaginary part = 2

Output:

The result after applying isnan() method to the given complex number (5+2j) = 
False

Note: The above input format is for dynamic input.

cmath.isnan() 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.isnan() method that determines whether a given complex number’s value is nan (Not a Number) or not.
  • Store it in another variable.
  • Print the above result after applying isnan() method to 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.isnan() method
# that determines whether a given complex number's value is nan (Not a Number)or not.
# Store it in another variable.
rslt = cmath.isnan(complexnumb)
# Print the above result after applying isnan() method to the given complex number.
print("The result after applying isnan() method to the given complex number", complexnumb,
      " = ")
print(rslt)

Output:

The result after applying isnan() method to the given complex number (3+4j)  = 
False

Similarly, try for the other examples

import cmath
complexnumb = 10 + float('nan')
rslt = cmath.isnan(complexnumb)
print("The result after applying isnan() method to the given complex number = ")
print(rslt)

Output:

The result after applying isnan() method to the given complex number = 
True

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.isnan() method that determines whether a given complex number’s value is nan (Not a Number) or not.
  • Store it in another variable.
  • Print the above result after applying isnan() method to 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.isnan() method
# that determines whether a given complex number's value is nan (Not a Number)
# or not.
# Store it in another variable.
rslt = cmath.isnan(complexnumb)
# Print the above result after applying isnan() method to the given complex number.
print("The result after applying isnan() method to the given complex number", complexnumb,
      " = ")
print(rslt)

Output:

Enter real part and complex part of the complex number = 5 2
The result after applying isnan() method to the given complex number (5+2j) = 
False

Python cmath.isnan() Method with Examples Read More »

Python cmath.isinf() Method with Examples

cmath.isinf() Method in Python:

The cmath.isinf() method determines whether or not a value is positive or negative infinity.

This method gives the following Boolean value: If the value is infinity, True; otherwise, False.

Syntax:

cmath.isinf(x)

Parameters

x: This is Required. The value used to test for infinity

Return Value:

Returns a bool value that is True if the value is infinite and False otherwise.

Examples:

Example1:

Input:

Given Complex Number = 3+4j

Output:

The result after applying isinf() method to the given complex number (3+4j)  = 
False

Example2:

Input:

Given realpart = 5
Given imaginary part = 2

Output:

Enter real part and complex part of the complex number = 5 2
The result after applying isinf() method to the given complex number (5+2j) = 
False

Note: The above input format is for dynamic input.

cmath.isinf() 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.isinf() method that determines whether a given complex number’s value is positive or negative infinity.
  • Store it in another variable.
  • Print the above result after applying isinf() method to 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.isinf() method
# that determines whether a given complex number's value is positive or
# negative infinity.
# Store it in another variable.
rslt = cmath.isinf(complexnumb)
# Print the above result after applying isinf() method to the given complex number.
print("The result after applying isinf() method to the given complex number", complexnumb,
      " = ")
print(rslt)

Output:

The result after applying isinf() method to the given complex number (3+4j)  = 
False

Similarly, try for the other examples

import cmath
complexnumb = complex(10 + float('inf'))
rslt = cmath.isinf(complexnumb)
print("The result after applying isinf() method to the given complex number", complexnumb,
      " = ")
print(rslt)

Output:

The result after applying isinf() method to the given complex number (inf+0j)  = 
True

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.isinf() method that determines whether a given complex number’s value is positive or negative infinity.
  • Store it in another variable.
  • Print the above result after applying isinf() method to 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.isinf() method
# that determines whether a given complex number's value is positive or
# negative infinity.
# Store it in another variable.
rslt = cmath.isinf(complexnumb)
# Print the above result after applying isinf() method to the given complex number.
print("The result after applying isinf() method to the given complex number", complexnumb,
      " = ")
print(rslt)

Output:

Enter real part and complex part of the complex number = 5 2
The result after applying isinf() method to the given complex number (5+2j) = 
False

Python cmath.isinf() Method with Examples Read More »

Python cmath.tanh() Method with Examples

cmath.tanh() Method in Python:

The cmath.tanh() method returns the complex number’s hyperbolic tangent.

Syntax:

cmath.tanh(x)

Parameters

x: This is Required. It is a number that will be used to calculate the hyperbolic tangent.

If the value is not a number, a TypeError is returned.

Return Value:

Returns a complex value that represents a complex number’s hyperbolic tangent.

Examples:

Example1:

Input:

Given Complex Number = 3+4j

Output:

The given complex number's (3+4j) hyperbolic tangent value = 
(1.000709536067233+0.00490825806749606j)

Example2:

Input:

Given realpart = 5
Given imaginary part = 2

Output:

The given complex number's (5+2j) hyperbolic tangent value = 
(1.0000593501490003-6.872163880119276e-05j)

Note: The above input format is for dynamic input.

cmath.tanh() 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.tanh() method that returns the given complex number’s hyperbolic tangent value.
  • Store it in another variable.
  • Print the hyperbolic tangent 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.tanh() method that
# returns the the given complex number's hyperbolic tangent value.
# Store it in another variable.
rslt = cmath.tanh(complexnumb)
# Print the hyperbolic tangent value of the given complex number.
print("The given complex number's", complexnumb,
      "hyperbolic tangent value = ")
print(rslt)

Output:

The given complex number's (3+4j) hyperbolic tangent value = 
(1.000709536067233+0.00490825806749606j)

Similarly, try for the other examples

import cmath
complexnumb = -2-1j
rslt = cmath.tanh(complexnumb)
print("The given complex number's", complexnumb,
      "hyperbolic tangent value = ")
print(rslt)

Output:

The given complex number's (-2-1j) hyperbolic tangent value = 
(-1.0147936161466335-0.0338128260798967j)

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.tanh() method that returns the given complex number’s hyperbolic tangent value.
  • Store it in another variable.
  • Print the hyperbolic tangent 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.tanh() method that
# returns the the given complex number's hyperbolic tangent value.
# Store it in another variable.
rslt = cmath.tanh(complexnumb)
# Print the hyperbolic tangent value of the given complex number.
print("The given complex number's", complexnumb,
      "hyperbolic tangent value = ")
print(rslt)

Output:

Enter real part and complex part of the complex number = 5 2
The given complex number's (5+2j) hyperbolic tangent value = 
(1.0000593501490003-6.872163880119276e-05j)

Python cmath.tanh() Method with Examples Read More »

Python cmath.exp() Method with Examples

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)

Python cmath.exp() Method with Examples Read More »

Python cmath.polar() Method with Examples

cmath.polar() Method in Python:

A complex number is converted to polar coordinates using the cmath.polar() method. It returns a tuple consisting of modulus and phase.

A complex number in polar coordinates is defined by modulus r and phase angle phi.

Syntax:

cmath.polar(x)

Parameters

x: This is Required. A number used to calculate the polar coordinates of

Return Value:

Returns a tuple value containing polar coordinates.

Examples:

Example1:

Input:

Given Complex Number = 3+4j

Output:

The polar coordinates of given complex number (3+4j)  = 
(5.0, 0.9272952180016122)

Example2:

Input:

Given realpart = 5
Given imaginary part = 2

Output:

The polar coordinates of given complex number (5+2j) = 
(5.385164807134504, 0.3805063771123649)

Note: The above input format is for dynamic input.

cmath.polar() 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.polar() method that converts the given complex number to polar coordinates and returns a tuple consisting of modulus and phase.
  • Store it in another variable.
  • Print the result tuple consisting of modulus and phase.
  • 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.polar() method
# that converts the given complex number to polar coordinates and returns a
# tuple consisting of modulus and phase.
# Store it in another variable.
rslt = cmath.polar(complexnumb)
# Print the result tuple consisting of modulus and phase.
print("The polar coordinates of given complex number", complexnumb,
      " = ")
print(rslt)

Output:

The polar coordinates of given complex number (3+4j)  = 
(5.0, 0.9272952180016122)

Similarly, try for the other examples

import cmath
complexnumb = -1-2j
rslt = cmath.polar(complexnumb)
print("The polar coordinates of given complex number", complexnumb,
      " = ")
print(rslt)

Output:

The polar coordinates of given complex number (-1-2j)  = 
(2.23606797749979, -2.0344439357957027)

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.polar() method that converts the given complex number to polar coordinates and returns a tuple consisting of modulus and phase.
  • Store it in another variable.
  • Print the result tuple consisting of modulus and phase.
  • 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.polar() method
# that converts the given complex number to polar coordinates and returns a
# tuple consisting of modulus and phase.
# Store it in another variable.
rslt = cmath.polar(complexnumb)
# Print the above result tuple consisting of modulus and phase.
print("The polar coordinates of given complex number", complexnumb,
      " = ")
print(rslt)

Output:

Enter real part and complex part of the complex number = 5 2
The polar coordinates of given complex number (5+2j) = 
(5.385164807134504, 0.3805063771123649)

Python cmath.polar() Method with Examples Read More »

Python cmath.sin() Method with Examples

cmath.sin() Method in Python:

The sine of a number is returned by the cmath.sin() method.

Sine is a trigonometric function that represents the ratio of a right triangle’s opposite side to its hypotenuse.

Syntax:

cmath.sin(x)

Parameters

x: This is Required. It is a number that can be used to calculate the sine of

Return Value:

Returns a complex value that denotes the sine of a complex number.

Examples:

Example1:

Input:

Given Complex Number = 3+4j

Output:

The given complex number's (3+4j) sine value = 
(3.853738037919377-27.016813258003932j)

Example2:

Input:

Given realpart = 5
Given imaginary part = 2

Output:

The given complex number's (5+2j) sine value = 
(-3.6076607742131563+1.0288031496599335j)

Note: The above input format is for dynamic input.

cmath.sin() 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.sin() method that returns the given complex number’s sine value.
  • Store it in another variable.
  • Print the sine 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.sin() method that
# returns the given complex number's sine value.
# Store it in another variable.
rslt = cmath.sin(complexnumb)
# Print the sine value of the given complex number.
print("The given complex number's", complexnumb,
      "sine value = ")
print(rslt)

Output:

The given complex number's (3+4j) sine value = 
(3.853738037919377-27.016813258003932j)

Similarly, try for the other examples

import cmath
complexnumb = -1-2j
rslt = cmath.sin(complexnumb)
print("The given complex number's", complexnumb,
      "sine value = ")
print(rslt)

Output:

The given complex number's (-1-2j) sine value = 
(-3.165778513216168-1.9596010414216063j)

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.sin() method that returns the given complex number’s sine value.
  • Store it in another variable.
  • Print the sine 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.sin() method that
# returns the given complex number's sine value.
# Store it in another variable.
rslt = cmath.sin(complexnumb)
# Print the sine value of the given complex number.
print("The given complex number's", complexnumb,
      "sine value = ")
print(rslt)

Output:

Enter real part and complex part of the complex number = 5 2
The given complex number's (5+2j) sine value = 
(-3.6076607742131563+1.0288031496599335j)

Python cmath.sin() Method with Examples Read More »

Python cmath.sinh() Method with Examples

cmath.sinh() Method in Python:

The cmath.sinh() method returns the given complex number’s hyperbolic sine.

Syntax:

cmath.sinh(x)

Parameters

x: This is Required. It is a number used to calculate the hyperbolic sine of

Return Value:

Returns a complex value that represents the complex number’s hyperbolic sine.

Examples:

Example1:

Input:

Given Complex Number = 3+4j

Output:

The given complex number's (3+4j) hyperbolic sine value = 
(-6.5481200409110025-7.61923172032141j)

Example2:

Input:

Given realpart = 5
Given imaginary part = 2

Output:

The given complex number's (5+2j) hyperbolic sine value = 
(-30.879431343588244+67.47891523845588j)

Note: The above input format is for dynamic input.

cmath.sinh() 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.sinh() method that returns the given complex number’s hyperbolic sine value.
  • Store it in another variable.
  • Print the hyperbolic sine 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.sinh() method that
# returns the given complex number's hyperbolic sine value.
# Store it in another variable.
rslt = cmath.sinh(complexnumb)
# Print the hyperbolic sine value of the given complex number.
print("The given complex number's", complexnumb,
      "hyperbolic sine value = ")
print(rslt)

Output:

The given complex number's (3+4j) hyperbolic sine value = 
(-6.5481200409110025-7.61923172032141j)

Similarly, try for the other examples

import cmath
complexnumb = -1-3j
rslt = cmath.sinh(complexnumb)
print("The given complex number's", complexnumb,
      "hyperbolic sine value = ")
print(rslt)

Output:

The given complex number's (-1-3j) hyperbolic sine value = 
(1.1634403637032504-0.21775955162215221j)

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.sinh() method that returns the given complex number’s hyperbolic sine value.
  • Store it in another variable.
  • Print the hyperbolic sine 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.sinh() method that
# returns the given complex number's hyperbolic sine value.
# Store it in another variable.
rslt = cmath.sinh(complexnumb)
# Print the hyperbolic sine value of the given complex number.
print("The given complex number's", complexnumb,
      "hyperbolic sine value = ")
print(rslt)

Output:

Enter real part and complex part of the complex number = 5 2
The given complex number's (5+2j) hyperbolic sine value = 
(-30.879431343588244+67.47891523845588j)

Python cmath.sinh() Method with Examples Read More »

Python cmath.cosh() Method with Examples

cmath.cosh() Method in Python:

The cmath.cosh() method returns the given complex number’s hyperbolic cosine.

Syntax:

cmath.cosh(x)

Parameters

x: This is Required. It is a number for calculating the hyperbolic cosine of

Return Value:

Returns a complex value that represents the complex number’s hyperbolic cosine.

Examples:

Example1:

Input:

Given Complex Number = 3+4j

Output:

The given complex number's (3+4j) hyperbolic cosine value = 
(-6.580663040551157-7.581552742746545j)

Example2:

Input:

Given realpart = 5
Given imaginary part = 2

Output:

The given complex number's (5+2j) hyperbolic cosine value = 
(-30.88223531891674+67.47278844058752j)

Note: The above input format is for dynamic input.

cmath.cosh() 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.cosh() method that returns the given complex number’s hyperbolic cosine value.
  • Store it in another variable.
  • Print the hyperbolic cosine 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.cosh() method that
# returns the given complex number's hyperbolic cosine value.
# Store it in another variable.
rslt = cmath.cosh(complexnumb)
# Print the hyperbolic cosine value of the given complex number.
print("The given complex number's", complexnumb,
      "hyperbolic cosine value. = ")
print(rslt)

Output:

The given complex number's (3+4j) hyperbolic cosine value. = 
(-6.580663040551157-7.581552742746545j)

Similarly, try for the other examples

import cmath
complexnumb = -5-1j
rslt = cmath.cosh(complexnumb)
print("The given complex number's", complexnumb,
      "hyperbolic cosine value = ")
print(rslt)

Output:

The given complex number's (-5-1j) hyperbolic cosine value = 
(40.09580630629883+62.43984868079963j)

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.cosh() method that returns the given complex number’s hyperbolic cosine value.
  • Store it in another variable.
  • Print the hyperbolic cosine 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.cosh() method that
# returns the given complex number's hyperbolic cosine value.
# Store it in another variable.
rslt = cmath.cosh(complexnumb)
# Print the hyperbolic cosine value of the given complex number.
print("The given complex number's", complexnumb,
      "hyperbolic cosine value = ")
print(rslt)

Output:

Enter real part and complex part of the complex number = 5 2
The given complex number's (5+2j) hyperbolic cosine value = 
(-30.88223531891674+67.47278844058752j)

Python cmath.cosh() Method with Examples Read More »

Python cmath.cos() Method with Examples

cmath.cos() Method in Python:

The cosine of a complex number is returned by the cmath.cos() method.

Syntax:

cmath.cos(x)

Parameters

x: This is Required. It is a number that can be used to calculate the cosine of

Return Value:

Returns a complex value that denotes the cosine of a complex number.

Examples:

Example1:

Input:

Given Complex Number = 3+4j

Output:

The given complex number's (3+4j) cosine value = 
(-27.034945603074224-3.851153334811777j)

Example2:

Input:

Given realpart = 5
Given imaginary part = 2

Output:

The given complex number's (5+2j) cosine value = 
(1.0671926518731156+3.4778844858991573j)

Note: The above input format is for dynamic input.

cmath.cos() 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.cos() method that returns the given complex number’s cosine value.
  • Store it in another variable.
  • Print the cosine 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.cos() method that
# returns the given complex number's cosine value.
# Store it in another variable.
rslt = cmath.cos(complexnumb)
# Print the cosine value of the given complex number.
print("The given complex number's", complexnumb,
      "cosine value = ")
print(rslt)

Output:

The given complex number's (3+4j) cosine value = 
(-27.034945603074224-3.851153334811777j)

Similarly, try for the other examples

import cmath
complexnumb = -1-2j
rslt = cmath.cos(complexnumb)
print("The given complex number's", complexnumb,
      "cosine value = ")
print(rslt)

Output:

The given complex number's (-1-2j) cosine value = 
(2.0327230070196656-3.0518977991518j)

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.cos() method that returns the given complex number’s cosine value.
  • Store it in another variable.
  • Print the cosine 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.cos() method that
# returns the given complex number's cosine value.
# Store it in another variable.
rslt = cmath.cos(complexnumb)
# Print the cosine value of the given complex number.
print("The given complex number's", complexnumb,
      "cosine value = ")
print(rslt)

Output:

Enter real part and complex part of the complex number = 5 2
The given complex number's (5+2j) cosine value = 
(1.0671926518731156+3.4778844858991573j)

Python cmath.cos() Method with Examples Read More »