Skip to content

Commit 172914c

Browse files
committed
Complex: Added phase and amplitude methods
1 parent da7e4f8 commit 172914c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

2019/complex_utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Small library for complex numbers
33
"""
4-
from math import sqrt
4+
from math import sqrt, atan2
55

66

77
class ReturnTypeWrapper(type):
@@ -51,6 +51,12 @@ def __add__(self, no):
5151
def __sub__(self, no):
5252
return SuperComplex(self.real - no.real, self.imag - no.imag)
5353

54+
def phase(self):
55+
return atan2(self.imag, self.real)
56+
57+
def amplitude(self):
58+
return sqrt(self.imag ** 2 + self.real ** 2)
59+
5460

5561
j = SuperComplex(1j)
5662

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy