-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprogram31.py
More file actions
36 lines (31 loc) · 791 Bytes
/
program31.py
File metadata and controls
36 lines (31 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Spectral methods in MATLAB. Lloyd
Program 31
"""
# Gamma function via complex integral, trapezoid rule
from numpy import *
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import axes3d
N = 70
theta = -pi + (2*pi/N)*arange(0.5,N)
c = -11
r = 16
x = arange(-3.5,4.1,0.1)
y = arange(-2.5,2.6,0.1)
[xx,yy] = meshgrid(x,y)
zz = xx +1j*yy
gaminv = 0*zz
for i in range(0,N):
t = c + r*exp(1j*theta[i])
gaminv = gaminv + exp(t)*t**(-zz)*(t-c)
gaminv = gaminv/N
gam = 1./gaminv
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_surface(xx, yy, abs(gam), rstride=1, cstride=1, cmap="coolwarm", alpha=0.3)
ax.set_xlabel('Re(z)')
ax.set_ylabel('Im(z)')
ax.set_xlim(-3.5, 4)
ax.set_ylim(-2.5, 2.5)
ax.set_zlim(0, 6)
plt.show()