Answer:
import cmath
import matplotlib.pyplot as plt
# Take register number as input
register_number = input("Enter your register number: ")
# Compute the sum of digits of the register number
n = sum(int(digit) for digit in register_number)
while n >= 10:
n = sum(int(digit) for digit in str(n))
# Find the nth roots of unity
roots = [cmath.exp(2j * cmath.pi * k / n) for k in range(n)]
# Convert roots to polar coordinates
r = [cmath.polar(root)[0] for root in roots]
theta = [cmath.polar(root)[1] for root in roots]
# Plot the roots in the polar coordinates
fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')
ax.plot(theta, r, 'o', markersize=10)
ax.set_rticks([0.5, 1, 1.5, 2]) # Customize the radial ticks
ax.set_rlabel_position(-22.5) # Offset radial labels from plotted line
ax.grid(True)
plt.title(f"{n}-th root of complex numbers in polar coordinates")
plt.show()
Sample Input & Output:
Enter your register number: 1848803
Output:
"Attached Below"
Step-by-step explanation:
Here is how the program works:
The user is prompted to enter their register number.
The program computes the sum of digits of the register number and reduces it to a single digit by iterating until the sum is less than 10.
The program finds the nth roots of unity using the cmath.exp function and a for loop.
The program converts the roots to polar coordinates using the cmath.polar function.
The program plots the roots in the polar coordinates using the matplotlib.pyplot module and its plot and subplot functions. It also customizes the radial ticks, radial label position, and adds a grid to the plot.