多元函数连续

这段代码展示了如何利用Python的numpy和matplotlib库创建3D图形。用户可以输入x轴和y轴的长度以及x和y的幂指数,程序会生成一个基于给定数学模型(z=sqrt(x^n1+y^n2))的3D图形,并允许自定义坐标轴标签和标题。
摘要由CSDN通过智能技术生成

在这里插入图片描述
下面展示一些 内联代码片

import numpy as np

import matplotlib.pyplot as plt


fig=plt.figure()

ax = fig.add_subplot(111, projection='3d')

print("Welcometo use 3D graphic generator, the formula model is z=sqrt(x^n1+y^n2).\n")

a1=input("pleaseenter x axis length value(x),actual display range is from - x to x:\n")

a1=float(a1)

print("Thex axis actual display range is from - "+str(a1)+" to"+str(a1)+":\n")

a2=input("pleaseenter y axis length value(y),actual display range is from - y to y:\n")

a2=float(a2)

print("They axis actual display range is from - "+str(a2)+" to"+str(a2)+":\n")

a3=input("pleaseenter n power number of x value:(please enter an integer)\n")

a3=int(a3)

print("The power number of x value is "+str(a3)+".\n")

a4=input("pleaseenter n power number of y value:(please enter an integer)\n")

a4=int(a4)

print("Thepower number of y value is "+str(a4)+".\n")

X=np.arange(-a1,a1,0.5)

Y=np.arange(-a2,a2,0.5)

X,Y=np.meshgrid(X,Y)

epsilon = 1e-15  # 设置一个极小值
Z = (X**2*Y)/(X**2+Y**2+epsilon)
ax.plot_surface(X,Y,Z,rstride=2,cstride=2,alpha=0.5,cmap=plt.cm.rainbow)

x1=input("pleaseenter x label name:\n")

x2=input("pleaseenter y label name:\n")

x3=input("pleaseenter z label name:\n")

x4=input("pleaseenter title label name:\n")

ax.set_xlabel(x1,fontsize=20)

ax.set_ylabel(x2,fontsize=20)

ax.set_zlabel(x3,fontsize=20)

ax.set_title(x4,fontsize=25)

ax.view_init(30,35)

b1=a1+4

b2=a2+4

cset=ax.contour(X,Y, Z, zdir = 'x', offset = -b1, cmap = plt.cm.hot)

cset=ax.contour(X,Y, Z, zdir = 'y', offset = -b2, cmap = plt.cm.hot)

cset=ax.contour(X,Y, Z, zdir = 'z', offset = -7, cmap = plt.cm.hot)

ax.set_xlim(-b1,b1)

ax.set_ylim(-b2,b2)

ax.set_zlim(-8,8)

plt.show()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值