python實現:目標優化演算法——遺傳演算法

zhu_weiquan發表於2018-01-22
#### 簡單案例:


max f (x1, x2) = 21.5 + x1·sin(4 pi x1) + x2·sin(20 pi x2)
s. t.      -3.0 <= x1 <= 12.1
            4.1 <= x2 <= 5.8

from matplotlib import pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D


fig = plt.figure()
ax = Axes3D(fig)
X,Y = np.mgrid[-3:12.1:20j,4.1:5.8:20j]
Z = 21.5 + X * np.sin(4 * np.pi * X) + Y * np.sin(20 * np.pi * Y)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='rainbow')
plt.show()




python畫三維圖

相關文章