sympy and mpmath give “TypeError: cannot create mpf” when using the erf() function within solveset()

一曲冷凌霜 提交于 2019-12-02 07:27:47

Losing the mpmath import of erf, and use the sympy version resolves your error.

from sympy import Symbol, solveset, S, erf, log, sqrt

percentage = 0.95
mode = 2
Xmin = 1.
Xmax = 1.5
s = Symbol('s', real=True)

eqn = (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)

solveset(eqn, s)

Note also:

  • you don't have to import log and sqrt from mpmath. It won't make a difference to your result here to get them from sympy
  • you can specify the Real domain on the variable s, saves you doing so on the solveset call(s).

Example of further usage is in the package tests here if you need it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!