25 lines
617 B
Python
25 lines
617 B
Python
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
|
|
def eggholder(x):
|
|
return (-(x[1] + 47) * np.sin(np.sqrt(abs(x[0]/2 + (x[1] + 47))))
|
|
-x[0] * np.sin(np.sqrt(abs(x[0] - (x[1] + 47)))))
|
|
|
|
bounds = [(-512, 512), (-512, 512)]
|
|
|
|
x = np.arange(-512, 513)
|
|
y = np.arange(-512, 513)
|
|
xgrid, ygrid = np.meshgrid(x, y)
|
|
xy = np.stack([xgrid, ygrid])
|
|
|
|
fig = plt.figure(figsize=(6, 4))
|
|
ax = fig.add_subplot(111, projection='3d')
|
|
ax.view_init(45, -45)
|
|
ax.plot_surface(xgrid, ygrid, eggholder(xy), cmap='terrain')
|
|
ax.set_xlabel('x')
|
|
ax.set_ylabel('y')
|
|
ax.set_zlabel('eggholder(x, y)')
|
|
|
|
fig.tight_layout()
|
|
plt.show()
|