import numpy as np
import matplotlib.pyplot as plt
# 定义双变量函数
def func(X):
x1, x2 = X
return (x1-3.14)**2 + (x2-2.72)**2 + np.sin(4*x1+1.41) - np.cos(4*x2-1.73)
# 生成双变量网格点
x = np.arange(10).reshape(-1, 1)
x1, x2 = np.meshgrid(x, x)
# 求解
y = np.asarray([func((x1.flatten()[i], x2.flatten()[i])) for i in range(100)]).reshape(10, 10)
# 绘图
fig = plt.figure(dpi=300, figsize=(6, 4))
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x1, x2, y, cmap='jet', antialiased=True)



