带有函数和 scipy 的多个参数

问题描述

以下代码需要使用 scipy 优化器针对 x 进行优化和最小化。 问题是它适用于单个参数,但当函数采用多个值时,它无法处理。

此代码运行良好。

from scipy.optimize import root
b = 1
def func(x):
    # result when x = 0,but result equation depends also on b value.
    result = x + b
    return  result

sol = root(func,0.1)
print(sol.x,sol.fun)

但这不起作用.....

b =[ 1,2,3,4,5]

def func(x,b):
    # result when x = 0,but result equation depends also on b value.
    result = x + b
    return  result

for B in b:
    sol = root(lambda x,B: func(x,B),0.1)
    print(sol.x,sol.fun)

如何通过b迭代得到结果?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)