%matplotlib inline
from pylab import *
def elliptic_ysquared(x, a, b):
return x**3 + a * x + b
x = linspace(-4, 4, 1000)
def plot_ellipse(a, b):
ysq = elliptic_ysquared(x, a, b)
plot(x, sqrt(ysq))
plot(x, -sqrt(ysq))
ylim(-10, 10)
xlim(-4, 4)
from IPython.html.widgets import interact
interact(plot_ellipse,
a=(-10, 10),
b=(-20, 20))
def perfract(x, t, m, M):
x=x/t
return m+(M-m)*(x-np.floor(x))
def domaincol_co(w,s):
H=Hcomplex(w)
m=0.7 # brightness is restricted to [0.7,1]; interval suggested by E Wegert
M=1
n=15 # n=number of isochromatic lines per cycle
isol=perfract(H, 1.0/n, m, M) # isochromatic lines
modul=np.absolute(w)
Logm=np.log(modul)
Logm=np.nan_to_num(Logm)
modc=perfract(Logm, 2*np.pi/n, m, M)# lines of constant log-modulus
V=modc*isol
S = 0.9*np.ones_like(H, float)
HSV = np.dstack((H,S,V))
RGB = hsv_to_rgb(HSV)
return RGB
def plot_domain(color_func, f, re=[-1,1], im= [-1,1], Title='',
s=0.9, N=200, daxis=None):
w=func_vals(f, re, im, N)
domc=color_func(w, s)
plt.xlabel("$\Re(z)$")
plt.ylabel("$\Im(z)$")
plt.title(Title)
if(daxis):
plt.imshow(domc, origin="lower", extent=[re[0], re[1], im[0], im[1]])
else:
plt.imshow(domc, origin="lower")
plt.axis('off')
def func_vals(f, re, im, N): #evaluates the complex function at the nodes of the grid
#re and im are tuples, re=(a,b) and im=(c,d), defining the rectangular region
#N is the number of nodes per unit interval
l=re[1]-re[0]
h=im[1]-im[0]
resL=N*l #horizontal resolution
resH=N*h#vertical resolution
x=np.linspace(re[0], re[1],resL)
y=np.linspace(im[0], im[1], resH)
x,y=np.meshgrid(x,y)
z=x+1j*y
w=f(z)
return w
def Hcomplex(z):# computes the hue corresponding to the complex number z
H=np.angle(z)/(2*np.pi)+1
return np.mod(H,1)
from matplotlib.colors import hsv_to_rgb
plt.rcParams['figure.figsize'] = 8, 5
ab=(-np.pi, np.pi)
cd=(-2,2)
f=lambda z: sqrt(z**3 - 3 * z + 3)
plot_domain(domaincol_co, f, re=ab, im=cd, Title='$f(z)=ctan(z)$', N=300, daxis=True)
def interactive_color(a, b):
plt.rcParams['figure.figsize'] = 8, 5
ab=(-np.pi, np.pi)
cd=(-2,2)
f=lambda z: sqrt(z**3 + a * z + b)
plot_domain(domaincol_co, f, re=ab, im=cd, Title='$f(z)=ctan(z)$', N=300, daxis=True)
interact(interactive_color,
a=(-10, 10),
b=(-10, 10))
for x in range(7):
for y in range(7):
if (x*x + y*y) % 7 == 1:
print(x, y)
0 1 0 6 1 0 2 2 2 5 5 2 5 5 6 0
class F7:
def __init__(self, x):
self.int = x%7
def __str__(self):
return str(self.int)
__repr__ = __str__
F7.__eq__ = lambda a,b: a.int==b.int
F7.__add__
F7.__sub__
F6.__mul__
The companion website: http://ecchacks.cr.yp.to/.