使用fsolve在python中求解隐式方程

问题描述

我想写一个程序来求 Q,y,b,x,S0 的值,然后从下图中找到 n 的值

enter image description here

我用 f solve 来写这段代码

from scipy.optimize import fsolve
def f(n,Q=float(input("Q=")),y=float(input("y=")),b=float(input("b=")),x=float(input("x=")),S_0=float(input("S0="))):
    return (1/n)*((y*(b+x*y))**(5/3))/((b+2*y*(1+x**2)**(1/2))**(2/3))*S_0-Q
a=fsolve(f,1)
print(a)
print(f(a))

但它给出了一个错误的结果作为我在这里输入的输出

Q=21
y=7.645
b=2
x=1
S0=0.002
/usr/lib/python3/dist-packages/scipy/optimize/minpack.py:236: RuntimeWarning: The iteration is not making good progress,as measured by the 
  improvement from the last ten iterations.
  warnings.warn(msg,RuntimeWarning)
[ 1.]
[-20.68503025]

我在 Online Python 中写了这个。我不知道这个错误是什么意思。输出也是错误的。对于此特定输入,答案应为 n=0.015。我该如何修复此代码

解决方法

我重新排列了您的等式,这以某种方式得到了您的预期结果。我真的不太确定是什么问题,抱歉!

    return (S_0/Q)*((y*(b+x*y))**(5/3)/(b+2*y*(1+x**2)**(1/2))**(2/3))-n