[zurück]

2.6. Komplexe Zahlen

[vor]

Mit dem Befehl dir lassen sich alle Funktionen des Moduls cmath anzeigen.

print(dir(math)) ['__doc__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atanh', 'cos', 'cosh', 'e', 'exp', 'isinf', 'isnan', 'log', 'log10', 'phase', 'pi', 'polar', 'rect', 'sin', 'sinh', 'sqrt', 'tan', 'tanh']

Komplexe Zahlen erzeugen

print(3+4j) (3+4j)
print(complex(3, 4)) (3+4j)

Real- und Imaginärteil

print(complex(3, 4).real) 3.0
print(complex(3, 4).imag) 4.0

Konjugiert komplexe Zahl

print(complex(3, 4).conjugate()) (3-4j)

phase(x)

print(cmath.phase(complex(1, 1))) 0.785398163397
print(math.atan2(1, 1)) 0.785398163397
print(cmath.phase(complex(2, 1))) 0.463647609001
print(math.atan2(1, 2)) 0.463647609001
print(cmath.phase(complex(-1.0, 0.0))) 3.14159265359
print(cmath.phase(complex(-1.0, -0.0))) -3.14159265359

polar(x)

print(cmath.polar(complex(1, 0))) (1.0, 0.0)
print(cmath.polar(complex(1, 1))) (1.4142135623730951, 0.78539816339744828)
print(cmath.polar(complex(0, 1))) (1.0, 1.5707963267948966)
print(cmath.polar(complex(-1, 1))) (1.4142135623730951, 2.3561944901923448)
print(cmath.polar(complex(-1, 0))) (1.0, 3.1415926535897931)
print(cmath.polar(complex(-1, -1))) (1.4142135623730951, -2.3561944901923448)
print(cmath.polar(complex(0, -1))) (1.0, -1.5707963267948966)
print(cmath.polar(complex(1, -1))) (1.4142135623730951, -0.78539816339744828)

polar(x) in Grad

print(str(cmath.polar(complex(1, 0))[0])+" "+str(math.degrees(cmath.polar(complex(1, 0))[1]))+"°") 1.0 0.0°
print(str(cmath.polar(complex(1, 1))[0])+" "+str(math.degrees(cmath.polar(complex(1, 1))[1]))+"°") 1.41421356237 45.0°
print(str(cmath.polar(complex(0, 1))[0])+" "+str(math.degrees(cmath.polar(complex(0, 1))[1]))+"°") 1.0 90.0°
print(str(cmath.polar(complex(-1, 1))[0])+" "+str(math.degrees(cmath.polar(complex(-1, 1))[1]))+"°") 1.41421356237 135.0°
print(str(cmath.polar(complex(-1, 0))[0])+" "+str(math.degrees(cmath.polar(complex(-1, 0))[1]))+"°") 1.0 180.0°
print(str(cmath.polar(complex(-1, -1))[0])+" "+str(math.degrees(cmath.polar(complex(-1, -1))[1]))+"°") 1.41421356237 -135.0°
print(str(cmath.polar(complex(0, -1))[0])+" "+str(math.degrees(cmath.polar(complex(0, -1))[1]))+"°") 1.0 -90.0°
print(str(cmath.polar(complex(1, -1))[0])+" "+str(math.degrees(cmath.polar(complex(1, -1))[1]))+"°") 1.41421356237 -45.0°

print(cmath.polar(complex(1, 1))[0]) 1.41421356237
print(abs(complex(1, 1))) 1.41421356237
print(cmath.polar(complex(1, 1))[1]) 0.785398163397


[zurück] [Inhaltsverzeichnis] [vor]