python - sympy and mpmath give "TypeError: cannot create mpf" when using the erf() function within solveset() -


i have 4 input variables (floats):

  • xmax
  • xmin
  • percentage
  • mode

and want solve following (rather long) equation 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 

i want use mpmath , sympy solve equation, gives me following error message:

typeerror: cannot create mpf 0.707106781186547*(-s**2 - 0.287682072451781)/s

my code follows:

from mpmath import erf, log, sqrt sympy import symbol, solveset, s  percentage = 0.95 mode = 2 xmin = 1. xmax = 1.5 s = symbol('s')  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, domain=s.reals) 

mpf float type created mpmath.

i think narrowed down problem erf() function, returns

emptyset() 

when run

solveset(log(xmax) - (log(mode) + s ** 2), s, domain=s.reals) 

i cannot figure out try next, appreciated!

i thought issue math equation solved in matlab, problem coming sympy or mpmath.

losing mpmath import of erf, , use sympy version resolves 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 import log , sqrt mpmath. won't make difference result here them sympy
  • you can specify real domain on variable s, saves doing on solveset call(s).

example of further usage in package tests here if need it.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -