[Tutor] Complex roots

Matt Williams matthew.williams at cancer.org.uk
Thu Dec 9 12:52:15 CET 2004


Further to my previous post, please find some code below:

Hope this helps,
Matt

#Complex number Roots
#Matt Williams 9.12.04

import math

number=complex(0.5,0)
n=float(3)

size=math.sqrt((number.real**2)+(number.imag**2))


arg=math.radians(360/n)

root=1/n

modulus=size**root

theta=float(0)
roots={}
i=0
while i<n:
    y=round(modulus*(math.sin(theta)),3)
    x=round(modulus*(math.cos(theta)),3)
    roots[i]=(x,y)
    theta=theta+arg
    i=i+1

print roots



More information about the Tutor mailing list