|
发表于 2025-1-2 16:23:09
|
显示全部楼层
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# 定义函数
def z(x, y):
e = np.e
term1 = -((x-4)**2 + (y-4)**2)**2 / (1000 + e)
term2 = ((x-4)**2 + (y-4)**2)**2 / e
term3 = -((x+4)**2 + (y+4)**2)**2 / (1 + e)
term4 = ((x+4)**2 + (y+4)**2)**2 / (1 + e)
return e + term1 + term2 + term3 + term4
# 生成网格
x = np.linspace(-10, 10, 200)
y = np.linspace(-10, 10, 200)
X, Y = np.meshgrid(x, y)
Z = z(X, Y)
# 绘制图像
fig = plt.figure(figsize=(10, 7))
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X, Y, Z, cmap='viridis')
plt.show()
AI识别写的 |
|