2.5 分别画出下列二次曲面

点击查看代码
import numpy as np  
import matplotlib.pyplot as plt  
from mpl_toolkits.mplot3d import Axes3D  
  
# 定义参数u和v  
u = np.linspace(-2, 2, 400)  
v = np.linspace(0, 2 * np.pi, 400)  
U, V = np.meshgrid(u, v)  
  
# 根据参数方程计算x, y, z  
x = np.sqrt(1 + U**2 + V**2) * np.cos(V)  
y = np.sqrt(1 + U**2 + V**2) * np.sin(V)  
z = U  
  
# 创建图形和坐标轴  
fig = plt.figure()  
ax = fig.add_subplot(111, projection='3d')  
  
# 绘制曲面  
ax.plot_surface(x, y, z, cmap='viridis', edgecolor='none')  
  
# 设置坐标轴标签  
ax.set_xlabel('X')  
ax.set_ylabel('Y')  
ax.set_zlabel('Z')  
  
# 显示图形  
plt.show()
 
print("学号:3004")


import numpy as np  
import matplotlib.pyplot as plt  
from mpl_toolkits.mplot3d import Axes3D  
  
# 定义参数u和v  
u = np.linspace(-2, 2, 400)  
v = np.linspace(-2, 2, 400)  
U, V = np.meshgrid(u, v)  
  
# 根据方程计算x, y, z  
X, Y = U, V  
Z = X**2 + Y**2  
  
# 创建图形和坐标轴  
fig = plt.figure()  
ax = fig.add_subplot(111, projection='3d')  
  
# 绘制曲面  
ax.plot_surface(X, Y, Z, cmap='viridis', edgecolor='none')  
  
# 设置坐标轴标签  
ax.set_xlabel('X')  
ax.set_ylabel('Y')  
ax.set_zlabel('Z')  
  
# 显示图形  
plt.show()
 
print("学号:3004")

posted on 2024-09-06 16:30  黄元元  阅读(36)  评论(0编辑  收藏  举报