我想播种一个隐式函数,它包含幂函数,并且索引存在小数。
我尝试通过scipy解决此问题,但是它告诉我电源中遇到的无效值,并且我尝试通过sympy解决它,但是无论我等待多长时间,它都无法输出答案。
这是隐式函数 https://imgur.com/o00dQYE
#####using scipy
from scipy.optimize import fsolve
import numpy as np
global Ccu, Czn, EC50Cu, EC50Zn, bCu, bZn
Ccu = 1
Czn = 1
EC50Cu = 0.000419
bCu = 0.2388
EC50Zn = 0.9319
bZn = 0.50946
def fomula(a):
# return Ccu/(EC50Cu * (((100-RRE)/RRE)**(1/bCu))) - 1
return Ccu/EC50Cu + Czn/EC50Zn * a ** (1/bCu-1/bZn) - a ** (1/bCu)
a = fsolve(fomula, 0)
print(a)
#####using sympy
from sympy import *
from sympy.parsing.sympy_parser import parse_expr
EC50Cu = 0.000419
bCu = 0.2388
EC50Zn = 0.9319
bZn = 0.50946
Ccu = 1
Czn = 1
x = Symbol('x')
s = solve(Ccu/EC50Cu + Czn/EC50Zn * x ** (1/bCu-1/bZn) - x ** (1/bCu),x)
print(N(s[0],10))
答案 0 :(得分:0)
import numpy as np
# input
Ccu,Czn = 1,1
EC50Cu = 0.000419
bCu = 0.2388
EC50Zn = 0.9319
bZn = 0.50946
# accuracy
acc = 0.001
for i in np.arange(1,99,acc):
RRE = i
a=Ccu/(EC50Cu * (((100-RRE)/RRE)**(1/bCu))) + Czn/(EC50Zn * (((100-RRE)/RRE)**(1/bZn)))
if (a-1)>-acc and (a-1)<acc:
print(i,a)
我知道RRE的范围,所以我只是遍历范围,并根据需要过滤答案。
答案 1 :(得分:0)
当您需要数字答案时,请考虑使用..tit(->y<-)ById
,但您需要进行初步猜测...而且某些功能对此比其他功能更敏感。但是您可以使用SymPy探索该功能:
nsolve
所以看起来根在6到8之间:
>>> eq = Ccu/EC50Cu + Czn/EC50Zn * x ** (1/bCu-1/bZn) - x ** (1/bCu)
>>> [(i, eq.subs(x,i).n(2)) for i in range(0,10,2)]
[(0, 2.4e+3), (2, 2.4e+3), (4, 2.1e+3), (6, 6.3e+2), (8, -3.6e+3)]