I have to implement a class called ComplexNumbers
which is representing a complex number and I'm not allowed to use the built in types for that.
I already have overwritten the operators (__add__
, __sub__
, __mul__
, __abs__
, __str_
which allows to perform basic operations.
But now I'm stuck with overwriting the __div__
operator.
Allowed to use:
I'm using float
to represent the imaginary part of the number and float
to represent the rel part.
What I have already tried:
- I looked up how to perform a division of complex numbers (handwritten)
- I have done an example calculation
- Thought about how to implement it programatically without any good result
Explanation of how to divide complex numbers:
http://www.mathwarehouse.com/algebra/complex-number/divide/how-to-divide-complex-numbers.php
My implementation of multiply:
def __mul__(self, other):
real = (self.re * other.re - self.im * other.im)
imag = (self.re * other.im + other.re * self.im)
return ComplexNumber(real, imag)
int
? – Tamishatammafloat
the type of the imaginary part isint
– Louvarint
? – Antenatalfloat
– Louvar(x+yi)/z
to(x/z) + ((y/z)i)
– Tamishatamma