{"id":25422,"date":"2021-11-12T14:59:41","date_gmt":"2021-11-12T09:29:41","guid":{"rendered":"https:\/\/python-programs.com\/?p=25422"},"modified":"2021-11-14T15:02:16","modified_gmt":"2021-11-14T09:32:16","slug":"python-cmath-tanh-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-cmath-tanh-method-with-examples\/","title":{"rendered":"Python cmath.tanh() Method with Examples"},"content":{"rendered":"
cmath.tanh() Method in Python:<\/strong><\/p>\n The cmath.tanh() method returns the complex number’s hyperbolic tangent.<\/p>\n Syntax:<\/strong><\/p>\n Parameters<\/strong><\/p>\n x:<\/strong> This is Required. It is a number that will be used to calculate the hyperbolic tangent.<\/p>\n If the value is not a number, a TypeError is returned.<\/p>\n Return Value:<\/strong><\/p>\n Returns a complex value that represents a complex number’s hyperbolic tangent.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Note:<\/strong> The above input format is for dynamic input.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Similarly, try for the other examples<\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n 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 …<\/p>\ncmath.tanh(x)<\/pre>\n
Given Complex Number = 3+4j<\/pre>\n
The given complex number's (3+4j) hyperbolic tangent value = \r\n(1.000709536067233+0.00490825806749606j)<\/pre>\n
Given realpart = 5\r\nGiven imaginary part = 2<\/pre>\n
The given complex number's (5+2j) hyperbolic tangent value = \r\n(1.0000593501490003-6.872163880119276e-05j)<\/pre>\n
cmath.tanh() Method with Examples in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Import cmath module(for complex number operations) using the import keyword.\r\nimport cmath\r\n# Give the complex number as static input and store it in a variable.\r\ncomplexnumb = 3+4j\r\n# Pass the given complex number as an argument to the cmath.tanh() method that\r\n# returns the the given complex number's hyperbolic tangent value.\r\n# Store it in another variable.\r\nrslt = cmath.tanh(complexnumb)\r\n# Print the hyperbolic tangent value of the given complex number.\r\nprint(\"The given complex number's\", complexnumb,\r\n \"hyperbolic tangent value = \")\r\nprint(rslt)\r\n<\/pre>\n
The given complex number's (3+4j) hyperbolic tangent value = \r\n(1.000709536067233+0.00490825806749606j)<\/pre>\n
import cmath\r\ncomplexnumb = -2-1j\r\nrslt = cmath.tanh(complexnumb)\r\nprint(\"The given complex number's\", complexnumb,\r\n \"hyperbolic tangent value = \")\r\nprint(rslt)\r\n<\/pre>\n
The given complex number's (-2-1j) hyperbolic tangent value = \r\n(-1.0147936161466335-0.0338128260798967j)<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Import cmath module(for complex number operations) using the import keyword.\r\nimport cmath\r\n# Give the real part and imaginary part of the complex number as user input\r\n# using map(), int(), split().\r\n# Store it in two variables.\r\nrealnumb, imaginarynumb = map(int, input(\r\n 'Enter real part and complex part of the complex number = ').split())\r\n# Using a complex() function convert those two variables into a complex number.\r\ncomplexnumb = complex(realnumb, imaginarynumb)\r\n\r\n# Pass the given complex number as an argument to the cmath.tanh() method that\r\n# returns the the given complex number's hyperbolic tangent value.\r\n# Store it in another variable.\r\nrslt = cmath.tanh(complexnumb)\r\n# Print the hyperbolic tangent value of the given complex number.\r\nprint(\"The given complex number's\", complexnumb,\r\n \"hyperbolic tangent value = \")\r\nprint(rslt)\r\n<\/pre>\n
Enter real part and complex part of the complex number = 5 2\r\nThe given complex number's (5+2j) hyperbolic tangent value = \r\n(1.0000593501490003-6.872163880119276e-05j)<\/pre>\n","protected":false},"excerpt":{"rendered":"