Skip to main content

Python cmath Module

 

Python cmath Module


Python cmath Module

Python has a built-in module that you can use for mathematical tasks for complex numbers.

The methods in this module accepts intfloat, and complex numbers. It even accepts Python objects that has a __complex__() or __float__() method.

The methods in this module almost always return a complex number. If the return value can be expressed as a real number, the return value has an imaginary part of 0.

The cmath module has a set of methods and constants.


cMath Methods

MethodDescription
cmath.acos(x)Returns the arc cosine value of x
cmath.acosh(x)Returns the hyperbolic arc cosine of x
cmath.asin(x)Returns the arc sine of x
cmath.asinh(x)Returns the hyperbolic arc sine of x
cmath.atan(x)Returns the arc tangent value of x
cmath.atanh(x)Returns the hyperbolic arctangent value of x
cmath.cos(x)Returns the cosine of x
cmath.cosh(x)Returns the hyperbolic cosine of x
cmath.exp(x)Returns the value of Ex, where E is Euler's number (approximately 2.718281...), and x is the number passed to it
cmath.isclose()Checks whether two values are close, or not
cmath.isfinite(x)Checks whether x is a finite number
cmath.isinf(x)Check whether x is a positive or negative infinty
cmath.isnan(x)Checks whether x is NaN (not a number)
cmath.log(x[, base])Returns the logarithm of x to the base
cmath.log10(x)Returns the base-10 logarithm of x
cmath.phase()Return the phase of a complex number
cmath.polar()Convert a complex number to polar coordinates
cmath.rect()Convert polar coordinates to rectangular form
cmath.sin(x)Returns the sine of x
cmath.sinh(x)Returns the hyperbolic sine of x
cmath.sqrt(x)Returns the square root of x
cmath.tan(x)Returns the tangent of x
cmath.tanh(x)Returns the hyperbolic tangent of x

cMath Constants

ConstantDescription
cmath.eReturns Euler's number (2.7182...)
cmath.infReturns a floating-point positive infinity value
cmath.infjReturns a complex infinity value
cmath.nanReturns floating-point NaN (Not a Number) value
cmath.nanjReturns coplext NaN (Not a Number) value
cmath.piReturns PI (3.1415...)
cmath.tauReturns tau (6.2831...)

Comments

Popular posts from this blog

Python Modules

  Python  Modules What is a Module? Consider a module to be the same as a code library. A file containing a set of functions you want to include in your application. Create a Module To create a module just save the code you want in a file with the file extension  .py : Example Save this code in a file named  mymodule.py def  greeting(name):    print ( "Hello, "  + name) Use a Module Now we can use the module we just created, by using the  import  statement: Example Import the module named mymodule, and call the greeting function: import  mymodule mymodule.greeting( "Jonathan" ) Note:  When using a function from a module, use the syntax:  module_name.function_name . Variables in Module The module can contain functions, as already described, but also variables of all types (arrays, dictionaries, objects etc): Example Save this code in the file  mymodule.py person1 = {    "name" :  "John" ,    "age" :  36 ,    "country" :  "

Python Getting Started

  Python  Getting Started Python Install Many PCs and Macs will have python already installed. To check if you have python installed on a Windows PC, search in the start bar for Python or run the following on the Command Line (cmd.exe): C:\Users\ Your Name >python --version To check if you have python installed on a Linux or Mac, then on linux open the command line or on Mac open the Terminal and type: python --version If you find that you do not have python installed on your computer, then you can download it for free from the following website:  https://www.python.org/ Python Quickstart Python is an interpreted programming language, this means that as a developer you write Python (.py) files in a text editor and then put those files into the python interpreter to be executed. The way to run a python file is like this on the command line: C:\Users\ Your Name >python helloworld.py Where "helloworld.py" is the name of your python file. Let's write our first Python fi

Python Introduction

  Python  Introduction What is Python? Python is a popular programming language. It was created by Guido van Rossum, and released in 1991. It is used for: web development (server-side), software development, mathematics, system scripting. What can Python do? Python can be used on a server to create web applications. Python can be used alongside software to create workflows. Python can connect to database systems. It can also read and modify files. Python can be used to handle big data and perform complex mathematics. Python can be used for rapid prototyping, or for production-ready software development. Why Python? Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc). Python has a simple syntax similar to the English language. Python has syntax that allows developers to write programs with fewer lines than some other programming languages. Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that prototypin