Skip to main content

No project description provided

Project description

complexNumbers

Use complex numbers in python.

1 Initial Complex

z = Complex(value)

value can be 5 different datatypes:

  • int
  • float
  • complex
  • str
  • Complex

1.1 int, float

They are used when a real number should be become a complex number. (no imaginary part)

1.2 complex

Standard complex numbers also can be initialed. (e.g.: 1+1j)

1.3 str

With a string there can be entered complex numbers in the cartesian and polar form.

1.3.1 cartesian form

should be entered like this: "x+yj"

1.3.2 polar form

Modulus and argument are separated by e^. (e.g.: 1e^1)

1.4 Complex

Value can also be the same type as the own class.

2 Variables

The class has following __self__ variables.

  • real: real part of the cartesian form
  • imaginary: imaginary part of the cartesian form
  • modulus: modulus of the polar form
  • argument: argument of the polar form in the range [0; 2Pi[

3 Methods

The class can be used with the following methods:

  • __add__ , __radd__ , __iadd__ equals + , +=
  • __sub__ , __rsub__ , __isub__ equals - , -=
  • __mul__ , __rmul__ , __imul__ equals * , *=
  • __truediv__ , __rtruediv__ , __itruediv__ equals / , /=
  • __pow__ equals ** ATTENTION: only real numbers can be used as power and when used to get a root only one solution returns.
  • __eq__ equals ==
  • __ne__ equals !=
  • __abs__ equals abs() returns the modulus
  • __str__ equals str() returns the number in cartesian form (e.g.: "1+1j")
  • root(n) returns a list with all possible roots of the complex number. n is the power of the root (e.g.: n = 2 ... square root)

4 Example

>>> a = Complex("1+1j")
>>> b = Complex("1e^1")
>>> print(a.modulus)
1.4142135623730951
>>> print(a.argument)
0.7853981633974483
>>> print(b.real)
0.5403023058681398
>>> print(b.imaginary)
0.8414709848078965
>>> print(a+b)
1.5403023058681398+1.8414709848078965j
>>> print(a-b)
0.45969769413186023+0.1585290151921035j
>>> print(a*b)
-0.30116867893975674+1.3817732906760363j
>>> print(a/b)
1.3817732906760363-0.30116867893975674j
>>> print(a**2)
1.2246467991473535e-16+2.0000000000000004j
>>> print(b**0.5)
0.8775825618903728+0.479425538604203j
>>> print(b.root())
[0.8775825618903728+0.479425538604203j, -0.8775825618903728-0.4794255386042029j]
>>> print(abs(b)
1.0
>>> print(a == a)
True
>>> print(a != b)
True

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

complexNumbers-0.0.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

complexNumbers-0.0.1-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file complexNumbers-0.0.1.tar.gz.

File metadata

  • Download URL: complexNumbers-0.0.1.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for complexNumbers-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4eb71a47bd13571354b091895e75c6bf5c79dd157ee9610197ba1235df3f1cc9
MD5 217a83dfde0beb6ee7d9b684b4a1c3f3
BLAKE2b-256 36f84278091eeaf0c3998372992f2fe20dde4438bb7cb42c788a74f20f633279

See more details on using hashes here.

File details

Details for the file complexNumbers-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: complexNumbers-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for complexNumbers-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 534e2efa5a862bfbb72d3d656838d234c3fd6b36f3e4bd40cc632f6b02c33e16
MD5 751bea3cb71aee01a6b5144eb6e8ab63
BLAKE2b-256 e3a42e1543a02c7130df82a95908633adb2a3cf98ecc130c1ce6214744ec0254

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page