dimanche 12 juin 2016

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 I want to solve the following (rather long) equation for x:

> (1/2+1/2*erf((log(Xmax)-(log(mode)+x**2))/(sqrt(2)*x))-(1/2+1/2*erf((log(Xmin)-(log(mode)+x**2))/(sqrt(2)*x))) - percentage == 0

I want to use mpmath and sympy to solve the equation, but it gives me the following error message:

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

My code is as follows:

from mpmath import erf, log, sqrt
from 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)+x**2))/(sqrt(2)*x))-(1/2+1/2*erf((log(Xmin)-(log(mode)+x**2))/(sqrt(2)*x))) - percentage)

solveset(eqn, s, domain=S.Reals)

mpf is the float type created by mpmath.

I think I narrowed down the problem to the erf() function, it returns

EmptySet()

when i run

solveset(log(Xmax) - (log(mode) + s ** 2), s, domain=S.Reals)

I cannot figure out what to try next, any help would be appreciated!

I initially thought it was an issue with the math but the equation is solved successfully in matlab, so the problem is probably coming from sympy or mpmath.


Aucun commentaire:

Enregistrer un commentaire