我有4个输入变量(浮点数):
I have 4 input variables (floats):
最大 Xmin 百分比 模式 我想为s求解以下(相当长的)方程:
Xmax Xmin percentage mode and I want to solve the following (rather long) equation for s:
> (1/2+1/2*erf((log(Xmax)-(log(mode)+s**2))/(sqrt(2)*s))-(1/2+1/2*erf((log(Xmin)-(log(mode)+s**2))/(sqrt(2)*s))) - percentage == 0我想用sympy来求解方程,但是它返回一个ConditionSet对象(这意味着它不能求解方程)
I want to use sympy to solve the equation, but it returns a ConditionSet Object (meaning that it cannot solve the equation)
我的代码如下:
from sympy import * def CalcScaleParam(mode, CIfact, percentage): s = Symbol('s', Real=True) eqn = (1/2+1/2*erf((log(4)-(log(2)+s**2))/(sqrt(2)*s))-(1/2+1/2*erf((log(1)-(log(2)+s**2))/(sqrt(2)*s)))) - 0.95 sigma = solveset(eqn, s) print(sigma) CalcScaleParam(2,2, 0.9545)我的Matlab代码如下:
My Matlab code is as follows:
function sigma = Test() syms s eqn =(1/2+1/2*erf((log(4)-(log(2)+s^2))/(sqrt(2)*s))-(1/2+1/2*erf((log(1)-(log(2)+s^2))/(sqrt(2)*s)))) - 0.95 == 0; sigma = solve(eqn,s); end并返回sigma = 0.335
And returns sigma=0.335
起初我以为这是数学问题,但是由于方程式已在Matlab中成功解决,所以我怀疑问题出在sympy.
I initially thought it was an issue with the math but since the equation is solved successfully in matlab I suspect that the problem is coming from sympy.
推荐答案分数使用Python的整数除法,得到1/2 == 0.整个表达式简化为-0.95.使用1./2或0.5或Rational(1,2)声明它.您可能还必须将百分比0.95表示为Rational(19,20).
The fractions are using Python's integer division, which gives 1/2 == 0. The entire expression reduces to -0.95. Declare it using 1./2 or 0.5, or maybe Rational(1,2). You might also have to express the percentage 0.95 as Rational(19,20).
更多推荐
Sympy在求解方程式时返回一个ConditionSet对象,而在求解相同方程式时,matlab返回一个浮点数
发布评论