Skip to content

Instantly share code, notes, and snippets.

@fernandolopez
Created September 23, 2012 01:53
Show Gist options
  • Save fernandolopez/3768514 to your computer and use it in GitHub Desktop.
Save fernandolopez/3768514 to your computer and use it in GitHub Desktop.
para mate4
from pylab import *
import cmath
ion()
def zroots(k, z):
roots = []
theta = arctan2(z.imag, z.real)
modroot = abs(z)**(1.0/k)
for i in range(k):
real = modroot * cos(float(theta+2*i*pi)/k)
imag = modroot * sin(float(theta+2*i*pi)/k)
roots.append(complex(real, imag))
return roots
def polarplot(zs):
polar()
for z in zs:
p = cmath.polar(z)
plot((0,p[1]), (0,p[0]))
def rootandplot(k, z):
clf()
zs = zroots(k, z)
zs.insert(0, z)
polarplot(zs)
titles = ["k=" + str(i) for i in range(k)]
titles.insert(0, str(z))
legend(titles)
def funcplot(func, args, *opts, **kopts):
ys = []
for arg in args:
ys.append(func(arg))
plot(args, ys, *opts, **kopts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment