python中fsolve的使用

求解线性方程组的函数fsolve的使用遇到了问题

res = fsolve(lambda x: ((12.1 + 3) / 0.0001 - 2 ** x + 1), 30)
>>> res
array([17.20419858])

**问题1:这句代码是求解(12.1+3)/0.0001-2x + 1 = 30的x值的意思么?
**

>>> res = fsolve(lambda x: ((12.1 + 3) / 0.0001 - 2 ** x + 1), 0)
D:\anaconda\lib\site-packages\scipy\optimize\minpack.py:162: RuntimeWarning: The iteration is not making good progress, as measured by the
  improvement from the last ten iterations.
  warnings.warn(msg, RuntimeWarning)
>>> res = fsolve(lambda x: ((12.1 + 3) / 0.0001 - 2 ** x + 1), 10)
>>> res
array([10.])
>>> res = fsolve(lambda x: ((12.1 + 3) / 0.0001 - 2 ** x + 1), 20)
>>> res
array([17.20419858])
>>> res = fsolve(lambda x: ((12.1 + 3) / 0.0001 - 2 ** x + 1), 15)
>>> res
array([17.20419858])
>>> res = fsolve(lambda x: ((12.1 + 3) / 0.0001 - 2 ** x + 1), 10)
>>> res
array([10.])
>>> res = fsolve(lambda x: ((12.1 + 3) / 0.0001 - 2 ** x + 1), 9)
>>> res
array([9.])
>>> res = fsolve(lambda x: ((12.1 + 3) / 0.0001 - 2 ** x + 1), [0])
>>>
>>> res
array([0.])

问题2:为什么将30替换为0会报错?

问题3:为什么将30替换为[0]不会报错,但输出为0?这个结果应该不是方程(12.1+3)/0.0001-2x + 1 = 0的解

问题4:为什么30替换为14,20,输出结果是正确的,替换为10,9,等就出现了问题

问题5:这句代码res = fsolve(lambda x: ((12.1 + 3) / 0.0001 - 2 *x + 1), 30)可以用来求解-3到12.1内的实数转化为二进制数的位数(精度为0.0001)么?为什么用30,可以替换为其他数么?

我查了关于fsolve函数的使用,还是没太明白

你好,我最近也遇到这个问题了,目前已经解决了,现在写下我的个人理解:
最基本的fsolve使用方法就不说了,主要说为什么是30(其他也行,但是要注意,影响结果),这个代码应该是遗传算法里面求解染色体长度的,使用的二进制表示,要求是在[-3,12,.1],精度0.0001,想要实现这样的要求需要2^17< (12.1+3)/0.0001 <2^18,使用fsolve解出(12.1 + 3) / 0.0001 - 2 ** x + 1=0的x就行了。至于设置为30,个人理解是你设定的初始值要比实际求出的大(30>18),不然没法求出正确的值,不然初始值为6,那结果就是6,初始值是2,结果就是2。
(个人理解,并不深刻)

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 以帮助更多的人 ^-^