Python fsolve()抱怨形状。为什么?
发布于 2021-01-29 14:59:28
具有函数f(x,y,z),我需要求解约束f(x,y,z)= 0,然后对其进行绘制。我试图为每对(y,z)查找f(x,y,z)= 0的值x:
from numpy import *
from scipy.optimize import fsolve
def func(x,y,z):
return x+y+z
y = linspace(0,1,100)
z = linspace(0,1,100)
x0 = zeros((y.size,z.size)) + 0.5 # the initial guess
yz = (y[:,newaxis],z[newaxis,:]) # the other parameters
x, info, iterations, message = fsolve(func,x0,yz)
contour(y,z,x)
Python(2.7.5)说“ TypeError:fsolve:’func’参数’func’的输入和输出形状不匹配。”
但是,如果我自己进行测试,它会具有相同的形状:
func(x0,y[:,newaxis],z[:,newaxis]).shape == x0.shape
返回True。
为什么fsolve()抱怨?
关注者
0
被浏览
58
1 个回答