🛠️ToolsShed

Kalkulator Bilangan Kompleks

Lakukan operasi aritmatika pada bilangan kompleks dan konversi antara bentuk persegi panjang dan kutub.

A = a + bi

B = a + bi

Pertanyaan yang Sering Diajukan

Implementasi Kode

import cmath
import math

# Create complex numbers
z1 = 3 + 4j
z2 = 1 - 2j

# Arithmetic
print(z1 + z2)   # (4+2j)
print(z1 - z2)   # (2+6j)
print(z1 * z2)   # (11-2j)
print(z1 / z2)   # (-1+2j)

# Properties
print(z1.real)   # 3.0
print(z1.imag)   # 4.0
print(abs(z1))   # 5.0  (modulus)
print(z1.conjugate())  # (3-4j)

# Polar form
r, theta = cmath.polar(z1)
print(f"r={r:.3f}, theta={math.degrees(theta):.2f}°")
# r=5.000, theta=53.13°

# From polar back to rectangular
z_back = cmath.rect(r, theta)
print(z_back)  # (3+4j)

# Complex math functions
print(cmath.exp(1j * math.pi))  # Euler: e^(i*pi) ≈ -1+0j
print(cmath.sqrt(-1))           # 1j
print(cmath.log(z1))            # complex logarithm

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.