Sympy在求解方程式时返回一个ConditionSet对象,而在求解相同方程式时,matlab返回一个浮点数

编程入门 行业动态 更新时间:2024-10-27 07:23:28
本文介绍了Sympy在求解方程式时返回一个ConditionSet对象,而在求解相同方程式时,matlab返回一个浮点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有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返回一个浮点数

本文发布于:2023-11-29 18:36:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647262.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方程式   而在   对象   浮点数   Sympy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!