{"id":25425,"date":"2021-11-13T14:59:37","date_gmt":"2021-11-13T09:29:37","guid":{"rendered":"https:\/\/python-programs.com\/?p=25425"},"modified":"2021-11-14T15:01:47","modified_gmt":"2021-11-14T09:31:47","slug":"python-cmath-log-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-cmath-log-method-with-examples\/","title":{"rendered":"Python cmath.log() Method with Examples"},"content":{"rendered":"
cmath.log() Method in Python:<\/strong><\/p>\n The logarithm of a complex value is returned by the cmath.log() method.<\/p>\n This method takes a single argument and returns the natural logarithm of that argument with base e.<\/p>\n This method takes two arguments and returns the logarithm of the first argument (x) multiplied by the base of the second argument (base).<\/p>\n Syntax:<\/strong><\/p>\n Parameters<\/strong><\/p>\n x:<\/strong> This is Required. Specifies the value for which the logarithm should be calculated.<\/p>\n base:<\/strong> This is Optional. The logarithmic base that should be used. ‘e’ is the default.<\/p>\n Return Value:<\/strong><\/p>\n Returns a complex value that represents the natural logarithm of a number or the base logarithm of a number.<\/p>\n Changelog:<\/strong> The base parameter has been added.<\/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 Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" cmath.log() Method in Python: The logarithm of a complex value is returned by the cmath.log() method. This method takes a single argument and returns the natural logarithm of that argument with base e. This method takes two arguments and returns the logarithm of the first argument (x) multiplied by the base of the second argument …<\/p>\ncmath.log(x, base)<\/pre>\n
\n
Given Complex Number = 3+4j<\/pre>\n
The given complex number's (3+4j) logarithm value = \r\n(1.6094379124341003+0.9272952180016122j)<\/pre>\n
Given realpart = 5\r\nGiven imaginary part = 2\r\nGiven base value = 4<\/pre>\n
The given complex number's (5+2j) logarithm value for the given base{ 4.0 } = \r\n(1.214495248781893+0.27447733164331733j)<\/pre>\n
cmath.log<\/strong>() Method with Examples in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
1)With a single argument<\/h5>\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.log() method that\r\n# returns the the given complex number's logarithm value.\r\n# Store it in another variable.\r\nrslt = cmath.log(complexnumb)\r\n# Print the logarithm value of the given complex number.\r\nprint(\"The given complex number's\", complexnumb,\r\n \"logarithm value = \")\r\nprint(rslt)\r\n<\/pre>\n
The given complex number's (3+4j) logarithm value = \r\n(1.6094379124341003+0.9272952180016122j)<\/pre>\n
2)With two arguments<\/h5>\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 = 4\r\n# Give the base value as static input and store it in another variable.\r\ngvn_basevalu = 8\r\n# Pass the given complex number, base value as the arguments to the cmath.log()\r\n# method that returns the given complex number's logarithm value for\r\n# the given base.\r\n# Store it in another variable.\r\nrslt = cmath.log(complexnumb, gvn_basevalu)\r\n# Print the logarithm value of the given complex number for the given base.\r\nprint(\"The given complex number's\", complexnumb,\r\n \"logarithm value for the given base{\", gvn_basevalu, \"} = \")\r\nprint(rslt)\r\n<\/pre>\n
The given complex number's 4 logarithm value for the given base{ 8 } = \r\n(0.6666666666666667+0j)<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
1)With a single argument<\/h5>\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.log() method that\r\n# returns the the given complex number's logarithm value.\r\n# Store it in another variable.\r\nrslt = cmath.log(complexnumb)\r\n# Print the logarithm value of the given complex number.\r\nprint(\"The given complex number's\", complexnumb,\r\n \"logarithm 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) logarithm value = \r\n(1.6836479149932368+0.3805063771123649j)<\/pre>\n
2)With two arguments<\/h5>\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# Give the base value as user input using the float(input()) function and\r\n# store it in another variable.\r\ngvn_basevalu = float(input(\"Enter some random number = \"))\r\n# Pass the given complex number, base value as the arguments to the cmath.log()\r\n# method that returns the given complex number's logarithm value for\r\n# the given base.\r\n# Store it in another variable.\r\nrslt = cmath.log(complexnumb, gvn_basevalu)\r\n# Print the logarithm value of the given complex number for the given base.\r\nprint(\"The given complex number's\", complexnumb,\r\n \"logarithm value for the given base{\", gvn_basevalu, \"} = \")\r\nprint(rslt)\r\n<\/pre>\n
Enter real part and complex part of the complex number = 5 2\r\nEnter some random number = 4\r\nThe given complex number's (5+2j) logarithm value for the given base{ 4.0 } = \r\n(1.214495248781893+0.27447733164331733j)<\/pre>\n