import numpy
from scipy.optimize import fsolve
def f(x, y, z):
#y = [1,1,3,3,5,5] 是個list
#z = [你要傳的那些東西]
x = map( float, x )
x,y,z = map(numpy.array, (x,y,z) )
a,b,c,d,e,f = x
p1 = numpy.array( [a,d,a,d,a,d] )
p2 = numpy.array( [b,e,b,e,b,e] )
p3 = numpy.array( [c,f,c,f,c,f] )
return list( y*p1 + y*p2 + p3 - z )
result = fsolve(f, [0,0,0,0,0,0])
沒跑過
參考一下吧
※ 引述《diesnow (0 0)》之銘言:
: 請問用Fslove中要解近似值~
: 其中的
: 1,1,3,3,5,5
: -10,-19,-26,-41,42,-63
: 這些想改成可以由外部傳遞進去
: 要怎麼傳才好Orz 感謝
: 一樣是求a,b,c,d,e,f
: from scipy.optimize import fsolve
: def f(x):
: a = float(x[0])
: print(x[0])
: b = float(x[1])
: c = float(x[2])
: d = float(x[3])
: e = float(x[4])
: f = float(x[5])
: return [
: 1*a+1*b+c-10,
: 1*d+1*e+f-19,
: 3*a+3*b+c-26,
: 3*d+3*e+f-41,
: 5*a+5*b+c-42,
: 5*d+5*e+f-63
: ]
: result = fsolve(f, [0,0,0,0,0,0])