美文网首页
python实现:目标优化算法——遗传算法

python实现:目标优化算法——遗传算法

作者: Weiquan_ | 来源:发表于2018-01-21 00:24 被阅读0次

简单案例:

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画三维图

3维图

相关文章

网友评论

      本文标题:python实现:目标优化算法——遗传算法

      本文链接:https://www.haomeiwen.com/subject/rmpxaxtx.html