import sympy # 引入解方程的专业模块sympy
x,y,z = sympy.symbols("x y z") # 申明未知数"x"和"y"
a = sympy.solve([(x**2 + 9/4*y**2 + z**2 - 1)**3 -x**2 * z**3 - 9/80 * y**2 * z**3],x-1,y-6,[x,y,z]) # 写入需要解的方程组
print(a)

TypeError Traceback (most recent call last)
in ()
1 import sympy # 引入解方程的专业模块sympy
2 x,y,z = sympy.symbols("x y z") # 申明未知数"x"和"y"
----> 3 a = sympy.solve([(x**2 + 9/4*y**2 + z**2 - 1)**3 -x**2 * z**3 - 9/80 * y**2 * z**3],x-1,y-6,[x,y,z]) # 写入需要解的方程组
4 print(a)

D:\Anaconda3\lib\site-packages\sympy\solvers\solvers.py in solve(f, symbols, **flags)
895 exclude = [exclude]
896 exclude = set().union(
[e.free_symbols for e in sympify(exclude)])
--> 897 symbols = [s for s in symbols if s not in exclude]
898
899 # real/imag handling -----------------------------

D:\Anaconda3\lib\site-packages\sympy\solvers\solvers.py in (.0)
895 exclude = [exclude]
896 exclude = set().union(*[e.free_symbols for e in sympify(exclude)])
--> 897 symbols = [s for s in symbols if s not in exclude]
898
899 # real/imag handling -----------------------------

TypeError: unhashable type: 'list'

1个回答

``````import numpy as np
import matplotlib.pyplot as plt
import math
import mpl_toolkits.mplot3d
import sympy as sympy

def solvez(x, y):
z = sympy.symbols('z')
result = 0.0
try:
result = float(sympy.solve((x**2+9/4*y**2+z**2-1)**3-x**2*z**3-9/80*y**2*z**3, z)[0].evalf())
except TypeError as e:
pass
return result

fig = plt.figure()  #定义新的三维坐标轴
ax3 = plt.axes(projection='3d')

#定义三维数据
xx = np.arange(-2,2,0.1)
yy = np.arange(-2,2,0.1)
X, Y = np.meshgrid(xx, yy)

Z = np.zeros((len(X), len(Y)), dtype=float)

for i in range(0,len(X)):
for j in range(0,len(Y)):
Z[i][j] = solvez(X[i][j],Y[i][j])

#作图
ax3.plot_surface(X,Y,Z,cmap='rainbow')
#ax3.contour(X,Y,Z, zdim='z',offset=-2，cmap='rainbow)   #等高线图，要设置offset，为Z的最小值
plt.show()
``````

JonathanYan 回复请你们大家多多姿瓷我菠菜菌: 我知道
4 个月之前 回复

4 个月之前 回复

4 个月之前 回复